aboutsummaryrefslogtreecommitdiffstats
path: root/em-format
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2012-12-05 05:45:44 +0800
committerMatthew Barnes <mbarnes@redhat.com>2012-12-08 03:01:04 +0800
commit2f0d83cf74b94d5e6272c07179df6e6c7a929789 (patch)
treecf6b432d7992770ac8841f242cb487c2ac31a7fc /em-format
parent13f4544dafe211a748b064b86a8af4085d042b2b (diff)
downloadgsoc2013-evolution-2f0d83cf74b94d5e6272c07179df6e6c7a929789.tar.gz
gsoc2013-evolution-2f0d83cf74b94d5e6272c07179df6e6c7a929789.tar.zst
gsoc2013-evolution-2f0d83cf74b94d5e6272c07179df6e6c7a929789.zip
EMailFormatterContext: Keep a reference to EMailPartList.
Replace the individual components of an EMailPartList with a reference on the EMailPartList itself in EMailFormatContext. Easier to manage.
Diffstat (limited to 'em-format')
-rw-r--r--em-format/e-mail-formatter-attachment.c6
-rw-r--r--em-format/e-mail-formatter-message-rfc822.c16
-rw-r--r--em-format/e-mail-formatter-print-headers.c14
-rw-r--r--em-format/e-mail-formatter-print.c20
-rw-r--r--em-format/e-mail-formatter-quote-attachment.c2
-rw-r--r--em-format/e-mail-formatter-quote-message-rfc822.c2
-rw-r--r--em-format/e-mail-formatter-quote.c24
-rw-r--r--em-format/e-mail-formatter-text-html.c12
-rw-r--r--em-format/e-mail-formatter-text-plain.c7
-rw-r--r--em-format/e-mail-formatter.c74
-rw-r--r--em-format/e-mail-formatter.h6
11 files changed, 98 insertions, 85 deletions
diff --git a/em-format/e-mail-formatter-attachment.c b/em-format/e-mail-formatter-attachment.c
index 62fa65e597..e8660fc0b8 100644
--- a/em-format/e-mail-formatter-attachment.c
+++ b/em-format/e-mail-formatter-attachment.c
@@ -157,7 +157,7 @@ emfe_attachment_format (EMailFormatterExtension *extension,
}
}
- store = find_attachment_store (context->parts, part->id);
+ store = find_attachment_store (context->part_list->list, part->id);
if (store) {
GList *attachments = e_attachment_store_get_attachments (store);
if (!g_list_find (attachments, empa->attachment)) {
@@ -281,8 +281,8 @@ emfe_attachment_format (EMailFormatterExtension *extension,
GSList *att_parts;
att_parts = e_mail_part_list_get_iter (
- context->parts,
- empa->attachment_view_part_id);
+ context->part_list->list,
+ empa->attachment_view_part_id);
if (att_parts && att_parts->data) {
ok = e_mail_formatter_format_as (
diff --git a/em-format/e-mail-formatter-message-rfc822.c b/em-format/e-mail-formatter-message-rfc822.c
index 50e3a7bec7..78dfe3f45d 100644
--- a/em-format/e-mail-formatter-message-rfc822.c
+++ b/em-format/e-mail-formatter-message-rfc822.c
@@ -84,7 +84,8 @@ emfe_message_rfc822_format (EMailFormatterExtension *extension,
/* Print content of the message normally */
context->mode = E_MAIL_FORMATTER_MODE_NORMAL;
- iter = e_mail_part_list_get_iter (context->parts, part->id);
+ iter = e_mail_part_list_get_iter (
+ context->part_list->list, part->id);
end = g_strconcat (part->id, ".end", NULL);
for (iter = g_slist_next (iter); iter; iter = g_slist_next (iter)) {
@@ -136,7 +137,8 @@ emfe_message_rfc822_format (EMailFormatterExtension *extension,
gchar *end;
/* Part is EMailPartAttachment */
- iter = e_mail_part_list_get_iter (context->parts, part->id);
+ iter = e_mail_part_list_get_iter (
+ context->part_list->list, part->id);
iter = g_slist_next (iter);
if (!iter || !iter->next || !iter->data)
@@ -189,20 +191,26 @@ emfe_message_rfc822_format (EMailFormatterExtension *extension,
g_free (end);
} else {
+ CamelFolder *folder;
+ const gchar *message_uid;
gchar *str;
gchar *uri;
EMailPart *p;
GSList *iter;
- iter = e_mail_part_list_get_iter (context->parts, part->id);
+ iter = e_mail_part_list_get_iter (
+ context->part_list->list, part->id);
if (!iter || !iter->next)
return FALSE;
p = iter->data;
+ folder = context->part_list->folder;
+ message_uid = context->part_list->message_uid;
+
uri = e_mail_part_build_uri (
- context->folder, context->message_uid,
+ folder, message_uid,
"part_id", G_TYPE_STRING, p->id,
"mode", G_TYPE_INT, E_MAIL_FORMATTER_MODE_RAW,
"headers_collapsable", G_TYPE_INT, 0,
diff --git a/em-format/e-mail-formatter-print-headers.c b/em-format/e-mail-formatter-print-headers.c
index a16264b9bf..8cda0e598f 100644
--- a/em-format/e-mail-formatter-print-headers.c
+++ b/em-format/e-mail-formatter-print-headers.c
@@ -108,8 +108,14 @@ emfpe_headers_format (EMailFormatterExtension *extension,
header->flags | E_MAIL_FORMATTER_HEADER_FLAG_NOLINKS,
"UTF-8");
} else {
- raw_header.value = g_strdup (camel_medium_get_header (
- CAMEL_MEDIUM (context->message), header->name));
+ CamelMimeMessage *message;
+ const gchar *header_value;
+
+ message = context->part_list->message;
+
+ header_value = camel_medium_get_header (
+ CAMEL_MEDIUM (message), header->name);
+ raw_header.value = g_strdup (header_value);
if (raw_header.value && *raw_header.value) {
e_mail_formatter_format_header (formatter, str,
@@ -130,7 +136,7 @@ emfpe_headers_format (EMailFormatterExtension *extension,
raw_header.name = _("Security");
tmp = g_string_new ("");
/* Find first secured part. */
- for (parts_iter = context->parts; parts_iter; parts_iter = parts_iter->next) {
+ for (parts_iter = context->part_list->list; parts_iter; parts_iter = parts_iter->next) {
EMailPart *mail_part = parts_iter->data;
if (mail_part == NULL)
@@ -179,7 +185,7 @@ emfpe_headers_format (EMailFormatterExtension *extension,
/* Count attachments and display the number as a header */
attachments_count = 0;
- for (parts_iter = context->parts; parts_iter; parts_iter = parts_iter->next) {
+ for (parts_iter = context->part_list->list; parts_iter; parts_iter = parts_iter->next) {
EMailPart *mail_part = parts_iter->data;
if (!mail_part)
diff --git a/em-format/e-mail-formatter-print.c b/em-format/e-mail-formatter-print.c
index 1ca3bbae7f..9a57c1f6b5 100644
--- a/em-format/e-mail-formatter-print.c
+++ b/em-format/e-mail-formatter-print.c
@@ -39,7 +39,7 @@ write_attachments_list (EMailFormatter *formatter,
GCancellable *cancellable)
{
GString *str;
- GSList *iter;
+ GSList *link;
if (!attachments)
return;
@@ -53,8 +53,8 @@ write_attachments_list (EMailFormatter *formatter,
"<tr><th>%s</th><th>%s</th></tr>\n",
_("Attachments"), _("Name"), _("Size"));
- for (iter = attachments; iter; iter = iter->next) {
- EMailPartAttachment *part = iter->data;
+ for (link = attachments; link != NULL; link = g_slist_next (link)) {
+ EMailPartAttachment *part = link->data;
EAttachment *attachment;
GFileInfo *fi;
gchar *name, *size;
@@ -99,7 +99,7 @@ mail_formatter_print_run (EMailFormatter *formatter,
CamelStream *stream,
GCancellable *cancellable)
{
- GSList *iter;
+ GSList *list, *link;
GSList *attachments;
context->mode = E_MAIL_FORMATTER_MODE_PRINTING;
@@ -116,21 +116,21 @@ mail_formatter_print_run (EMailFormatter *formatter,
cancellable, NULL);
attachments = NULL;
- for (iter = context->parts; iter; iter = g_slist_next (iter)) {
+ list = context->part_list->list;
- EMailPart *part;
+ for (link = list; link != NULL ; link = g_slist_next (link)) {
+ EMailPart *part = link->data;
gboolean ok;
if (g_cancellable_is_cancelled (cancellable))
break;
- part = iter->data;
- if (!part)
+ if (part == NULL)
continue;
if (part->is_hidden && !part->is_error) {
if (g_str_has_suffix (part->id, ".rfc822")) {
- iter = e_mail_formatter_find_rfc822_end_iter (iter);
+ link = e_mail_formatter_find_rfc822_end_iter (link);
}
continue;
@@ -155,7 +155,7 @@ mail_formatter_print_run (EMailFormatter *formatter,
* of the whole message has been formatted by
* message_rfc822 formatter */
if (ok && g_str_has_suffix (part->id, ".rfc822")) {
- iter = e_mail_formatter_find_rfc822_end_iter (iter);
+ link = e_mail_formatter_find_rfc822_end_iter (link);
continue;
}
diff --git a/em-format/e-mail-formatter-quote-attachment.c b/em-format/e-mail-formatter-quote-attachment.c
index 82f10239cb..5f88d97bff 100644
--- a/em-format/e-mail-formatter-quote-attachment.c
+++ b/em-format/e-mail-formatter-quote-attachment.c
@@ -80,7 +80,7 @@ emfqe_attachment_format (EMailFormatterExtension *extension,
return FALSE;
iter = e_mail_part_list_get_iter (
- context->parts, empa->attachment_view_part_id);
+ context->part_list->list, empa->attachment_view_part_id);
if (!iter || !iter->data)
return FALSE;
diff --git a/em-format/e-mail-formatter-quote-message-rfc822.c b/em-format/e-mail-formatter-quote-message-rfc822.c
index ae2433f08c..037b5b4b71 100644
--- a/em-format/e-mail-formatter-quote-message-rfc822.c
+++ b/em-format/e-mail-formatter-quote-message-rfc822.c
@@ -81,7 +81,7 @@ emfqe_message_rfc822_format (EMailFormatterExtension *extension,
camel_stream_write_string (stream, header, cancellable, NULL);
g_free (header);
- iter = e_mail_part_list_get_iter (context->parts, part->id);
+ iter = e_mail_part_list_get_iter (context->part_list->list, part->id);
if (!iter) {
return FALSE;
}
diff --git a/em-format/e-mail-formatter-quote.c b/em-format/e-mail-formatter-quote.c
index a86dad06af..fcd2a06b48 100644
--- a/em-format/e-mail-formatter-quote.c
+++ b/em-format/e-mail-formatter-quote.c
@@ -50,7 +50,7 @@ mail_formatter_quote_run (EMailFormatter *formatter,
EMailFormatterQuote *qf;
EMailFormatterQuoteContext *qf_context;
GSettings *settings;
- GSList *iter;
+ GSList *list, *link;
if (g_cancellable_is_cancelled (cancellable))
return;
@@ -87,8 +87,10 @@ mail_formatter_quote_run (EMailFormatter *formatter,
"<blockquote type=cite>\n", cancellable, NULL);
}
- for (iter = context->parts; iter; iter = g_slist_next (iter)) {
- EMailPart *part = iter->data;
+ list = context->part_list->list;
+
+ for (link = list; link != NULL; link = g_slist_next (link)) {
+ EMailPart *part = link->data;
if (!part)
continue;
@@ -101,23 +103,21 @@ mail_formatter_quote_run (EMailFormatter *formatter,
if (g_str_has_suffix (part->id, ".rfc822")) {
gchar *end = g_strconcat (part->id, ".end", NULL);
- while (iter) {
- EMailPart *p = iter->data;
- if (!p) {
- iter = g_slist_next (iter);
- if (!iter) {
+ while (link != NULL) {
+ EMailPart *p = link->data;
+ if (p == NULL) {
+ link = g_slist_next (link);
+ if (link == NULL)
break;
- }
continue;
}
if (g_strcmp0 (p->id, end) == 0)
break;
- iter = g_slist_next (iter);
- if (!iter) {
+ link = g_slist_next (link);
+ if (link == NULL)
break;
- }
}
g_free (end);
diff --git a/em-format/e-mail-formatter-text-html.c b/em-format/e-mail-formatter-text-html.c
index 8b23a1897e..2b6fccd127 100644
--- a/em-format/e-mail-formatter-text-html.c
+++ b/em-format/e-mail-formatter-text-html.c
@@ -238,10 +238,7 @@ emfe_text_html_format (EMailFormatterExtension *extension,
* that WebKit can handle it */
if (!valid) {
EMailFormatterContext c = {
- .folder = context->folder,
- .message = context->message,
- .message_uid = context->message_uid,
- .parts = context->parts,
+ .part_list = context->part_list,
.flags = context->flags,
.mode = E_MAIL_FORMATTER_MODE_RAW,
};
@@ -311,10 +308,15 @@ emfe_text_html_format (EMailFormatterExtension *extension,
g_string_free (string, TRUE);
} else {
+ CamelFolder *folder;
+ const gchar *message_uid;
gchar *uri, *str;
+ folder = context->part_list->folder;
+ message_uid = context->part_list->message_uid;
+
uri = e_mail_part_build_uri (
- context->folder, context->message_uid,
+ folder, message_uid,
"part_id", G_TYPE_STRING, part->id,
"mode", G_TYPE_INT, E_MAIL_FORMATTER_MODE_RAW,
NULL);
diff --git a/em-format/e-mail-formatter-text-plain.c b/em-format/e-mail-formatter-text-plain.c
index 40b9358aa4..74e7f2dc3b 100644
--- a/em-format/e-mail-formatter-text-plain.c
+++ b/em-format/e-mail-formatter-text-plain.c
@@ -146,10 +146,15 @@ emfe_text_plain_format (EMailFormatterExtension *extension,
return TRUE;
} else {
+ CamelFolder *folder;
+ const gchar *message_uid;
gchar *uri, *str;
+ folder = context->part_list->folder;
+ message_uid = context->part_list->message_uid;
+
uri = e_mail_part_build_uri (
- context->folder, context->message_uid,
+ folder, message_uid,
"part_id", G_TYPE_STRING, part->id,
"mode", G_TYPE_INT, E_MAIL_FORMATTER_MODE_RAW,
NULL);
diff --git a/em-format/e-mail-formatter.c b/em-format/e-mail-formatter.c
index ad69c4b1dd..f878841836 100644
--- a/em-format/e-mail-formatter.c
+++ b/em-format/e-mail-formatter.c
@@ -80,21 +80,32 @@ enum {
static gint signals[LAST_SIGNAL];
static EMailFormatterContext *
-mail_formatter_create_context (EMailFormatter *formatter)
+mail_formatter_create_context (EMailFormatter *formatter,
+ EMailPartList *part_list,
+ EMailFormatterMode mode,
+ guint32 flags)
{
EMailFormatterClass *class;
+ EMailFormatterContext *context;
class = E_MAIL_FORMATTER_GET_CLASS (formatter);
g_warn_if_fail (class->context_size >= sizeof (EMailFormatterContext));
- return g_malloc0 (class->context_size);
+ context = g_malloc0 (class->context_size);
+ context->part_list = g_object_ref (part_list);
+ context->mode = mode;
+ context->flags = flags;
+
+ return context;
}
static void
-mail_formatter_free_context (EMailFormatter *formatter,
- EMailFormatterContext *context)
+mail_formatter_free_context (EMailFormatterContext *context)
{
+ if (context->part_list != NULL)
+ g_object_unref (context->part_list);
+
g_free (context);
}
@@ -355,31 +366,32 @@ mail_formatter_run (EMailFormatter *formatter,
CamelStream *stream,
GCancellable *cancellable)
{
- GSList *iter;
+ GSList *list, *link;
gchar *hdr;
hdr = e_mail_formatter_get_html_header (formatter);
camel_stream_write_string (stream, hdr, cancellable, NULL);
g_free (hdr);
- for (iter = context->parts; iter; iter = iter->next) {
+ list = context->part_list->list;
- EMailPart *part;
+ for (link = list; link != NULL; link = g_slist_next (link)) {
+
+ EMailPart *part = link->data;
gboolean ok;
if (g_cancellable_is_cancelled (cancellable))
break;
- part = iter->data;
- if (!part)
+ if (part == NULL)
continue;
if (part->is_hidden && !part->is_error) {
if (g_str_has_suffix (part->id, ".rfc822")) {
- iter = e_mail_formatter_find_rfc822_end_iter (iter);
+ link = e_mail_formatter_find_rfc822_end_iter (link);
}
- if (!iter)
+ if (link == NULL)
break;
continue;
@@ -400,9 +412,9 @@ mail_formatter_run (EMailFormatter *formatter,
* of the whole message has been formatted by
* message_rfc822 formatter */
if (ok && g_str_has_suffix (part->id, ".rfc822")) {
- iter = e_mail_formatter_find_rfc822_end_iter (iter);
+ link = e_mail_formatter_find_rfc822_end_iter (link);
- if (!iter)
+ if (link == NULL)
break;
continue;
@@ -433,14 +445,14 @@ mail_formatter_run (EMailFormatter *formatter,
if (g_str_has_suffix (part->id, ".rfc822")) {
do {
- part = iter->data;
+ part = link->data;
if (part && g_str_has_suffix (part->id, ".rfc822.end"))
break;
- iter = iter->next;
- } while (iter);
+ link = g_slist_next (link);
+ } while (link != NULL);
- if (!iter)
+ if (link == NULL)
break;
}
}
@@ -771,18 +783,13 @@ e_mail_formatter_format_sync (EMailFormatter *formatter,
formatter_class = E_MAIL_FORMATTER_GET_CLASS (formatter);
g_return_if_fail (formatter_class->run != NULL);
- context = mail_formatter_create_context (formatter);
- context->message = parts->message;
- context->folder = parts->folder;
- context->message_uid = parts->message_uid;
- context->parts = parts->list;
- context->flags = flags;
- context->mode = mode;
+ context = mail_formatter_create_context (
+ formatter, parts, mode, flags);
formatter_class->run (
formatter, context, stream, cancellable);
- mail_formatter_free_context (formatter, context);
+ mail_formatter_free_context (context);
}
static void
@@ -835,14 +842,8 @@ e_mail_formatter_format (EMailFormatter *formatter,
return;
}
- context = mail_formatter_create_context (formatter);
- context->message = g_object_ref (parts->message);
- context->folder = g_object_ref (parts->folder);
- context->message_uid = g_strdup (parts->message_uid);
- context->parts = g_slist_copy (parts->list);
- g_slist_foreach (context->parts, (GFunc) e_mail_part_ref, NULL);
- context->flags = flags;
- context->mode = mode;
+ context = mail_formatter_create_context (
+ formatter, parts, mode, flags);
g_object_set_data (G_OBJECT (simple), "context", context);
g_object_set_data (G_OBJECT (simple), "stream", stream);
@@ -866,12 +867,7 @@ e_mail_formatter_format_finished (EMailFormatter *formatter,
context = g_object_get_data (G_OBJECT (result), "context");
- g_free (context->message_uid);
- g_object_unref (context->message);
- g_object_unref (context->folder);
- g_slist_foreach (context->parts, (GFunc) e_mail_part_unref, NULL);
- g_slist_free (context->parts);
- mail_formatter_free_context (formatter, context);
+ mail_formatter_free_context (context);
return g_object_get_data (G_OBJECT (result), "stream");
}
diff --git a/em-format/e-mail-formatter.h b/em-format/e-mail-formatter.h
index d7e578f794..6d344ada85 100644
--- a/em-format/e-mail-formatter.h
+++ b/em-format/e-mail-formatter.h
@@ -89,11 +89,7 @@ struct _EMailFormatterHeader {
};
struct _EMailFormatterContext {
- CamelMimeMessage *message;
- CamelFolder *folder;
- gchar *message_uid;
- GSList *parts;
-
+ EMailPartList *part_list;
EMailFormatterMode mode;
guint32 flags;