Skip to content
This repository
Browse code

When doing SMTP auth if PLAIN is not available, fallback to LOGIN. Al…

…so some TLS fixes for older servers
  • Loading branch information...
commit 1ce5f390c78486a88db379138febe07700cde44e 1 parent 9aec18f
Matt Ronge authored November 09, 2012

Showing 2 changed files with 14 additions and 25 deletions. Show diff stats Hide diff stats

  1. 37  Source/CTESMTP.m
  2. 2  iOSPorts
37  Source/CTESMTP.m
@@ -101,22 +101,12 @@ - (BOOL)helo {
101 101
 
102 102
 
103 103
 - (BOOL)startTLS {
104  
-    mailstream_low * low;
105  
-    int fd;
106  
-    mailstream_low * new_low;
107  
-
108  
-    int ret = mailesmtp_starttls([self resource]);
  104
+    int ret = mailsmtp_socket_starttls([self resource]);
109 105
     if (ret != MAIL_NO_ERROR) {
110 106
         self.lastError = MailCoreCreateErrorFromSMTPCode(ret);
111 107
         return NO;
112 108
     }
113 109
 
114  
-    low = mailstream_get_low([self resource]->stream);
115  
-    fd = mailstream_low_get_fd(low);
116  
-    new_low = mailstream_low_tls_open(fd);
117  
-    mailstream_low_free(low);
118  
-    mailstream_set_low([self resource]->stream, new_low);
119  
-
120 110
     ret = mailesmtp_ehlo([self resource]);
121 111
     if (ret != MAIL_NO_ERROR) {
122 112
         self.lastError = MailCoreCreateErrorFromSMTPCode(ret);
@@ -152,19 +142,18 @@ - (BOOL)authenticateWithUsername:(NSString *)username password:(NSString *)passw
152 142
         remote_ip_port = NULL;
153 143
     else
154 144
         remote_ip_port = remote_ip_port_buf;
155  
- /*
156  
-    in most case, login = auth_name = user@domain
157  
-    and realm = server hostname full qualified domain name
158  
-
159  
-    int mailesmtp_auth_sasl(mailsmtp * session, const char * auth_type,
160  
-        const char * server_fqdn,
161  
-        const char * local_ip_port,
162  
-        const char * remote_ip_port,
163  
-        const char * login, const char * auth_name,
164  
-        const char * password, const char * realm);
165  
-
166  
- */		
167  
-    ret = mailesmtp_auth_sasl([self resource], "PLAIN", cServer, local_ip_port, remote_ip_port,
  145
+
  146
+    char *authType = "PLAIN";
  147
+    mailsmtp *session = [self resource];
  148
+    if (session->auth & MAILSMTP_AUTH_CHECKED) {
  149
+        // If the server doesn't support PLAIN but does support the older LOGIN,
  150
+        // fall back to LOGIN. This can happen with older servers like Exchange 2003
  151
+        if (!(session->auth & MAILSMTP_AUTH_PLAIN) && session->auth & MAILSMTP_AUTH_LOGIN) {
  152
+            authType = "LOGIN";
  153
+        }
  154
+    }
  155
+    
  156
+    ret = mailesmtp_auth_sasl(session, authType, cServer, local_ip_port, remote_ip_port,
168 157
                             cUsername, cUsername, cPassword, cServer);
169 158
     if (ret != MAIL_NO_ERROR) {
170 159
         self.lastError = MailCoreCreateErrorFromSMTPCode(ret);
2  iOSPorts
... ...
@@ -1 +1 @@
1  
-Subproject commit ae668453f2a153ca19a8485db23b73f270ea3ed8
  1
+Subproject commit 2bca07dff7b7a78b46411617a5025de6b32bacad

0 notes on commit 1ce5f39

Please sign in to comment.
Something went wrong with that request. Please try again.