aboutsummaryrefslogtreecommitdiffstats
path: root/camel
diff options
context:
space:
mode:
Diffstat (limited to 'camel')
-rw-r--r--camel/camel-mime-message.c85
-rw-r--r--camel/camel-mime-message.h1
-rw-r--r--camel/gstring-util.c46
-rw-r--r--camel/gstring-util.h1
4 files changed, 127 insertions, 6 deletions
diff --git a/camel/camel-mime-message.c b/camel/camel-mime-message.c
index 01f9b48e27..2a4a9e8897 100644
--- a/camel/camel-mime-message.c
+++ b/camel/camel-mime-message.c
@@ -30,8 +30,14 @@
typedef enum {
HEADER_UNKNOWN,
- HEADER_FROM
+ HEADER_FROM,
+ HEADER_REPLY_TO,
+ HEADER_SUBJECT,
+ HEADER_TO,
+ HEADER_CC,
+ HEADER_BCC
} CamelHeaderType;
+
static GHashTable *header_name_table;
@@ -77,6 +83,11 @@ _init_header_name_table()
{
header_name_table = g_hash_table_new (g_string_hash, g_string_equal_for_hash);
g_hash_table_insert (header_name_table, g_string_new ("From"), (gpointer)HEADER_FROM);
+ g_hash_table_insert (header_name_table, g_string_new ("Reply-To"), (gpointer)HEADER_REPLY_TO);
+ g_hash_table_insert (header_name_table, g_string_new ("Subject"), (gpointer)HEADER_SUBJECT);
+ g_hash_table_insert (header_name_table, g_string_new ("To"), (gpointer)HEADER_TO);
+ g_hash_table_insert (header_name_table, g_string_new ("Cc"), (gpointer)HEADER_CC);
+ g_hash_table_insert (header_name_table, g_string_new ("Bcc"), (gpointer)HEADER_BCC);
}
@@ -542,28 +553,90 @@ _write_to_file (CamelDataWrapper *data_wrapper, FILE *file)
/*******************************/
/* mime message header parsing */
+static void
+_set_recipient_list_from_string (CamelMimeMessage *message, GString *recipient_type, GString *recipients_string)
+{
+ GList *recipients_list;
+ CAMEL_LOG (FULL_DEBUG,"CamelMimeMessage::_set_recipient_list_from_string parsing ##%s##\n", recipients_string->str);
+ recipients_list = g_string_split (recipients_string, ',');
+ g_hash_table_insert (message->recipients, recipient_type, recipients_list);
+
+}
+
static gboolean
_parse_header_pair (CamelMimePart *mime_part, GString *header_name, GString *header_value)
{
CamelHeaderType header_type;
CamelMimeMessage *message = CAMEL_MIME_MESSAGE (mime_part);
+ gboolean header_handled = FALSE;
header_type = (CamelHeaderType) g_hash_table_lookup (header_name_table, header_name);
switch (header_type) {
case HEADER_FROM:
- camel_log(FULL_DEBUG,
+ CAMEL_LOG (FULL_DEBUG,
"CamelMimeMessage::parse_header_pair found HEADER_FROM : %s\n",
header_value->str );
camel_mime_message_set_from (message, header_value);
- g_string_free (header_name, TRUE);
- return TRUE;
+ header_handled = TRUE;
+ break;
+
+ case HEADER_REPLY_TO:
+ CAMEL_LOG (FULL_DEBUG,
+ "CamelMimeMessage::parse_header_pair found HEADER_REPLY_YO : %s\n",
+ header_value->str );
+
+ camel_mime_message_set_reply_to (message, header_value);
+ header_handled = TRUE;
+ break;
+
+ case HEADER_SUBJECT:
+ CAMEL_LOG (FULL_DEBUG,
+ "CamelMimeMessage::parse_header_pair found HEADER_SUBJECT : %s\n",
+ header_value->str );
+
+ camel_mime_message_set_subject (message, header_value);
+ header_handled = TRUE;
+ break;
+
+ case HEADER_TO:
+ CAMEL_LOG (FULL_DEBUG,
+ "CamelMimeMessage::parse_header_pair found HEADER_TO : %s\n",
+ header_value->str );
+
+ _set_recipient_list_from_string (message, g_string_new ("To"), header_value);
+ g_string_free (header_value, TRUE);
+ header_handled = TRUE;
+ break;
+
+ case HEADER_CC:
+ CAMEL_LOG (FULL_DEBUG,
+ "CamelMimeMessage::parse_header_pair found HEADER_CC : %s\n",
+ header_value->str );
+
+ _set_recipient_list_from_string (message, g_string_new ("Cc"), header_value);
+ g_string_free (header_value, TRUE);
+ header_handled = TRUE;
+ break;
+
+ case HEADER_BCC:
+ CAMEL_LOG (FULL_DEBUG,
+ "CamelMimeMessage::parse_header_pair found HEADER_BCC : %s\n",
+ header_value->str );
+
+ _set_recipient_list_from_string (message, g_string_new ("Bcc"), header_value);
+ g_string_free (header_value, TRUE);
+ header_handled = TRUE;
break;
- }
- return parent_class->parse_header_pair (mime_part, header_name, header_value);
+ }
+ if (header_handled) {
+ g_string_free (header_name, TRUE);
+ return TRUE;
+ } else
+ return parent_class->parse_header_pair (mime_part, header_name, header_value);
}
diff --git a/camel/camel-mime-message.h b/camel/camel-mime-message.h
index b00f723f21..73d1cb9388 100644
--- a/camel/camel-mime-message.h
+++ b/camel/camel-mime-message.h
@@ -110,6 +110,7 @@ GtkType camel_mime_message_get_type (void);
/* public methods */
CamelMimeMessage *camel_mime_message_new_with_session (CamelSession *session);
+
void camel_mime_message_set_received_date (CamelMimeMessage *mime_message, GString *received_date);
GString *camel_mime_message_get_received_date (CamelMimeMessage *mime_message);
GString *camel_mime_message_get_sent_date (CamelMimeMessage *mime_message);
diff --git a/camel/gstring-util.c b/camel/gstring-util.c
index 5d11fa91a8..32ecb9b031 100644
--- a/camel/gstring-util.c
+++ b/camel/gstring-util.c
@@ -246,3 +246,49 @@ g_string_list_free (GList *string_list)
g_list_foreach(string_list, __g_string_list_free_string, NULL);
g_list_free(string_list);
}
+
+
+
+
+
+
+GList *
+g_string_split (GString *string, char sep)
+{
+ GList *result = NULL;
+ gint first, last, pos;
+ gchar *str;
+ gchar *new_str;
+ GString *new_gstring;
+
+ g_assert (string);
+ str = string->str;
+ if (!str) return NULL;
+
+ first = 0;
+ last = strlen(str) - 1;
+
+ /* strip leading and trailing separators */
+ while ( (first<=last) && (str[first]==sep) )
+ first++;
+
+ while ( (first<=last) && (str[last]==sep) )
+ last--;
+
+ CAMEL_LOG(FULL_DEBUG,"g_string_split:: stripping done\n");
+
+ while (first<=last) {
+ pos = first;
+ /* find next separator */
+ while ((pos<=last) && (str[pos]!=sep)) pos++;
+ if (first != pos) {
+ new_str = g_strndup (str+first, pos-first);
+ new_gstring = g_string_new (new_str);
+ g_free (new_str);
+ result = g_list_append (result, new_gstring);
+ }
+ first = pos + 1;
+ }
+
+ return result;
+}
diff --git a/camel/gstring-util.h b/camel/gstring-util.h
index 8d88bf18af..a29d760cc5 100644
--- a/camel/gstring-util.h
+++ b/camel/gstring-util.h
@@ -52,6 +52,7 @@ gboolean g_string_equal_for_hash (gconstpointer v, gconstpointer v2);
gboolean g_string_equal_for_glist (gconstpointer v, gconstpointer v2);
guint g_string_hash (gconstpointer v);
void g_string_list_free (GList *string_list);
+GList *g_string_split (GString *string, char sep);
#ifdef __cplusplus
}