[PATCH v5 1/2] mime node: Record depth-first part numbers
authorAustin Clements <amdragon@MIT.EDU>
Mon, 23 Jan 2012 23:33:09 +0000 (18:33 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:43:04 +0000 (09:43 -0800)
84/39a60dbd2247c91520de0db552fdb3e1911731 [new file with mode: 0644]

diff --git a/84/39a60dbd2247c91520de0db552fdb3e1911731 b/84/39a60dbd2247c91520de0db552fdb3e1911731
new file mode 100644 (file)
index 0000000..fad4451
--- /dev/null
@@ -0,0 +1,204 @@
+Return-Path: <amthrax@drake.mit.edu>\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 B550C421192\r
+       for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 15:33:18 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[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 5Y3FsERrmEhk for <notmuch@notmuchmail.org>;\r
+       Mon, 23 Jan 2012 15:33:18 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-2.mit.edu (DMZ-MAILSEC-SCANNER-2.MIT.EDU\r
+       [18.9.25.13])\r
+       by olra.theworths.org (Postfix) with ESMTP id E15A0429E21\r
+       for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 15:33:17 -0800 (PST)\r
+X-AuditID: 1209190d-b7fbf6d0000008ba-1d-4f1dee3dd8ae\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+       by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 0B.68.02234.D3EED1F4; Mon, 23 Jan 2012 18:33:17 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q0NNXHln027010; \r
+       Mon, 23 Jan 2012 18:33:17 -0500\r
+Received: from drake.mit.edu (26-4-180.dynamic.csail.mit.edu [18.26.4.180])\r
+       (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0NNXFAD027080\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Mon, 23 Jan 2012 18:33:16 -0500 (EST)\r
+Received: from amthrax by drake.mit.edu with local (Exim 4.77)\r
+       (envelope-from <amthrax@drake.mit.edu>)\r
+       id 1RpTNz-00053f-7j; Mon, 23 Jan 2012 18:33:15 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v5 1/2] mime node: Record depth-first part numbers\r
+Date: Mon, 23 Jan 2012 18:33:09 -0500\r
+Message-Id: <1327361590-19273-2-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.7.3\r
+In-Reply-To: <1327361590-19273-1-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
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFjrHIsWRmVeSWpSXmKPExsUixG6nrmv7TtbfYNckeYurW/vZLZqmO1tc\r
+       vzmT2eLNynmsDiweO2fdZfc4/HUhi8et+6/ZPZ6tusUcwBLFZZOSmpNZllqkb5fAlXHm4R+W\r
+       gvnKFSdbVrA0MG6U7mLk5JAQMJGYs+ARI4QtJnHh3nq2LkYuDiGBfYwScz7/g3I2MEocvf4A\r
+       yjnOJLFjdhcLSIuQwHxGiY8TJEFsNgENiW37l4ONEhGQlth5dzZrFyMHB7NAgcTkC8YgYWEB\r
+       J4k/d3rBSlgEVCW+fvjCBmLzCjhIfGiCsCUEFCTOrT7HDmJzCjhKnL35jRFkjJBAucSeq4YT\r
+       GPkXMDKsYpRNya3SzU3MzClOTdYtTk7My0st0jXSy80s0UtNKd3ECAo2TkneHYzvDiodYhTg\r
+       YFTi4ZWYKesvxJpYVlyZe4hRkoNJSZTX9TVQiC8pP6UyI7E4I76oNCe1+BCjBAezkgiv2jmg\r
+       HG9KYmVValE+TEqag0VJnFdV652fkEB6YklqdmpqQWoRTFaGg0NJgrfoLVCjYFFqempFWmZO\r
+       CUKaiYMTZDgP0PB0kBre4oLE3OLMdIj8KUZFKXHeYpCEAEgiozQPrheWDF4xigO9IsxbDlLF\r
+       A0wkcN2vgAYzAQ3myJMCGVySiJCSamDUnWG7Vc7qq5CUw4YSSfsvFszrIhJvfn/rdGrT4i8N\r
+       P5m4eRN5Ul5ez95t6rBnVrD277vpQbOCjGbMVRWROZTTssi451LWCsGZBRcmX7P0bzxQFhL4\r
+       Y6sus2rhceFzpwRKNiXV5VzkNtx7fEXFlttvvS1bi7Z8lTo+N6X88EnxvH9PM2RED+sosRRn\r
+       JBpqMRcVJwIA3sR3XeECAAA=\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:33:19 -0000\r
+\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
+ 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