aboutsummaryrefslogtreecommitdiffstats
path: root/em-format
diff options
context:
space:
mode:
authorDan Vrátil <dvratil@redhat.com>2012-07-13 16:55:12 +0800
committerDan Vrátil <dvratil@redhat.com>2012-07-13 16:55:12 +0800
commitbd2af6d508bee034e7251e5171eff28427ce1546 (patch)
tree8e48bf3b68606ab4e036bbe46e2ffe50ccbe2192 /em-format
parent759741ebd64a2c7c4953214d7790c3dad3de031e (diff)
downloadgsoc2013-evolution-bd2af6d508bee034e7251e5171eff28427ce1546.tar.gz
gsoc2013-evolution-bd2af6d508bee034e7251e5171eff28427ce1546.tar.zst
gsoc2013-evolution-bd2af6d508bee034e7251e5171eff28427ce1546.zip
Bug 679323 - Formatting errors when replying in inline mode
Diffstat (limited to 'em-format')
-rw-r--r--em-format/e-mail-formatter-quote-headers.c137
1 files changed, 134 insertions, 3 deletions
diff --git a/em-format/e-mail-formatter-quote-headers.c b/em-format/e-mail-formatter-quote-headers.c
index 5c31e39362..064e4b2bd8 100644
--- a/em-format/e-mail-formatter-quote-headers.c
+++ b/em-format/e-mail-formatter-quote-headers.c
@@ -62,6 +62,138 @@ G_DEFINE_TYPE_EXTENDED (
E_TYPE_MAIL_FORMATTER_EXTENSION,
e_mail_formatter_quote_formatter_extension_interface_init))
+
+static void
+emfqe_format_text_header (EMailFormatter *emf,
+ GString *buffer,
+ const gchar *label,
+ const gchar *value,
+ guint32 flags,
+ gint is_html)
+{
+ const gchar *html;
+ gchar *mhtml = NULL;
+
+ if (value == NULL)
+ return;
+
+ while (*value == ' ')
+ value++;
+
+ if (!is_html)
+ html = mhtml = camel_text_to_html (value, 0, 0);
+ else
+ html = value;
+
+ if (flags & E_MAIL_FORMATTER_HEADER_FLAG_BOLD)
+ g_string_append_printf (
+ buffer, "<b>%s</b>: %s<br>", label, html);
+ else
+ g_string_append_printf (
+ buffer, "%s: %s<br>", label, html);
+
+ g_free (mhtml);
+}
+
+/* XXX: This is copied in e-mail-formatter-utils.c */
+static const gchar *addrspec_hdrs[] = {
+ "Sender", "From", "Reply-To", "To", "Cc", "Bcc",
+ "Resent-Sender", "Resent-From", "Resent-Reply-To",
+ "Resent-To", "Resent-Cc", "Resent-Bcc", NULL
+};
+
+static void
+emfqe_format_header (EMailFormatter *formatter,
+ GString *buffer,
+ CamelMedium *part,
+ struct _camel_header_raw *header,
+ guint32 flags,
+ const gchar *charset)
+{
+ CamelMimeMessage *msg = (CamelMimeMessage *) part;
+ gchar *name, *buf, *value = NULL;
+ const gchar *txt, *label;
+ gboolean addrspec = FALSE;
+ gint is_html = FALSE;
+ gint i;
+
+ name = g_alloca (strlen (header->name) + 1);
+ strcpy (name, header->name);
+ e_mail_formatter_canon_header_name (name);
+
+ /* Never quote Bcc headers */
+ if (g_str_equal (name, "Bcc") || g_str_equal (name, "Resent-Bcc"))
+ return;
+
+ for (i = 0; addrspec_hdrs[i]; i++) {
+ if (!strcmp (name, addrspec_hdrs[i])) {
+ addrspec = TRUE;
+ break;
+ }
+ }
+
+ label = _(name);
+
+ if (addrspec) {
+ struct _camel_header_address *addrs;
+ GString *html;
+
+ if (!(txt = camel_medium_get_header (part, name)))
+ return;
+
+ buf = camel_header_unfold (txt);
+ addrs = camel_header_address_decode (
+ txt, e_mail_formatter_get_charset (formatter) ?
+ e_mail_formatter_get_charset (formatter) :
+ e_mail_formatter_get_default_charset (formatter));
+ if (addrs == NULL) {
+ g_free (buf);
+ return;
+ }
+
+ g_free (buf);
+
+ html = g_string_new ("");
+ e_mail_formatter_format_address (formatter, html,
+ addrs, name, FALSE, FALSE);
+ camel_header_address_unref (addrs);
+ txt = value = html->str;
+ g_string_free (html, FALSE);
+ flags |= E_MAIL_FORMATTER_HEADER_FLAG_BOLD;
+ is_html = TRUE;
+ } else if (!strcmp (name, "Subject")) {
+ txt = camel_mime_message_get_subject (msg);
+ label = _("Subject");
+ flags |= E_MAIL_FORMATTER_HEADER_FLAG_BOLD;
+ } else if (!strcmp (name, "X-Evolution-Mailer")) { /* pseudo-header */
+ if (!(txt = camel_medium_get_header (part, "x-mailer")))
+ if (!(txt = camel_medium_get_header (part, "user-agent")))
+ if (!(txt = camel_medium_get_header (part, "x-newsreader")))
+ if (!(txt = camel_medium_get_header (part, "x-mimeole")))
+ return;
+
+ txt = value = camel_header_format_ctext (txt, charset);
+
+ label = _("Mailer");
+ flags |= E_MAIL_FORMATTER_HEADER_FLAG_BOLD;
+ } else if (!strcmp (name, "Date") || !strcmp (name, "Resent-Date")) {
+ if (!(txt = camel_medium_get_header (part, name)))
+ return;
+
+ flags |= E_MAIL_FORMATTER_HEADER_FLAG_BOLD;
+ } else {
+ txt = camel_medium_get_header (part, name);
+ buf = camel_header_unfold (txt);
+ txt = value = camel_header_decode_string (txt, charset);
+ g_free (buf);
+ }
+
+ emfqe_format_text_header (formatter, buffer, label, txt, flags, is_html);
+
+ g_free (value);
+}
+
+
static gboolean
emqfe_headers_format (EMailFormatterExtension *extension,
EMailFormatter *formatter,
@@ -99,15 +231,14 @@ emqfe_headers_format (EMailFormatterExtension *extension,
if (g_strcmp0 (raw_header->name, h->name) == 0) {
- e_mail_formatter_format_header (
+ emfqe_format_header (
formatter, buffer, (CamelMedium *) part->part,
raw_header, flags, charset);
-
- g_string_append (buffer, "<br>\n");
break;
}
}
}
+
g_string_append (buffer, "<br>\n");
camel_stream_write_string (stream, buffer->str, cancellable, NULL);