2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2001 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #define MSGBUFSIZE 8192
31 static gint verbose = 1;
32 static gchar smtp_response[MSGBUFSIZE];
34 gint smtp_helo(SockInfo *sock, const gchar *hostname, gboolean esmtp)
37 return esmtp_ehlo(sock, hostname);
39 sock_printf(sock, "HELO %s\r\n", hostname);
41 log_print("SMTP> HELO %s\n", hostname);
47 gint smtp_from(SockInfo *sock, const gchar *from,
48 const gchar *userid, const gchar *passwd,
49 gboolean use_smtp_auth)
51 gchar buf[MSGBUFSIZE];
52 SMTPAuthType authtype;
55 /* exist AUTH-Type CRAM_MD5 */
56 if (esmtp_auth_cram_md5(sock) == SM_ERROR) {
57 /* exist AUTH-Type LOGIN */
58 if (esmtp_auth_login(sock) == SM_ERROR)
61 authtype = SMTPAUTH_LOGIN;
63 authtype = SMTPAUTH_CRAM_MD5;
65 if (esmtp_auth(sock, authtype, userid, passwd) != SM_OK)
69 if (strchr(from, '<'))
70 g_snprintf(buf, sizeof(buf), "MAIL FROM: %s", from);
72 g_snprintf(buf, sizeof(buf), "MAIL FROM: <%s>", from);
74 sock_printf(sock, "%s\r\n", buf);
76 log_print("SMTP> %s\n", buf);
81 gint smtp_rcpt(SockInfo *sock, const gchar *to)
83 gchar buf[MSGBUFSIZE];
86 g_snprintf(buf, sizeof(buf), "RCPT TO: %s", to);
88 g_snprintf(buf, sizeof(buf), "RCPT TO: <%s>", to);
90 sock_printf(sock, "%s\r\n", buf);
92 log_print("SMTP> %s\n", buf);
97 gint smtp_data(SockInfo *sock)
99 sock_printf(sock, "DATA\r\n");
101 log_print("SMTP> DATA\n");
103 return smtp_ok(sock);
106 gint smtp_rset(SockInfo *sock)
108 sock_printf(sock, "RSET\r\n");
110 log_print("SMTP> RSET\n");
112 return smtp_ok(sock);
115 gint smtp_quit(SockInfo *sock)
117 sock_printf(sock, "QUIT\r\n");
119 log_print("SMTP> QUIT\n");
121 return smtp_ok(sock);
124 gint smtp_eom(SockInfo *sock)
126 sock_printf(sock, ".\r\n");
128 log_print("SMTP> . (EOM)\n");
130 return smtp_ok(sock);
133 gint smtp_ok(SockInfo *sock)
135 while ((sock_gets(sock, smtp_response, sizeof(smtp_response) - 1))
137 if (strlen(smtp_response) < 4)
139 strretchomp(smtp_response);
142 log_print("SMTP< %s\n", smtp_response);
144 if ((smtp_response[0] == '1' || smtp_response[0] == '2' ||
145 smtp_response[0] == '3') &&
146 (smtp_response[3] == ' ' || smtp_response[3] == '\0'))
148 else if (smtp_response[3] != '-')
150 else if (smtp_response[0] == '5' &&
151 smtp_response[1] == '0' &&
152 (smtp_response[2] == '4' ||
153 smtp_response[2] == '3' ||
154 smtp_response[2] == '1'))
158 return SM_UNRECOVERABLE;