Permalink
Browse files

Merge branch 'master' of github.com:mronge/MailCore

  • Loading branch information...
mronge committed Jun 3, 2013
2 parents b048483 + d44138b commit 1b20901351814d773295e3928a837dcf513d147f
View
@@ -5,7 +5,34 @@
\/_/ \/_/ \/_/\/_/ \/_/ \/_____/ \/_____/ \/_____/ \/_/ /_/ \/_____/
-##Getting the code
+## What is MailCore
+
+MailCore is a Mac and iOS library designed to ease the pain of dealing with e-mail protocols. MailCore makes the process of sending e-mail easy by hiding the nasty details like MIME composition from you. Instead, there is a single method required to send a message. Checking e-mail on an IMAP server is a more complex beast, but MailCore makes the job much simpler by presenting everything as a set of objects like Messages, Folders and Accounts.
+
+## Example
+
+This example shows how you can send email using MailCore.
+
+```obj-c
+CTCoreMessage *msg = [[CTCoreMessage alloc] init];
+CTCoreAddress *toAddress = [CTCoreAddress addressWithName:@"Monkey"
+ email:@"monkey@monkey.com"];
+[msg setTo:[NSSet setWithObject:toAddress]];
+[msg setBody:@"This is a test message!"];
+
+NSError *error;
+BOOL success = [CTSMTPConnection sendMessage:testMsg
+ server:@"mail.test.com"
+ username:@"test"
+ password:@"test"
+ port:587
+ connectionType:CTSMTPConnectionTypeStartTLS
+ useAuth:YES
+ error:&error];
+```
+
+
+## Getting the code
First checkout the code and pulldown the required dependencies as submodules:
@@ -15,13 +42,45 @@ First checkout the code and pulldown the required dependencies as submodules:
Now open up MailCore.xcodeproj and build either the iOS static library or the Mac OS X framework depending on your needs.
-##Website
+## Adding MailCore to Your iOS Project
+
+1. First checkout the latest code and make sure you get the required submodules
+2. Locate MailCore.xcodeproj and add it to your project as a subproject. You can do this by dragging the Mailcore.xcodeproj file into your Xcode project.
+3. Navigate to your app’s target and switch to your app’s Build Phases. Once in Build Phases expand “Link Binary With Libraries” and click the + button. And add these libraries:
+```
+ libmailcore.a
+ libssl.a
+ libsasl2.a
+ libcrypto.a
+ libiconv.dylib
+ CFNetwork.framework
+```
+
+4. Add “MailCore iOS” under “Target Dependencies”
+5. Under your app’s target, switch to Build Settings. Locate “Header Search Paths” in the Build Settings and add `"$(BUILT_PRODUCTS_DIR)/../../include"`
+6. You are now ready to use MailCore. To use MailCore add `#import <MailCore/MailCore.h>` to the top of your Objective-C files.
+
+## Adding MailCore to Your Mac Project
+
+1. First checkout the latest code and make sure you get the required submodules
+2. Locate MailCore.xcodeproj and add it to your project as a subproject. You can do this by dragging the Mailcore.xcodeproj file into your Xcode project.
+3. Navigate to your app’s target and switch to your app’s Build Phases. Once in Build Phases expand “Link Binary With Libraries” and click the + button. From there add MailCore.framework.
+4. While still under Build Phases click “Add Build Phase” in the lower right and select “Add Copy Files”. A new copy files phase will be added, make sure the destination is set to “Frameworks”. Now add MailCore.framework to that copy files phase by using the + button.
+5. Add “MailCore” under “Target Dependencies”
+6. You are now ready to use MailCore. To use MailCore add `#import <MailCore/MailCore.h>` to the top of your Objective-C files.
+
+## More Docs
+
+* [Getting Started](https://github.com/MailCore/MailCore/wiki/Getting-Started)
+* [FAQ](https://github.com/MailCore/MailCore/wiki/FAQ)
+* [API Docs](http://libmailcore.com/api/)
+* [Wiki](https://github.com/MailCore/MailCore/wiki)
-The official site contains documentation, FAQs, and step by step instructions on how to include MailCore
+## Consulting
-http://www.libmailcore.com
+Consulting services are available via [Central Atomics](http://www.centralatomics.com). At Central Atomics we have years of experience working on email apps. If you need custom e-mail functionality developed, please get in touch via our website.
Thanks,
Matt Ronge
-[@mronge](http://www.twitter.com/mronge)
+[@mronge](http://www.twitter.com/mronge)
View
@@ -316,6 +316,9 @@ - (NSSet *)allFoldersExtended {
for (flagIter = clist_begin(flags->mbf_oflags); flagIter != NULL; flagIter = flagIter->next) {
oflagStruct = flagIter->data;
flagName = oflagStruct->of_flag_ext;
+ if (flagName == NULL && oflagStruct->of_type == MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
+ flagName = "NoInferiors";
+ }
flagNameObject = (NSString *)CFStringCreateWithCString(NULL, flagName, kCFStringEncodingUTF7_IMAP);
[listResult addFlag:flagNameObject];
[flagNameObject release];
View
@@ -121,6 +121,35 @@
*/
- (NSArray *)messagesFromUID:(NSUInteger)startUID to:(NSUInteger)endUID withFetchAttributes:(CTFetchAttributes)attrs;
+
+/**
+ Use this method to download message lists from the server.
+
+ This method uses sequence numbers indexset to determine which messages to download.
+
+ @param sequenceNumbers The indexset of sequence numbers to load.
+ @param attrs This controls what is fetched.
+ @return Returns a NSArray of CTCoreMessage's. Returns nil on error
+ @see messagesFromSequenceNumber:to:withFetchAttributes:
+ */
+- (NSArray *)messagesWithSequenceNumbers:(NSIndexSet *)sequenceNumbers
+ fetchAttributes:(CTFetchAttributes)attrs;
+
+
+/**
+ Use this method to download message lists from the server.
+
+ This method uses uid numbers indexset to determine which messages to download.
+
+ @param uidNumbers The indexset of uid numbers to load.
+ @param attrs This controls what is fetched.
+ @return Returns a NSArray of CTCoreMessage's. Returns nil on error
+ @see messagesFromSequenceNumber:to:withFetchAttributes:
+ */
+- (NSArray *)messagesWithUIDs:(NSIndexSet *)uidNumbers
+ fetchAttributes:(CTFetchAttributes)attrs;
+
+
/**
Pulls the sequence number for the message with the specified uid.
It does not perform UID validation, and the sequence ID is only
@@ -212,6 +241,31 @@
*/
- (BOOL)setFlags:(NSUInteger)flags forMessage:(CTCoreMessage *)msg;
+/**
+ Retrieves the message extension flags.
+ @return Return YES on success, NO on error. Call method lastError to get error if one occurred
+ */
+- (BOOL)extensionFlagsForMessage:(CTCoreMessage *)msg flags:(NSArray **)flags;
+
+/**
+ Sets the message's extension flags on the server.
+ @return Return YES on success, NO on error. Call method lastError to get error if one occurred
+ */
+- (BOOL)setExtensionFlags:(NSArray *)flags forMessage:(CTCoreMessage *)msg;
+
+/**
+ Retrieves the message's flags and extension flags, take a look at the
+ documentation for flagsForMessage:
+ @return Return YES on success, NO on error. Call method lastError to get error if one occurred
+ */
+- (BOOL)flagsForMessage:(CTCoreMessage *)msg flags:(NSUInteger *)flags extensionFlags:(NSArray **)extensionFlags;
+
+/**
+ Sets the message's flags and extension flags on the server.
+ @return Return YES on success, NO on error. Call method lastError to get error if one occurred
+ */
+- (BOOL)setFlags:(NSUInteger)flags extensionFlags:(NSArray *)extensionFlags forMessage:(CTCoreMessage *)msg;
+
/**
Deletes all messages contained in the folder that are marked for
deletion. Deleting messages in IMAP is a little strange, first
View
@@ -641,6 +641,27 @@ - (NSArray *)messagesFromUID:(NSUInteger)startUID to:(NSUInteger)endUID withFetc
return results;
}
+- (NSArray *)messagesWithSequenceNumbers:(NSIndexSet *)sequenceNumbers
+ fetchAttributes:(CTFetchAttributes)attrs {
+ struct mailimap_set *set = mailimap_set_new_empty();
+ [sequenceNumbers enumerateRangesUsingBlock:^(NSRange range, BOOL *stop) {
+ mailimap_set_add_interval(set, range.location, range.location + range.length - 1);
+ }];
+
+ return [self messagesForSet:set fetchAttributes:attrs uidFetch:NO];
+
+}
+
+- (NSArray *)messagesWithUIDs:(NSIndexSet *)uidNumbers
+ fetchAttributes:(CTFetchAttributes)attrs {
+ struct mailimap_set *set = mailimap_set_new_empty();
+ [uidNumbers enumerateRangesUsingBlock:^(NSRange range, BOOL *stop) {
+ mailimap_set_add_interval(set, range.location, range.location + range.length - 1);
+ }];
+
+ return [self messagesForSet:set fetchAttributes:attrs uidFetch:YES];
+}
+
- (CTCoreMessage *)messageWithUID:(NSUInteger)uid {
int err;
struct mailmessage *msgStruct;
@@ -683,11 +704,67 @@ - (CTCoreMessage *)messageWithUID:(NSUInteger)uid {
already depends on CTCoreMessage so we aren't adding any dependencies here. */
- (BOOL)flagsForMessage:(CTCoreMessage *)msg flags:(NSUInteger *)flags {
+ return [self flagsForMessage:msg flags:flags extensionFlags:NULL];
+}
+
+
+- (BOOL)setFlags:(NSUInteger)flags forMessage:(CTCoreMessage *)msg {
+ BOOL success = [self connect];
+ if (!success) {
+ return NO;
+ }
+
+ int err;
+ [msg messageStruct]->msg_flags->fl_flags=flags;
+ err = mailmessage_check([msg messageStruct]);
+ if (err != MAIL_NO_ERROR) {
+ self.lastError = MailCoreCreateErrorFromIMAPCode(err);
+ return NO;
+ }
+ err = mailfolder_check(myFolder);
+ if (err != MAIL_NO_ERROR) {
+ self.lastError = MailCoreCreateErrorFromIMAPCode(err);
+ return NO;
+ }
+ return YES;
+}
+
+- (BOOL)extensionFlagsForMessage:(CTCoreMessage *)msg flags:(NSArray **)flags {
+ return [self flagsForMessage:msg flags:NULL extensionFlags:flags];
+}
+
+- (BOOL)setExtensionFlags:(NSArray *)flags forMessage:(CTCoreMessage *)msg {
BOOL success = [self connect];
if (!success) {
return NO;
}
+
+ int err;
+ clist *extensionFlags = MailCoreClistFromStringArray(flags);
+ if ([msg messageStruct]->msg_flags->fl_extension) {
+ clist_free([msg messageStruct]->msg_flags->fl_extension);
+ [msg messageStruct]->msg_flags->fl_extension = NULL;
+ }
+ [msg messageStruct]->msg_flags->fl_extension = extensionFlags;
+ err = mailmessage_check([msg messageStruct]);
+ if (err != MAIL_NO_ERROR) {
+ self.lastError = MailCoreCreateErrorFromIMAPCode(err);
+ return NO;
+ }
+ err = mailfolder_check(myFolder);
+ if (err != MAIL_NO_ERROR) {
+ self.lastError = MailCoreCreateErrorFromIMAPCode(err);
+ return NO;
+ }
+ return YES;
+}
+- (BOOL)flagsForMessage:(CTCoreMessage *)msg flags:(NSUInteger *)flags extensionFlags:(NSArray **)extensionFlags {
+ BOOL success = [self connect];
+ if (!success) {
+ return NO;
+ }
+
self.lastError = nil;
int err;
struct mail_flags *flagStruct;
@@ -696,19 +773,31 @@ - (BOOL)flagsForMessage:(CTCoreMessage *)msg flags:(NSUInteger *)flags {
self.lastError = MailCoreCreateErrorFromIMAPCode(err);
return NO;
}
- *flags = flagStruct->fl_flags;
+ if (flags) {
+ *flags = flagStruct->fl_flags;
+ }
+ if (extensionFlags) {
+ NSArray *extionsionFlags = MailCoreStringArrayFromClist(flagStruct->fl_extension);
+ *extensionFlags = extionsionFlags;
+ }
+
return YES;
}
-
-- (BOOL)setFlags:(NSUInteger)flags forMessage:(CTCoreMessage *)msg {
+- (BOOL)setFlags:(NSUInteger)flags extensionFlags:(NSArray *)extensionFlags forMessage:(CTCoreMessage *)msg {
BOOL success = [self connect];
if (!success) {
return NO;
}
-
+
int err;
- [msg messageStruct]->msg_flags->fl_flags=flags;
+ [msg messageStruct]->msg_flags->fl_flags = flags;
+ clist *extensions = MailCoreClistFromStringArray(extensionFlags);
+ if ([msg messageStruct]->msg_flags->fl_extension) {
+ clist_free([msg messageStruct]->msg_flags->fl_extension);
+ [msg messageStruct]->msg_flags->fl_extension = NULL;
+ }
+ [msg messageStruct]->msg_flags->fl_extension = extensions;
err = mailmessage_check([msg messageStruct]);
if (err != MAIL_NO_ERROR) {
self.lastError = MailCoreCreateErrorFromIMAPCode(err);
@@ -722,7 +811,6 @@ - (BOOL)setFlags:(NSUInteger)flags forMessage:(CTCoreMessage *)msg {
return YES;
}
-
- (BOOL)expunge {
int err;
BOOL success = [self connect];
@@ -899,4 +987,6 @@ int uid_list_to_env_list(clist * fetch_result, struct mailmessage_list ** result
err:
return res;
}
+
+
@end
View
@@ -42,13 +42,21 @@
@class CTCoreFolder, CTCoreAddress, CTCoreAttachment, CTMIME;
+typedef enum {
+ CTCoreMessageUrgentPriority = 1,
+ CTCoreMessageNormalPriority = 2,
+ CTCoreMessageNonUrgentPriority
+} CTCoreMessagePriority;
+
+
@interface CTCoreMessage : NSObject {
struct mailmessage *myMessage;
struct mailimf_single_fields *myFields;
CTMIME *myParsedMIME;
NSUInteger mySequenceNumber;
NSError *lastError;
CTCoreFolder *parentFolder;
+ CTCoreMessagePriority mailPriority;
}
/**
If an error occurred (nil or return of NO) call this method to get the error
@@ -163,6 +171,11 @@
*/
- (NSDate *)senderDate;
+/**
+ Returns YES if the message is deleted.
+ */
+- (BOOL)isDeleted;
+
/**
Returns YES if the message is unread.
*/
@@ -207,6 +220,14 @@
*/
- (NSUInteger)flags;
+/**
+ Returns the message extionsion flags.
+
+ The extension flags contain flags other than standard flags in flags property. This include "Draft" flag.
+ See MailCoreTypes.h for a list of constants
+ */
+- (NSArray *)extionsionFlags;
+
/**
Set the message sequence number.
@@ -326,6 +347,13 @@
*/
- (NSString *)rfc822Header;
+
+/**
+ Sets the outgoing message's priority header value.
+ Support for Mail Prioirty header defined in IMAP 4021 and X-Prioirty header.
+ */
+- (void)setMailPriority:(CTCoreMessagePriority)priority;
+
/* Intended for advanced use only */
- (struct mailmessage *)messageStruct;
- (mailimap *)imapSession;
Oops, something went wrong.

0 comments on commit 1b20901

Please sign in to comment.