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 0A18C429E54 for ; Mon, 23 Jan 2012 14:38:38 -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 2zvMBLeQFHfm for ; Mon, 23 Jan 2012 14:38:37 -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 202F3429E21 for ; Mon, 23 Jan 2012 14:38:36 -0800 (PST) Received: by bkbzt19 with SMTP id zt19so1782240bkb.26 for ; Mon, 23 Jan 2012 14:38:35 -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=zVi4hNELe+v81INSGDuYzniUcsTy8U9IJATbr4MermE=; b=wm+5ljffm6M1BZAynbdo7lUZ7Q1CmfUkMIAZLLuaziEHMSb7gcQhzNShG92UDV527Y yXDNbQgbGf1zPfCUkyNpupF8uq9ZHONl8BGOtYUVY/9jd92+sFH2j6LarJgoLOcvWDGw Slc0w4M7bpy7HfPsDbd+LaZDWrKgyP1NmbLs4= Received: by 10.204.154.211 with SMTP id p19mr4072050bkw.130.1327358315691; Mon, 23 Jan 2012 14:38:35 -0800 (PST) Received: from localhost ([91.144.186.21]) by mx.google.com with ESMTPS id ga13sm31546122bkc.5.2012.01.23.14.38.34 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 23 Jan 2012 14:38:34 -0800 (PST) From: Dmitry Kurochkin To: Austin Clements , notmuch@notmuchmail.org Subject: Re: [PATCH v2 3/3] show: Introduce mime_node formatter callback In-Reply-To: <1327285873-4713-4-git-send-email-amdragon@mit.edu> References: <1326918507-28033-1-git-send-email-amdragon@mit.edu> <1327285873-4713-1-git-send-email-amdragon@mit.edu> <1327285873-4713-4-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 02:37:30 +0400 Message-ID: <8739b6niz9.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: Mon, 23 Jan 2012 22:38:38 -0000 On Sun, 22 Jan 2012 21:31:13 -0500, Austin Clements wrote: > This callback is the gateway to the new mime_node_t-based formatters. > This maintains backwards compatibility so the formatters can be > transitioned one at a time. Once all formatters are converted, the > formatter structure can be reduced to only message_set_{start,sep,end} > and part, most of show_message can be deleted, and all of > show-message.c can be deleted. Few comments below. > --- > notmuch-client.h | 6 ++++++ > notmuch-reply.c | 2 +- > notmuch-show.c | 23 +++++++++++++++++++---- > 3 files changed, 26 insertions(+), 5 deletions(-) > > diff --git a/notmuch-client.h b/notmuch-client.h > index abfe5d3..59606b4 100644 > --- a/notmuch-client.h > +++ b/notmuch-client.h > @@ -62,8 +62,14 @@ > #define STRINGIFY(s) STRINGIFY_(s) > #define STRINGIFY_(s) #s > > +struct mime_node; > +struct notmuch_show_params; > + > typedef struct notmuch_show_format { > const char *message_set_start; > + void (*part) (const void *ctx, > + struct mime_node *node, int indent, > + struct notmuch_show_params *params); Can we make the params parameter const? > const char *message_start; > void (*message) (const void *ctx, > notmuch_message_t *message, > diff --git a/notmuch-reply.c b/notmuch-reply.c > index bf67960..f55b1d2 100644 > --- a/notmuch-reply.c > +++ b/notmuch-reply.c > @@ -31,7 +31,7 @@ static void > reply_part_content (GMimeObject *part); > > static const notmuch_show_format_t format_reply = { > - "", > + "", NULL, > "", NULL, > "", NULL, reply_headers_message_part, ">\n", > "", > diff --git a/notmuch-show.c b/notmuch-show.c > index 682aa71..8185b02 100644 > --- a/notmuch-show.c > +++ b/notmuch-show.c > @@ -42,7 +42,7 @@ static void > format_part_end_text (GMimeObject *part); > > 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", > @@ -89,7 +89,7 @@ static void > format_part_end_json (GMimeObject *part); > > static const notmuch_show_format_t format_json = { > - "[", > + "[", NULL, > "{", format_message_json, > "\"headers\": {", format_headers_json, format_headers_message_part_json, "}", > ", \"body\": [", > @@ -110,7 +110,7 @@ format_message_mbox (const void *ctx, > unused (int indent)); > > static const notmuch_show_format_t format_mbox = { > - "", > + "", NULL, > "", format_message_mbox, > "", NULL, NULL, "", > "", > @@ -129,7 +129,7 @@ static void > format_part_content_raw (GMimeObject *part); > > static const notmuch_show_format_t format_raw = { > - "", > + "", NULL, > "", NULL, > "", NULL, format_headers_message_part_text, "\n", > "", > @@ -850,6 +850,21 @@ show_message (void *ctx, > int indent, > notmuch_show_params_t *params) > { > + if (format->part) { > + void *local = talloc_new (ctx); > + mime_node_t *root, *part; > + > + if (mime_node_open (local, message, params->cryptoctx, params->decrypt, > + &root) != NOTMUCH_STATUS_SUCCESS) > + goto DONE; > + part = mime_node_seek_dfs (root, params->part < 0 ? 0 : params->part); This should be done as a separate patch, but it looks like zero and negative params->part is handled in the same way so we can change it to always be non-negative. > + if (part) > + format->part (local, part, indent, params); > + DONE: > + talloc_free (local); > + return; Please move part assignment inside the if and remove the goto: if (mime_node_open() == success && (part = seek())) format->part(); Regards, Dmitry > + } > + > if (params->part <= 0) { > fputs (format->message_start, stdout); > if (format->message) > -- > 1.7.7.3 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch