Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #84 from pitiphong-p/extionsion_flags_support

Support for get/set the extension flags for CTCoreMessage.
  • Loading branch information...
commit 8fb4ed3bbea5f403fc25c23faa0e36cc7a0a1f5b 2 parents e22a886 + 1169458
@mronge mronge authored
View
25 Source/CTCoreFolder.h
@@ -242,6 +242,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
you need to set the message flag CTFlagDeleted to CTFlagSet, and
View
81 Source/CTCoreFolder.m
@@ -704,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;
@@ -717,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);
@@ -743,7 +811,6 @@ - (BOOL)setFlags:(NSUInteger)flags forMessage:(CTCoreMessage *)msg {
return YES;
}
-
- (BOOL)expunge {
int err;
BOOL success = [self connect];
@@ -920,4 +987,6 @@ int uid_list_to_env_list(clist * fetch_result, struct mailmessage_list ** result
err:
return res;
}
+
+
@end
View
8 Source/CTCoreMessage.h
@@ -208,6 +208,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.
This will NOT set any thing on the server.
View
42 Source/CTCoreMessage.m
@@ -464,6 +464,13 @@ - (NSUInteger)flags {
return 0;
}
+- (NSArray *)extionsionFlags {
+ if (myMessage != NULL && myMessage->msg_flags != NULL) {
+ return MailCoreStringArrayFromClist(myMessage->msg_flags->fl_extension);
+ }
+ return nil;
+}
+
- (NSUInteger)sequenceNumber {
return mySequenceNumber;
}
@@ -520,12 +527,12 @@ - (NSArray *)inReplyTo {
if (myFields->fld_in_reply_to == NULL)
return nil;
else
- return [self _stringArrayFromClist:myFields->fld_in_reply_to->mid_list];
+ return MailCoreStringArrayFromClist(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]);
+ struct mailimf_in_reply_to *imf = mailimf_in_reply_to_new(MailCoreClistFromStringArray(messageIds));
if (myFields->fld_in_reply_to != NULL) {
mailimf_in_reply_to_free(myFields->fld_in_reply_to);
@@ -540,12 +547,12 @@ - (NSArray *)references {
if (myFields->fld_references == NULL)
return nil;
else
- return [self _stringArrayFromClist:myFields->fld_references->mid_list];
+ return MailCoreStringArrayFromClist(myFields->fld_references->mid_list);
}
- (void)setReferences:(NSArray *)messageIds {
- struct mailimf_references *imf = mailimf_references_new([self _clistFromStringArray:messageIds]);
+ struct mailimf_references *imf = mailimf_references_new(MailCoreClistFromStringArray(messageIds));
if (myFields->fld_references != NULL) {
mailimf_references_free(myFields->fld_references);
@@ -816,32 +823,5 @@ - (struct mailimf_address_list *)_IMFAddressListFromAddresssList:(NSSet *)addres
return imfList;
}
-- (NSArray *)_stringArrayFromClist:(clist *)list {
- clistiter *iter;
- NSMutableArray *stringSet = [NSMutableArray array];
- char *string;
-
- if(list == NULL)
- return stringSet;
-
- for(iter = clist_begin(list); iter != NULL; iter = clist_next(iter)) {
- string = clist_content(iter);
- NSString *strObj = [[NSString alloc] initWithUTF8String:string];
- [stringSet addObject:strObj];
- [strObj release];
- }
-
- 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/MailCoreUtilities.h
@@ -51,3 +51,7 @@ NSError* MailCoreCreateErrorFromIMAPCode(int errcode);
NSError* MailCoreCreateErrorFromSMTPCode(int errcode);
NSString *MailCoreDecodeMIMEPhrase(char *data);
+
+NSArray * MailCoreStringArrayFromClist(clist *list);
+clist *MailCoreClistFromStringArray(NSArray *strings);
+
View
28 Source/MailCoreUtilities.m
@@ -284,3 +284,31 @@ void MailCoreDisableLogging() {
free(decodedSubject);
return result;
}
+
+NSArray * MailCoreStringArrayFromClist(clist *list) {
+ clistiter *iter;
+ NSMutableArray *stringSet = [NSMutableArray array];
+ char *string;
+
+ if(list == NULL)
+ return stringSet;
+
+ for(iter = clist_begin(list); iter != NULL; iter = clist_next(iter)) {
+ string = clist_content(iter);
+ NSString *strObj = [[NSString alloc] initWithUTF8String:string];
+ [stringSet addObject:strObj];
+ [strObj release];
+ }
+
+ return stringSet;
+}
+
+clist *MailCoreClistFromStringArray(NSArray *strings) {
+ clist * str_list = clist_new();
+
+ for (NSString *str in strings) {
+ clist_append(str_list, strdup([str UTF8String]));
+ }
+
+ return str_list;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.