39
40
char smtp_response[MSGBUFSIZE];
41
static char smtp_mode = 'S';
43
void SMTP_setmode(char sl)
44
/* set whether we are speaking SMTP or LMTP */
49
int SMTP_helo(int sock,const char *host)
42
int SMTP_helo(int sock, char smtp_mode, const char *host)
50
43
/* send a "HELO" message to the SMTP listener */
54
47
SockPrintf(sock,"HELO %s\r\n", host);
55
48
if (outlevel >= O_MONITOR)
56
report(stdout, "SMTP> HELO %s\n", host);
49
report(stdout, "%cMTP> HELO %s\n", smtp_mode, host);
50
ok = SMTP_ok(sock, smtp_mode);
61
static void SMTP_auth_error(int sock, char *msg)
54
static void SMTP_auth_error(int sock, const char *msg)
63
56
SockPrintf(sock, "*\r\n");
64
57
SockRead(sock, smtp_response, sizeof(smtp_response) - 1);
65
58
if (outlevel >= O_MONITOR) report(stdout, msg);
68
static void SMTP_auth(int sock, char *username, char *password, char *buf)
61
static void SMTP_auth(int sock, char smtp_mode, char *username, char *password, char *buf)
69
62
/* ESMTP Authentication support for fetchmail by Wojciech Polak */
105
98
report(stdout, GT_("Challenge decoded: %s\n"), b64buf);
106
99
hmac_md5(password, strlen(password),
107
100
b64buf, strlen(b64buf), digest, sizeof(digest));
109
101
snprintf(tmp, sizeof(tmp),
112
#endif /* HAVE_SNPRINTF */
113
102
"%s %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
114
103
username, digest[0], digest[1], digest[2], digest[3],
115
104
digest[4], digest[5], digest[6], digest[7], digest[8],
119
108
to64frombits(b64buf, tmp, strlen(tmp));
120
109
SockPrintf(sock, "%s\r\n", b64buf);
110
SMTP_ok(sock, smtp_mode);
123
112
else if (strstr(buf, "PLAIN")) {
125
114
if (outlevel >= O_MONITOR)
126
115
report(stdout, GT_("ESMTP PLAIN Authentication...\n"));
128
snprintf(tmp, sizeof(tmp),
131
#endif /* HAVE_SNPRINTF */
132
"^%s^%s", username, password);
116
snprintf(tmp, sizeof(tmp), "^%s^%s", username, password);
134
118
len = strlen(tmp);
135
119
for (c = len - 1; c >= 0; c--)
140
124
to64frombits(b64buf, tmp, len);
141
125
SockPrintf(sock, "AUTH PLAIN %s\r\n", b64buf);
126
SMTP_ok(sock, smtp_mode);
144
128
else if (strstr(buf, "LOGIN")) {
145
129
if (outlevel >= O_MONITOR)
179
163
to64frombits(b64buf, password, strlen(password));
180
164
SockPrintf(sock, "%s\r\n", b64buf);
165
SMTP_ok(sock, smtp_mode);
186
int SMTP_ehlo(int sock, const char *host, char *name, char *password, int *opt)
170
int SMTP_ehlo(int sock, char smtp_mode, const char *host, char *name, char *password, int *opt)
187
171
/* send a "EHLO" message to the SMTP listener, return extension status bits */
193
177
if (outlevel >= O_MONITOR)
194
178
report(stdout, "%cMTP> %cHLO %s\n",
195
179
smtp_mode, (smtp_mode == 'S') ? 'E' : smtp_mode, host);
198
182
while ((SockRead(sock, smtp_response, sizeof(smtp_response)-1)) != -1)
208
192
smtp_response[n] = '\0';
209
193
if (outlevel >= O_MONITOR)
210
report(stdout, "SMTP< %s\n", smtp_response);
194
report(stdout, "%cMTP< %s\n", smtp_mode, smtp_response);
211
195
for (hp = extensions; hp->name; hp++)
212
196
if (!strncasecmp(hp->name, smtp_response+4, strlen(hp->name))) {
213
197
*opt |= hp->value;
214
198
if (strncmp(hp->name, "AUTH ", 5) == 0)
215
strncpy(auth_response, smtp_response, sizeof(auth_response));
199
strncpy(auth_response, smtp_response, sizeof(auth_response));
216
200
auth_response[sizeof(auth_response)-1] = '\0';
218
202
if ((smtp_response[0] == '1' || smtp_response[0] == '2' || smtp_response[0] == '3') && smtp_response[3] == ' ') {
219
203
if (*opt & ESMTP_AUTH)
220
SMTP_auth(sock, name, password, auth_response);
204
SMTP_auth(sock, smtp_mode, name, password, auth_response);
223
207
else if (smtp_response[3] != '-')
226
210
return SM_UNRECOVERABLE;
229
int SMTP_from(int sock, const char *from, const char *opts)
213
int SMTP_from(int sock, char smtp_mode, const char *from, const char *opts)
230
214
/* send a "MAIL FROM:" message to the SMTP listener */
233
217
char buf[MSGBUFSIZE];
235
219
if (from[0]=='<')
237
snprintf(buf, sizeof(buf),
240
#endif /* HAVE_SNPRINTF */
241
"MAIL FROM:%s", from);
220
snprintf(buf, sizeof(buf), "MAIL FROM:%s", from);
244
snprintf(buf, sizeof(buf),
247
#endif /* HAVE_SNPRINTF */
248
"MAIL FROM:<%s>", from);
222
snprintf(buf, sizeof(buf), "MAIL FROM:<%s>", from);
251
224
snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), "%s", opts);
254
#endif /* HAVE_SNPRINTF */
255
225
SockPrintf(sock,"%s\r\n", buf);
256
226
if (outlevel >= O_MONITOR)
257
227
report(stdout, "%cMTP> %s\n", smtp_mode, buf);
228
ok = SMTP_ok(sock, smtp_mode);
262
int SMTP_rcpt(int sock, const char *to)
232
int SMTP_rcpt(int sock, char smtp_mode, const char *to)
263
233
/* send a "RCPT TO:" message to the SMTP listener */
267
237
SockPrintf(sock,"RCPT TO:<%s>\r\n", to);
268
238
if (outlevel >= O_MONITOR)
269
239
report(stdout, "%cMTP> RCPT TO:<%s>\n", smtp_mode, to);
240
ok = SMTP_ok(sock, smtp_mode);
274
int SMTP_data(int sock)
244
int SMTP_data(int sock, char smtp_mode)
275
245
/* send a "DATA" message to the SMTP listener */
279
249
SockPrintf(sock,"DATA\r\n");
280
250
if (outlevel >= O_MONITOR)
281
251
report(stdout, "%cMTP> DATA\n", smtp_mode);
252
ok = SMTP_ok(sock, smtp_mode);
286
int SMTP_rset(int sock)
256
int SMTP_rset(int sock, char smtp_mode)
287
257
/* send a "RSET" message to the SMTP listener */
291
261
SockPrintf(sock,"RSET\r\n");
292
262
if (outlevel >= O_MONITOR)
293
263
report(stdout, "%cMTP> RSET\n", smtp_mode);
264
ok = SMTP_ok(sock, smtp_mode);
298
int SMTP_quit(int sock)
268
int SMTP_quit(int sock, char smtp_mode)
299
269
/* send a "QUIT" message to the SMTP listener */
303
273
SockPrintf(sock,"QUIT\r\n");
304
274
if (outlevel >= O_MONITOR)
305
275
report(stdout, "%cMTP> QUIT\n", smtp_mode);
276
ok = SMTP_ok(sock, smtp_mode);
310
int SMTP_eom(int sock)
280
int SMTP_eom(int sock, char smtp_mode)
311
281
/* send a message data terminator to the SMTP listener */