Skip to content
This repository
Browse code

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
Matt Ronge authored April 04, 2013
25  Source/CTCoreFolder.h
@@ -242,6 +242,31 @@
242 242
 - (BOOL)setFlags:(NSUInteger)flags forMessage:(CTCoreMessage *)msg;
243 243
 
244 244
 /**
  245
+ Retrieves the message extension flags.
  246
+ @return Return YES on success, NO on error. Call method lastError to get error if one occurred
  247
+ */
  248
+- (BOOL)extensionFlagsForMessage:(CTCoreMessage *)msg flags:(NSArray **)flags;
  249
+
  250
+/**
  251
+ Sets the message's extension flags on the server.
  252
+ @return Return YES on success, NO on error. Call method lastError to get error if one occurred
  253
+ */
  254
+- (BOOL)setExtensionFlags:(NSArray *)flags forMessage:(CTCoreMessage *)msg;
  255
+
  256
+/**
  257
+ Retrieves the message's flags and extension flags, take a look at the
  258
+ documentation for flagsForMessage:
  259
+ @return Return YES on success, NO on error. Call method lastError to get error if one occurred
  260
+ */
  261
+- (BOOL)flagsForMessage:(CTCoreMessage *)msg flags:(NSUInteger *)flags extensionFlags:(NSArray **)extensionFlags;
  262
+
  263
+/**
  264
+ Sets the message's flags and extension flags on the server.
  265
+ @return Return YES on success, NO on error. Call method lastError to get error if one occurred
  266
+ */
  267
+- (BOOL)setFlags:(NSUInteger)flags extensionFlags:(NSArray *)extensionFlags forMessage:(CTCoreMessage *)msg;
  268
+
  269
+/**
245 270
  Deletes all messages contained in the folder that are marked for
246 271
  deletion. Deleting messages in IMAP is a little strange, first
247 272
  you need to set the message flag CTFlagDeleted to CTFlagSet, and
81  Source/CTCoreFolder.m
@@ -704,11 +704,67 @@ - (CTCoreMessage *)messageWithUID:(NSUInteger)uid {
704 704
     already depends on CTCoreMessage so we aren't adding any dependencies here. */
705 705
 
706 706
 - (BOOL)flagsForMessage:(CTCoreMessage *)msg flags:(NSUInteger *)flags {
  707
+    return [self flagsForMessage:msg flags:flags extensionFlags:NULL];
  708
+}
  709
+
  710
+
  711
+- (BOOL)setFlags:(NSUInteger)flags forMessage:(CTCoreMessage *)msg {
707 712
     BOOL success = [self connect];
708 713
     if (!success) {
709 714
         return NO;
710 715
     }
711 716
 
  717
+    int err;
  718
+    [msg messageStruct]->msg_flags->fl_flags=flags;
  719
+    err = mailmessage_check([msg messageStruct]);
  720
+    if (err != MAIL_NO_ERROR) {
  721
+        self.lastError = MailCoreCreateErrorFromIMAPCode(err);
  722
+        return NO;
  723
+    }
  724
+    err = mailfolder_check(myFolder);
  725
+    if (err != MAIL_NO_ERROR) {
  726
+        self.lastError = MailCoreCreateErrorFromIMAPCode(err);
  727
+        return NO;
  728
+    }
  729
+    return YES;
  730
+}
  731
+
  732
+- (BOOL)extensionFlagsForMessage:(CTCoreMessage *)msg flags:(NSArray **)flags {
  733
+    return [self flagsForMessage:msg flags:NULL extensionFlags:flags];
  734
+}
  735
+
  736
+- (BOOL)setExtensionFlags:(NSArray *)flags forMessage:(CTCoreMessage *)msg {
  737
+    BOOL success = [self connect];
  738
+    if (!success) {
  739
+        return NO;
  740
+    }
  741
+    
  742
+    int err;
  743
+    clist *extensionFlags = MailCoreClistFromStringArray(flags);
  744
+    if ([msg messageStruct]->msg_flags->fl_extension) {
  745
+        clist_free([msg messageStruct]->msg_flags->fl_extension);
  746
+        [msg messageStruct]->msg_flags->fl_extension = NULL;
  747
+    }
  748
+    [msg messageStruct]->msg_flags->fl_extension = extensionFlags;
  749
+    err = mailmessage_check([msg messageStruct]);
  750
+    if (err != MAIL_NO_ERROR) {
  751
+        self.lastError = MailCoreCreateErrorFromIMAPCode(err);
  752
+        return NO;
  753
+    }
  754
+    err = mailfolder_check(myFolder);
  755
+    if (err != MAIL_NO_ERROR) {
  756
+        self.lastError = MailCoreCreateErrorFromIMAPCode(err);
  757
+        return NO;
  758
+    }
  759
+    return YES;
  760
+}
  761
