aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog22
-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
-rw-r--r--tests/test2.c12
6 files changed, 160 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 63c2b1c970..adf502dbae 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+1999-05-27 bertrand <Bertrand.Guiheneuf@inria.fr>
+
+ * tests/test2.c (main): rewrite message obtained via
+ parsing into a file. Actually, it works pretty well :))
+
+ * camel/camel-mime-message.c (_set_recipient_list_from_string):
+ create recipient list form a comma separated string.
+ (_parse_header_pair): added recipient lists parsing.
+
+ * camel/camel-mime-part.c (_parse_header_pair):
+ new (protected) method. Parse a head pair and
+ decides what to do with it.
+
+ (_add_header): Call in _parse_header_pair
+
+ * camel/camel-mime-message.c (_parse_header_pair):
+ overload header parsing MimePart mthod.
+
+ * camel/gstring-util.c (g_string_split):
+ new func: split a gstring into a GList of
+ substring.
+
1999-05-26 bertrand <Bertrand.Guiheneuf@inria.fr>
* camel/gmime-utils.c (get_header_lines_from_file):
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
}
diff --git a/tests/test2.c b/tests/test2.c
index 4fa3bc59f1..dbb2b29ad0 100644
--- a/tests/test2.c
+++ b/tests/test2.c
@@ -29,6 +29,7 @@ void
main (int argc, char**argv)
{
FILE *input_file;
+ FILE *output_file;
GHashTable *header_table;
CamelMimeMessage *message;
@@ -36,7 +37,7 @@ main (int argc, char**argv)
gtk_init (&argc, &argv);
- camel_debug_level = WARNING;
+ camel_debug_level = FULL_DEBUG;
message = camel_mime_message_new_with_session( (CamelSession *)NULL);
input_file = fopen ("mail.test", "r");
@@ -51,6 +52,15 @@ main (int argc, char**argv)
else printf("header is empty, no header line present\n");
fclose (input_file);
+
+ output_file = fopen ("mail2.test", "w");
+ if (!output_file) {
+ perror("could not open output file");
+ exit(2);
+ }
+ camel_data_wrapper_write_to_file (CAMEL_DATA_WRAPPER (message), output_file);
+ fclose (output_file);
+
}