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 4C780429E54 for ; Mon, 23 Jan 2012 17:33:45 -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 f70La6sAEDmk for ; Mon, 23 Jan 2012 17:33:44 -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 D0BFE429E21 for ; Mon, 23 Jan 2012 17:33:43 -0800 (PST) Received: by bkbzt19 with SMTP id zt19so1887462bkb.26 for ; Mon, 23 Jan 2012 17:33:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:subject:in-reply-to:references:user-agent:date:message-id :mime-version:content-type; bh=IesD17Hs1dHa9Qz6sRY0gVntzjFxoRzOiRWFHkl/fG8=; b=OC6G6mdnPFxNAnchT4rGR0j3ginzDzkKNjODlnLSbo5dTwBxJHRQQlC7AkVkVnNvy7 HyEaTl6UNV4awE4Tv9oEO8gThoHnRI99Nsn9P3Dkr3ywZfoQWGR4OUKMwslWD4g0fbxZ Cn76CIzk/ErI7DAFqWpc0PJmfvvMAxz2F35QI= Received: by 10.204.152.201 with SMTP id h9mr4171823bkw.105.1327368820742; Mon, 23 Jan 2012 17:33:40 -0800 (PST) Received: from localhost ([91.144.186.21]) by mx.google.com with ESMTPS id cz3sm26899808bkb.3.2012.01.23.17.33.39 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 23 Jan 2012 17:33:39 -0800 (PST) From: Dmitry Kurochkin To: Austin Clements , notmuch@notmuchmail.org Subject: Re: [RFC PATCH 4/5] show: Convert text format to the new self-recursive style In-Reply-To: <1326332973-30225-5-git-send-email-amdragon@mit.edu> References: <1326332973-30225-1-git-send-email-amdragon@mit.edu> <1326332973-30225-5-git-send-email-amdragon@mit.edu> User-Agent: Notmuch/0.11+100~gd650abf (http://notmuchmail.org) Emacs/23.3.1 (x86_64-pc-linux-gnu) Date: Tue, 24 Jan 2012 05:32:35 +0400 Message-ID: <87obttnavg.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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: Tue, 24 Jan 2012 01:33:45 -0000 On Wed, 11 Jan 2012 20:49:32 -0500, Austin Clements wrote: > This is all code movement and a smidgen of glue. This moves the > existing text formatter code into one self-recursive function, but > doesn't change any of the logic. The next patch will actually take > advantage of what the new structure has to offer. The patch looks good to me. Regards, Dmitry > --- > notmuch-show.c | 267 +++++++++++++++++++++++++++++--------------------------- > 1 files changed, 140 insertions(+), 127 deletions(-) > > diff --git a/notmuch-show.c b/notmuch-show.c > index ad54d69..3241965 100644 > --- a/notmuch-show.c > +++ b/notmuch-show.c > @@ -21,40 +21,17 @@ > #include "notmuch-client.h" > > static void > -format_message_text (unused (const void *ctx), > - notmuch_message_t *message, > - int indent); > -static void > -format_headers_text (const void *ctx, > - notmuch_message_t *message); > - > -static void > format_headers_message_part_text (GMimeMessage *message); > > static void > -format_part_start_text (GMimeObject *part, > - int *part_count); > - > -static void > -format_part_content_text (GMimeObject *part); > - > -static void > -format_part_end_text (GMimeObject *part); > +format_part_text (const void *ctx, mime_node_t *node, > + int indent, notmuch_show_params_t *params); > > static const notmuch_show_format_t format_text = { > - "", NULL, > - "\fmessage{ ", format_message_text, > - "\fheader{\n", format_headers_text, format_headers_message_part_text, "\fheader}\n", > - "\fbody{\n", > - format_part_start_text, > - NULL, > - NULL, > - format_part_content_text, > - format_part_end_text, > - "", > - "\fbody}\n", > - "\fmessage}\n", "", > - "" > + .message_set_start = "", > + .part = format_part_text, > + .message_set_sep = "", > + .message_set_end = "" > }; > > static void > @@ -140,6 +117,9 @@ static const notmuch_show_format_t format_raw = { > "" > }; > > +static void > +show_text_part_content (GMimeObject *part, GMimeStream *stream_out); > + > static const char * > _get_tags_as_string (const void *ctx, notmuch_message_t *message) > { > @@ -187,13 +167,138 @@ _get_one_line_summary (const void *ctx, notmuch_message_t *message) > } > > static void > -format_message_text (unused (const void *ctx), notmuch_message_t *message, int indent) > +format_part_text (const void *ctx, mime_node_t *node, > + int indent, notmuch_show_params_t *params) > { > - printf ("id:%s depth:%d match:%d filename:%s\n", > - notmuch_message_get_message_id (message), > - indent, > - notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH), > - notmuch_message_get_filename (message)); > + /* The disposition and content-type metadata are associated with > + * the envelope for message parts */ > + GMimeObject *meta = node->envelope_part ? > + GMIME_OBJECT (node->envelope_part) : node->part; > + GMimeContentType *content_type = g_mime_object_get_content_type (meta); > + 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", > + 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); > + > + 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); > + } > + > + if (cid) > + printf (", Content-id: %s", cid); > + > + printf (", Content-type: %s\n", g_mime_content_type_to_string (content_type)); > + } > + > + if (node->envelope_part) { > + GMimeMessage *message = GMIME_MESSAGE (node->part); > + InternetAddressList *recipients; > + const char *recipients_string; > + > + printf ("\fheader{\n"); > + 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); > + 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 ("Date: %s\n", g_mime_message_get_date_as_string (message)); > + printf ("\fheader}\n"); > + } > + > + if (!node->envelope_file) { > + 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); > + 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 > + { > + 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)) { > + 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"); > + } > + } > } > > static void > @@ -334,26 +439,6 @@ format_message_mbox (const void *ctx, > fclose (file); > } > > - > -static void > -format_headers_text (const void *ctx, notmuch_message_t *message) > -{ > - const char *headers[] = { > - "Subject", "From", "To", "Cc", "Bcc", "Date" > - }; > - const char *name, *value; > - unsigned int i; > - > - 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); > - } > -} > - > static void > format_headers_message_part_text (GMimeMessage *message) > { > @@ -503,78 +588,6 @@ signer_status_to_string (GMimeSignerStatus x) > } > > static void > -format_part_start_text (GMimeObject *part, int *part_count) > -{ > - GMimeContentDisposition *disposition = g_mime_object_get_content_disposition (part); > - > - if (disposition && > - strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0) > - { > - printf ("\fattachment{ ID: %d", *part_count); > - > - } else { > - > - printf ("\fpart{ ID: %d", *part_count); > - } > -} > - > -static void > -format_part_content_text (GMimeObject *part) > -{ > - const char *cid = g_mime_object_get_content_id (part); > - GMimeContentType *content_type = g_mime_object_get_content_type (GMIME_OBJECT (part)); > - > - if (GMIME_IS_PART (part)) > - { > - const char *filename = g_mime_part_get_filename (GMIME_PART (part)); > - 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 (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); > - 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 > - { > - printf ("Non-text part: %s\n", > - g_mime_content_type_to_string (content_type)); > - } > -} > - > -static void > -format_part_end_text (GMimeObject *part) > -{ > - GMimeContentDisposition *disposition; > - > - disposition = g_mime_object_get_content_disposition (part); > - if (disposition && > - strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0) > - { > - printf ("\fattachment}\n"); > - } > - else > - { > - printf ("\fpart}\n"); > - } > -} > - > -static void > format_part_start_json (unused (GMimeObject *part), int *part_count) > { > printf ("{\"id\": %d", *part_count); > -- > 1.7.7.3 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch