Skip to content
Browse files

Merge pull request #91 from pitiphong-p/outgoing_priority_header

Add support for outgoing mail priority header.
  • Loading branch information...
2 parents 66a8511 + 2e1e550 commit d716226a79babe020ce96b3edb98fa0f28a7dcab @mronge mronge committed Jun 1, 2013
Showing with 60 additions and 1 deletion.
  1. +15 −0 Source/CTCoreMessage.h
  2. +45 −1 Source/CTCoreMessage.m
View
15 Source/CTCoreMessage.h
@@ -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
@@ -339,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;
View
46 Source/CTCoreMessage.m
@@ -635,9 +635,49 @@ - (NSString *)render {
clist *references = (myFields->fld_references != NULL) ? (myFields->fld_references->mid_list) : NULL;
char *subject = (myFields->fld_subject != NULL) ? (myFields->fld_subject->sbj_value) : NULL;
+ fields = mailimf_fields_new_with_data(from, sender, replyTo, to, cc, bcc, inReplyTo, references, subject);
+
+ if (self->mailPriority != 0) {
+ char * xPriorityValue;
+ char * rfcPriorityValue;
+ switch (self->mailPriority) {
+ case CTCoreMessageUrgentPriority: {
+ xPriorityValue = "1";
+ rfcPriorityValue = "urgent";
+ break;
+ }
+ case CTCoreMessageNormalPriority: {
+ xPriorityValue = "3";
+ rfcPriorityValue = "normal";
+ break;
+ }
+ case CTCoreMessageNonUrgentPriority: {
+ xPriorityValue = "5";
+ rfcPriorityValue = "non-urgent";
+ break;
+ }
+
+ default:
+ break;
+ }
+
+ struct mailimf_optional_field * priority = mailimf_optional_field_new("X-Priority", xPriorityValue);
+
+ struct mailimf_field * priorityField = mailimf_field_new(MAILIMF_FIELD_OPTIONAL_FIELD, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, priority);
+ mailimf_fields_add(fields, priorityField);
+
+ priority = mailimf_optional_field_new("Priority", rfcPriorityValue);
+ priorityField = mailimf_field_new(MAILIMF_FIELD_OPTIONAL_FIELD, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, priority);
+
+ mailimf_fields_add(fields, priorityField);
+ }
//TODO uh oh, when this get freed it frees stuff in the CTCoreMessage
//TODO Need to make sure that fields gets freed somewhere
- fields = mailimf_fields_new_with_data(from, sender, replyTo, to, cc, bcc, inReplyTo, references, subject);
[(CTMIME_MessagePart *)msgPart setIMFFields:fields];
}
return [myParsedMIME render];
@@ -706,6 +746,10 @@ - (NSString *)rfc822Header {
return [nsresult autorelease];
}
+- (void)setMailPriority:(CTCoreMessagePriority)priority {
+ mailPriority = priority;
+}
+
- (struct mailmessage *)messageStruct {
return myMessage;
}

0 comments on commit d716226

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