unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Austin Clements <amdragon@MIT.EDU>
To: notmuch@notmuchmail.org
Subject: [PATCH 2/3] reply: Convert default reply format to self-recursive style
Date: Thu, 22 Mar 2012 23:34:06 -0400	[thread overview]
Message-ID: <1332473647-9133-3-git-send-email-amdragon@mit.edu> (raw)
In-Reply-To: <1332473647-9133-1-git-send-email-amdragon@mit.edu>

This re-arranges the default reply formatter code to use the
mime_node_t abstraction.  There are no semantic changes.
---
 notmuch-reply.c |  119 +++++++++++++++++++++----------------------------------
 1 files changed, 45 insertions(+), 74 deletions(-)

diff --git a/notmuch-reply.c b/notmuch-reply.c
index 2f5ed3d..84a1220 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -24,28 +24,6 @@
 #include "gmime-filter-headers.h"
 
 static void
-reply_headers_message_part (GMimeMessage *message);
-
-static void
-reply_part_content (GMimeObject *part);
-
-static const notmuch_show_format_t format_reply = {
-    "", NULL,
-	"", NULL,
-	    "", NULL, reply_headers_message_part, ">\n",
-	    "",
-	        NULL,
-	        NULL,
-	        NULL,
-	        reply_part_content,
-	        NULL,
-	        "",
-	    "",
-	"", "",
-    ""
-};
-
-static void
 show_reply_headers (GMimeMessage *message)
 {
     GMimeStream *stream_stdout = NULL, *stream_filter = NULL;
@@ -65,66 +43,55 @@ show_reply_headers (GMimeMessage *message)
 }
 
 static void
-reply_headers_message_part (GMimeMessage *message)
+format_part_reply (mime_node_t *node)
 {
-    InternetAddressList *recipients;
-    const char *recipients_string;
+    int i;
 
-    printf ("> From: %s\n", g_mime_message_get_sender (message));
-    recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);
-    recipients_string = internet_address_list_to_string (recipients, 0);
-    if (recipients_string)
-	printf ("> To: %s\n",
-		recipients_string);
-    recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC);
-    recipients_string = internet_address_list_to_string (recipients, 0);
-    if (recipients_string)
-	printf ("> Cc: %s\n",
-		recipients_string);
-    printf ("> Subject: %s\n", g_mime_message_get_subject (message));
-    printf ("> Date: %s\n", g_mime_message_get_date_as_string (message));
-}
+    if (GMIME_IS_MESSAGE (node->part)) {
+	GMimeMessage *message = GMIME_MESSAGE (node->part);
+	InternetAddressList *recipients;
+	const char *recipients_string;
 
+	printf ("> From: %s\n", g_mime_message_get_sender (message));
+	recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);
+	recipients_string = internet_address_list_to_string (recipients, 0);
+	if (recipients_string)
+	    printf ("> To: %s\n",
+		    recipients_string);
+	recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC);
+	recipients_string = internet_address_list_to_string (recipients, 0);
+	if (recipients_string)
+	    printf ("> Cc: %s\n",
+		    recipients_string);
+	printf ("> Subject: %s\n", g_mime_message_get_subject (message));
+	printf ("> Date: %s\n", g_mime_message_get_date_as_string (message));
+	printf (">\n");
+    } else if (GMIME_IS_PART (node->part)) {
+	GMimeContentType *content_type = g_mime_object_get_content_type (node->part);
+	GMimeContentDisposition *disposition = g_mime_object_get_content_disposition (node->part);
 
-static void
-reply_part_content (GMimeObject *part)
-{
-    GMimeContentType *content_type = g_mime_object_get_content_type (GMIME_OBJECT (part));
-    GMimeContentDisposition *disposition = g_mime_object_get_content_disposition (part);
-
-    if (g_mime_content_type_is_type (content_type, "multipart", "*") ||
-	g_mime_content_type_is_type (content_type, "message", "rfc822"))
-    {
-	/* Output nothing, since multipart subparts will be handled individually. */
-    }
-    else if (g_mime_content_type_is_type (content_type, "application", "pgp-encrypted") ||
-	     g_mime_content_type_is_type (content_type, "application", "pgp-signature"))
-    {
-	/* Ignore PGP/MIME cruft parts */
-    }
-    else if (g_mime_content_type_is_type (content_type, "text", "*") &&
-	!g_mime_content_type_is_type (content_type, "text", "html"))
-    {
-	GMimeStream *stream_stdout = g_mime_stream_file_new (stdout);
-	g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream_stdout), FALSE);
-	show_text_part_content (part, stream_stdout, NOTMUCH_SHOW_TEXT_PART_REPLY);
-	g_object_unref(stream_stdout);
-    }
-    else
-    {
-	if (disposition &&
-	    strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0)
-	{
-	    const char *filename = g_mime_part_get_filename (GMIME_PART (part));
+	if (g_mime_content_type_is_type (content_type, "application", "pgp-encrypted") ||
+	    g_mime_content_type_is_type (content_type, "application", "pgp-signature")) {
+	    /* Ignore PGP/MIME cruft parts */
+	} else if (g_mime_content_type_is_type (content_type, "text", "*") &&
+		   !g_mime_content_type_is_type (content_type, "text", "html")) {
+	    GMimeStream *stream_stdout = g_mime_stream_file_new (stdout);
+	    g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream_stdout), FALSE);
+	    show_text_part_content (node->part, stream_stdout, NOTMUCH_SHOW_TEXT_PART_REPLY);
+	    g_object_unref(stream_stdout);
+	} else if (disposition &&
+		   strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0) {
+	    const char *filename = g_mime_part_get_filename (GMIME_PART (node->part));
 	    printf ("Attachment: %s (%s)\n", filename,
 		    g_mime_content_type_to_string (content_type));
-	}
-	else
-	{
+	} else {
 	    printf ("Non-text part: %s\n",
 		    g_mime_content_type_to_string (content_type));
 	}
     }
