Fix bug #2875, "SMTP session disconnects before recieving multi-line
[claws.git] / src / common / smtp.c
index 3646741b01f2406f24f8c962db581bf22995896a..e540d1fc057d6924b6582ba1cf065248bcbd6ded 100644 (file)
@@ -19,6 +19,7 @@
 
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
+#include "claws-features.h"
 #endif
 
 #include <glib.h>
@@ -124,7 +125,7 @@ static void smtp_session_destroy(Session *session)
 
 gint smtp_from(SMTPSession *session)
 {
-       gchar buf[MSGBUFSIZE];
+       gchar buf[MESSAGEBUFSIZE];
        gchar *mail_size = NULL;
 
        cm_return_val_if_fail(session->from != NULL, SM_ERROR);
@@ -188,7 +189,7 @@ static gint smtp_auth(SMTPSession *session)
 
 static gint smtp_auth_recv(SMTPSession *session, const gchar *msg)
 {
-       gchar buf[MSGBUFSIZE];
+       gchar buf[MESSAGEBUFSIZE];
 
        switch (session->auth_type) {
        case SMTPAUTH_LOGIN:
@@ -264,7 +265,7 @@ static gint smtp_auth_recv(SMTPSession *session, const gchar *msg)
 
 static gint smtp_auth_login_user_recv(SMTPSession *session, const gchar *msg)
 {
-       gchar buf[MSGBUFSIZE];
+       gchar buf[MESSAGEBUFSIZE];
 
        session->state = SMTP_AUTH_LOGIN_PASS;
 
@@ -284,7 +285,7 @@ static gint smtp_auth_login_user_recv(SMTPSession *session, const gchar *msg)
 
 static gint smtp_ehlo(SMTPSession *session)
 {
-       gchar buf[MSGBUFSIZE];
+       gchar buf[MESSAGEBUFSIZE];
 
        session->state = SMTP_EHLO;
 
@@ -363,7 +364,7 @@ static gint smtp_auth_cram_md5(SMTPSession *session)
 
 static gint smtp_auth_plain(SMTPSession *session)
 {
-       gchar buf[MSGBUFSIZE];
+       gchar buf[MESSAGEBUFSIZE];
 
        /* 
         * +1      +1      +1
@@ -428,7 +429,7 @@ static gint smtp_auth_login(SMTPSession *session)
 
 static gint smtp_helo(SMTPSession *session)
 {
-       gchar buf[MSGBUFSIZE];
+       gchar buf[MESSAGEBUFSIZE];
 
        session->state = SMTP_HELO;
 
@@ -443,7 +444,7 @@ static gint smtp_helo(SMTPSession *session)
 
 static gint smtp_rcpt(SMTPSession *session)
 {
-       gchar buf[MSGBUFSIZE];
+       gchar buf[MESSAGEBUFSIZE];
        gchar *to;
 
        cm_return_val_if_fail(session->cur_to != NULL, SM_ERROR);
@@ -540,6 +541,10 @@ static gint smtp_session_recv_msg(Session *session, const gchar *msg)
                break;
        }
 
+       /* ignore all multiline responses except for EHLO */
+       if (msg[3] == '-' && smtp_session->state != SMTP_EHLO)
+               return session_recv_msg(session);
+
        if (msg[0] == '5' && msg[1] == '0' &&
            (msg[2] == '4' || msg[2] == '3' || msg[2] == '1')) {
                log_warning(LOG_PROTOCOL, _("error occurred on SMTP session\n"));
@@ -577,10 +582,6 @@ static gint smtp_session_recv_msg(Session *session, const gchar *msg)
                return -1;
        }
 
-       /* ignore all multiline responses except for EHLO */
-       if (cont && smtp_session->state != SMTP_EHLO)
-               return session_recv_msg(session);
-
        switch (smtp_session->state) {
        case SMTP_READY:
                if (strstr(msg, "ESMTP"))