Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 2B472429E34 for ; Mon, 30 Jan 2012 15:38:48 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5MDRU5Uq9zDL for ; Mon, 30 Jan 2012 15:38:47 -0800 (PST) Received: from mail-bk0-f53.google.com (mail-bk0-f53.google.com [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id C78D5431FBC for ; Mon, 30 Jan 2012 15:38:46 -0800 (PST) Received: by bke11 with SMTP id 11so1973525bke.26 for ; Mon, 30 Jan 2012 15:38:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:in-reply-to:references:user-agent:date :message-id:mime-version:content-type; bh=cV3X5UuScXPp4C0jZyMEgr2tieLSl1uzr6cz4ZtPFTo=; b=AJyvfCZPyQ5zzn68s1SVPEMTqxhsDezebdphGlkGi/oiTXEGx3u2Kob7bllhtd1KjD NUUttKnO2vXemBjt2XHn/oZrp3a3bv3ZkTOvjnkf8o62K+IDPPkXFypgaqsBf5P0SXfs DftvRJoM/6xOo7VusBcDsZBrjW5wLRHSOtD6U= Received: by 10.204.157.17 with SMTP id z17mr9378762bkw.37.1327966725499; Mon, 30 Jan 2012 15:38:45 -0800 (PST) Received: from localhost ([91.144.186.21]) by mx.google.com with ESMTPS id 20sm30234379bkr.0.2012.01.30.15.38.43 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 30 Jan 2012 15:38:44 -0800 (PST) From: Dmitry Kurochkin To: Austin Clements , notmuch@notmuchmail.org Subject: Re: [PATCH 2/2] show: Simplify new text formatter code In-Reply-To: <1327560926-22401-3-git-send-email-amdragon@mit.edu> References: <1327560926-22401-1-git-send-email-amdragon@mit.edu> <1327560926-22401-3-git-send-email-amdragon@mit.edu> User-Agent: Notmuch/0.11+139~gd9b7cab (http://notmuchmail.org) Emacs/23.3.1 (x86_64-pc-linux-gnu) Date: Tue, 31 Jan 2012 03:37:33 +0400 Message-ID: <87lioooj7m.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: tomi.ollila@iki.fi X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Jan 2012 23:38:48 -0000 On Thu, 26 Jan 2012 01:55:26 -0500, Austin Clements wrote: > This makes the text formatter take advantage of the new code > structure. The previously duplicated header logic is now unified, > several things that we used to compute repeatedly across different > callbacks are now computed once, and the code is simpler overall and > 32% shorter. > > Unifying the header logic causes this to format some dates slightly > differently, so the two affected test cases are updated. > --- Looks good to me. Two minor comments, which can be freely ignored, are below. > notmuch-show.c | 88 +++++++++++++-------------------------------------- > test/crypto | 2 +- > test/thread-naming | 16 +++++----- > 3 files changed, 32 insertions(+), 74 deletions(-) > > diff --git a/notmuch-show.c b/notmuch-show.c > index 6a890b2..30f6501 100644 > --- a/notmuch-show.c > +++ b/notmuch-show.c > @@ -727,67 +727,48 @@ format_part_text (const void *ctx, mime_node_t *node, > GMimeObject *meta = node->envelope_part ? > GMIME_OBJECT (node->envelope_part) : node->part; > GMimeContentType *content_type = g_mime_object_get_content_type (meta); > + const notmuch_bool_t leaf = GMIME_IS_PART (node->part); > + const char *part_type; > int i; > > if (node->envelope_file) { > notmuch_message_t *message = node->envelope_file; > - const char *headers[] = { > - "Subject", "From", "To", "Cc", "Bcc", "Date" > - }; > - const char *name, *value; > - unsigned int i; > > - printf ("\fmessage{ "); > - printf ("id:%s depth:%d match:%d filename:%s\n", > + part_type = "message"; > + printf ("\f%s{ id:%s depth:%d match:%d filename:%s\n", > + part_type, > notmuch_message_get_message_id (message), > indent, > notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH), > notmuch_message_get_filename (message)); > - > - printf ("\fheader{\n"); > - > - printf ("%s\n", _get_one_line_summary (ctx, message)); > - > - for (i = 0; i < ARRAY_SIZE (headers); i++) { > - name = headers[i]; > - value = notmuch_message_get_header (message, name); > - if (value && strlen (value)) > - printf ("%s: %s\n", name, value); > - } > - printf ("\fheader}\n"); > } else { > GMimeContentDisposition *disposition = g_mime_object_get_content_disposition (meta); > const char *cid = g_mime_object_get_content_id (meta); > + const char *filename = leaf ? > + g_mime_part_get_filename (GMIME_PART (node->part)) : NULL; > > if (disposition && > strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0) > - { > - printf ("\fattachment{ ID: %d", node->part_num); > - > - } else { > - > - printf ("\fpart{ ID: %d", node->part_num); > - } > - > - if (GMIME_IS_PART (node->part)) > - { > - const char *filename = g_mime_part_get_filename (GMIME_PART (node->part)); > - if (filename) > - printf (", Filename: %s", filename); > - } > + part_type = "attachment"; > + else > + part_type = "part"; Others may disagree, but I would write this using the (? :) operator. Not important, feel free to leave it as is. > > + printf ("\f%s{ ID: %d", part_type, node->part_num); > + if (filename) > + printf (", Filename: %s", filename); > if (cid) > printf (", Content-id: %s", cid); > - > printf (", Content-type: %s\n", g_mime_content_type_to_string (content_type)); > } > > - if (node->envelope_part) { > + if (GMIME_IS_MESSAGE (node->part)) { > GMimeMessage *message = GMIME_MESSAGE (node->part); > InternetAddressList *recipients; > const char *recipients_string; > > printf ("\fheader{\n"); > + if (node->envelope_file) > + printf ("%s\n", _get_one_line_summary (ctx, node->envelope_file)); > printf ("Subject: %s\n", g_mime_message_get_subject (message)); > printf ("From: %s\n", g_mime_message_get_sender (message)); > recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO); > @@ -800,9 +781,11 @@ format_part_text (const void *ctx, mime_node_t *node, > printf ("Cc: %s\n", recipients_string); > printf ("Date: %s\n", g_mime_message_get_date_as_string (message)); > printf ("\fheader}\n"); > + > + printf ("\fbody{\n"); > } > > - if (!node->envelope_file) { > + if (leaf) { > if (g_mime_content_type_is_type (content_type, "text", "*") && > !g_mime_content_type_is_type (content_type, "text", "html")) > { > @@ -810,45 +793,20 @@ format_part_text (const void *ctx, mime_node_t *node, > g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream_stdout), FALSE); > show_text_part_content (node->part, stream_stdout); > g_object_unref(stream_stdout); > - } > - else if (g_mime_content_type_is_type (content_type, "multipart", "*") || > - g_mime_content_type_is_type (content_type, "message", "rfc822")) > - { > - /* Do nothing for multipart since its content will be printed > - * when recursing. */ > - } > - else > - { > + } else { > printf ("Non-text part: %s\n", > g_mime_content_type_to_string (content_type)); > } > } > > - if (GMIME_IS_MESSAGE (node->part)) > - printf ("\fbody{\n"); > - > for (i = 0; i < node->nchildren; i++) > format_part_text (ctx, mime_node_child (node, i), indent, params); > > - if (GMIME_IS_MESSAGE (node->part)) > + if (GMIME_IS_MESSAGE (node->part)) { Since the if body is one line, I would prefer to remove the closing bracket rather than adding the opening one. Regards, Dmitry > printf ("\fbody}\n"); > - > - if (node->envelope_file) { > - printf ("\fmessage}\n"); > - } else { > - GMimeContentDisposition *disposition; > - > - disposition = g_mime_object_get_content_disposition (meta); > - if (disposition && > - strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0) > - { > - printf ("\fattachment}\n"); > - } > - else > - { > - printf ("\fpart}\n"); > - } > } > + > + printf ("\f%s}\n", part_type); > } > > static void > diff --git a/test/crypto b/test/crypto > index 446a58b..1dbb60a 100755 > --- a/test/crypto > +++ b/test/crypto > @@ -159,7 +159,7 @@ Notmuch Test Suite (2000-01-01) (encrypted inbox) > Subject: test encrypted message 001 > From: Notmuch Test Suite > To: test_suite@notmuchmail.org > -Date: 01 Jan 2000 12:00:00 -0000 > +Date: Sat, 01 Jan 2000 12:00:00 +0000 > header} > body{ > part{ ID: 1, Content-type: multipart/encrypted > diff --git a/test/thread-naming b/test/thread-naming > index 2ce9216..942e593 100755 > --- a/test/thread-naming > +++ b/test/thread-naming > @@ -71,7 +71,7 @@ Notmuch Test Suite (2001-01-05) (unread) > Subject: thread-naming: Initial thread subject > From: Notmuch Test Suite > To: Notmuch Test Suite > -Date: Fri, 05 Jan 2001 15:43:56 -0000 > +Date: Fri, 05 Jan 2001 15:43:56 +0000 > header} > body{ > part{ ID: 1, Content-type: text/plain > @@ -85,7 +85,7 @@ Notmuch Test Suite (2001-01-06) (inbox unread) > Subject: thread-naming: Older changed subject > From: Notmuch Test Suite > To: Notmuch Test Suite > -Date: Sat, 06 Jan 2001 15:43:56 -0000 > +Date: Sat, 06 Jan 2001 15:43:56 +0000 > header} > body{ > part{ ID: 1, Content-type: text/plain > @@ -99,7 +99,7 @@ Notmuch Test Suite (2001-01-07) (inbox unread) > Subject: thread-naming: Newer changed subject > From: Notmuch Test Suite > To: Notmuch Test Suite > -Date: Sun, 07 Jan 2001 15:43:56 -0000 > +Date: Sun, 07 Jan 2001 15:43:56 +0000 > header} > body{ > part{ ID: 1, Content-type: text/plain > @@ -113,7 +113,7 @@ Notmuch Test Suite (2001-01-08) (unread) > Subject: thread-naming: Final thread subject > From: Notmuch Test Suite > To: Notmuch Test Suite > -Date: Mon, 08 Jan 2001 15:43:56 -0000 > +Date: Mon, 08 Jan 2001 15:43:56 +0000 > header} > body{ > part{ ID: 1, Content-type: text/plain > @@ -127,7 +127,7 @@ Notmuch Test Suite (2001-01-09) (inbox unread) > Subject: Re: thread-naming: Initial thread subject > From: Notmuch Test Suite > To: Notmuch Test Suite > -Date: Tue, 09 Jan 2001 15:43:45 -0000 > +Date: Tue, 09 Jan 2001 15:43:45 +0000 > header} > body{ > part{ ID: 1, Content-type: text/plain > @@ -141,7 +141,7 @@ Notmuch Test Suite (2001-01-10) (inbox unread) > Subject: Aw: thread-naming: Initial thread subject > From: Notmuch Test Suite > To: Notmuch Test Suite > -Date: Wed, 10 Jan 2001 15:43:45 -0000 > +Date: Wed, 10 Jan 2001 15:43:45 +0000 > header} > body{ > part{ ID: 1, Content-type: text/plain > @@ -155,7 +155,7 @@ Notmuch Test Suite (2001-01-11) (inbox unread) > Subject: Vs: thread-naming: Initial thread subject > From: Notmuch Test Suite > To: Notmuch Test Suite > -Date: Thu, 11 Jan 2001 15:43:45 -0000 > +Date: Thu, 11 Jan 2001 15:43:45 +0000 > header} > body{ > part{ ID: 1, Content-type: text/plain > @@ -169,7 +169,7 @@ Notmuch Test Suite (2001-01-12) (inbox unread) > Subject: Sv: thread-naming: Initial thread subject > From: Notmuch Test Suite > To: Notmuch Test Suite > -Date: Fri, 12 Jan 2001 15:43:45 -0000 > +Date: Fri, 12 Jan 2001 15:43:45 +0000 > header} > body{ > part{ ID: 1, Content-type: text/plain > -- > 1.7.7.3 >