[balsa/gtk3] Handle text/rfc822-headers parts (Albrecht D reß)



commit 3d1bf973e166c9436ae0098ee048b4cc523f9d9c
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Sun Mar 1 15:42:07 2015 -0500

    Handle text/rfc822-headers parts (Albrecht Dreß)
    
        * libbalsa/body.[hc]: parse text/rfc822-headers parts,
          and store them in the body structure
        * src/balsa-mime-widget.c, src/balsa-mime-widget-message.c:
          display a text/rfc822-headers part
        * src/balsa-print-object.c: print a text/rfc822-headers part

 ChangeLog                       |   10 ++++++++++
 libbalsa/body.c                 |   38 ++++++++++++++++++++++++++++++++++++++
 libbalsa/body.h                 |    2 +-
 src/balsa-mime-widget-message.c |   11 +++++++++++
 src/balsa-mime-widget.c         |    3 ++-
 src/balsa-print-object.c        |   19 ++++++++++++++-----
 6 files changed, 76 insertions(+), 7 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e68f48a..f0685ae 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2015-03-01  Albrecht Dreß
 
+       Display and print text/rfc822-headers parts
+
+       * libbalsa/body.[hc]: parse text/rfc822-headers parts,
+       and store them in the body structure
+       * src/balsa-mime-widget.c, src/balsa-mime-widget-message.c:
+       display a text/rfc822-headers part
+       * src/balsa-print-object.c: print a text/rfc822-headers part
+
+2015-03-01  Albrecht Dreß
+
        Obfuscate the message-id header
 
        * libbalsa/send.c (libbalsa_set_message_id): obfuscate the
diff --git a/libbalsa/body.c b/libbalsa/body.c
index c321cfb..bac3c66 100644
--- a/libbalsa/body.c
+++ b/libbalsa/body.c
@@ -216,6 +216,35 @@ libbalsa_message_body_set_multipart(LibBalsaMessageBody * body,
 }
 
 static void
