[evolution] Add e_mail_part_set_mime_type().



commit 875746e0ef57dc6f0592397d5ba9e561d8751c13
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sat May 18 20:59:16 2013 -0400

    Add e_mail_part_set_mime_type().

 em-format/e-mail-parser-message-deliverystatus.c  |    2 +-
 em-format/e-mail-parser-message-external.c        |    2 +-
 em-format/e-mail-parser-message-rfc822.c          |    2 +-
 em-format/e-mail-parser-secure-button.c           |    2 +-
 em-format/e-mail-parser-source.c                  |    2 +-
 em-format/e-mail-parser-text-html.c               |    2 +-
 em-format/e-mail-parser-text-plain.c              |    6 +++++-
 em-format/e-mail-parser.c                         |    2 +-
 em-format/e-mail-part.c                           |   13 +++++++++++++
 em-format/e-mail-part.h                           |    2 ++
 modules/prefer-plain/e-mail-parser-prefer-plain.c |    2 +-
 11 files changed, 28 insertions(+), 9 deletions(-)
---
diff --git a/em-format/e-mail-parser-message-deliverystatus.c 
b/em-format/e-mail-parser-message-deliverystatus.c
index 8e7fc80..9b672c5 100644
--- a/em-format/e-mail-parser-message-deliverystatus.c
+++ b/em-format/e-mail-parser-message-deliverystatus.c
@@ -58,7 +58,7 @@ empe_msg_deliverystatus_parse (EMailParserExtension *extension,
        len = part_id->len;
        g_string_append (part_id, ".delivery-status");
        mail_part = e_mail_part_new (part, part_id->str);
-       mail_part->mime_type = g_strdup ("text/plain");
+       e_mail_part_set_mime_type (mail_part, "text/plain");
 
        g_string_truncate (part_id, len);
 
diff --git a/em-format/e-mail-parser-message-external.c b/em-format/e-mail-parser-message-external.c
index 1868796..8668df5 100644
--- a/em-format/e-mail-parser-message-external.c
+++ b/em-format/e-mail-parser-message-external.c
@@ -160,7 +160,7 @@ addPart:
        len = part_id->len;
        g_string_append (part_id, ".msg_external");
        mail_part = e_mail_part_new (part, part_id->str);
-       mail_part->mime_type = g_strdup (mime_type);
+       e_mail_part_set_mime_type (mail_part, mime_type);
        g_string_truncate (part_id, len);
 
        g_queue_push_tail (out_mail_parts, mail_part);
diff --git a/em-format/e-mail-parser-message-rfc822.c b/em-format/e-mail-parser-message-rfc822.c
index 31bca87..e9bfab1 100644
--- a/em-format/e-mail-parser-message-rfc822.c
+++ b/em-format/e-mail-parser-message-rfc822.c
@@ -66,7 +66,7 @@ empe_msg_rfc822_parse (EMailParserExtension *extension,
 
        /* Create an empty PURI that will represent start of the RFC message */
        mail_part = e_mail_part_new (part, part_id->str);
-       mail_part->mime_type = g_strdup ("message/rfc822");
+       e_mail_part_set_mime_type (mail_part, "message/rfc822");
        g_queue_push_tail (out_mail_parts, mail_part);
 
        /* Sometime the actual message is encapsulated in another
diff --git a/em-format/e-mail-parser-secure-button.c b/em-format/e-mail-parser-secure-button.c
index 865bcec..2e2d996 100644
--- a/em-format/e-mail-parser-secure-button.c
+++ b/em-format/e-mail-parser-secure-button.c
@@ -55,7 +55,7 @@ empe_secure_button_parse (EMailParserExtension *extension,
        len = part_id->len;
        g_string_append (part_id, ".secure_button");
        mail_part = e_mail_part_new (part, part_id->str);
-       mail_part->mime_type = g_strdup ("application/vnd.evolution.widget.secure-button");
+       e_mail_part_set_mime_type (mail_part, parser_mime_types[0]);
        g_string_truncate (part_id, len);
 
        g_queue_push_tail (out_mail_parts, mail_part);
diff --git a/em-format/e-mail-parser-source.c b/em-format/e-mail-parser-source.c
index b13d34b..9a8759c 100644
--- a/em-format/e-mail-parser-source.c
+++ b/em-format/e-mail-parser-source.c
@@ -56,7 +56,7 @@ empe_source_parse (EMailParserExtension *extension,
        g_string_append (part_id, ".source");
 
        mail_part = e_mail_part_new (part, part_id->str);
-       mail_part->mime_type = g_strdup ("application/vnd.evolution.source");
+       e_mail_part_set_mime_type (mail_part, parser_mime_types[0]);
        g_string_truncate (part_id, len);
 
        g_queue_push_tail (out_mail_parts, mail_part);
diff --git a/em-format/e-mail-parser-text-html.c b/em-format/e-mail-parser-text-html.c
index b9a4653..bfb8cae 100644
--- a/em-format/e-mail-parser-text-html.c
+++ b/em-format/e-mail-parser-text-html.c
@@ -79,7 +79,7 @@ empe_text_html_parse (EMailParserExtension *extension,
        g_string_append (part_id, ".text_html");
 
        mail_part = e_mail_part_new (part, part_id->str);
-       mail_part->mime_type = g_strdup ("text/html");
+       e_mail_part_set_mime_type (mail_part, "text/html");
        e_mail_part_set_cid (mail_part, cid);
        g_string_truncate (part_id, len);
 
diff --git a/em-format/e-mail-parser-text-plain.c b/em-format/e-mail-parser-text-plain.c
index 24b4b24..c6f4d1e 100644
--- a/em-format/e-mail-parser-text-plain.c
+++ b/em-format/e-mail-parser-text-plain.c
@@ -92,11 +92,15 @@ process_part (EMailParser *parser,
 
        } else if (!camel_content_type_is (type, "text", "calendar")) {
                GQueue work_queue = G_QUEUE_INIT;
+               gchar *mime_type;
 
                g_string_append_printf (part_id, ".plain_text.%d", part_number);
 
                mail_part = e_mail_part_new (part, part_id->str);
-               mail_part->mime_type = camel_content_type_simple (type);
+
+               mime_type = camel_content_type_simple (type);
+               e_mail_part_set_mime_type (mail_part, mime_type);
+               g_free (mime_type);
 
                g_string_truncate (part_id, s_len);
 
diff --git a/em-format/e-mail-parser.c b/em-format/e-mail-parser.c
index 08c0083..46eec59 100644
--- a/em-format/e-mail-parser.c
+++ b/em-format/e-mail-parser.c
@@ -601,7 +601,7 @@ e_mail_parser_error (EMailParser *parser,
        g_mutex_unlock (&parser->priv->mutex);
 
        mail_part = e_mail_part_new (part, uri);
-       mail_part->mime_type = g_strdup (mime_type);
+       e_mail_part_set_mime_type (mail_part, mime_type);
        mail_part->is_error = TRUE;
 
        g_free (uri);
diff --git a/em-format/e-mail-part.c b/em-format/e-mail-part.c
index 8633a36..07b6063 100644
--- a/em-format/e-mail-part.c
+++ b/em-format/e-mail-part.c
@@ -254,6 +254,19 @@ e_mail_part_get_mime_type (EMailPart *part)
        return part->mime_type;
 }
 
+void
+e_mail_part_set_mime_type (EMailPart *part,
+                           const gchar *mime_type)
+{
+       g_return_if_fail (part != NULL);
+
+       if (g_strcmp0 (mime_type, part->mime_type) == 0)
+               return;
+
+       g_free (part->mime_type);
+       part->mime_type = g_strdup (mime_type);
+}
+
 static EMailPartValidityPair *
 mail_part_find_validity_pair (EMailPart *part,
                               guint32 validity_type)
diff --git a/em-format/e-mail-part.h b/em-format/e-mail-part.h
index fb5edde..f4a1bcd 100644
--- a/em-format/e-mail-part.h
+++ b/em-format/e-mail-part.h
@@ -107,6 +107,8 @@ gboolean    e_mail_part_id_has_substr       (EMailPart *part,
                                                 const gchar *substr);
 CamelMimePart *        e_mail_part_ref_mime_part       (EMailPart *part);
 const gchar *  e_mail_part_get_mime_type       (EMailPart *part);
+void           e_mail_part_set_mime_type       (EMailPart *part,
+                                                const gchar *mime_type);
 void           e_mail_part_update_validity     (EMailPart *part,
                                                 CamelCipherValidity *validity,
                                                 guint32 validity_type);
diff --git a/modules/prefer-plain/e-mail-parser-prefer-plain.c 
b/modules/prefer-plain/e-mail-parser-prefer-plain.c
index df23c79..32605dd 100644
--- a/modules/prefer-plain/e-mail-parser-prefer-plain.c
+++ b/modules/prefer-plain/e-mail-parser-prefer-plain.c
@@ -120,7 +120,7 @@ make_part_attachment (EMailParser *parser,
                len = part_id->len;
                g_string_append (part_id, ".text_html");
                mail_part = e_mail_part_new (part, part_id->str);
-               mail_part->mime_type = g_strdup ("text/html");
+               e_mail_part_set_mime_type (mail_part, "text/html");
                g_string_truncate (part_id, len);
 
                g_queue_push_tail (&work_queue, mail_part);


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