[evolution-data-server/gnome-3-8] Make camel_mime_message_dump() dump message contents



commit 21660e8c46717d05d7c0101b6c614ab1540a78ce
Author: Dan Williams <dcbw redhat com>
Date:   Thu May 2 15:36:22 2013 -0500

    Make camel_mime_message_dump() dump message contents
    
    Previously unimplemented.  Dumps in hex and ASCII:
    
    class: CamelMimeMessage
    mime-type: text/plain; charset="UTF-8"
    content class: CamelDataWrapper
    content mime-type: text/plain; charset="UTF-8"
    content len 967
        4f 6e 20 54 68 75 2c 20 32 30 31 33 2d 30 35 2d    On Thu, 2013-05-
        30 32 20 61 74 20 31 34 3a 31 37 20 2d 30 35 30    02 at 14:17 -050
        30 2c 20 44 61 6e 20 57 69 6c 6c 69 61 6d 73 20    0, Dan Williams
        77 72 6f 74 65 3a 0a 3e 20 4f 6e 20 54 68 75 2c    wrote:.> On Thu,
        20 32 30 31 33 2d 30 35 2d 30 32 20 61 74 20 31     2013-05-02 at 1
        31 3a 35 33 20 2d 30 37 30 30 2c 20 4c 69 6e 75    1:53 -0700, Linu
        73 20 54 6f 72 76 61 6c 64 73 20 77 72 6f 74 65    s Torvalds wrote
        3a 0a 3e 20 3e 20 4f 6e 20 54 68 75 2c 20 4d 61    :.> > On Thu, Ma
        79 20 32 2c 20 32 30 31 33 20 61 74 20 31 31 3a    y 2, 2013 at 11:
    
    (02:09:38 PM) mbarnes: dcbw: nice, I forgot about camel_mime_message_dump() -- go ahead and commit that
    
    (cherry picked from commit f69531d1bca0ddf379b1da9516e302d2325bd31b)

 camel/camel-mime-message.c |   42 ++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 40 insertions(+), 2 deletions(-)
---
diff --git a/camel/camel-mime-message.c b/camel/camel-mime-message.c
index 3c1c44e..05d3bfe 100644
--- a/camel/camel-mime-message.c
+++ b/camel/camel-mime-message.c
@@ -1289,6 +1289,33 @@ camel_mime_message_has_attachment (CamelMimeMessage *message)
 }
 
 static void
+dumpline (const char *indent, guint8 *data, gsize data_len)
+{
+       int j;
+       char *gutter;
+       guint gutter_size;
+
+       g_return_if_fail (data_len <= 16);
+
+       gutter_size = ((16 - data_len) * 3) + 4;
+       gutter = alloca (gutter_size + 1);
+       memset (gutter, ' ', gutter_size);
+       gutter[gutter_size] = 0;
+
+       printf ("%s    ", indent);
+       /* Hex dump */
+       for (j = 0; j < data_len; j++)
+               printf ("%s%02x", j > 0 ? " " : "", data[j]);
+
+       /* ASCII dump */
+       printf ("%s", gutter);
+       for (j = 0; j < data_len; j++) {
+               printf ("%c", isprint (data[j]) ? data[j] : '.');
+       }
+       printf ("\n");
+}
+
+static void
 cmm_dump_rec (CamelMimeMessage *msg,
               CamelMimePart *part,
               gint body,
@@ -1298,6 +1325,7 @@ cmm_dump_rec (CamelMimeMessage *msg,
        gint parts, i;
        gint go = TRUE;
        gchar *s;
+       const GByteArray *data;
 
        s = alloca (depth + 1);
        memset (s, ' ', depth);
@@ -1314,6 +1342,17 @@ cmm_dump_rec (CamelMimeMessage *msg,
        printf ("%scontent class: %s\n", s, G_OBJECT_TYPE_NAME (containee));
        printf ("%scontent mime-type: %s\n", s, camel_content_type_format (((CamelDataWrapper *) 
containee)->mime_type));
 
+       data = camel_data_wrapper_get_byte_array (containee);
+       if (body && data) {
+               guint t = 0;
+
+               printf ("%scontent len %d\n", s, data->len);
+               for (t = 0; t < data->len / 16; t++)
+                       dumpline (s, &data->data[t * 16], 16);
+               if (data->len % 16)
+                       dumpline (s, &data->data[t * 16], data->len % 16);
+       }
+
        /* using the object types is more accurate than using the mime/types */
        if (CAMEL_IS_MULTIPART (containee)) {
                parts = camel_multipart_get_number ((CamelMultipart *) containee);
@@ -1334,8 +1373,7 @@ cmm_dump_rec (CamelMimeMessage *msg,
  *
  * Dump information about the mime message to stdout.
  *
- * If body is TRUE, then dump body content of the message as well
- * (currently unimplemented).
+ * If body is TRUE, then dump body content of the message as well.
  **/
 void
 camel_mime_message_dump (CamelMimeMessage *message,


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