Commit 2f0d83cf authored by Matthew Barnes's avatar Matthew Barnes
Browse files

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.
parent 13f4544d
......@@ -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 (
......
......@@ -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,
......
......@@ -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)
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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");
}
......
......@@ -89,11 +89,7 @@ struct _EMailFormatterHeader {
};
struct _EMailFormatterContext {
CamelMimeMessage *message;
CamelFolder *folder;
gchar *message_uid;
GSList *parts;
EMailPartList *part_list;
EMailFormatterMode mode;
guint32 flags;
......
......@@ -102,10 +102,7 @@ handle_mail_request (GSimpleAsyncResult *res,
if (val)
context.mode = atoi (val);
context.message = part_list->message;
context.message_uid = part_list->message_uid;
context.folder = part_list->folder;
context.parts = part_list->list;
context.part_list = g_object_ref (part_list);
context.uri = request->priv->full_uri;
if (context.mode == E_MAIL_FORMATTER_MODE_PRINTING)
......@@ -146,6 +143,9 @@ handle_mail_request (GSimpleAsyncResult *res,
context.flags, context.mode, cancellable);
}
g_object_unref (context.part_list);
context.part_list = NULL;
/* Convert the GString to GInputStream and send it back to WebKit */
ba = camel_stream_mem_get_byte_array (CAMEL_STREAM_MEM (request->priv->output_stream));
if (!ba->data) {
......@@ -166,7 +166,7 @@ handle_mail_request (GSimpleAsyncResult *res,
g_object_unref (formatter);
stream = g_memory_input_stream_new_from_data (
(gchar *) ba->data, ba->len, NULL);
(gchar *) ba->data, ba->len, NULL);
g_simple_async_result_set_op_res_gpointer (res, stream, NULL);
}
......
......@@ -90,25 +90,31 @@ emfe_itip_format (EMailFormatterExtension *extension,
itip_view_write (formatter, buffer);
} else {
CamelFolder *folder;
CamelMimeMessage *message;
const gchar *message_uid;
gchar *uri;
folder = context->part_list->folder;
message = context->part_list->message;
message_uid = context->part_list->message_uid;
/* mark message as containing calendar, thus it will show the
* icon in message list now on */
if (context->message_uid && context->folder &&
if (message_uid != NULL && folder != NULL &&
!camel_folder_get_message_user_flag (
context->folder, context->message_uid, "$has_cal")) {
folder, message_uid, "$has_cal")) {
camel_folder_set_message_user_flag (
context->folder, context->message_uid,
"$has_cal", TRUE);
folder, message_uid, "$has_cal", TRUE);
}
itip_part->folder = g_object_ref (context->folder);
itip_part->uid = g_strdup (context->message_uid);
itip_part->msg = g_object_ref (context->message);
itip_part->folder = g_object_ref (folder);
itip_part->uid = g_strdup (message_uid);
itip_part->msg = g_object_ref (message);
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);
......
......@@ -319,13 +319,18 @@ emfe_text_highlight_format (EMailFormatterExtension *extension,
g_free ((gchar *) argv[3]);
pango_font_description_free (fd);
} else {
CamelFolder *folder;
const gchar *message_uid;
gchar *uri, *str;
gchar *syntax;
folder = context->part_list->folder;
message_uid = context->part_list->message_uid;
syntax = get_syntax (part, NULL);
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,
"__formatas", G_TYPE_STRING, syntax,
......
......@@ -89,6 +89,8 @@ emfe_vcard_inline_format (EMailFormatterExtension *extension,
vcard_part->formatter, contact, stream, cancellable);
} else {
CamelFolder *folder;
const gchar *message_uid;
gchar *str, *uri;
gint length;
const gchar *label = NULL;
......@@ -100,14 +102,17 @@ emfe_vcard_inline_format (EMailFormatterExtension *extension,
if (length < 1)
return FALSE;
if (!vcard_part->message_uid && context->message_uid)
vcard_part->message_uid = g_strdup (context->message_uid);
folder = context->part_list->folder;
message_uid = context->part_list->message_uid;
if (!vcard_part->folder && context->folder)
vcard_part->folder = g_object_ref (context->folder);
if (vcard_part->message_uid == NULL && message_uid != NULL)
vcard_part->message_uid = g_strdup (message_uid);
if (vcard_part->folder == NULL && folder != NULL)
vcard_part->folder = g_object_ref (folder);
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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment