sync with 0.7.8cvs10
[claws.git] / src / smtp.c
index 82067c825bdd9610ace07abdb20640ccf5e1f829..bf7eda42ad2d3c46018ab2a0f633730efebb9590 100644 (file)
@@ -43,13 +43,11 @@ static gint smtp_ok(SockInfo *sock, gchar *buf, gint len);
 Session *smtp_session_new(const gchar *server, gushort port,
                          const gchar *domain,
                          const gchar *user, const gchar *pass,
-                         SSLType ssl_type,
-                         SMTPAuthType enable_auth_type)
+                         SSLType ssl_type)
 #else
 Session *smtp_session_new(const gchar *server, gushort port,
                          const gchar *domain,
-                         const gchar *user, const gchar *pass,
-                         SMTPAuthType enable_auth_type)
+                         const gchar *user, const gchar *pass)
 #endif
 {
        SMTPSession *session;
@@ -91,7 +89,7 @@ Session *smtp_session_new(const gchar *server, gushort port,
                domain = get_domain_name();
 
        if (use_esmtp)
-               val = smtp_ehlo(sock, domain, &avail_auth_type, enable_auth_type);
+               val = smtp_ehlo(sock, domain, &avail_auth_type);
        else
                val = smtp_helo(sock, domain);
        if (val != SM_OK) {
@@ -112,7 +110,7 @@ Session *smtp_session_new(const gchar *server, gushort port,
                        sock_close(sock);
                        return NULL;
                }
-               val = smtp_ehlo(sock, domain, &avail_auth_type, enable_auth_type);
+               val = smtp_ehlo(sock, domain, &avail_auth_type);
                if (val != SM_OK) {
                        log_warning(_("Error occurred while sending EHLO\n"));
                        sock_close(sock);
@@ -146,7 +144,8 @@ void smtp_session_destroy(SMTPSession *session)
        g_free(session->pass);
 }
 
-gint smtp_from(SMTPSession *session, const gchar *from)
+gint smtp_from(SMTPSession *session, const gchar *from,
+              SMTPAuthType forced_auth_type)
 {
        gchar buf[MSGBUFSIZE];
 
@@ -154,7 +153,7 @@ gint smtp_from(SMTPSession *session, const gchar *from)
        g_return_val_if_fail(from != NULL, SM_ERROR);
 
        if (session->user) {
-               if (smtp_auth(session) != SM_OK)
+               if (smtp_auth(session, forced_auth_type) != SM_OK)
                        return SM_AUTHFAIL;
        }
 
@@ -170,7 +169,7 @@ gint smtp_from(SMTPSession *session, const gchar *from)
        return smtp_ok(SESSION(session)->sock, NULL, 0);
 }
 
-gint smtp_auth(SMTPSession *session)
+gint smtp_auth(SMTPSession *session, SMTPAuthType forced_auth_type)
 {
        gchar buf[MSGBUFSIZE];
        SMTPAuthType authtype = 0;
@@ -184,10 +183,14 @@ gint smtp_auth(SMTPSession *session)
 
        sock = SESSION(session)->sock;
 
-       if ((session->avail_auth_type & SMTPAUTH_CRAM_MD5) != 0 &&
+       if ((forced_auth_type == SMTPAUTH_CRAM_MD5 ||
+            (forced_auth_type == 0 &&
+             (session->avail_auth_type & SMTPAUTH_CRAM_MD5) != 0)) &&
            smtp_auth_cram_md5(sock, buf, sizeof(buf)) == SM_OK)
                authtype = SMTPAUTH_CRAM_MD5;
-       else if ((session->avail_auth_type & SMTPAUTH_LOGIN) != 0 &&
+       else if ((forced_auth_type == SMTPAUTH_LOGIN ||
+                 (forced_auth_type == 0 &&
+                  (session->avail_auth_type & SMTPAUTH_LOGIN) != 0)) &&
                 smtp_auth_login(sock, buf, sizeof(buf)) == SM_OK)
                authtype = SMTPAUTH_LOGIN;
        else {
@@ -263,8 +266,7 @@ gint smtp_auth(SMTPSession *session)
 }
 
 gint smtp_ehlo(SockInfo *sock, const gchar *hostname,
-              SMTPAuthType *avail_auth_type,
-              SMTPAuthType  enable_auth_type)
+              SMTPAuthType *avail_auth_type)
 {
        gchar buf[MSGBUFSIZE];
 
@@ -285,15 +287,13 @@ gint smtp_ehlo(SockInfo *sock, const gchar *hostname,
                if (strncmp(buf, "250-", 4) == 0) {
                        gchar *p = buf;
                        p += 4;
-                       
-                       if (g_strncasecmp(p, "AUTH ", 5) == 0 ||
-                          (g_strncasecmp(p, "AUTH=", 5) == 0)) {       /* CLAWS: qmail */
+                       if (g_strncasecmp(p, "AUTH", 4) == 0) {
                                p += 5;
-                               if (strcasestr(p, "LOGIN") && (enable_auth_type & SMTPAUTH_LOGIN))
+                               if (strcasestr(p, "LOGIN"))
                                        *avail_auth_type |= SMTPAUTH_LOGIN;
-                               if (strcasestr(p, "CRAM-MD5") && (enable_auth_type & SMTPAUTH_CRAM_MD5))
+                               if (strcasestr(p, "CRAM-MD5"))
                                        *avail_auth_type |= SMTPAUTH_CRAM_MD5;
-                               if (strcasestr(p, "DIGEST-MD5") && (enable_auth_type & SMTPAUTH_DIGEST_MD5))
+                               if (strcasestr(p, "DIGEST-MD5"))
                                        *avail_auth_type |= SMTPAUTH_DIGEST_MD5;
                        }
                } else if ((buf[0] == '1' || buf[0] == '2' || buf[0] == '3') &&