Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@mronge mronge authored
Showing with 14 additions and 25 deletions.
  1. +13 −24 Source/CTESMTP.m
  2. +1 −1  iOSPorts
View
37 Source/CTESMTP.m
@@ -101,22 +101,12 @@ - (BOOL)helo {
- (BOOL)startTLS {
- mailstream_low * low;
- int fd;
- mailstream_low * new_low;
-
- int ret = mailesmtp_starttls([self resource]);
+ int ret = mailsmtp_socket_starttls([self resource]);
if (ret != MAIL_NO_ERROR) {
self.lastError = MailCoreCreateErrorFromSMTPCode(ret);
return NO;
}
- low = mailstream_get_low([self resource]->stream);
- fd = mailstream_low_get_fd(low);
- new_low = mailstream_low_tls_open(fd);
- mailstream_low_free(low);
- mailstream_set_low([self resource]->stream, new_low);
-
ret = mailesmtp_ehlo([self resource]);
if (ret != MAIL_NO_ERROR) {
self.lastError = MailCoreCreateErrorFromSMTPCode(ret);
@@ -152,19 +142,18 @@ - (BOOL)authenticateWithUsername:(NSString *)username password:(NSString *)passw
remote_ip_port = NULL;
else
remote_ip_port = remote_ip_port_buf;
- /*
- in most case, login = auth_name = user@domain
- and realm = server hostname full qualified domain name
-
- int mailesmtp_auth_sasl(mailsmtp * session, const char * auth_type,
- const char * server_fqdn,
- const char * local_ip_port,
- const char * remote_ip_port,
- const char * login, const char * auth_name,
- const char * password, const char * realm);
-
- */
- ret = mailesmtp_auth_sasl([self resource], "PLAIN", cServer, local_ip_port, remote_ip_port,
+
+ char *authType = "PLAIN";
+ mailsmtp *session = [self resource];
+ if (session->auth & MAILSMTP_AUTH_CHECKED) {
+ // If the server doesn't support PLAIN but does support the older LOGIN,
+ // fall back to LOGIN. This can happen with older servers like Exchange 2003
+ if (!(session->auth & MAILSMTP_AUTH_PLAIN) && session->auth & MAILSMTP_AUTH_LOGIN) {
+ authType = "LOGIN";
+ }
+ }
+
+ ret = mailesmtp_auth_sasl(session, authType, cServer, local_ip_port, remote_ip_port,
cUsername, cUsername, cPassword, cServer);
if (ret != MAIL_NO_ERROR) {
self.lastError = MailCoreCreateErrorFromSMTPCode(ret);
2  iOSPorts
@@ -1 +1 @@
-Subproject commit ae668453f2a153ca19a8485db23b73f270ea3ed8
+Subproject commit 2bca07dff7b7a78b46411617a5025de6b32bacad
Please sign in to comment.
Something went wrong with that request. Please try again.