diff options
author | Matt Ronge <mronge@mronge.com> | 2014-03-14 16:28:36 -0500 |
---|---|---|
committer | Matt Ronge <mronge@mronge.com> | 2014-03-14 16:28:36 -0500 |
commit | ad5e306b3af920169ae1842a7fd2cfce8fcf5022 (patch) | |
tree | 0c0ab421bd536cbd312f72c839559c01f515acfe /src/core | |
parent | 3bda01fedffff8e705ae0f99fa9028a389255f9d (diff) | |
parent | 976108f9503a0e466e11e7bc3ee772d0b2c9ea38 (diff) |
Merge branch 'master' of github.com:MailCore/mailcore2
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/abstract/MCMessageConstants.h | 3 | ||||
-rw-r--r-- | src/core/basetypes/MCOperationQueue.cc | 12 | ||||
-rw-r--r-- | src/core/basetypes/MCOperationQueue.h | 1 | ||||
-rw-r--r-- | src/core/basetypes/MCSet.cc | 2 | ||||
-rw-r--r-- | src/core/imap/MCIMAPSearchExpression.cc | 16 | ||||
-rw-r--r-- | src/core/imap/MCIMAPSearchExpression.h | 3 | ||||
-rwxr-xr-x | src/core/imap/MCIMAPSession.cc | 12 | ||||
-rw-r--r-- | src/core/provider/MCMailProvider.cc | 67 | ||||
-rw-r--r-- | src/core/provider/MCMailProvider.h | 5 | ||||
-rw-r--r-- | src/core/security/MCCertificateUtils.cc | 74 | ||||
-rw-r--r-- | src/core/smtp/MCSMTPSession.cc | 12 |
11 files changed, 171 insertions, 36 deletions
diff --git a/src/core/abstract/MCMessageConstants.h b/src/core/abstract/MCMessageConstants.h index c2f77c89..dcc1c7cd 100644 --- a/src/core/abstract/MCMessageConstants.h +++ b/src/core/abstract/MCMessageConstants.h @@ -23,6 +23,7 @@ namespace mailcore { AuthTypeSASLNTLM = 1 << 6, AuthTypeSASLKerberosV4 = 1 << 7, AuthTypeXOAuth2 = 1 << 8, + AuthTypeXOAuth2Outlook = 1 << 9, }; enum IMAPFolderFlag { @@ -195,9 +196,11 @@ namespace mailcore { IMAPSearchKindSizeLarger, IMAPSearchKindSizeSmaller, IMAPSearchKindGmailThreadID, + IMAPSearchKindGmailMessageID, IMAPSearchKindGmailRaw, IMAPSearchKindOr, IMAPSearchKindAnd, + IMAPSearchKindNot, }; enum ErrorCode { diff --git a/src/core/basetypes/MCOperationQueue.cc b/src/core/basetypes/MCOperationQueue.cc index 73b62f19..3619530b 100644 --- a/src/core/basetypes/MCOperationQueue.cc +++ b/src/core/basetypes/MCOperationQueue.cc @@ -49,6 +49,16 @@ void OperationQueue::addOperation(Operation * op) startThread(); } +void OperationQueue::cancelAllOperations() +{ + pthread_mutex_lock(&mLock); + for (unsigned int i = 0 ; i < mOperations->count() ; i ++) { + Operation * op = (Operation *) mOperations->objectAtIndex(i); + op->cancel(); + } + pthread_mutex_unlock(&mLock); +} + void OperationQueue::runOperationsOnThread(OperationQueue * queue) { queue->runOperations(); @@ -115,7 +125,7 @@ void OperationQueue::runOperations() if (needsCheckRunning) { retain(); // (1) - MCLog("check running %p", this); + //MCLog("check running %p", this); #if __APPLE__ performMethodOnDispatchQueue((Object::Method) &OperationQueue::checkRunningOnMainThread, this, mDispatchQueue); #else diff --git a/src/core/basetypes/MCOperationQueue.h b/src/core/basetypes/MCOperationQueue.h index 202dec40..b5f29143 100644 --- a/src/core/basetypes/MCOperationQueue.h +++ b/src/core/basetypes/MCOperationQueue.h @@ -21,6 +21,7 @@ namespace mailcore { virtual ~OperationQueue(); virtual void addOperation(Operation * op); + virtual void cancelAllOperations(); virtual unsigned int count(); diff --git a/src/core/basetypes/MCSet.cc b/src/core/basetypes/MCSet.cc index ad615388..ceccbdcc 100644 --- a/src/core/basetypes/MCSet.cc +++ b/src/core/basetypes/MCSet.cc @@ -45,7 +45,7 @@ Set * Set::setWithArray(Array * objects) String * Set::description() { String * result = String::string(); - result->appendUTF8Format("<%s:%p ", className(), this); + result->appendUTF8Format("<%s:%p ", MCUTF8(className()), this); result->appendString(mHash->allKeys()->description()); result->appendUTF8Characters(">"); return result; diff --git a/src/core/imap/MCIMAPSearchExpression.cc b/src/core/imap/MCIMAPSearchExpression.cc index 5838be00..cd3ccc2d 100644 --- a/src/core/imap/MCIMAPSearchExpression.cc +++ b/src/core/imap/MCIMAPSearchExpression.cc @@ -313,6 +313,14 @@ IMAPSearchExpression * IMAPSearchExpression::searchGmailThreadID(uint64_t number return (IMAPSearchExpression *) expr->autorelease(); } +IMAPSearchExpression * IMAPSearchExpression::searchGmailMessageID(uint64_t number) +{ + IMAPSearchExpression * expr = new IMAPSearchExpression(); + expr->mKind = IMAPSearchKindGmailMessageID; + expr->mLongNumber = number; + return (IMAPSearchExpression *) expr->autorelease(); +} + IMAPSearchExpression * IMAPSearchExpression::searchGmailRaw(String * searchExpr) { IMAPSearchExpression * expr = new IMAPSearchExpression(); @@ -339,6 +347,14 @@ IMAPSearchExpression * IMAPSearchExpression::searchOr(IMAPSearchExpression * lef return (IMAPSearchExpression *) expr->autorelease(); } +IMAPSearchExpression * IMAPSearchExpression::searchNot(IMAPSearchExpression * notExpr) +{ + IMAPSearchExpression * expr = new IMAPSearchExpression(); + expr->mKind = IMAPSearchKindNot; + MC_SAFE_REPLACE_RETAIN(IMAPSearchExpression, expr->mLeftExpression, notExpr); + return (IMAPSearchExpression *) expr->autorelease(); +} + IMAPSearchKind IMAPSearchExpression::kind() { return mKind; diff --git a/src/core/imap/MCIMAPSearchExpression.h b/src/core/imap/MCIMAPSearchExpression.h index c108fd2b..a0647216 100644 --- a/src/core/imap/MCIMAPSearchExpression.h +++ b/src/core/imap/MCIMAPSearchExpression.h @@ -54,9 +54,12 @@ namespace mailcore { static IMAPSearchExpression * searchSizeLarger(uint32_t size); static IMAPSearchExpression * searchSizeSmaller(uint32_t size); static IMAPSearchExpression * searchGmailThreadID(uint64_t number); + static IMAPSearchExpression * searchGmailMessageID(uint64_t number); static IMAPSearchExpression * searchGmailRaw(String * expr); static IMAPSearchExpression * searchAnd(IMAPSearchExpression * left, IMAPSearchExpression * right); static IMAPSearchExpression * searchOr(IMAPSearchExpression * left, IMAPSearchExpression * right); + static IMAPSearchExpression * searchNot(IMAPSearchExpression * notExpr); + public: // subclass behavior IMAPSearchExpression(IMAPSearchExpression * other); diff --git a/src/core/imap/MCIMAPSession.cc b/src/core/imap/MCIMAPSession.cc index faabc522..b387e48f 100755 --- a/src/core/imap/MCIMAPSession.cc +++ b/src/core/imap/MCIMAPSession.cc @@ -837,6 +837,7 @@ void IMAPSession::login(ErrorCode * pError) break; case AuthTypeXOAuth2: + case AuthTypeXOAuth2Outlook: r = mailimap_oauth2_authenticate(mImap, utf8username, MCUTF8(mOAuth2Token)); break; } @@ -2791,7 +2792,11 @@ static struct mailimap_search_key * searchKeyFromSearchExpression(IMAPSearchExpr case IMAPSearchKindGmailThreadID: { return mailimap_search_key_new_xgmthrid(expression->longNumber()); - } + } + case IMAPSearchKindGmailMessageID: + { + return mailimap_search_key_new_xgmmsgid(expression->longNumber()); + } case IMAPSearchKindRead: { return mailimap_search_key_new(MAILIMAP_SEARCH_KEY_SEEN, @@ -2906,6 +2911,11 @@ static struct mailimap_search_key * searchKeyFromSearchExpression(IMAPSearchExpr clist_append(list, searchKeyFromSearchExpression(expression->rightExpression())); return mailimap_search_key_new_multiple(list); } + case IMAPSearchKindNot: + { + return mailimap_search_key_new_not(searchKeyFromSearchExpression(expression->leftExpression())); + } + default: MCAssert(0); return NULL; diff --git a/src/core/provider/MCMailProvider.cc b/src/core/provider/MCMailProvider.cc index 7a8cb4cb..aec6f348 100644 --- a/src/core/provider/MCMailProvider.cc +++ b/src/core/provider/MCMailProvider.cc @@ -22,7 +22,7 @@ void MailProvider::init() mSmtpServices = new Array(); mPopServices = new Array(); mDomainMatch = new Array(); - mMxSet = new Set(); + mMxMatch = new Array(); mMailboxPaths = NULL; } @@ -39,7 +39,7 @@ MailProvider::MailProvider(MailProvider * other) MC_SAFE_REPLACE_COPY(Array, mSmtpServices, other->mSmtpServices); MC_SAFE_REPLACE_COPY(Array, mPopServices, other->mPopServices); MC_SAFE_REPLACE_COPY(Array, mDomainMatch, other->mDomainMatch); - MC_SAFE_REPLACE_COPY(Set, mMxSet, other->mMxSet); + MC_SAFE_REPLACE_COPY(Array, mMxMatch, other->mMxMatch); MC_SAFE_REPLACE_COPY(HashMap, mMailboxPaths, other->mMailboxPaths); } @@ -48,7 +48,7 @@ MailProvider::~MailProvider() MC_SAFE_RELEASE(mImapServices); MC_SAFE_RELEASE(mSmtpServices); MC_SAFE_RELEASE(mPopServices); - MC_SAFE_RELEASE(mMxSet); + MC_SAFE_RELEASE(mMxMatch); MC_SAFE_RELEASE(mDomainMatch); MC_SAFE_RELEASE(mMailboxPaths); MC_SAFE_RELEASE(mIdentifier); @@ -68,7 +68,6 @@ void MailProvider::fillWithInfo(HashMap * info) Array * smtpInfos; Array * popInfos; HashMap * serverInfo; - Array * mxs; MC_SAFE_RELEASE(mDomainMatch); if (info->objectForKey(MCSTR("domain-match")) != NULL) { @@ -78,10 +77,9 @@ void MailProvider::fillWithInfo(HashMap * info) if (info->objectForKey(MCSTR("mailboxes")) != NULL) { mMailboxPaths = (HashMap *) info->objectForKey(MCSTR("mailboxes"))->retain(); } - mxs = (Array *) info->objectForKey(MCSTR("mx")); - mMxSet->removeAllObjects(); - mc_foreacharray(String, mx, mxs) { - mMxSet->addObject(mx->lowercaseString()); + MC_SAFE_RELEASE(mMxMatch); + if (info->objectForKey(MCSTR("mx-match")) != NULL) { + mMxMatch = (Array *) info->objectForKey(MCSTR("mx-match"))->retain(); } serverInfo = (HashMap *) info->objectForKey(MCSTR("servers")); @@ -148,25 +146,11 @@ bool MailProvider::matchEmail(String * email) return false; domain = (String *) components->lastObject(); - cDomain = domain->UTF8Characters(); - + mc_foreacharray(String, match, mDomainMatch) { - regex_t r; - bool matched; - - match = String::stringWithUTF8Format("^%s$", match->UTF8Characters()); - if (regcomp(&r, match->UTF8Characters(), REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0) - continue; - - matched = false; - if (regexec(&r, cDomain, 0, NULL, 0) == 0) { - matched = true; - } - - regfree(&r); - - if (matched) + if (matchDomain(match, domain)){ return true; + } } return false; @@ -174,7 +158,36 @@ bool MailProvider::matchEmail(String * email) bool MailProvider::matchMX(String * hostname) { - return mMxSet->containsObject(hostname->lowercaseString()); + mc_foreacharray(String, match, mMxMatch) { + if (matchDomain(match, hostname)){ + return true; + } + } + + return false; +} + +bool MailProvider::matchDomain(String * match, String * domain) +{ + const char * cDomain; + regex_t r; + bool matched; + + cDomain = domain->UTF8Characters(); + match = String::stringWithUTF8Format("^%s$", match->UTF8Characters()); + matched = false; + + if (regcomp(&r, match->UTF8Characters(), REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0){ + return matched; + } + + if (regexec(&r, cDomain, 0, NULL, 0) == 0) { + matched = true; + } + + regfree(&r); + + return matched; } String * MailProvider::sentMailFolderPath() @@ -232,7 +245,7 @@ bool MailProvider::isMainFolder(String * folderPath, String * prefix) } String * MailProvider::description() -{ +{ return String::stringWithUTF8Format("<%s:%p, %s>", className()->UTF8Characters(), this, MCUTF8(mIdentifier)); } diff --git a/src/core/provider/MCMailProvider.h b/src/core/provider/MCMailProvider.h index 026482b3..29ab4fa6 100644 --- a/src/core/provider/MCMailProvider.h +++ b/src/core/provider/MCMailProvider.h @@ -57,12 +57,13 @@ namespace mailcore { private: String * mIdentifier; Array * /* String */ mDomainMatch; + Array * /* String */ mMxMatch; Array * /* NetService */ mImapServices; Array * /* NetService */ mSmtpServices; Array * /* NetService */ mPopServices; HashMap * mMailboxPaths; - Set * mMxSet; + virtual bool matchDomain(String * match, String * domain); void init(); }; @@ -70,4 +71,4 @@ namespace mailcore { #endif -#endif
\ No newline at end of file +#endif diff --git a/src/core/security/MCCertificateUtils.cc b/src/core/security/MCCertificateUtils.cc index 00f4ed9e..e6e46cbf 100644 --- a/src/core/security/MCCertificateUtils.cc +++ b/src/core/security/MCCertificateUtils.cc @@ -11,6 +11,12 @@ #if __APPLE__ #include <CoreFoundation/CoreFoundation.h> #include <Security/Security.h> +#else +#include <openssl/bio.h> +#include <openssl/x509.h> +#include <openssl/x509_vfy.h> +#include <openssl/pem.h> +#include <openssl/err.h> #endif #include "MCLog.h" @@ -78,8 +84,70 @@ free_certs: err: return result; #else - //TODO check certificate - // for other platforms too. - return true; + bool result = false; + X509_STORE * store = NULL; + X509_STORE_CTX * storectx = NULL; + STACK_OF(X509) * certificates = NULL; + int status; + + carray * cCerts = mailstream_get_certificate_chain(stream); + if (cCerts == NULL) { + fprintf(stderr, "warning: No certificate chain retrieved"); + goto err; + } + + store = X509_STORE_new(); + if (store == NULL) { + goto free_certs; + } + + status = X509_STORE_set_default_paths(store); + if (status != 1) { + printf("Error loading the system-wide CA certificates"); + } + + certificates = sk_X509_new_null(); + for(unsigned int i = 0 ; i < carray_count(cCerts) ; i ++) { + MMAPString * str; + str = (MMAPString *) carray_get(cCerts, i); + if (str == NULL) { + goto free_certs; + } + BIO *bio = BIO_new_mem_buf((void *) str->str, str->len); + X509 *certificate = d2i_X509_bio(bio, NULL); + BIO_free(bio); + if (!sk_X509_push(certificates, certificate)) { + goto free_certs; + } + } + + storectx = X509_STORE_CTX_new(); + if (storectx == NULL) { + goto free_certs; + } + + status = X509_STORE_CTX_init(storectx, store, sk_X509_value(certificates, 0), certificates); + if (status != 1) { + goto free_certs; + } + + status = X509_verify_cert(storectx); + if (status == 1) { + result = true; + } + +free_certs: + mailstream_certificate_chain_free(cCerts); + if (certificates != NULL) { + sk_X509_pop_free((STACK_OF(X509) *) certificates, X509_free); + } + if (storectx != NULL) { + X509_STORE_CTX_free(storectx); + } + if (store != NULL) { + X509_STORE_free(store); + } +err: + return result; #endif } diff --git a/src/core/smtp/MCSMTPSession.cc b/src/core/smtp/MCSMTPSession.cc index b9f71cb9..c6f28ff9 100644 --- a/src/core/smtp/MCSMTPSession.cc +++ b/src/core/smtp/MCSMTPSession.cc @@ -400,7 +400,8 @@ void SMTPSession::login(ErrorCode * pError) { int r; - if ((authType() != AuthTypeXOAuth2) && ((username() == NULL) || (password() == NULL))) { + if ((authType() != AuthTypeXOAuth2) && (authType() != AuthTypeXOAuth2Outlook) && + ((username() == NULL) || (password() == NULL))) { mState = STATE_LOGGEDIN; * pError = ErrorNone; return; @@ -525,6 +526,15 @@ void SMTPSession::login(ErrorCode * pError) r = mailsmtp_oauth2_authenticate(mSmtp, utf8Username, MCUTF8(mOAuth2Token)); break; } + + case AuthTypeXOAuth2Outlook: { + const char * utf8Username = MCUTF8(mUsername); + if (utf8Username == NULL) { + utf8Username = ""; + } + r = mailsmtp_oauth2_outlook_authenticate(mSmtp, utf8Username, MCUTF8(mOAuth2Token)); + break; + } } if (r == MAILSMTP_ERROR_STREAM) { * pError = ErrorConnection; |