Patch that adds support for storing priority flags in new messages



	Hi,

	I've developed a simple patch that adds support for setting priority
flags in TnyCamelHeaderMsg, using the tny_header_set_flags API.

	The previous implementation of set_flags/unset_flags warned that these
operations weren't supported in new messages. The new implementation
warns the user only when the flags are not priority flags. If you set
priority flags, they're translated to the corresponding headers.
-- 
José Dapena Paz <jdapena igalia com>
Igalia
Index: libtinymail-camel/tny-camel-msg-header.c
===================================================================
--- libtinymail-camel/tny-camel-msg-header.c	(revision 2094)
+++ libtinymail-camel/tny-camel-msg-header.c	(working copy)
@@ -190,14 +190,50 @@
 static void
 tny_camel_msg_header_set_flags (TnyHeader *self, TnyHeaderFlags mask)
 {
-	g_warning ("tny_header_set_flags: This is a header instance for a new message. It has no flags.\n");
-	return;
+	TnyHeaderPriorityFlags priority_flags;
+	TnyCamelMsgHeader *me = TNY_CAMEL_MSG_HEADER (self);
+
+	if (mask ^ TNY_HEADER_FLAG_PRIORITY) {
+		g_warning ("tny_header_set_flags: This is a header instance for a new message. Non-priority flags are not supported.\n");
+		return;
+	}
+	priority_flags = mask & TNY_HEADER_FLAG_PRIORITY;
+
+	camel_medium_remove_header (CAMEL_MEDIUM (me->msg), "X-MSMail-Priority");
+	camel_medium_remove_header (CAMEL_MEDIUM (me->msg), "X-Priority");
+
+	switch (priority_flags) {
+	case TNY_HEADER_FLAG_HIGH_PRIORITY:
+		camel_medium_add_header (CAMEL_MEDIUM (me->msg), "X-MSMail-Priority", "High");
+		camel_medium_add_header (CAMEL_MEDIUM (me->msg), "X-Priority", "1");
+		break;
+	case TNY_HEADER_FLAG_LOW_PRIORITY:
+		camel_medium_add_header (CAMEL_MEDIUM (me->msg), "X-MSMail-Priority", "Low");
+		camel_medium_add_header (CAMEL_MEDIUM (me->msg), "X-Priority", "3");
+		break;
+	case TNY_HEADER_FLAG_NORMAL_PRIORITY:
+		camel_medium_add_header (CAMEL_MEDIUM (me->msg), "X-MSMail-Priority", "Normal");
+		camel_medium_add_header (CAMEL_MEDIUM (me->msg), "X-Priority", "2");
+		break;
+	};
+	
 }
 
 static void
 tny_camel_msg_header_unset_flags (TnyHeader *self, TnyHeaderFlags mask)
 {
-	g_warning ("tny_header_unset_flags: This is a header instance for a new message. It has no flags.\n");
+	TnyHeaderPriorityFlags priority_flags;
+	TnyCamelMsgHeader *me = TNY_CAMEL_MSG_HEADER (self);
+
+	if (mask ^ TNY_HEADER_FLAG_PRIORITY) {
+		g_warning ("tny_header_set_flags: This is a header instance for a new message. Non-priority flags are not supported.\n");
+		return;
+	}
+	priority_flags = mask & TNY_HEADER_FLAG_PRIORITY;
+	if (priority_flags) {
+		camel_medium_remove_header (CAMEL_MEDIUM (me->msg), "X-MSMail-Priority");
+		camel_medium_remove_header (CAMEL_MEDIUM (me->msg), "X-Priority");
+	}
 	return;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]