aboutsummaryrefslogtreecommitdiffstats
path: root/em-format
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2013-05-17 01:06:56 +0800
committerMatthew Barnes <mbarnes@redhat.com>2013-05-20 01:07:20 +0800
commitcd5a55f9812643109be6c2b0ed5d8f8ce655a4a9 (patch)
tree271b673b6e311d5cb44acdd0b6c1d1830aa6982e /em-format
parentf6f11a1da2dfa2c7616cd18b36a44fefd66f0c75 (diff)
downloadgsoc2013-evolution-cd5a55f9812643109be6c2b0ed5d8f8ce655a4a9.tar
gsoc2013-evolution-cd5a55f9812643109be6c2b0ed5d8f8ce655a4a9.tar.gz
gsoc2013-evolution-cd5a55f9812643109be6c2b0ed5d8f8ce655a4a9.tar.bz2
gsoc2013-evolution-cd5a55f9812643109be6c2b0ed5d8f8ce655a4a9.tar.lz
gsoc2013-evolution-cd5a55f9812643109be6c2b0ed5d8f8ce655a4a9.tar.xz
gsoc2013-evolution-cd5a55f9812643109be6c2b0ed5d8f8ce655a4a9.tar.zst
gsoc2013-evolution-cd5a55f9812643109be6c2b0ed5d8f8ce655a4a9.zip
em-format cleanups.
Diffstat (limited to 'em-format')
-rw-r--r--em-format/e-mail-formatter-attachment-bar.c25
-rw-r--r--em-format/e-mail-formatter-attachment.c80
-rw-r--r--em-format/e-mail-formatter-error.c2
-rw-r--r--em-format/e-mail-formatter-image.c11
-rw-r--r--em-format/e-mail-formatter-print-headers.c30
-rw-r--r--em-format/e-mail-formatter-print.c51
-rw-r--r--em-format/e-mail-formatter-quote-attachment.c2
-rw-r--r--em-format/e-mail-formatter-quote-headers.c3
-rw-r--r--em-format/e-mail-formatter-quote.c7
-rw-r--r--em-format/e-mail-formatter-secure-button.c1
-rw-r--r--em-format/e-mail-formatter-utils.c4
-rw-r--r--em-format/e-mail-formatter.c8
-rw-r--r--em-format/e-mail-parser-attachment-bar.c4
-rw-r--r--em-format/e-mail-parser-message-external.c19
-rw-r--r--em-format/e-mail-parser-multipart-digest.c7
-rw-r--r--em-format/e-mail-parser-multipart-mixed.c8
-rw-r--r--em-format/e-mail-parser-text-plain.c8
-rw-r--r--em-format/e-mail-parser.c23
-rw-r--r--em-format/e-mail-part-attachment-bar.h14
-rw-r--r--em-format/e-mail-part-attachment.h14
-rw-r--r--em-format/e-mail-part-list.c22
-rw-r--r--em-format/e-mail-part.c11
-rw-r--r--em-format/e-mail-part.h16
23 files changed, 216 insertions, 154 deletions
diff --git a/em-format/e-mail-formatter-attachment-bar.c b/em-format/e-mail-formatter-attachment-bar.c
index f91500ed1d..61c1509cd1 100644
--- a/em-format/e-mail-formatter-attachment-bar.c
+++ b/em-format/e-mail-formatter-attachment-bar.c
@@ -64,17 +64,8 @@ emfe_attachment_bar_format (EMailFormatterExtension *extension,
camel_stream_write_string (stream, str, cancellable, NULL);
g_free (str);
- return TRUE;
-}
-static void
-unset_bar_from_store_data (GObject *store,
- EAttachmentBar *bar)
-{
- /*
- if (E_IS_ATTACHMENT_STORE (store))
- g_object_set_data (store, "attachment-bar", NULL);
- */
+ return TRUE;
}
static GtkWidget *
@@ -83,17 +74,15 @@ emfe_attachment_bar_get_widget (EMailFormatterExtension *extension,
EMailPart *part,
GHashTable *params)
{
- EMailPartAttachmentBar *empab;
+ EAttachmentStore *store;
GtkWidget *widget;
- g_return_val_if_fail (E_MAIL_PART_IS (part, EMailPartAttachmentBar), NULL);
+ g_return_val_if_fail (E_IS_MAIL_PART_ATTACHMENT_BAR (part), NULL);
+
+ store = E_MAIL_PART_ATTACHMENT_BAR (part)->store;
- empab = (EMailPartAttachmentBar *) part;
- widget = e_attachment_bar_new (empab->store);
- g_object_set_data (G_OBJECT (empab->store), "attachment-bar", widget);
- g_object_weak_ref (
- G_OBJECT (widget),
- (GWeakNotify) unset_bar_from_store_data, empab->store);
+ widget = e_attachment_bar_new (store);
+ g_object_set_data (G_OBJECT (store), "attachment-bar", widget);
return widget;
}
diff --git a/em-format/e-mail-formatter-attachment.c b/em-format/e-mail-formatter-attachment.c
index 54647edd4a..08b0da2042 100644
--- a/em-format/e-mail-formatter-attachment.c
+++ b/em-format/e-mail-formatter-attachment.c
@@ -44,22 +44,25 @@ G_DEFINE_TYPE (
E_TYPE_MAIL_FORMATTER_EXTENSION)
static const gchar *formatter_mime_types[] = {
- "application/vnd.evolution.attachment",
+ E_MAIL_PART_ATTACHMENT_MIME_TYPE,
"application/vnd.evolution.widget.attachment-button",
NULL
};
static EAttachmentStore *
find_attachment_store (EMailPartList *part_list,
- const gchar *start_id)
+ EMailPart *start)
{
EAttachmentStore *store = NULL;
GQueue queue = G_QUEUE_INIT;
GList *head, *link;
+ const gchar *start_id;
gchar *tmp, *pos;
EMailPart *part;
gchar *id;
+ start_id = start->id;
+
e_mail_part_list_queue_parts (part_list, NULL, &queue);
head = g_queue_peek_head_link (&queue);
@@ -94,7 +97,7 @@ find_attachment_store (EMailPartList *part_list,
g_free (tmp);
if (part != NULL)
- store = ((EMailPartAttachmentBar *) part)->store;
+ store = E_MAIL_PART_ATTACHMENT_BAR (part)->store;
while (!g_queue_is_empty (&queue))
e_mail_part_unref (g_queue_pop_head (&queue));
@@ -117,17 +120,21 @@ emfe_attachment_format (EMailFormatterExtension *extension,
GQueue *extensions;
EMailPartAttachment *empa;
CamelMimeFilterToHTMLFlags flags;
- gchar *attachment_part_id;
+ const gchar *attachment_part_id;
- g_return_val_if_fail (E_MAIL_PART_IS (part, EMailPartAttachment), FALSE);
+ g_return_val_if_fail (E_IS_MAIL_PART_ATTACHMENT (part), FALSE);
empa = (EMailPartAttachment *) part;
if ((context->mode == E_MAIL_FORMATTER_MODE_NORMAL) ||
(context->mode == E_MAIL_FORMATTER_MODE_PRINTING) ||
(context->mode == E_MAIL_FORMATTER_MODE_ALL_HEADERS)) {
+ EAttachment *attachment;
GList *head, *link;
+ attachment = g_object_ref (
+ E_MAIL_PART_ATTACHMENT (part)->attachment);
+
head = g_queue_peek_head_link (&part->validities);
for (link = head; link != NULL; link = g_list_next (link)) {
@@ -138,43 +145,45 @@ emfe_attachment_format (EMailFormatterExtension *extension,
if ((pair->validity_type & E_MAIL_PART_VALIDITY_SIGNED) != 0)
e_attachment_set_signed (
- empa->attachment,
+ attachment,
pair->validity->sign.status);
if ((pair->validity_type & E_MAIL_PART_VALIDITY_ENCRYPTED) != 0)
e_attachment_set_encrypted (
- empa->attachment,
+ attachment,
pair->validity->encrypt.status);
}
- store = find_attachment_store (context->part_list, part->id);
+ store = find_attachment_store (context->part_list, part);
if (store) {
GList *attachments = e_attachment_store_get_attachments (store);
- if (!g_list_find (attachments, empa->attachment)) {
+ if (!g_list_find (attachments, attachment)) {
e_attachment_store_add_attachment (
- store, empa->attachment);
+ store, attachment);
}
g_list_free (attachments);
} else {
g_warning ("Failed to locate attachment-bar for %s", part->id);
}
+
+ g_object_unref (attachment);
}
- /* If the attachment is requested as RAW, then call the handler directly
- * and do not append any other code. */
+ /* If the attachment is requested as RAW, then call the
+ * handler directly and do not append any other code. */
if ((context->mode == E_MAIL_FORMATTER_MODE_RAW) ||
(context->mode == E_MAIL_FORMATTER_MODE_PRINTING)) {
- EMailExtensionRegistry *reg;
+ EMailExtensionRegistry *registry;
GQueue *extensions;
GList *iter;
- reg = e_mail_formatter_get_extension_registry (formatter);
+
+ registry = e_mail_formatter_get_extension_registry (formatter);
extensions = e_mail_extension_registry_get_for_mime_type (
- reg, empa->snoop_mime_type);
- if (!extensions) {
+ registry, empa->snoop_mime_type);
+ if (extensions == NULL)
extensions = e_mail_extension_registry_get_fallback (
- reg, empa->snoop_mime_type);
- }
+ registry, empa->snoop_mime_type);
if (!extensions)
return FALSE;
@@ -184,23 +193,29 @@ emfe_attachment_format (EMailFormatterExtension *extension,
EAttachment *attachment;
GFileInfo *fi;
const gchar *description;
+ const gchar *display_name;
+
+ attachment = g_object_ref (
+ E_MAIL_PART_ATTACHMENT (part)->attachment);
- attachment = empa->attachment;
fi = e_attachment_get_file_info (attachment);
+ display_name = g_file_info_get_display_name (fi);
description = e_attachment_get_description (attachment);
if (description && *description) {
name = g_strdup_printf (
"<h2>Attachment: %s (%s)</h2>\n",
- description, g_file_info_get_display_name (fi));
+ description, display_name);
} else {
name = g_strdup_printf (
"<h2>Attachment: %s</h2>\n",
- g_file_info_get_display_name (fi));
+ display_name);
}
camel_stream_write_string (stream, name, cancellable, NULL);
g_free (name);
+
+ g_object_unref (attachment);
}
for (iter = g_queue_peek_head_link (extensions); iter; iter = iter->next) {
@@ -343,28 +358,35 @@ emfe_attachment_get_widget (EMailFormatterExtension *extension,
EMailPart *part,
GHashTable *params)
{
- EMailPartAttachment *empa;
+ EAttachment *attachment;
EAttachmentStore *store;
EAttachmentView *view;
GtkWidget *widget;
- g_return_val_if_fail (E_MAIL_PART_IS (part, EMailPartAttachment), NULL);
- empa = (EMailPartAttachment *) part;
+ g_return_val_if_fail (E_IS_MAIL_PART_ATTACHMENT (part), NULL);
+
+ attachment = g_object_ref (
+ E_MAIL_PART_ATTACHMENT (part)->attachment);
- store = find_attachment_store (context, part->id);
+ store = find_attachment_store (context, part);
widget = e_attachment_button_new ();
- g_object_set_data (G_OBJECT (widget), "uri", part->id);
+ g_object_set_data_full (
+ G_OBJECT (widget),
+ "uri", g_strdup (part->id),
+ (GDestroyNotify) g_free);
e_attachment_button_set_attachment (
- E_ATTACHMENT_BUTTON (widget), empa->attachment);
+ E_ATTACHMENT_BUTTON (widget), attachment);
+
view = g_object_get_data (G_OBJECT (store), "attachment-bar");
- if (view) {
+ if (view != NULL)
e_attachment_button_set_view (
E_ATTACHMENT_BUTTON (widget), view);
- }
gtk_widget_set_can_focus (widget, TRUE);
gtk_widget_show (widget);
+ g_object_unref (attachment);
+
return widget;
}
diff --git a/em-format/e-mail-formatter-error.c b/em-format/e-mail-formatter-error.c
index d5fd64b50d..a329abfffd 100644
--- a/em-format/e-mail-formatter-error.c
+++ b/em-format/e-mail-formatter-error.c
@@ -54,7 +54,7 @@ emfe_error_format (EMailFormatterExtension *extension,
CamelDataWrapper *dw;
gchar *html;
- dw = camel_medium_get_content ((CamelMedium *) part->part);
+ dw = camel_medium_get_content (CAMEL_MEDIUM (part->part));
html = g_strdup_printf (
"<div class=\"part-container\" style=\""
diff --git a/em-format/e-mail-formatter-image.c b/em-format/e-mail-formatter-image.c
index 82c635827a..f69a59cdba 100644
--- a/em-format/e-mail-formatter-image.c
+++ b/em-format/e-mail-formatter-image.c
@@ -104,8 +104,8 @@ emfe_image_format (EMailFormatterExtension *extension,
}
} else {
-
gchar *buffer;
+ const gchar *mime_type;
if (!e_mail_formatter_get_animate_images (formatter)) {
@@ -121,11 +121,16 @@ emfe_image_format (EMailFormatterExtension *extension,
content = g_base64_encode ((guchar *) ba->data, ba->len);
}
+ mime_type = part->mime_type;
+ if (mime_type == NULL)
+ mime_type = "image/*";
+
/* The image is already base64-encrypted so we can directly
* paste it to the output */
buffer = g_strdup_printf (
- "<img src=\"data:%s;base64,%s\" style=\"max-width: 100%%;\" />",
- part->mime_type ? part->mime_type : "image/*", content);
+ "<img src=\"data:%s;base64,%s\" "
+ " style=\"max-width: 100%%;\" />",
+ mime_type, content);
camel_stream_write_string (stream, buffer, cancellable, NULL);
g_free (buffer);
diff --git a/em-format/e-mail-formatter-print-headers.c b/em-format/e-mail-formatter-print-headers.c
index 03d35c300c..b739d6ce96 100644
--- a/em-format/e-mail-formatter-print-headers.c
+++ b/em-format/e-mail-formatter-print-headers.c
@@ -87,7 +87,8 @@ emfpe_headers_format (EMailFormatterExtension *extension,
if (header->value && *header->value) {
raw_header.value = header->value;
- e_mail_formatter_format_header (formatter, str,
+ e_mail_formatter_format_header (
+ formatter, str,
CAMEL_MEDIUM (part->part), &raw_header,
header->flags | E_MAIL_FORMATTER_HEADER_FLAG_NOLINKS,
"UTF-8");
@@ -102,7 +103,8 @@ emfpe_headers_format (EMailFormatterExtension *extension,
raw_header.value = g_strdup (header_value);
if (raw_header.value && *raw_header.value) {
- e_mail_formatter_format_header (formatter, str,
+ e_mail_formatter_format_header (
+ formatter, str,
CAMEL_MEDIUM (part->part), &raw_header,
header->flags | E_MAIL_FORMATTER_HEADER_FLAG_NOLINKS,
"UTF-8");
@@ -115,7 +117,7 @@ emfpe_headers_format (EMailFormatterExtension *extension,
g_queue_free_full (headers_queue, (GDestroyNotify) e_mail_formatter_header_free);
- /* Get prefix of this PURI */
+ /* Get prefix of this PURI */
part_id_prefix = g_strndup (part->id, g_strrstr (part->id, ".") - part->id);
/* Add encryption/signature header */
@@ -164,7 +166,8 @@ emfpe_headers_format (EMailFormatterExtension *extension,
if (tmp->len > 0) {
raw_header.value = tmp->str;
e_mail_formatter_format_header (
- formatter, str, CAMEL_MEDIUM (part->part), &raw_header,
+ formatter, str,
+ CAMEL_MEDIUM (part->part), &raw_header,
E_MAIL_FORMATTER_HEADER_FLAG_BOLD |
E_MAIL_FORMATTER_HEADER_FLAG_NOLINKS, "UTF-8");
}
@@ -174,22 +177,29 @@ emfpe_headers_format (EMailFormatterExtension *extension,
attachments_count = 0;
for (link = head; link != NULL; link = g_list_next (link)) {
- EMailPart *mail_part = link->data;
+ EMailPart *mail_part = E_MAIL_PART (link->data);
if (!g_str_has_prefix (mail_part->id, part_id_prefix))
continue;
- if (mail_part->is_attachment && !mail_part->cid &&
- !mail_part->is_hidden) {
- attachments_count++;
- }
+ if (!mail_part->is_attachment)
+ continue;
+
+ if (mail_part->is_hidden)
+ continue;
+
+ if (mail_part->cid != NULL)
+ continue;
+
+ attachments_count++;
}
if (attachments_count > 0) {
raw_header.name = _("Attachments");
raw_header.value = g_strdup_printf ("%d", attachments_count);
e_mail_formatter_format_header (
- formatter, str, CAMEL_MEDIUM (part->part), &raw_header,
+ formatter, str,
+ CAMEL_MEDIUM (part->part), &raw_header,
E_MAIL_FORMATTER_HEADER_FLAG_BOLD |
E_MAIL_FORMATTER_HEADER_FLAG_NOLINKS, "UTF-8");
g_free (raw_header.value);
diff --git a/em-format/e-mail-formatter-print.c b/em-format/e-mail-formatter-print.c
index a2e19ed4bd..f73fc493cf 100644
--- a/em-format/e-mail-formatter-print.c
+++ b/em-format/e-mail-formatter-print.c
@@ -37,17 +37,12 @@ void e_mail_formatter_print_internal_extensions_load (EMailExtensionRegistry *er
static gpointer e_mail_formatter_print_parent_class = 0;
static void
-write_attachments_list (EMailFormatter *formatter,
- EMailFormatterContext *context,
- GSList *attachments,
- CamelStream *stream,
- GCancellable *cancellable)
+mail_formatter_print_write_attachments (EMailFormatter *formatter,
+ GQueue *attachments,
+ CamelStream *stream,
+ GCancellable *cancellable)
{
GString *str;
- GSList *link;
-
- if (attachments == NULL)
- return;
str = g_string_new (
"<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\" "
@@ -58,21 +53,22 @@ write_attachments_list (EMailFormatter *formatter,
"<tr><th>%s</th><th>%s</th></tr>\n",
_("Attachments"), _("Name"), _("Size"));
- for (link = attachments; link != NULL; link = g_slist_next (link)) {
- EMailPartAttachment *part = link->data;
+ while (!g_queue_is_empty (attachments)) {
+ EMailPartAttachment *part;
EAttachment *attachment;
GFileInfo *file_info;
gchar *name, *size;
const gchar *description;
const gchar *display_name;
- if (part == NULL)
- continue;
+ part = g_queue_pop_head (attachments);
+ attachment = g_object_ref (part->attachment);
- attachment = part->attachment;
file_info = e_attachment_get_file_info (attachment);
- if (file_info == NULL)
+ if (file_info == NULL) {
+ g_object_unref (attachment);
continue;
+ }
description = e_attachment_get_description (attachment);
display_name = g_file_info_get_display_name (file_info);
@@ -92,6 +88,8 @@ write_attachments_list (EMailFormatter *formatter,
g_free (name);
g_free (size);
+
+ g_object_unref (attachment);
}
g_string_append (str, "</table>\n");
@@ -108,8 +106,8 @@ mail_formatter_print_run (EMailFormatter *formatter,
GCancellable *cancellable)
{
GQueue queue = G_QUEUE_INIT;
+ GQueue attachments = G_QUEUE_INIT;
GList *head, *link;
- GSList *attachments;
context->mode = E_MAIL_FORMATTER_MODE_PRINTING;
@@ -126,14 +124,13 @@ mail_formatter_print_run (EMailFormatter *formatter,
"<body style=\"background: #FFF; color: #000;\">",
cancellable, NULL);
- attachments = NULL;
-
e_mail_part_list_queue_parts (context->part_list, NULL, &queue);
head = g_queue_peek_head_link (&queue);
for (link = head; link != NULL; link = g_list_next (link)) {
- EMailPart *part = link->data;
+ EMailPart *part = E_MAIL_PART (link->data);
+ const gchar *mime_type;
gboolean ok;
if (g_cancellable_is_cancelled (cancellable))
@@ -147,19 +144,20 @@ mail_formatter_print_run (EMailFormatter *formatter,
continue;
}
- if (part->mime_type == NULL)
+ mime_type = part->mime_type;
+ if (mime_type == NULL)
continue;
if (part->is_attachment) {
if (part->cid != NULL)
continue;
- attachments = g_slist_append (attachments, part);
+ g_queue_push_tail (&attachments, part);
}
ok = e_mail_formatter_format_as (
formatter, context, part, stream,
- part->mime_type, cancellable);
+ mime_type, cancellable);
/* If the written part was message/rfc822 then
* jump to the end of the message, because content
@@ -175,10 +173,11 @@ mail_formatter_print_run (EMailFormatter *formatter,
while (!g_queue_is_empty (&queue))
e_mail_part_unref (g_queue_pop_head (&queue));
- write_attachments_list (
- formatter, context, attachments, stream, cancellable);
-
- g_slist_free (attachments);
+ /* This consumes the attachments queue. */
+ if (!g_queue_is_empty (&attachments))
+ mail_formatter_print_write_attachments (
+ formatter, &attachments,
+ stream, cancellable);
camel_stream_write_string (stream, "</body></html>", cancellable, NULL);
}
diff --git a/em-format/e-mail-formatter-quote-attachment.c b/em-format/e-mail-formatter-quote-attachment.c
index fd44249819..6f5068bae1 100644
--- a/em-format/e-mail-formatter-quote-attachment.c
+++ b/em-format/e-mail-formatter-quote-attachment.c
@@ -43,7 +43,7 @@ G_DEFINE_TYPE (
E_TYPE_MAIL_FORMATTER_QUOTE_EXTENSION)
static const gchar *formatter_mime_types[] = {
- "application/vnd.evolution.attachment",
+ E_MAIL_PART_ATTACHMENT_MIME_TYPE,
NULL
};
diff --git a/em-format/e-mail-formatter-quote-headers.c b/em-format/e-mail-formatter-quote-headers.c
index ce4fd785fa..fa6c02752b 100644
--- a/em-format/e-mail-formatter-quote-headers.c
+++ b/em-format/e-mail-formatter-quote-headers.c
@@ -219,7 +219,8 @@ emqfe_headers_format (EMailFormatterExtension *extension,
if (g_strcmp0 (raw_header->name, h->name) == 0) {
emfqe_format_header (
- formatter, buffer, (CamelMedium *) part->part,
+ formatter, buffer,
+ (CamelMedium *) part->part,
raw_header, flags, charset);
break;
}
diff --git a/em-format/e-mail-formatter-quote.c b/em-format/e-mail-formatter-quote.c
index c8f83860ee..f810f231a7 100644
--- a/em-format/e-mail-formatter-quote.c
+++ b/em-format/e-mail-formatter-quote.c
@@ -103,7 +103,7 @@ mail_formatter_quote_run (EMailFormatter *formatter,
head = g_queue_peek_head_link (&queue);
for (link = head; link != NULL; link = g_list_next (link)) {
- EMailPart *part = link->data;
+ EMailPart *part = E_MAIL_PART (link->data);
if (g_str_has_suffix (part->id, ".headers") &&
!(qf_context->qf_flags & E_MAIL_FORMATTER_QUOTE_FLAG_HEADERS)) {
@@ -115,7 +115,10 @@ mail_formatter_quote_run (EMailFormatter *formatter,
continue;
}
- if (part->is_hidden || part->is_attachment)
+ if (part->is_hidden)
+ continue;
+
+ if (part->is_attachment)
continue;
e_mail_formatter_format_as (
diff --git a/em-format/e-mail-formatter-secure-button.c b/em-format/e-mail-formatter-secure-button.c
index 442a6d3e26..83e88d5752 100644
--- a/em-format/e-mail-formatter-secure-button.c
+++ b/em-format/e-mail-formatter-secure-button.c
@@ -93,6 +93,7 @@ emfe_secure_button_format (EMailFormatterExtension *extension,
camel_stream_write_string (stream, str, cancellable, NULL);
g_free (str);
+
return TRUE;
}
diff --git a/em-format/e-mail-formatter-utils.c b/em-format/e-mail-formatter-utils.c
index d5bff2ecd0..775ef1d6cc 100644
--- a/em-format/e-mail-formatter-utils.c
+++ b/em-format/e-mail-formatter-utils.c
@@ -474,13 +474,13 @@ e_mail_formatter_find_rfc822_end_iter (GList *rfc822_start_iter)
g_return_val_if_fail (rfc822_start_iter != NULL, NULL);
- part = (EMailPart *) link->data;
+ part = E_MAIL_PART (link->data);
g_return_val_if_fail (part != NULL, NULL);
end = g_strconcat (part->id, ".end", NULL);
while (link != NULL) {
- part = (EMailPart *) link->data;
+ part = E_MAIL_PART (link->data);
g_return_val_if_fail (part != NULL, NULL);
if (g_strcmp0 (part->id, end) == 0)
diff --git a/em-format/e-mail-formatter.c b/em-format/e-mail-formatter.c
index 4bc8dcd7fd..ad203d83ad 100644
--- a/em-format/e-mail-formatter.c
+++ b/em-format/e-mail-formatter.c
@@ -1035,16 +1035,18 @@ e_mail_formatter_format_text (EMailFormatter *formatter,
CamelMimeFilter *windows = NULL;
CamelStream *mem_stream = NULL;
CamelDataWrapper *dw;
+ CamelContentType *mime_type;
if (g_cancellable_is_cancelled (cancellable))
return;
dw = CAMEL_DATA_WRAPPER (part->part);
+ mime_type = dw->mime_type;
- if (formatter->priv->charset) {
+ if (formatter->priv->charset != NULL) {
charset = formatter->priv->charset;
- } else if (dw->mime_type
- && (charset = camel_content_type_param (dw->mime_type, "charset"))
+ } else if (mime_type != NULL
+ && (charset = camel_content_type_param (mime_type, "charset"))
&& g_ascii_strncasecmp (charset, "iso-8859-", 9) == 0) {
CamelStream *null;
diff --git a/em-format/e-mail-parser-attachment-bar.c b/em-format/e-mail-parser-attachment-bar.c
index 5e36b83b6f..1ceebe577c 100644
--- a/em-format/e-mail-parser-attachment-bar.c
+++ b/em-format/e-mail-parser-attachment-bar.c
@@ -49,7 +49,7 @@ G_DEFINE_TYPE (
E_TYPE_MAIL_PARSER_EXTENSION)
static const gchar *parser_mime_types[] = {
- "application/vnd.evolution.widget.attachment-bar",
+ E_MAIL_PART_ATTACHMENT_BAR_MIME_TYPE,
NULL
};
@@ -69,7 +69,7 @@ empe_attachment_bar_parse (EMailParserExtension *extension,
empab = (EMailPartAttachmentBar *) e_mail_part_subclass_new (
part, part_id->str, sizeof (EMailPartAttachmentBar),
(GFreeFunc) mail_part_attachment_bar_free);
- empab->parent.mime_type = g_strdup ("application/vnd.evolution.widget.attachment-bar");
+ empab->parent.mime_type = g_strdup (parser_mime_types[0]);
empab->store = E_ATTACHMENT_STORE (e_attachment_store_new ());
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 32ba0515dd..1868796884 100644
--- a/em-format/e-mail-parser-message-external.c
+++ b/em-format/e-mail-parser-message-external.c
@@ -55,10 +55,10 @@ empe_msg_external_parse (EMailParserExtension *extension,
CamelMimePart *newpart;
CamelContentType *type;
const gchar *access_type;
+ const gchar *mime_type;
gchar *url = NULL, *desc = NULL;
gchar *content;
gint len;
- gchar *mime_type;
newpart = camel_mime_part_new ();
@@ -67,8 +67,9 @@ empe_msg_external_parse (EMailParserExtension *extension,
access_type = camel_content_type_param (type, "access-type");
if (!access_type) {
const gchar *msg = _("Malformed external-body part");
- mime_type = g_strdup ("text/plain");
- camel_mime_part_set_content (newpart, msg, strlen (msg), mime_type);
+ mime_type = "text/plain";
+ camel_mime_part_set_content (
+ newpart, msg, strlen (msg), mime_type);
goto addPart;
}
@@ -135,9 +136,10 @@ empe_msg_external_parse (EMailParserExtension *extension,
goto fail;
}
- mime_type = g_strdup ("text/html");
+ mime_type = "text/html";
content = g_strdup_printf ("<a href=\"%s\">%s</a>", url, desc);
- camel_mime_part_set_content (newpart, content, strlen (content), mime_type);
+ camel_mime_part_set_content (
+ newpart, content, strlen (content), mime_type);
g_free (content);
g_free (url);
@@ -149,15 +151,16 @@ fail:
content = g_strdup_printf (
_("Pointer to unknown external data (\"%s\" type)"),
access_type);
- mime_type = g_strdup ("text/plain");
- camel_mime_part_set_content (newpart, content, strlen (content), mime_type);
+ mime_type = "text/plain";
+ camel_mime_part_set_content (
+ newpart, content, strlen (content), mime_type);
g_free (content);
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 = mime_type;
+ mail_part->mime_type = g_strdup (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-multipart-digest.c b/em-format/e-mail-parser-multipart-digest.c
index 5d33103b1e..8cf80be00f 100644
--- a/em-format/e-mail-parser-multipart-digest.c
+++ b/em-format/e-mail-parser-multipart-digest.c
@@ -88,6 +88,7 @@ empe_mp_digest_parse (EMailParserExtension *extension,
} else {
GQueue work_queue = G_QUEUE_INIT;
EMailPart *mail_part;
+ gboolean wrap_as_attachment;
e_mail_parser_parse_part_as (
parser, subpart, part_id, "message/rfc822",
@@ -95,8 +96,12 @@ empe_mp_digest_parse (EMailParserExtension *extension,
mail_part = g_queue_peek_head (&work_queue);
+ wrap_as_attachment =
+ (mail_part != NULL) &&
+ !mail_part->is_attachment;
+
/* Force the message to be collapsable */
- if (mail_part != NULL && !mail_part->is_attachment)
+ if (wrap_as_attachment)
e_mail_parser_wrap_as_attachment (
parser, subpart, part_id, &work_queue);
diff --git a/em-format/e-mail-parser-multipart-mixed.c b/em-format/e-mail-parser-multipart-mixed.c
index 1d14fced68..5b8f9c1d7f 100644
--- a/em-format/e-mail-parser-multipart-mixed.c
+++ b/em-format/e-mail-parser-multipart-mixed.c
@@ -89,15 +89,17 @@ empe_mp_mixed_parse (EMailParserExtension *extension,
* not multipart/related. */
if (mail_part != NULL &&
mail_part->cid != NULL &&
- (!mail_part->is_attachment || mail_part->is_hidden)) {
+ (!mail_part->is_attachment ||
+ mail_part->is_hidden)) {
e_mail_parser_wrap_as_attachment (
parser, subpart, part_id, &work_queue);
- /* Force messages to be expandable */
+ /* Force messages to be expandable */
} else if (mail_part == NULL ||
(camel_content_type_is (ct, "message", "rfc822") &&
- mail_part != NULL && !mail_part->is_attachment)) {
+ mail_part != NULL &&
+ !mail_part->is_attachment)) {
e_mail_parser_wrap_as_attachment (
parser, subpart, part_id, &work_queue);
diff --git a/em-format/e-mail-parser-text-plain.c b/em-format/e-mail-parser-text-plain.c
index b6cd0ec6ca..24b4b24344 100644
--- a/em-format/e-mail-parser-text-plain.c
+++ b/em-format/e-mail-parser-text-plain.c
@@ -78,7 +78,7 @@ process_part (EMailParser *parser,
GQueue *out_mail_parts)
{
CamelContentType *type;
- EMailPart *empart;
+ EMailPart *mail_part;
gint s_len = part_id->len;
if (part_is_empty (part))
@@ -95,12 +95,12 @@ process_part (EMailParser *parser,
g_string_append_printf (part_id, ".plain_text.%d", part_number);
- empart = e_mail_part_new (part, part_id->str);
- empart->mime_type = camel_content_type_simple (type);
+ mail_part = e_mail_part_new (part, part_id->str);
+ mail_part->mime_type = camel_content_type_simple (type);
g_string_truncate (part_id, s_len);
- g_queue_push_tail (&work_queue, empart);
+ g_queue_push_tail (&work_queue, mail_part);
if (is_attachment)
e_mail_parser_wrap_as_attachment (
diff --git a/em-format/e-mail-parser.c b/em-format/e-mail-parser.c
index 294b058766..174d88ca69 100644
--- a/em-format/e-mail-parser.c
+++ b/em-format/e-mail-parser.c
@@ -356,12 +356,16 @@ e_mail_parser_parse_sync (EMailParser *parser,
e_mail_part_list_queue_parts (part_list, NULL, &queue);
while (!g_queue_is_empty (&queue)) {
- EMailPart *part = g_queue_pop_head (&queue);
+ EMailPart *part;
+
+ part = g_queue_pop_head (&queue);
printf (
" id: %s | cid: %s | mime_type: %s | "
"is_hidden: %d | is_attachment: %d\n",
- part->id, part->cid, part->mime_type,
+ part->id,
+ part->cid,
+ part->mime_type,
part->is_hidden ? 1 : 0,
part->is_attachment ? 1 : 0);
@@ -456,12 +460,16 @@ e_mail_parser_parse_finish (EMailParser *parser,
e_mail_part_list_queue_parts (part_list, NULL, &queue);
while (!g_queue_is_empty (&queue)) {
- EMailPart *part = g_queue_pop_head (&queue);
+ EMailPart *part;
+
+ part = g_queue_pop_head (&queue);
printf (
" id: %s | cid: %s | mime_type: %s | "
"is_hidden: %d | is_attachment: %d\n",
- part->id, part->cid, part->mime_type,
+ part->id,
+ part->cid,
+ part->mime_type,
part->is_hidden ? 1 : 0,
part->is_attachment ? 1 : 0);
@@ -567,6 +575,7 @@ e_mail_parser_error (EMailParser *parser,
const gchar *format,
...)
{
+ const gchar *mime_type = "application/vnd.evolution.error";
EMailPart *mail_part;
CamelMimePart *part;
gchar *errmsg;
@@ -582,9 +591,7 @@ e_mail_parser_error (EMailParser *parser,
part = camel_mime_part_new ();
camel_mime_part_set_content (
- part,
- errmsg, strlen (errmsg),
- "application/vnd.evolution.error");
+ part, errmsg, strlen (errmsg), mime_type);
g_free (errmsg);
va_end (ap);
@@ -594,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 ("application/vnd.evolution.error");
+ mail_part->mime_type = g_strdup (mime_type);
mail_part->is_error = TRUE;
g_free (uri);
diff --git a/em-format/e-mail-part-attachment-bar.h b/em-format/e-mail-part-attachment-bar.h
index 87b6311b5d..38e644f801 100644
--- a/em-format/e-mail-part-attachment-bar.h
+++ b/em-format/e-mail-part-attachment-bar.h
@@ -1,4 +1,6 @@
/*
+ * e-mail-part-attachment-bar.h
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
@@ -17,12 +19,16 @@
#ifndef E_MAIL_PART_ATTACHMENT_BAR_H
#define E_MAIL_PART_ATTACHMENT_BAR_H
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
#include <em-format/e-mail-part.h>
+#define E_MAIL_PART_ATTACHMENT_BAR(part) \
+ ((EMailPartAttachmentBar *) part)
+#define E_IS_MAIL_PART_ATTACHMENT_BAR(part) \
+ (E_MAIL_PART_IS (part, EMailPartAttachmentBar))
+
+#define E_MAIL_PART_ATTACHMENT_BAR_MIME_TYPE \
+ "application/vnd.evolution.widget.attachment-bar"
+
typedef struct _EMailPartAttachmentBar {
EMailPart parent;
diff --git a/em-format/e-mail-part-attachment.h b/em-format/e-mail-part-attachment.h
index cd07e3634b..d44c599e4c 100644
--- a/em-format/e-mail-part-attachment.h
+++ b/em-format/e-mail-part-attachment.h
@@ -1,4 +1,6 @@
/*
+ * e-mail-part-attachment.h
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
@@ -17,13 +19,15 @@
#ifndef E_MAIL_PART_ATTACHMENT_H
#define E_MAIL_PART_ATTACHMENT_H
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
#include <em-format/e-mail-part.h>
-#define E_MAIL_PART_ATTACHMENT(p) ((EMailPartAttachment *) p)
+#define E_MAIL_PART_ATTACHMENT(part) \
+ ((EMailPartAttachment *) part)
+#define E_IS_MAIL_PART_ATTACHMENT(part) \
+ (E_MAIL_PART_IS (part, EMailPartAttachment))
+
+#define E_MAIL_PART_ATTACHMENT_MIME_TYPE \
+ "application/vnd.evolution.attachment"
G_BEGIN_DECLS
diff --git a/em-format/e-mail-part-list.c b/em-format/e-mail-part-list.c
index 641a88c947..e6ccc5733b 100644
--- a/em-format/e-mail-part-list.c
+++ b/em-format/e-mail-part-list.c
@@ -318,15 +318,16 @@ e_mail_part_list_ref_part (EMailPartList *part_list,
head = g_queue_peek_head_link (&part_list->priv->queue);
for (link = head; link != NULL; link = g_list_next (link)) {
- EMailPart *part = link->data;
+ EMailPart *candidate = E_MAIL_PART (link->data);
+ const gchar *candidate_id;
- if (by_cid && (g_strcmp0 (part->cid, part_id) == 0)) {
- match = e_mail_part_ref (part);
- break;
- }
+ if (by_cid)
+ candidate_id = candidate->cid;
+ else
+ candidate_id = candidate->id;
- if (!by_cid && (g_strcmp0 (part->id, part_id) == 0)) {
- match = e_mail_part_ref (part);
+ if (g_strcmp0 (candidate_id, part_id) == 0) {
+ match = e_mail_part_ref (candidate);
break;
}
}
@@ -368,9 +369,12 @@ e_mail_part_list_queue_parts (EMailPartList *part_list,
if (part_id != NULL) {
for (; link != NULL; link = g_list_next (link)) {
- EMailPart *part = link->data;
+ EMailPart *candidate = E_MAIL_PART (link->data);
+ const gchar *candidate_id;
+
+ candidate_id = candidate->id;
- if (g_strcmp0 (part->id, part_id) == 0)
+ if (g_strcmp0 (candidate_id, part_id) == 0)
break;
}
}
diff --git a/em-format/e-mail-part.c b/em-format/e-mail-part.c
index 9e280e07bf..5b39e0a8f5 100644
--- a/em-format/e-mail-part.c
+++ b/em-format/e-mail-part.c
@@ -16,10 +16,6 @@
*
*/
-#include <camel/camel.h>
-
-#include "e-mail-part.h"
-
/**
* EMailPart:
*
@@ -28,10 +24,13 @@
*
* #EMailPart is not GObject-based, but has a simple reference counting.
*
- * Each #EMailPart must have a unique ID. The ID is a dot-separated hierarchical
- * description of the location of the part within the email message.
+ * Each #EMailPart must have a unique ID. The ID is a dot-separated
+ * hierarchical description of the location of the part within the email
+ * message.
*/
+#include "e-mail-part.h"
+
struct _EMailPartPrivate {
guint ref_cnt;
gsize instance_size;
diff --git a/em-format/e-mail-part.h b/em-format/e-mail-part.h
index 3d59d46087..9131e7fbdb 100644
--- a/em-format/e-mail-part.h
+++ b/em-format/e-mail-part.h
@@ -16,8 +16,8 @@
*
*/
-#ifndef E_MAIL_PART_H_
-#define E_MAIL_PART_H_
+#ifndef E_MAIL_PART_H
+#define E_MAIL_PART_H
#include <camel/camel.h>
#include <webkit/webkitdom.h>
@@ -37,11 +37,11 @@ typedef void (*EMailPartDOMBindFunc) (EMailPart *part,
WebKitDOMElement *element);
typedef enum {
- E_MAIL_PART_VALIDITY_NONE = 0,
- E_MAIL_PART_VALIDITY_PGP = 1 << 0,
- E_MAIL_PART_VALIDITY_SMIME = 1 << 1,
- E_MAIL_PART_VALIDITY_SIGNED = 1 << 2,
- E_MAIL_PART_VALIDITY_ENCRYPTED = 1 << 3
+ E_MAIL_PART_VALIDITY_NONE = 0,
+ E_MAIL_PART_VALIDITY_PGP = 1 << 0,
+ E_MAIL_PART_VALIDITY_SMIME = 1 << 1,
+ E_MAIL_PART_VALIDITY_SIGNED = 1 << 2,
+ E_MAIL_PART_VALIDITY_ENCRYPTED = 1 << 3
} EMailPartValidityFlags;
typedef struct _EMailPartValidityPair EMailPartValidityPair;
@@ -104,4 +104,4 @@ CamelCipherValidity *
G_END_DECLS
-#endif /* E_MAIL_PART_H_ */
+#endif /* E_MAIL_PART_H */