+libbalsa_message_body_set_text_rfc822headers(LibBalsaMessageBody *body)
+{
+    GMimeStream *headers;
+    GError *err = NULL;
+
+    libbalsa_mailbox_lock_store(body->message->mailbox);
+    headers = libbalsa_message_body_get_stream(body, &err);
+    if (err != NULL) {
+       g_error_free(err);
+    }
+
+    if (headers != NULL) {
+       GMimeMessage *dummy_msg;
+       GMimeParser *parser;
+
+       g_mime_stream_reset(headers);
+       parser = g_mime_parser_new_with_stream(headers);
+       g_object_unref(headers);
+       dummy_msg = g_mime_parser_construct_message(parser);
+       g_object_unref(parser);
+
+       body->embhdrs = libbalsa_message_body_extract_embedded_headers(dummy_msg);
+       g_object_unref(dummy_msg);
+    }
+
+    libbalsa_mailbox_unlock_store(body->message->mailbox);
+}
+
+static void
 libbalsa_message_body_set_parts(LibBalsaMessageBody * body)
 {
     LibBalsaMessageBody **next_part = &body->parts;
@@ -224,6 +253,15 @@ libbalsa_message_body_set_parts(LibBalsaMessageBody * body)
        next_part = libbalsa_message_body_set_message_part(body, next_part);
     else if (GMIME_IS_MULTIPART(body->mime_part))
        next_part = libbalsa_message_body_set_multipart(body, next_part);
+    else {
+       gchar *mime_type;
+
+       mime_type = libbalsa_message_body_get_mime_type(body);
+       if (strcmp(mime_type, "text/rfc822-headers") == 0) {
+           libbalsa_message_body_set_text_rfc822headers(body);
+       }
+       g_free(mime_type);
+    }
 
     /* Free any parts that weren't used; the test isn't strictly
      * necessary, but it should fail unless something really strange has
diff --git a/libbalsa/body.h b/libbalsa/body.h
index ead50f6..954c264 100644
--- a/libbalsa/body.h
+++ b/libbalsa/body.h
@@ -71,7 +71,7 @@ struct _LibBalsaMessageBody {
     gchar *buffer;             /* holds raw data of the MIME part, or NULL */
     gchar *html_buffer;         /* holds the html representation of the part or NULL */
     ssize_t buflen;             /* size of the block */
-    LibBalsaMessageHeaders *embhdrs;  /* headers of a message/rfc822 part */
+    LibBalsaMessageHeaders *embhdrs;  /* headers of a message/rfc822 or text/rfc822-headers part */
     LibBalsaMessageBodyType body_type;
     gchar *content_type;        /* value of the Content-Type header of
                                  * the body including mime type with
diff --git a/src/balsa-mime-widget-message.c b/src/balsa-mime-widget-message.c
index 3d54f9f..c00329a 100644
--- a/src/balsa-mime-widget-message.c
+++ b/src/balsa-mime-widget-message.c
@@ -135,6 +135,17 @@ balsa_mime_widget_new_message(BalsaMessage * bm,
        gtk_box_pack_start(GTK_BOX(mw->container), emb_hdrs, FALSE, FALSE, 0);
 
        balsa_mime_widget_message_set_headers(bm, mw, mime_body);
+    } else if (!g_ascii_strcasecmp("text/rfc822-headers", content_type)) {
+       mw = g_object_new(BALSA_TYPE_MIME_WIDGET, NULL);
+       mw->widget = gtk_frame_new(_("message headers"));
+       mw->header_widget = bm_header_widget_new(bm, NULL);
+        gtk_widget_set_halign(mw->header_widget, GTK_ALIGN_END);
+        gtk_widget_set_hexpand(mw->header_widget, TRUE);
+        gtk_widget_set_valign(mw->header_widget, GTK_ALIGN_START);
+        gtk_widget_set_vexpand(mw->header_widget, FALSE);
+        g_object_set(G_OBJECT(mw->header_widget), "margin", 5, NULL);
+       gtk_container_add(GTK_CONTAINER(mw->widget), mw->header_widget);
+       balsa_mime_widget_message_set_headers(bm, mw, mime_body);
     }
 
     /* return the created widget (may be NULL) */
diff --git a/src/balsa-mime-widget.c b/src/balsa-mime-widget.c
index 318b69e..02a2d65 100644
--- a/src/balsa-mime-widget.c
+++ b/src/balsa-mime-widget.c
@@ -117,6 +117,7 @@ static mime_delegate_t mime_delegate[] =
     { {FALSE, "message/delivery-status",       balsa_mime_widget_new_text},
       {TRUE,  "message/",                      balsa_mime_widget_new_message},
       {FALSE, "text/calendar",                 balsa_mime_widget_new_vcalendar},
+      {FALSE, "text/rfc822-headers",           balsa_mime_widget_new_message},
       {TRUE,  "text/",                         balsa_mime_widget_new_text},
       {TRUE,  "multipart/",                    balsa_mime_widget_new_multipart},
       {TRUE,  "image/",                        balsa_mime_widget_new_image},
@@ -270,7 +271,7 @@ balsa_mime_widget_new_unknown(BalsaMessage * bm,
             g_object_unref(stream);
             use_content_type = libbalsa_vfs_content_type_of_buffer(buffer, size);
             if (g_ascii_strncasecmp(use_content_type, "text", 4) == 0
-                && libbalsa_text_attr_string(buffer) & LIBBALSA_TEXT_HI_BIT) {
+                && (libbalsa_text_attr_string(buffer) & LIBBALSA_TEXT_HI_BIT)) {
                 /* Hmmm...better stick with application/octet-stream. */
                 g_free(use_content_type);
                 use_content_type = g_strdup("application/octet-stream");
diff --git a/src/balsa-print-object.c b/src/balsa-print-object.c
index 8115018..6e9d27b 100644
--- a/src/balsa-print-object.c
+++ b/src/balsa-print-object.c
@@ -1,7 +1,7 @@
 /* -*-mode:c; c-style:k&r; c-basic-offset:4; -*- */
 /* Balsa E-Mail Client
- * Copyright (C) 1997-2013 Stuart Parmenter and others
- * Written by (C) Albrecht Dre� <albrecht dress arcor de> 2007
+ * Copyright (C) 1997-2015 Stuart Parmenter and others
+ * Written by (C) Albrecht Dreß <albrecht dress arcor de> 2007
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -14,9 +14,7 @@
  * GNU General Public License for more details.
  *  
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  
- * 02111-1307, USA.
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #if defined(HAVE_CONFIG_H) && HAVE_CONFIG_H
@@ -24,6 +22,7 @@
 #endif                          /* HAVE_CONFIG_H */
 #include "balsa-print-object.h"
 
+#include <glib/gi18n.h>
 #include <gtk/gtk.h>
 #include <libbalsa.h>
 #include "balsa-app.h"
@@ -106,6 +105,15 @@ balsa_print_object_emb_message(GList * list, GtkPrintContext * context,
     return balsa_print_object_header_from_body(list, context, mime_body, psetup);
 }
 
+static GList *
+balsa_print_object_emb_headers(GList * list, GtkPrintContext * context,
+            LibBalsaMessageBody * mime_body,
+            BalsaPrintSetup * psetup)
+{
+    list = balsa_print_object_frame_begin(list, _("message headers"), psetup);
+    list = balsa_print_object_header_from_body(list, context, mime_body, psetup);
+    return balsa_print_object_frame_end(list, psetup);
+}
 
 #ifdef HAVE_GPGME
 static GList *
@@ -137,6 +145,7 @@ balsa_print_objects_append_from_body(GList * list,
         { "text/directory",                -1, balsa_print_object_text_vcard },
         { "text/calendar",                 -1, balsa_print_object_text_calendar },
         { "text/plain",                    -1, balsa_print_object_text_plain },
+        { "text/rfc822-headers",          -1, balsa_print_object_emb_headers },
         { "text/",                          5, balsa_print_object_text },
         { "image/",                         6, balsa_print_object_image },
         { "message/rfc822",                -1, balsa_print_object_emb_message },


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]