aboutsummaryrefslogtreecommitdiffstats
path: root/smtp.c
diff options
context:
space:
mode:
authorMatthias Andree <matthias.andree@gmx.de>2009-05-25 12:35:54 +0000
committerMatthias Andree <matthias.andree@gmx.de>2009-05-25 12:35:54 +0000
commitbd2e568da48acbae7e0b43c48226541220b85340 (patch)
treef60ee29a3e1d8897c3e2713af7442938ad89c8ec /smtp.c
parentb2f54f5fbf4c98a3e37003d5642eab20c3971432 (diff)
downloadfetchmail-bd2e568da48acbae7e0b43c48226541220b85340.tar.gz
fetchmail-bd2e568da48acbae7e0b43c48226541220b85340.tar.bz2
fetchmail-bd2e568da48acbae7e0b43c48226541220b85340.zip
Enforce minimum recommended SMTP timeouts, apply to EHLO/LHLO as well.
Short timeouts could cause fetchmail to not wait long enough for the "250 Ok" after shipping a long message, particularly with synchronous mailers and extensive spam filtering. This caused fetchmail to re-fetch long messages. While the actual fix is making sure that the timeout is no shorter than the time the SMTP server takes to process the message, we now enforce the minimum RFC-5321 recommended timeouts even if the user configures a lower timeout. This is to fix Berlios Bug #10972, reported by Viktor Binzberger. NOTE: it is untested whether we will properly delete the message from the POP3/IMAP server or mark it as seen, as the upstream server may close the connection sooner. svn path=/branches/BRANCH_6-3/; revision=5338
Diffstat (limited to 'smtp.c')
-rw-r--r--smtp.c42
1 files changed, 25 insertions, 17 deletions
diff --git a/smtp.c b/smtp.c
index 96a708e3..61a6d93f 100644
--- a/smtp.c
+++ b/smtp.c
@@ -39,6 +39,7 @@ static struct opt extensions[] =
char smtp_response[MSGBUFSIZE];
+/* XXX: this must not be used for LMTP! */
int SMTP_helo(int sock, char smtp_mode, const char *host)
/* send a "HELO" message to the SMTP listener */
{
@@ -47,7 +48,7 @@ int SMTP_helo(int sock, char smtp_mode, const char *host)
SockPrintf(sock,"HELO %s\r\n", host);
if (outlevel >= O_MONITOR)
report(stdout, "%cMTP> HELO %s\n", smtp_mode, host);
- ok = SMTP_ok(sock, smtp_mode);
+ ok = SMTP_ok(sock, smtp_mode, TIMEOUT_HELO);
return ok;
}
@@ -107,7 +108,7 @@ static void SMTP_auth(int sock, char smtp_mode, char *username, char *password,
to64frombits(b64buf, tmp, strlen(tmp));
SockPrintf(sock, "%s\r\n", b64buf);
- SMTP_ok(sock, smtp_mode);
+ SMTP_ok(sock, smtp_mode, TIMEOUT_DEFAULT);
}
else if (strstr(buf, "PLAIN")) {
int len;
@@ -123,7 +124,7 @@ static void SMTP_auth(int sock, char smtp_mode, char *username, char *password,
}
to64frombits(b64buf, tmp, len);
SockPrintf(sock, "AUTH PLAIN %s\r\n", b64buf);
- SMTP_ok(sock, smtp_mode);
+ SMTP_ok(sock, smtp_mode, TIMEOUT_DEFAULT);
}
else if (strstr(buf, "LOGIN")) {
if (outlevel >= O_MONITOR)
@@ -162,7 +163,7 @@ static void SMTP_auth(int sock, char smtp_mode, char *username, char *password,
}
to64frombits(b64buf, password, strlen(password));
SockPrintf(sock, "%s\r\n", b64buf);
- SMTP_ok(sock, smtp_mode);
+ SMTP_ok(sock, smtp_mode, TIMEOUT_DEFAULT);
}
return;
}
@@ -172,17 +173,25 @@ int SMTP_ehlo(int sock, char smtp_mode, const char *host, char *name, char *pass
{
struct opt *hp;
char auth_response[511];
+ SIGHANDLERTYPE alrmsave;
+ const int tmout = (mytimeout >= TIMEOUT_HELO ? mytimeout : TIMEOUT_HELO);
SockPrintf(sock,"%cHLO %s\r\n", (smtp_mode == 'S') ? 'E' : smtp_mode, host);
if (outlevel >= O_MONITOR)
report(stdout, "%cMTP> %cHLO %s\n",
smtp_mode, (smtp_mode == 'S') ? 'E' : smtp_mode, host);
+ alrmsave = set_signal_handler(SIGALRM, null_signal_handler);
+ set_timeout(tmout);
+
*opt = 0;
while ((SockRead(sock, smtp_response, sizeof(smtp_response)-1)) != -1)
{
int n = strlen(smtp_response);
+ set_timeout(0);
+ (void)set_signal_handler(SIGALRM, alrmsave);
+
if (smtp_response[strlen(smtp_response)-1] == '\n')
smtp_response[strlen(smtp_response)-1] = '\0';
if (smtp_response[strlen(smtp_response)-1] == '\r')
@@ -206,6 +215,9 @@ int SMTP_ehlo(int sock, char smtp_mode, const char *host, char *name, char *pass
}
else if (smtp_response[3] != '-')
return SM_ERROR;
+
+ alrmsave = set_signal_handler(SIGALRM, null_signal_handler);
+ set_timeout(tmout);
}
return SM_UNRECOVERABLE;
}
@@ -225,7 +237,7 @@ int SMTP_from(int sock, char smtp_mode, const char *from, const char *opts)
SockPrintf(sock,"%s\r\n", buf);
if (outlevel >= O_MONITOR)
report(stdout, "%cMTP> %s\n", smtp_mode, buf);
- ok = SMTP_ok(sock, smtp_mode);
+ ok = SMTP_ok(sock, smtp_mode, TIMEOUT_MAIL);
return ok;
}
@@ -237,7 +249,7 @@ int SMTP_rcpt(int sock, char smtp_mode, const char *to)
SockPrintf(sock,"RCPT TO:<%s>\r\n", to);
if (outlevel >= O_MONITOR)
report(stdout, "%cMTP> RCPT TO:<%s>\n", smtp_mode, to);
- ok = SMTP_ok(sock, smtp_mode);
+ ok = SMTP_ok(sock, smtp_mode, TIMEOUT_RCPT);
return ok;
}
@@ -249,7 +261,7 @@ int SMTP_data(int sock, char smtp_mode)
SockPrintf(sock,"DATA\r\n");
if (outlevel >= O_MONITOR)
report(stdout, "%cMTP> DATA\n", smtp_mode);
- ok = SMTP_ok(sock, smtp_mode);
+ ok = SMTP_ok(sock, smtp_mode, TIMEOUT_DATA);
return ok;
}
@@ -261,7 +273,7 @@ int SMTP_rset(int sock, char smtp_mode)
SockPrintf(sock,"RSET\r\n");
if (outlevel >= O_MONITOR)
report(stdout, "%cMTP> RSET\n", smtp_mode);
- ok = SMTP_ok(sock, smtp_mode);
+ ok = SMTP_ok(sock, smtp_mode, TIMEOUT_DEFAULT);
return ok;
}
@@ -273,15 +285,13 @@ int SMTP_quit(int sock, char smtp_mode)
SockPrintf(sock,"QUIT\r\n");
if (outlevel >= O_MONITOR)
report(stdout, "%cMTP> QUIT\n", smtp_mode);
- ok = SMTP_ok(sock, smtp_mode);
+ ok = SMTP_ok(sock, smtp_mode, TIMEOUT_DEFAULT);
return ok;
}
int SMTP_eom(int sock, char smtp_mode)
/* send a message data terminator to the SMTP listener */
{
- int ok;
-
SockPrintf(sock,".\r\n");
if (outlevel >= O_MONITOR)
report(stdout, "%cMTP>. (EOM)\n", smtp_mode);
@@ -290,23 +300,21 @@ int SMTP_eom(int sock, char smtp_mode)
* When doing LMTP, must process many of these at the outer level.
*/
if (smtp_mode == 'S')
- ok = SMTP_ok(sock, smtp_mode);
+ return SMTP_ok(sock, smtp_mode, TIMEOUT_EOM);
else
- ok = SM_OK;
-
- return ok;
+ return SM_OK;
}
time_t last_smtp_ok = 0;
-int SMTP_ok(int sock, char smtp_mode)
+int SMTP_ok(int sock, char smtp_mode, int mintimeout)
/* returns status of SMTP connection */
{
SIGHANDLERTYPE alrmsave;
/* set an alarm for smtp ok */
alrmsave = set_signal_handler(SIGALRM, null_signal_handler);
- set_timeout(mytimeout);
+ set_timeout(mytimeout >= mintimeout ? mytimeout : mintimeout);
while ((SockRead(sock, smtp_response, sizeof(smtp_response)-1)) != -1)
{