+
+    for (i = 0; i < node->nchildren; i++)
+	format_part_reply (mime_node_child (node, i));
 }
 
 /* Is the given address configured as one of the user's "personal" or
@@ -550,7 +517,7 @@ notmuch_reply_format_default(void *ctx,
     GMimeMessage *reply;
     notmuch_messages_t *messages;
     notmuch_message_t *message;
-    const notmuch_show_format_t *format = &format_reply;
+    mime_node_t *root;
 
     for (messages = notmuch_query_search_messages (query);
 	 notmuch_messages_valid (messages);
@@ -577,7 +544,11 @@ notmuch_reply_format_default(void *ctx,
 		notmuch_message_get_header (message, "date"),
 		notmuch_message_get_header (message, "from"));
 
-	show_message_body (message, format, params);
+	if (mime_node_open (ctx, message, params->cryptoctx, params->decrypt,
+			    &root) == NOTMUCH_STATUS_SUCCESS) {
+	    format_part_reply (mime_node_child (root, 0));
+	    talloc_free (root);
+	}
 
 	notmuch_message_destroy (message);
     }
-- 
1.7.7.3

  parent reply	other threads:[~2012-03-23  3:34 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-23  3:34 [PATCH 0/3] Rewrite default reply format Austin Clements
2012-03-23  3:34 ` [PATCH 1/3] show/reply: Unify the code that extracts text parts Austin Clements
2012-03-23  3:34 ` Austin Clements [this message]
2012-03-23  3:34 ` [PATCH 3/3] reply: Move reply citation printing to the recursive MIME walk Austin Clements
2012-03-24 10:06 ` [PATCH 0/3] Rewrite default reply format Tomi Ollila
2012-03-27 21:57   ` Austin Clements
2012-03-27 21:59 ` [PATCH v2 " Austin Clements
2012-03-27 21:59   ` [PATCH v2 1/3] show/reply: Unify the code that extracts text parts Austin Clements
2012-03-27 21:59   ` [PATCH v2 2/3] reply: Convert default reply format to self-recursive style Austin Clements
2012-03-27 21:59   ` [PATCH v2 3/3] reply: Move reply citation printing to the recursive MIME walk Austin Clements
2012-03-31 11:31   ` [PATCH v2 0/3] Rewrite default reply format David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1332473647-9133-3-git-send-email-amdragon@mit.edu \
    --to=amdragon@mit.edu \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).