aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2013-06-07 22:30:22 +0800
committerMatthew Barnes <mbarnes@redhat.com>2013-06-08 03:47:03 +0800
commit257286b6ce8d12a8f7dc12490599d32f8e984776 (patch)
tree74534efc70fbabbf4ebe0ed02ae6a2444e1c75b5
parent863fee647958686bce10a0e0a499b78e72d64a41 (diff)
downloadgsoc2013-evolution-257286b6ce8d12a8f7dc12490599d32f8e984776.tar
gsoc2013-evolution-257286b6ce8d12a8f7dc12490599d32f8e984776.tar.gz
gsoc2013-evolution-257286b6ce8d12a8f7dc12490599d32f8e984776.tar.bz2
gsoc2013-evolution-257286b6ce8d12a8f7dc12490599d32f8e984776.tar.lz
gsoc2013-evolution-257286b6ce8d12a8f7dc12490599d32f8e984776.tar.xz
gsoc2013-evolution-257286b6ce8d12a8f7dc12490599d32f8e984776.tar.zst
gsoc2013-evolution-257286b6ce8d12a8f7dc12490599d32f8e984776.zip
EMailFormatterHeaders cleanups.
-rw-r--r--em-format/e-mail-formatter-headers.c67
-rw-r--r--em-format/e-mail-formatter-utils.c34
2 files changed, 58 insertions, 43 deletions
diff --git a/em-format/e-mail-formatter-headers.c b/em-format/e-mail-formatter-headers.c
index 3cd5fa553d..702b4a6a6d 100644
--- a/em-format/e-mail-formatter-headers.c
+++ b/em-format/e-mail-formatter-headers.c
@@ -50,10 +50,11 @@ static const gchar *formatter_mime_types[] = {
static void
format_short_headers (EMailFormatter *formatter,
GString *buffer,
- CamelMedium *part,
+ EMailPart *part,
guint32 flags,
GCancellable *cancellable)
{
+ CamelMimePart *mime_part;
GtkTextDirection direction;
const gchar *charset;
CamelContentType *ct;
@@ -67,9 +68,10 @@ format_short_headers (EMailFormatter *formatter,
if (g_cancellable_is_cancelled (cancellable))
return;
+ mime_part = e_mail_part_ref_mime_part (part);
direction = gtk_widget_get_default_direction ();
- ct = camel_mime_part_get_content_type ((CamelMimePart *) part);
+ ct = camel_mime_part_get_content_type (mime_part);
charset = camel_content_type_param (ct, "charset");
charset = camel_iconv_charset_name (charset);
hdr_charset = e_mail_formatter_dup_charset (formatter);
@@ -85,7 +87,7 @@ format_short_headers (EMailFormatter *formatter,
"id=\"__evo-short-headers\" style=\"display: %s\">",
flags & E_MAIL_FORMATTER_HEADER_FLAG_COLLAPSED ? "table" : "none");
- header = ((CamelMimePart *) part)->headers;
+ header = mime_part->headers;
while (header) {
if (!g_ascii_strcasecmp (header->name, "From")) {
GString *tmp;
@@ -141,38 +143,40 @@ format_short_headers (EMailFormatter *formatter,
g_string_free (from, TRUE);
g_free (evolution_imagesdir);
+
+ g_object_unref (mime_part);
}
static void
-write_contact_picture (CamelMimePart *part,
+write_contact_picture (CamelMimePart *mime_part,
gint size,
GString *buffer)
{
gchar *b64, *content_type;
CamelDataWrapper *dw;
CamelContentType *ct;
- GByteArray *ba;
+ GByteArray *ba = NULL;
- ba = NULL;
- dw = camel_medium_get_content (CAMEL_MEDIUM (part));
- if (dw) {
+ dw = camel_medium_get_content (CAMEL_MEDIUM (mime_part));
+ if (dw != NULL)
ba = camel_data_wrapper_get_byte_array (dw);
- }
- if (!ba || ba->len == 0) {
+ if (ba == NULL || ba->len == 0) {
+ const gchar *filename;
- if (camel_mime_part_get_filename (part)) {
+ filename = camel_mime_part_get_filename (mime_part);
+ if (filename != NULL) {
if (size >= 0) {
g_string_append_printf (
buffer,
"<img width=\"%d\" src=\"evo-file://%s\" />",
- size, camel_mime_part_get_filename (part));
+ size, filename);
} else {
g_string_append_printf (
buffer,
"<img src=\"evo-file://%s\" />",
- camel_mime_part_get_filename (part));
+ filename);
}
}
@@ -180,7 +184,7 @@ write_contact_picture (CamelMimePart *part,
}
b64 = g_base64_encode (ba->data, ba->len);
- ct = camel_mime_part_get_content_type (part);
+ ct = camel_mime_part_get_content_type (mime_part);
content_type = camel_content_type_simple (ct);
if (size >= 0) {
@@ -202,11 +206,12 @@ write_contact_picture (CamelMimePart *part,
static void
format_full_headers (EMailFormatter *formatter,
GString *buffer,
- CamelMedium *part,
+ EMailPart *part,
guint32 mode,
guint32 flags,
GCancellable *cancellable)
{
+ CamelMimePart *mime_part;
const gchar *charset;
CamelContentType *ct;
struct _camel_header_raw *header;
@@ -223,6 +228,8 @@ format_full_headers (EMailFormatter *formatter,
if (g_cancellable_is_cancelled (cancellable))
return;
+ mime_part = e_mail_part_ref_mime_part (part);
+
switch (gtk_widget_get_default_direction ()) {
case GTK_TEXT_DIR_RTL:
direction = "rtl";
@@ -235,7 +242,7 @@ format_full_headers (EMailFormatter *formatter,
break;
}
- ct = camel_mime_part_get_content_type ((CamelMimePart *) part);
+ ct = camel_mime_part_get_content_type (mime_part);
charset = camel_content_type_param (ct, "charset");
charset = camel_iconv_charset_name (charset);
hdr_charset = e_mail_formatter_dup_charset (formatter);
@@ -253,7 +260,7 @@ format_full_headers (EMailFormatter *formatter,
flags & E_MAIL_FORMATTER_HEADER_FLAG_COLLAPSED ? "none" : "table",
direction);
- header = ((CamelMimePart *) part)->headers;
+ header = mime_part->headers;
while (header != NULL) {
if (!g_ascii_strcasecmp (header->name, "Sender")) {
struct _camel_header_address *addrs;
@@ -339,7 +346,7 @@ format_full_headers (EMailFormatter *formatter,
/* dump selected headers */
if (mode & E_MAIL_FORMATTER_MODE_ALL_HEADERS) {
- header = ((CamelMimePart *) part)->headers;
+ header = mime_part->headers;
while (header != NULL) {
e_mail_formatter_format_header (
formatter, buffer,
@@ -360,7 +367,7 @@ format_full_headers (EMailFormatter *formatter,
EMailFormatterHeader *h = link->data;
gint mailer, face;
- header = ((CamelMimePart *) part)->headers;
+ header = mime_part->headers;
mailer = !g_ascii_strcasecmp (h->name, "X-Evolution-Mailer");
face = !g_ascii_strcasecmp (h->name, "Face");
@@ -431,7 +438,7 @@ format_full_headers (EMailFormatter *formatter,
g_string_append (buffer, "</table></td>");
- if (photo_name) {
+ if (photo_name != NULL) {
gchar *name;
name = g_uri_escape_string (photo_name, NULL, FALSE);
@@ -449,25 +456,27 @@ format_full_headers (EMailFormatter *formatter,
}
if (!contact_has_photo && face_decoded) {
- CamelMimePart *part;
+ CamelMimePart *image_part;
- part = camel_mime_part_new ();
+ image_part = camel_mime_part_new ();
camel_mime_part_set_content (
- (CamelMimePart *) part,
+ image_part,
(const gchar *) face_header_value,
face_header_len, "image/png");
g_string_append (
buffer,
"<td align=\"right\" valign=\"top\">");
- write_contact_picture (part, 48, buffer);
+ write_contact_picture (image_part, 48, buffer);
g_string_append (buffer, "</td>");
- g_object_unref (part);
+ g_object_unref (image_part);
g_free (face_header_value);
}
g_string_append (buffer, "</tr></table>");
+
+ g_object_unref (mime_part);
}
static gboolean
@@ -546,14 +555,14 @@ emfe_headers_format (EMailFormatterExtension *extension,
if (is_collapsable)
format_short_headers (
- formatter, buffer,
- CAMEL_MEDIUM (mime_part),
+ formatter,
+ buffer, part,
context->flags,
cancellable);
format_full_headers (
- formatter, buffer,
- CAMEL_MEDIUM (mime_part),
+ formatter,
+ buffer, part,
context->mode,
context->flags,
cancellable);
diff --git a/em-format/e-mail-formatter-utils.c b/em-format/e-mail-formatter-utils.c
index f3f6f24a20..1967a61ccd 100644
--- a/em-format/e-mail-formatter-utils.c
+++ b/em-format/e-mail-formatter-utils.c
@@ -47,6 +47,7 @@ e_mail_formatter_format_text_header (EMailFormatter *formatter,
{
GtkTextDirection direction;
const gchar *fmt, *html;
+ const gchar *display;
gchar *mhtml = NULL;
g_return_if_fail (E_IS_MAIL_FORMATTER (formatter));
@@ -104,9 +105,12 @@ e_mail_formatter_format_text_header (EMailFormatter *formatter,
"</tr>";
}
- g_string_append_printf (
- buffer, fmt,
- (flags & E_MAIL_FORMATTER_HEADER_FLAG_HIDDEN ? "none" : "table-row"), label, html);
+ if (flags & E_MAIL_FORMATTER_HEADER_FLAG_HIDDEN)
+ display = "none";
+ else
+ display = "table-row";
+
+ g_string_append_printf (buffer, fmt, display, label, html);
g_free (mhtml);
}
@@ -278,7 +282,7 @@ e_mail_formatter_format_header (EMailFormatter *formatter,
guint32 flags,
const gchar *charset)
{
- gchar *name, *buf, *value = NULL;
+ gchar *canon_name, *buf, *value = NULL;
const gchar *label, *txt;
gboolean addrspec = FALSE;
gchar *str_field = NULL;
@@ -289,18 +293,18 @@ e_mail_formatter_format_header (EMailFormatter *formatter,
g_return_if_fail (header_name != NULL);
g_return_if_fail (header_value != NULL);
- name = g_alloca (strlen (header_name) + 1);
- strcpy (name, header_name);
- e_mail_formatter_canon_header_name (name);
+ canon_name = g_alloca (strlen (header_name) + 1);
+ strcpy (canon_name, header_name);
+ e_mail_formatter_canon_header_name (canon_name);
for (i = 0; addrspec_hdrs[i]; i++) {
- if (g_str_equal (name, addrspec_hdrs[i])) {
+ if (g_str_equal (canon_name, addrspec_hdrs[i])) {
addrspec = TRUE;
break;
}
}
- label = _(name);
+ label = _(canon_name);
if (addrspec) {
struct _camel_header_address *addrs;
@@ -343,20 +347,21 @@ e_mail_formatter_format_header (EMailFormatter *formatter,
flags |= E_MAIL_FORMATTER_HEADER_FLAG_HTML;
flags |= E_MAIL_FORMATTER_HEADER_FLAG_BOLD;
- } else if (g_str_equal (name, "Subject")) {
+ } else if (g_str_equal (canon_name, "Subject")) {
buf = camel_header_unfold (header_value);
txt = value = camel_header_decode_string (buf, charset);
g_free (buf);
flags |= E_MAIL_FORMATTER_HEADER_FLAG_BOLD;
- } else if (g_str_equal (name, "X-evolution-mailer")) {
+ } else if (g_str_equal (canon_name, "X-Evolution-Mailer")) {
/* pseudo-header */
label = _("Mailer");
txt = value = camel_header_format_ctext (header_value, charset);
flags |= E_MAIL_FORMATTER_HEADER_FLAG_BOLD;
- } else if (g_str_equal (name, "Date") || g_str_equal (name, "Resent-Date")) {
+ } else if (g_str_equal (canon_name, "Date") ||
+ g_str_equal (canon_name, "Resent-Date")) {
CamelMimeFilterToHTMLFlags text_format_flags;
gint msg_offset, local_tz;
time_t msg_date;
@@ -411,7 +416,7 @@ e_mail_formatter_format_header (EMailFormatter *formatter,
flags |= E_MAIL_FORMATTER_HEADER_FLAG_HTML;
flags |= E_MAIL_FORMATTER_HEADER_FLAG_BOLD;
- } else if (g_str_equal (name, "Newsgroups")) {
+ } else if (g_str_equal (canon_name, "Newsgroups")) {
struct _camel_header_newsgroup *ng, *scan;
GString *html;
@@ -447,7 +452,8 @@ e_mail_formatter_format_header (EMailFormatter *formatter,
flags |= E_MAIL_FORMATTER_HEADER_FLAG_HTML;
flags |= E_MAIL_FORMATTER_HEADER_FLAG_BOLD;
- } else if (g_str_equal (name, "Received") || g_str_has_prefix (name, "X-")) {
+ } else if (g_str_equal (canon_name, "Received") ||
+ g_str_has_prefix (canon_name, "X-")) {
/* don't unfold Received nor extension headers */
txt = value = camel_header_decode_string (header_value, charset);