Re: [PATCH v5 1/2] mime node: Record depth-first part numbers
authorDmitry Kurochkin <dmitry.kurochkin@gmail.com>
Mon, 23 Jan 2012 23:36:17 +0000 (03:36 +0400)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:43:05 +0000 (09:43 -0800)
88/44d6499fbb122de5277345c98f080eeff055fa [new file with mode: 0644]

diff --git a/88/44d6499fbb122de5277345c98f080eeff055fa b/88/44d6499fbb122de5277345c98f080eeff055fa
new file mode 100644 (file)
index 0000000..4690fa1
--- /dev/null
@@ -0,0 +1,202 @@
+Return-Path: <dmitry.kurochkin@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id E0026429E54\r
+       for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 15:37:25 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id 9R2mJitzPYxz for <notmuch@notmuchmail.org>;\r
+       Mon, 23 Jan 2012 15:37:25 -0800 (PST)\r
+Received: from mail-bk0-f53.google.com (mail-bk0-f53.google.com\r
+       [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 13CCD429E21\r
+       for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 15:37:24 -0800 (PST)\r
+Received: by bkbzt19 with SMTP id zt19so1820797bkb.26\r
+       for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 15:37:23 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
+       h=from:to:cc:subject:in-reply-to:references:user-agent:date\r
+       :message-id:mime-version:content-type;\r
+       bh=ooJJXrUSWM99uGB/V3gmVPG0jx3wknCQpXD0+EzoHKg=;\r
+       b=Xjrk3Up1jBl2TnOhPTMZGXEG0PpHtKnR8LpYvft87ZdUvyM8VynZkjXjCFtgPIXFag\r
+       Gspq2HpJQaYTRepEeLyT/wDb3aJ7otBIWalkKcUdJWc2fgm8bROo2gvqgvM5ropIs/5/\r
+       +ZgJp8jWJjJp2p7j7lvyfyG4gPjSrVozxbl8Q=\r
+Received: by 10.205.129.132 with SMTP id hi4mr4045653bkc.44.1327361843662;\r
+       Mon, 23 Jan 2012 15:37:23 -0800 (PST)\r
+Received: from localhost ([91.144.186.21])\r
+       by mx.google.com with ESMTPS id ga13sm31844277bkc.5.2012.01.23.15.37.21\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Mon, 23 Jan 2012 15:37:22 -0800 (PST)\r
+From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>\r
+To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v5 1/2] mime node: Record depth-first part numbers\r
+In-Reply-To: <1327361590-19273-2-git-send-email-amdragon@mit.edu>\r
+References: <1326918507-28033-1-git-send-email-amdragon@mit.edu>\r
+       <1327361590-19273-1-git-send-email-amdragon@mit.edu>\r
+       <1327361590-19273-2-git-send-email-amdragon@mit.edu>\r
+User-Agent: Notmuch/0.11+100~gd650abf (http://notmuchmail.org) Emacs/23.3.1\r
+       (x86_64-pc-linux-gnu)\r
+Date: Tue, 24 Jan 2012 03:36:17 +0400\r
+Message-ID: <87ty3mm1ou.fsf@gmail.com>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Cc: tomi.ollila@iki.fi\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 23 Jan 2012 23:37:26 -0000\r
+\r
+On Mon, 23 Jan 2012 18:33:09 -0500, Austin Clements <amdragon@MIT.EDU> wrote:\r
+> This makes the part numbers readily accessible to formatters.\r
+> Hierarchical part numbering would be a more natural and efficient fit\r
+> for MIME and may be the way to go in the future, but depth-first\r
+> numbering maintains compatibility with what we currently do.\r
+\r
+LGTM\r
+\r
+Regards,\r
+  Dmitry\r
+\r
+> ---\r
+>  mime-node.c      |   38 +++++++++++++++++++++++++++++++++++---\r
+>  notmuch-client.h |   14 +++++++++++++-\r
+>  2 files changed, 48 insertions(+), 4 deletions(-)\r
+> \r
+> diff --git a/mime-node.c b/mime-node.c\r
+> index 27077f7..d6b4506 100644\r
+> --- a/mime-node.c\r
+> +++ b/mime-node.c\r
+> @@ -112,6 +112,11 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
+>      root->nchildren = 1;\r
+>      root->ctx = mctx;\r
+>  \r
+> +    root->parent = NULL;\r
+> +    root->part_num = 0;\r
+> +    root->next_child = 0;\r
+> +    root->next_part_num = 1;\r
+> +\r
+>      *root_out = root;\r
+>      return NOTMUCH_STATUS_SUCCESS;\r
+>  \r
+> @@ -137,7 +142,7 @@ _signature_validity_free (GMimeSignatureValidity **proxy)\r
+>  #endif\r
+>  \r
+>  static mime_node_t *\r
+> -_mime_node_create (const mime_node_t *parent, GMimeObject *part)\r
+> +_mime_node_create (mime_node_t *parent, GMimeObject *part)\r
+>  {\r
+>      mime_node_t *node = talloc_zero (parent, mime_node_t);\r
+>      GError *err = NULL;\r
+> @@ -150,6 +155,9 @@ _mime_node_create (const mime_node_t *parent, GMimeObject *part)\r
+>      talloc_free (node);\r
+>      return NULL;\r
+>      }\r
+> +    node->parent = parent;\r
+> +    node->part_num = node->next_part_num = -1;\r
+> +    node->next_child = 0;\r
+>  \r
+>      /* Deal with the different types of parts */\r
+>      if (GMIME_IS_PART (part)) {\r
+> @@ -267,9 +275,10 @@ _mime_node_create (const mime_node_t *parent, GMimeObject *part)\r
+>  }\r
+>  \r
+>  mime_node_t *\r
+> -mime_node_child (const mime_node_t *parent, int child)\r
+> +mime_node_child (mime_node_t *parent, int child)\r
+>  {\r
+>      GMimeObject *sub;\r
+> +    mime_node_t *node;\r
+>  \r
+>      if (!parent || child < 0 || child >= parent->nchildren)\r
+>      return NULL;\r
+> @@ -287,7 +296,30 @@ mime_node_child (const mime_node_t *parent, int child)\r
+>      INTERNAL_ERROR ("Unexpected GMimeObject type: %s",\r
+>                      g_type_name (G_OBJECT_TYPE (parent->part)));\r
+>      }\r
+> -    return _mime_node_create (parent, sub);\r
+> +    node = _mime_node_create (parent, sub);\r
+> +\r
+> +    if (child == parent->next_child && parent->next_part_num != -1) {\r
+> +    /* We're traversing in depth-first order.  Record the child's\r
+> +     * depth-first numbering. */\r
+> +    node->part_num = parent->next_part_num;\r
+> +    node->next_part_num = node->part_num + 1;\r
+> +\r
+> +    /* Prepare the parent for its next depth-first child. */\r
+> +    parent->next_child++;\r
+> +    parent->next_part_num = -1;\r
+> +\r
+> +    if (node->nchildren == 0) {\r
+> +        /* We've reached a leaf, so find the parent that has more\r
+> +         * children and set it up to number its next child. */\r
+> +        mime_node_t *iter = node->parent;\r
+> +        while (iter && iter->next_child == iter->nchildren)\r
+> +            iter = iter->parent;\r
+> +        if (iter)\r
+> +            iter->next_part_num = node->part_num + 1;\r
+> +    }\r
+> +    }\r
+> +\r
+> +    return node;\r
+>  }\r
+>  \r
+>  static mime_node_t *\r
+> diff --git a/notmuch-client.h b/notmuch-client.h\r
+> index 9c1d383..abfe5d3 100644\r
+> --- a/notmuch-client.h\r
+> +++ b/notmuch-client.h\r
+> @@ -297,6 +297,13 @@ typedef struct mime_node {\r
+>      /* The number of children of this part. */\r
+>      int nchildren;\r
+>  \r
+> +    /* The parent of this node or NULL if this is the root node. */\r
+> +    struct mime_node *parent;\r
+> +\r
+> +    /* The depth-first part number of this child if the MIME tree is\r
+> +     * being traversed in depth-first order, or -1 otherwise. */\r
+> +    int part_num;\r
+> +\r
+>      /* True if decryption of this part was attempted. */\r
+>      notmuch_bool_t decrypt_attempted;\r
+>      /* True if decryption of this part's child succeeded.  In this\r
+> @@ -324,6 +331,11 @@ typedef struct mime_node {\r
+>      /* Internal: For successfully decrypted multipart parts, the\r
+>       * decrypted part to substitute for the second child. */\r
+>      GMimeObject *decrypted_child;\r
+> +\r
+> +    /* Internal: The next child for depth-first traversal and the part\r
+> +     * number to assign it (or -1 if unknown). */\r
+> +    int next_child;\r
+> +    int next_part_num;\r
+>  } mime_node_t;\r
+>  \r
+>  /* Construct a new MIME node pointing to the root message part of\r
+> @@ -356,7 +368,7 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
+>   * an error message on stderr).\r
+>   */\r
+>  mime_node_t *\r
+> -mime_node_child (const mime_node_t *parent, int child);\r
+> +mime_node_child (mime_node_t *parent, int child);\r
+>  \r
+>  /* Return the nth child of node in a depth-first traversal.  If n is\r
+>   * 0, returns node itself.  Returns NULL if there is no such part. */\r
+> -- \r
+> 1.7.7.3\r
+> \r