+
  762
+- (BOOL)flagsForMessage:(CTCoreMessage *)msg flags:(NSUInteger *)flags extensionFlags:(NSArray **)extensionFlags {
  763
+    BOOL success = [self connect];
  764
+    if (!success) {
  765
+        return NO;
  766
+    }
  767
+    
712 768
     self.lastError = nil;
713 769
     int err;
714 770
     struct mail_flags *flagStruct;
@@ -717,19 +773,31 @@ - (BOOL)flagsForMessage:(CTCoreMessage *)msg flags:(NSUInteger *)flags {
717 773
         self.lastError = MailCoreCreateErrorFromIMAPCode(err);
718 774
         return NO;
719 775
     }
720  
-    *flags = flagStruct->fl_flags;
  776
+    if (flags) {
  777
+        *flags = flagStruct->fl_flags;
  778
+    }
  779
+    if (extensionFlags) {
  780
+        NSArray *extionsionFlags = MailCoreStringArrayFromClist(flagStruct->fl_extension);
  781
+        *extensionFlags = extionsionFlags;
  782
+    }
  783
+    
721 784
     return YES;
722 785
 }
723 786
 
724  
-
725  
-- (BOOL)setFlags:(NSUInteger)flags forMessage:(CTCoreMessage *)msg {
  787
+- (BOOL)setFlags:(NSUInteger)flags extensionFlags:(NSArray *)extensionFlags forMessage:(CTCoreMessage *)msg {
726 788
     BOOL success = [self connect];
727 789
     if (!success) {
728 790
         return NO;
729 791
     }
730  
-
  792
+    
731 793
     int err;
732  
-    [msg messageStruct]->msg_flags->fl_flags=flags;
  794
+    [msg messageStruct]->msg_flags->fl_flags = flags;
  795
+    clist *extensions = MailCoreClistFromStringArray(extensionFlags);
  796
+    if ([msg messageStruct]->msg_flags->fl_extension) {
  797
+        clist_free([msg messageStruct]->msg_flags->fl_extension);
  798
+        [msg messageStruct]->msg_flags->fl_extension = NULL;
  799
+    }
  800
+    [msg messageStruct]->msg_flags->fl_extension = extensions;
733 801
     err = mailmessage_check([msg messageStruct]);
734 802
     if (err != MAIL_NO_ERROR) {
735 803
         self.lastError = MailCoreCreateErrorFromIMAPCode(err);
@@ -743,7 +811,6 @@ - (BOOL)setFlags:(NSUInteger)flags forMessage:(CTCoreMessage *)msg {
743 811
     return YES;
744 812
 }
745 813
 
746  
-
747 814
 - (BOOL)expunge {
748 815
     int err;
749 816
     BOOL success = [self connect];
@@ -920,4 +987,6 @@ int uid_list_to_env_list(clist * fetch_result, struct mailmessage_list ** result
920 987
     err:
921 988
         return res;
922 989
 }
  990
+
  991
+
923 992
 @end
8  Source/CTCoreMessage.h
@@ -208,6 +208,14 @@
208 208
 - (NSUInteger)flags;
209 209
 
210 210
 /**
  211
+ Returns the message extionsion flags.
  212
+ 
  213
+ The extension flags contain flags other than standard flags in flags property. This include "Draft" flag.
  214
+ See MailCoreTypes.h for a list of constants
  215
+ */
  216
+- (NSArray *)extionsionFlags;
  217
+
  218
+/**
211 219
  Set the message sequence number.
212 220
  
213 221
  This will NOT set any thing on the server.
42  Source/CTCoreMessage.m
@@ -464,6 +464,13 @@ - (NSUInteger)flags {
464 464
     return 0;
465 465
 }
466 466
 
  467
+- (NSArray *)extionsionFlags {
  468
+  if (myMessage != NULL && myMessage->msg_flags != NULL) {
  469
+    return MailCoreStringArrayFromClist(myMessage->msg_flags->fl_extension);
  470
+  }
  471
+  return nil;
  472
+}
  473
+
467 474
 - (NSUInteger)sequenceNumber {
468 475
     return mySequenceNumber;
469 476
 }
@@ -520,12 +527,12 @@ - (NSArray *)inReplyTo {
520 527
     if (myFields->fld_in_reply_to == NULL)
521 528
         return nil;
522 529
     else
523  
-        return [self _stringArrayFromClist:myFields->fld_in_reply_to->mid_list];
  530
+        return MailCoreStringArrayFromClist(myFields->fld_in_reply_to->mid_list);
524 531
 }
525 532
 
526 533
 
527 534
 - (void)setInReplyTo:(NSArray *)messageIds {
528  
-	struct mailimf_in_reply_to *imf = mailimf_in_reply_to_new([self _clistFromStringArray:messageIds]);
  535
+	struct mailimf_in_reply_to *imf = mailimf_in_reply_to_new(MailCoreClistFromStringArray(messageIds));
529 536
 
530 537
     if (myFields->fld_in_reply_to != NULL) {
531 538
         mailimf_in_reply_to_free(myFields->fld_in_reply_to);
@@ -540,12 +547,12 @@ - (NSArray *)references {
540 547
     if (myFields->fld_references == NULL)
541 548
         return nil;
542 549
     else
543  
-        return [self _stringArrayFromClist:myFields->fld_references->mid_list];
  550
+        return MailCoreStringArrayFromClist(myFields->fld_references->mid_list);
544 551
 }
545 552
 
546 553
 
547 554
 - (void)setReferences:(NSArray *)messageIds {
548  
-    struct mailimf_references *imf = mailimf_references_new([self _clistFromStringArray:messageIds]);
  555
+    struct mailimf_references *imf = mailimf_references_new(MailCoreClistFromStringArray(messageIds));
549 556
 
550 557
     if (myFields->fld_references != NULL) {
551 558
         mailimf_references_free(myFields->fld_references);
@@ -816,32 +823,5 @@ - (struct mailimf_address_list *)_IMFAddressListFromAddresssList:(NSSet *)addres
816 823
     return imfList;
817 824
 }
818 825
 
819  
-- (NSArray *)_stringArrayFromClist:(clist *)list {
820  
-    clistiter *iter;
821  
-    NSMutableArray *stringSet = [NSMutableArray array];
822  
-	char *string;
823  
-	
824  
-    if(list == NULL)
825  
-        return stringSet;
826  
-	
827  
-    for(iter = clist_begin(list); iter != NULL; iter = clist_next(iter)) {
828  
-        string = clist_content(iter);
829  
-        NSString *strObj = [[NSString alloc] initWithUTF8String:string];
830  
-		[stringSet addObject:strObj];
831  
-        [strObj release];
832  
-    }
833  
-	
834  
-    return stringSet;
835  
-}
836  
-
837  
-- (clist *)_clistFromStringArray:(NSArray *)strings {
838  
-	clist * str_list = clist_new();
839  
-
840  
-	for (NSString *str in strings) {
841  
-		clist_append(str_list, strdup([str UTF8String]));
842  
-	}
843  
-
844  
-	return str_list;
845  
-}
846 826
 
847 827
 @end
4  Source/MailCoreUtilities.h
@@ -51,3 +51,7 @@ NSError* MailCoreCreateErrorFromIMAPCode(int errcode);
51 51
 NSError* MailCoreCreateErrorFromSMTPCode(int errcode);
52 52
 
53 53
 NSString *MailCoreDecodeMIMEPhrase(char *data);
  54
+
  55
+NSArray * MailCoreStringArrayFromClist(clist *list);
  56
+clist *MailCoreClistFromStringArray(NSArray *strings);
  57
+
28  Source/MailCoreUtilities.m
@@ -284,3 +284,31 @@ void MailCoreDisableLogging() {
284 284
     free(decodedSubject);
285 285
     return result;
286 286
 }
  287
+
  288
+NSArray * MailCoreStringArrayFromClist(clist *list) {
  289
+  clistiter *iter;
  290
+  NSMutableArray *stringSet = [NSMutableArray array];
  291
+	char *string;
  292
+	
  293
+  if(list == NULL)
  294
+    return stringSet;
  295
+	
  296
+  for(iter = clist_begin(list); iter != NULL; iter = clist_next(iter)) {
  297
+    string = clist_content(iter);
  298
+    NSString *strObj = [[NSString alloc] initWithUTF8String:string];
  299
+    [stringSet addObject:strObj];
  300
+    [strObj release];
  301
+  }
  302
+	
  303
+  return stringSet;
  304
+}
  305
+
  306
+clist *MailCoreClistFromStringArray(NSArray *strings) {
  307
+	clist * str_list = clist_new();
  308
+  
  309
+	for (NSString *str in strings) {
  310
+		clist_append(str_list, strdup([str UTF8String]));
  311
+	}
  312
+  
  313
+	return str_list;
  314
+}

0 notes on commit 8fb4ed3

Please sign in to comment.
Something went wrong with that request. Please try again.