2 Commits

Author SHA1 Message Date
Matt Ronge 2bc6f4e78e OAuth2 SMTP 2015-01-02 15:59:11 -06:00
Matt Ronge 9bfc4d9ae9 OAuth2 works via Gmail IMAP 2015-01-01 16:45:50 -06:00
10 changed files with 39 additions and 6 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
[submodule "libetpan"]
path = libetpan
url = https://github.com/dinhviethoa/libetpan.git
url = https://github.com/mronge/libetpan.git
[submodule "iOSPorts"]
path = iOSPorts
url = https://github.com/mronge/iOSPorts.git
+3
View File
@@ -95,6 +95,9 @@
self.lastError = MailCoreCreateErrorFromIMAPCode(err);
return NO;
}
struct imap_mailstorage *imap_storage = myStorage->sto_data;
imap_storage->imap_auth_type = authType;
err = mailstorage_connect(myStorage);
if (err == MAIL_ERROR_LOGIN) {
+1
View File
@@ -44,6 +44,7 @@
- (BOOL)helo;
- (BOOL)startTLS;
- (BOOL)authenticateWithUsername:(NSString *)username password:(NSString *)password server:(NSString *)server;
- (BOOL)authenticateWithUsername:(NSString *)username oauth2Token:(NSString *)oauthToken;
- (BOOL)setFrom:(NSString *)fromAddress;
- (BOOL)setRecipientAddress:(NSString *)recAddress;
@end
+13
View File
@@ -162,6 +162,19 @@ static int fill_local_ip_port(mailstream * stream, char * local_ip_port, size_t
return YES;
}
- (BOOL)authenticateWithUsername:(NSString *)username oauth2Token:(NSString *)oauthToken {
char *cUsername = (char *)[username cStringUsingEncoding:NSUTF8StringEncoding];
char *cToken = (char *)[oauthToken cStringUsingEncoding:NSUTF8StringEncoding];
int r = mailsmtp_oauth2_authenticate([self resource], cUsername, cToken);
if (r != MAIL_NO_ERROR) {
self.lastError = MailCoreCreateErrorFromSMTPCode(r);
return NO;
}
return YES;
}
- (BOOL)setFrom:(NSString *)fromAddress {
int ret = mailesmtp_mail([self resource], [fromAddress cStringUsingEncoding:NSUTF8StringEncoding], 1, "MailCoreSMTP");
+1
View File
@@ -52,6 +52,7 @@
- (BOOL)helo;
- (BOOL)startTLS;
- (BOOL)authenticateWithUsername:(NSString *)username password:(NSString *)password server:(NSString *)server;
- (BOOL)authenticateWithUsername:(NSString *)username oauth2Token:(NSString *)oauthToken;
- (BOOL)setFrom:(NSString *)fromAddress;
- (BOOL)setRecipients:(id)recipients;
- (BOOL)setRecipientAddress:(NSString *)recAddress;
+4
View File
@@ -89,6 +89,10 @@
return YES;
}
- (BOOL)authenticateWithUsername:(NSString *)username oauth2Token:(NSString *)oauthToken {
return YES;
}
- (BOOL)setFrom:(NSString *)fromAddress {
int ret = mailsmtp_mail([self resource], [fromAddress cStringUsingEncoding:NSUTF8StringEncoding]);
if (ret != MAIL_NO_ERROR) {
+2 -2
View File
@@ -51,7 +51,7 @@
@param password The password, if there is none then pass in an empty string.
@param port The port to use, the standard port is 25
@param connectionType What kind of connection, either: CTSMTPConnectionTypePlain, CTSMTPConnectionTypeStartTLS, CTSMTPConnectionTypeTLS
@param auth Pass in YES if you would like to use SASL authentication
@param authType None, Password, or OAuth2
@param error Will contain an error when the method returns NO
@return Returns YES on success, NO on error
*/
@@ -61,7 +61,7 @@
password:(NSString *)password
port:(unsigned int)port
connectionType:(CTSMTPConnectionType)connectionType
useAuth:(BOOL)auth
authType:(CTSMTPAuthType)authType
error:(NSError **)error;
/**
+7 -2
View File
@@ -42,7 +42,7 @@
@implementation CTSMTPConnection
+ (BOOL)sendMessage:(CTCoreMessage *)message server:(NSString *)server username:(NSString *)username
password:(NSString *)password port:(unsigned int)port connectionType:(CTSMTPConnectionType)connectionType
useAuth:(BOOL)auth error:(NSError **)error {
authType:(CTSMTPAuthType)authType error:(NSError **)error {
BOOL success;
mailsmtp *smtp = NULL;
smtp = mailsmtp_new(0, NULL);
@@ -71,11 +71,16 @@
goto error;
}
}
if (auth) {
if (authType == CTSMTPAuthTypePassword) {
success = [smtpObj authenticateWithUsername:username password:password server:server];
if (!success) {
goto error;
}
} else if (authType == CTSMTPAuthTypeOauth2) {
success = [smtpObj authenticateWithUsername:username oauth2Token:password];
if (!success) {
goto error;
}
}
success = [smtpObj setFrom:[[[message from] anyObject] email]];
+6
View File
@@ -70,6 +70,12 @@ typedef enum {
#define CTImapAuthTypePlain IMAP_AUTH_TYPE_PLAIN
typedef enum {
CTSMTPAuthTypeNone = 0,
CTSMTPAuthTypePassword,
CTSMTPAuthTypeOauth2,
} CTSMTPAuthType;
/** List of Message Flags **/
#define CTFlagNew MAIL_FLAG_NEW