Permalink
Browse files

Merge https://github.com/yonder-innovation/MailCore into HEAD

  • Loading branch information...
2 parents 92cc79a + a182d01 commit 829a82034260c10cf7cd4690c6cb8d87092c7ed9 @ovidiusabou ovidiusabou committed Sep 21, 2012
View
4 MailCore.xcodeproj/project.pbxproj
@@ -1020,7 +1020,6 @@
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = "libetpan/build-mac/include/**";
LIBRARY_SEARCH_PATHS = "";
- MACOSX_DEPLOYMENT_TARGET = 10.6;
SDKROOT = macosx;
};
name = Debug;
@@ -1037,7 +1036,6 @@
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = "libetpan/build-mac/include/**";
LIBRARY_SEARCH_PATHS = "";
- MACOSX_DEPLOYMENT_TARGET = 10.6;
SDKROOT = macosx;
};
name = Release;
@@ -1050,7 +1048,7 @@
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
- ONLY_ACTIVE_ARCH = YES;
+ ONLY_ACTIVE_ARCH = NO;
PRIVATE_HEADERS_FOLDER_PATH = ../../include/MailCore/Private;
PRODUCT_NAME = mailcore;
PUBLIC_HEADERS_FOLDER_PATH = ../../include/MailCore;
View
3 Source/CTCoreAccount.h
@@ -44,12 +44,15 @@
struct mailstorage *myStorage;
BOOL connected;
NSError *lastError;
+ NSString *pathDelimiter;
}
/**
If an error occurred (nil or return of NO) call this method to get the error
*/
@property(nonatomic, retain) NSError *lastError;
+@property(nonatomic, retain) NSString *pathDelimiter;
+
/**
Retrieves the list of all the available folders from the server.
@return Returns a NSSet which contains NSStrings of the folders pathnames, nil on error
View
21 Source/CTCoreAccount.m
@@ -39,7 +39,7 @@ @interface CTCoreAccount ()
@implementation CTCoreAccount
-@synthesize lastError;
+@synthesize lastError, pathDelimiter;
- (id)init {
self = [super init];
@@ -56,6 +56,7 @@ - (void)dealloc {
mailstorage_disconnect(myStorage);
mailstorage_free(myStorage);
self.lastError = nil;
+ self.pathDelimiter = nil;
[super dealloc];
}
@@ -201,13 +202,11 @@ - (NSSet *)subscribedFolders {
if (selectable) {
mailboxName = mailboxStruct->mb_name;
mailboxNameObject = [NSString stringWithCString:mailboxName encoding:NSUTF8StringEncoding];
-
- // Replace the delimiter with /, in MailCore we always use / as the delimiter
- // One potential problem is if the user has a / in their folder name....
+
if (mailboxStruct->mb_delimiter) {
- NSString *delimiter = [NSString stringWithFormat:@"%c", mailboxStruct->mb_delimiter];
- mailboxNameObject = [mailboxNameObject stringByReplacingOccurrencesOfString:delimiter withString:@"/"];
-
+ self.pathDelimiter = [NSString stringWithFormat:@"%c", mailboxStruct->mb_delimiter];
+ } else {
+ self.pathDelimiter = @"/";
}
[subscribedFolders addObject:mailboxNameObject];
}
@@ -246,12 +245,10 @@ - (NSSet *)allFolders {
mailboxName = mailboxStruct->mb_name;
mailboxNameObject = [NSString stringWithCString:mailboxName encoding:NSUTF8StringEncoding];
- // Replace the delimiter with /, in MailCore we always use / as the delimiter
- // One potential problem is if the user has a / in their folder name....
if (mailboxStruct->mb_delimiter) {
- NSString *delimiter = [NSString stringWithFormat:@"%c", mailboxStruct->mb_delimiter];
- mailboxNameObject = [mailboxNameObject stringByReplacingOccurrencesOfString:delimiter withString:@"/"];
-
+ self.pathDelimiter = [NSString stringWithFormat:@"%c", mailboxStruct->mb_delimiter];
+ } else {
+ self.pathDelimiter = @"/";
}
[allFolders addObject:mailboxNameObject];
}
View
5 Source/CTCoreFolder.h
@@ -140,11 +140,6 @@
- (BOOL)check;
/**
- The folder name.
-*/
-- (NSString *)name;
-
-/**
The entire path of folder.
*/
- (NSString *)path;
View
19 Source/CTCoreFolder.m
@@ -99,13 +99,6 @@ - (NSError *)lastError {
return lastError;
}
-- (NSString *)name {
- //Get the last part of the path
- NSArray *pathParts = [myPath componentsSeparatedByString:@"."];
- return [pathParts objectAtIndex:[pathParts count]-1];
-}
-
-
- (NSString *)path {
return myPath;
}
@@ -231,7 +224,10 @@ - (struct mailfolder *)folderStruct {
}
- (NSUInteger)uidValidity {
- [self connect];
+ BOOL success = [self connect];
+ if (!success) {
+ return 0;
+ }
mailimap *imapSession;
imapSession = [self imapSession];
if (imapSession->imap_selection_info != NULL) {
@@ -241,7 +237,10 @@ - (NSUInteger)uidValidity {
}
- (NSUInteger)uidNext {
- [self connect];
+ BOOL success = [self connect];
+ if (!success) {
+ return 0;
+ }
mailimap *imapSession;
imapSession = [self imapSession];
if (imapSession->imap_selection_info != NULL) {
@@ -588,7 +587,7 @@ - (BOOL)setFlags:(NSUInteger)flags forMessage:(CTCoreMessage *)msg {
self.lastError = MailCoreCreateErrorFromIMAPCode(err);
return NO;
}
- return [self check];
+ return YES;
}
View
28 Source/CTCoreMessage.h
@@ -86,11 +86,6 @@
*/
- (id)initWithString:(NSString *)msgData;
-/*
- Creates an empty message
-*/
-- (id)init;
-
/**
If a method returns nil or in the case of a BOOL returns NO, call this to get the error that occured
*/
@@ -263,9 +258,26 @@ The local timezone is the one set in the device running this code
- (void)setTo:(NSSet *)addresses;
/**
-Return the list of messageIds from the in-reply-to field
- */
-- (NSSet *)inReplyTo;
+ Return the list of messageIds from the in-reply-to field
+*/
+- (NSArray *)inReplyTo;
+
+/**
+ Sets the message's in-reply-to messageIds
+ @param messageIds A NSArray containing NSString messageId's
+*/
+- (void)setInReplyTo:(NSArray *)messageIds;
+
+/**
+ Return the list of messageIds from the references field
+*/
+- (NSArray *)references;
+
+/**
+ Sets the message's references
+ @param messageIds A NSArray containing NSString messageId's
+*/
+- (void)setReferences:(NSArray *)messageIds;
/**
Returns the list of people the message was cced to, returns an NSSet containing CTAddress's.
View
61 Source/CTCoreMessage.m
@@ -43,16 +43,6 @@
#import "CTMIME_HtmlPart.h"
#import "MailCoreUtilities.h"
-@interface CTCoreMessage ()
-- (CTCoreAddress *)_addressFromMailbox:(struct mailimf_mailbox *)mailbox;
-- (NSSet *)_addressListFromMailboxList:(struct mailimf_mailbox_list *)mailboxList;
-- (struct mailimf_mailbox_list *)_mailboxListFromAddressList:(NSSet *)addresses;
-- (NSSet *)_addressListFromIMFAddressList:(struct mailimf_address_list *)imfList;
-- (struct mailimf_address_list *)_IMFAddressListFromAddresssList:(NSSet *)addresses;
-- (void)_buildUpBodyText:(CTMIME *)mime result:(NSMutableString *)result;
-- (void)_buildUpHtmlBodyText:(CTMIME *)mime result:(NSMutableString *)result;
-@end
-
@implementation CTCoreMessage
@synthesize mime=myParsedMIME, lastError, parentFolder;
@@ -505,13 +495,46 @@ - (void)setTo:(NSSet *)addresses {
myFields->fld_to = mailimf_to_new(imf);
}
-- (NSSet *)inReplyTo {
+- (NSArray *)inReplyTo {
if (myFields->fld_in_reply_to == NULL)
return nil;
else
- return [self _stringSetFromClist:myFields->fld_in_reply_to->mid_list];
+ return [self _stringArrayFromClist:myFields->fld_in_reply_to->mid_list];
+}
+
+
+- (void)setInReplyTo:(NSArray *)messageIds {
+ struct mailimf_in_reply_to *imf = mailimf_in_reply_to_new([self _clistFromStringArray:messageIds]);
+
+ if (myFields->fld_in_reply_to != NULL) {
+ mailimf_in_reply_to_free(myFields->fld_in_reply_to);
+ myFields->fld_in_reply_to = imf;
+ }
+ else
+ myFields->fld_in_reply_to = imf;
+}
+
+
+- (NSArray *)references {
+ if (myFields->fld_references == NULL)
+ return nil;
+ else
+ return [self _stringArrayFromClist:myFields->fld_references->mid_list];
+}
+
+
+- (void)setReferences:(NSArray *)messageIds {
+ struct mailimf_references *imf = mailimf_references_new([self _clistFromStringArray:messageIds]);
+
+ if (myFields->fld_references != NULL) {
+ mailimf_references_free(myFields->fld_references);
+ myFields->fld_references = imf;
+ }
+ else
+ myFields->fld_references = imf;
}
+
- (NSSet *)cc {
if (myFields->fld_cc == NULL)
return nil;
@@ -759,9 +782,9 @@ - (struct mailimf_address_list *)_IMFAddressListFromAddresssList:(NSSet *)addres
return imfList;
}
-- (NSSet *)_stringSetFromClist:(clist *)list {
+- (NSArray *)_stringArrayFromClist:(clist *)list {
clistiter *iter;
- NSMutableSet *stringSet = [NSMutableSet set];
+ NSMutableArray *stringSet = [NSMutableArray array];
char *string;
if(list == NULL)
@@ -775,4 +798,14 @@ - (NSSet *)_stringSetFromClist:(clist *)list {
return stringSet;
}
+- (clist *)_clistFromStringArray:(NSArray *)strings {
+ clist * str_list = clist_new();
+
+ for (NSString *str in strings) {
+ clist_append(str_list, strdup([str UTF8String]));
+ }
+
+ return str_list;
+}
+
@end
View
4 Source/CTMIME_MultiPart.m
@@ -60,6 +60,7 @@ - (id)init {
self = [super init];
if (self) {
myContentList = [[NSMutableArray alloc] init];
+ self.contentType = @"multipart/mixed";
}
return self;
}
@@ -78,8 +79,7 @@ - (id)content {
}
- (struct mailmime *)buildMIMEStruct {
- //TODO make this smarter so it builds different types other than multipart/mixed
- struct mailmime *mime = mailmime_multiple_new("multipart/mixed");
+ struct mailmime *mime = mailmime_multiple_new([self.contentType UTF8String]);
NSEnumerator *enumer = [myContentList objectEnumerator];
View
6 Source/CTMIME_SinglePart.m
@@ -152,7 +152,7 @@ - (BOOL)fetchPartWithProgress:(CTProgressBlock)block {
if (mimeFields != NULL && mimeFields->fld_encoding != NULL)
encoding = mimeFields->fld_encoding->enc_type;
- char *fetchedData;
+ char *fetchedData = NULL;
size_t fetchedDataLen;
int r;
@@ -164,7 +164,9 @@ - (BOOL)fetchPartWithProgress:(CTProgressBlock)block {
mailimap_set_progress_callback(get_imap_session(mMessage), NULL, NULL, NULL);
}
if (r != MAIL_NO_ERROR) {
- mailmessage_fetch_result_free(mMessage, fetchedData);
+ if (fetchedData) {
+ mailmessage_fetch_result_free(mMessage, fetchedData);
+ }
self.lastError = MailCoreCreateErrorFromIMAPCode(r);
return NO;
}
View
4 Source/CTSMTPConnection.m
@@ -67,7 +67,7 @@ + (BOOL)sendMessage:(CTCoreMessage *)message server:(NSString *)server username:
}
}
if (auth) {
- [smtpObj authenticateWithUsername:username password:password server:server];
+ success = [smtpObj authenticateWithUsername:username password:password server:server];
if (!success) {
goto error;
}
@@ -129,7 +129,7 @@ + (BOOL)canConnectToServer:(NSString *)server username:(NSString *)username pass
}
}
if (auth) {
- [smtpObj authenticateWithUsername:username password:password server:server];
+ success = [smtpObj authenticateWithUsername:username password:password server:server];
if (!success) {
goto error;
}
View
6 Source/MailCore.h
@@ -39,3 +39,9 @@
#import <libetpan/libetpan.h>
#import "MailCoreTypes.h"
#import "MailCoreUtilities.h"
+#import "CTMIME_HtmlPart.h"
+#import "CTMIME_MessagePart.h"
+#import "CTMIME_MultiPart.h"
+#import "CTMIME_SinglePart.h"
+#import "CTMIME_TextPart.h"
+#import "CTMIME.h"
View
18 Source/MailCoreUtilities.m
@@ -67,10 +67,20 @@ void MailCoreDisableLogging() {
}
NSError* MailCoreCreateErrorFromSMTPCode(int errcode) {
- const char *errStr = mailsmtp_strerror(errcode);
NSString *description = @"Unknown error";
- if (errStr) {
- description = [[NSString alloc] initWithCString:errStr encoding:NSUTF8StringEncoding];
+
+ switch (errcode) {
+ case MAILSMTP_ERROR_AUTH_LOGIN:
+ description = @"Invalid username or password";
+ break;
+
+ default: {
+ const char *errStr = mailsmtp_strerror(errcode);
+ if (errStr) {
+ description = [[NSString alloc] initWithCString:errStr encoding:NSUTF8StringEncoding];
+ }
+ break;
+ }
}
return MailCoreCreateError(errcode, description);
}
@@ -257,7 +267,7 @@ void MailCoreDisableLogging() {
char *decodedSubject;
NSString *result;
- if (*data != '\0') {
+ if (data && *data != '\0') {
err = mailmime_encoded_phrase_parse(DEST_CHARSET, data, strlen(data),
&currToken, DEST_CHARSET, &decodedSubject);
2 iOSPorts
@@ -1 +1 @@
-Subproject commit f20f5115bdeb6fbbf008901d561a32999278b616
+Subproject commit ae668453f2a153ca19a8485db23b73f270ea3ed8
2 libetpan
@@ -1 +1 @@
-Subproject commit ed9109b1d4928cc9067fbcf375b3b0f8420b3e9a
+Subproject commit e43d8a0a11e4dea0876d199884fe9f4e0a39889f

0 comments on commit 829a820

Please sign in to comment.