[PATCH v2 2/9] cli: abstract new mailbox creation
authorJani Nikula <jani@nikula.org>
Thu, 3 Sep 2015 19:39:58 +0000 (22:39 +0300)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 21:49:30 +0000 (14:49 -0700)
68/33c1fd4ff9c9a8f62bbae5e7a2a69c049e006a [new file with mode: 0644]

diff --git a/68/33c1fd4ff9c9a8f62bbae5e7a2a69c049e006a b/68/33c1fd4ff9c9a8f62bbae5e7a2a69c049e006a
new file mode 100644 (file)
index 0000000..2f74031
--- /dev/null
@@ -0,0 +1,120 @@
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 0D0A26DE17BF\r
+ for <notmuch@notmuchmail.org>; Thu,  3 Sep 2015 12:40:28 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.416\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.416 tagged_above=-999 required=5 tests=[AWL=0.304,\r
+  RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id EoiBePqI9XWk for <notmuch@notmuchmail.org>;\r
+ Thu,  3 Sep 2015 12:40:26 -0700 (PDT)\r
+Received: from mail-wi0-f178.google.com (mail-wi0-f178.google.com\r
+ [209.85.212.178])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id D04F26DE1534\r
+ for <notmuch@notmuchmail.org>; Thu,  3 Sep 2015 12:40:15 -0700 (PDT)\r
+Received: by wiclk2 with SMTP id lk2so19111569wic.1\r
+ for <notmuch@notmuchmail.org>; Thu, 03 Sep 2015 12:40:13 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\r
+ :references:in-reply-to:references;\r
+ bh=7x21swL2LRVephKeotLrwmieDqRaO00TDhQTFy28Q6k=;\r
+ b=I5x4/Le4CQ9ij/EGute5b4TnQejQDVWowVLSBg8tooKl7i8AQzWvPa7388qDT4qxUt\r
+ 7gqhogx3SJBPY3/plgf+HuFw350Wm2weEHhD68LXLQKZHoF9rpszL7iUgwPfShBo9+to\r
+ F4BmBZ0c0fJdoDSsaG8Jt1gJpNzOXN2upHF4ZQz5xTlJkZTMlw8IJaFCNsY2iAiLb43Q\r
+ RuTCjtWihBrR6ln6KHcukkj0LmCb0oHN29pPjV36ghiKcJIH/2O3kcPBRrt27OuHLsxi\r
+ ojKEMrYAW8iHNP+rDvROz3g4nv0wbgDV0Q6ZWiMpenroqtPMpDrTYawX19yrXInuGtPR\r
+ m+Jw==\r
+X-Gm-Message-State:\r
+ ALoCoQkGyD9dt5hpwztHMVu/LAAJNdM8QVZLoj5UsCu4lYGGVU+2dTsrA6ROiRwotIvIaXa0Lbeq\r
+X-Received: by 10.180.104.68 with SMTP id gc4mr18128958wib.67.1441309212975;\r
+ Thu, 03 Sep 2015 12:40:12 -0700 (PDT)\r
+Received: from localhost (mobile-access-bcee4f-131.dhcp.inet.fi.\r
+ [188.238.79.131])\r
+ by smtp.gmail.com with ESMTPSA id c11sm114253wib.1.2015.09.03.12.40.12\r
+ (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Thu, 03 Sep 2015 12:40:12 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 2/9] cli: abstract new mailbox creation\r
+Date: Thu,  3 Sep 2015 22:39:58 +0300\r
+Message-Id:\r
+ <cf56a57d13ea2ae8f3115d602a640a11a2b7e5a0.1441308761.git.jani@nikula.org>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <cover.1441308761.git.jani@nikula.org>\r
+References: <cover.1441308761.git.jani@nikula.org>\r
+In-Reply-To: <cover.1441308761.git.jani@nikula.org>\r
+References: <cover.1441308761.git.jani@nikula.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.18\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: Thu, 03 Sep 2015 19:40:28 -0000\r
+\r
+We'll be needing more mailbox creation soon, so abstract it\r
+away. While at it, check for allocation failures. No other functional\r
+changes.\r
+---\r
+ notmuch-search.c | 23 +++++++++++++++++++----\r
+ 1 file changed, 19 insertions(+), 4 deletions(-)\r
+\r
+diff --git a/notmuch-search.c b/notmuch-search.c\r
+index 7fdc6acaa2fe..36f58eb8d54c 100644\r
+--- a/notmuch-search.c\r
++++ b/notmuch-search.c\r
+@@ -243,6 +243,21 @@ do_search_threads (search_context_t *ctx)\r
+     return 0;\r
+ }\r
\r
++static mailbox_t *new_mailbox (void *ctx, const char *name, const char *addr)\r
++{\r
++    mailbox_t *mailbox;\r
++\r
++    mailbox = talloc (ctx, mailbox_t);\r
++    if (! mailbox)\r
++      return NULL;\r
++\r
++    mailbox->name = talloc_strdup (mailbox, name);\r
++    mailbox->addr = talloc_strdup (mailbox, addr);\r
++    mailbox->count = 1;\r
++\r
++    return mailbox;\r
++}\r
++\r
+ /* Returns TRUE iff name and addr is duplicate. If not, stores the\r
+  * name/addr pair in order to detect subsequent duplicates. */\r
+ static notmuch_bool_t\r
+@@ -262,10 +277,10 @@ is_duplicate (const search_context_t *ctx, const char *name, const char *addr)\r
+       return TRUE;\r
+     }\r
\r
+-    mailbox = talloc (ctx->format, mailbox_t);\r
+-    mailbox->name = talloc_strdup (mailbox, name);\r
+-    mailbox->addr = talloc_strdup (mailbox, addr);\r
+-    mailbox->count = 1;\r
++    mailbox = new_mailbox (ctx->format, name, addr);\r
++    if (! mailbox)\r
++      return FALSE;\r
++\r
+     g_hash_table_insert (ctx->addresses, key, mailbox);\r
\r
+     return FALSE;\r
+-- \r
+2.1.4\r
+\r