--- /dev/null
+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 672416DE17D7\r
+ for <notmuch@notmuchmail.org>; Sat, 29 Aug 2015 07:56:47 -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.322\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.322 tagged_above=-999 required=5 tests=[AWL=0.398,\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 RnYGQTNEmNdK for <notmuch@notmuchmail.org>;\r
+ Sat, 29 Aug 2015 07:56:45 -0700 (PDT)\r
+Received: from mail-wi0-f176.google.com (mail-wi0-f176.google.com\r
+ [209.85.212.176])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 6B6036DE1552\r
+ for <notmuch@notmuchmail.org>; Sat, 29 Aug 2015 07:56:45 -0700 (PDT)\r
+Received: by wicne3 with SMTP id ne3so9345296wic.0\r
+ for <notmuch@notmuchmail.org>; Sat, 29 Aug 2015 07:56:43 -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=PvDF5BMMZrU5mAQhKHsgspX1B+SuJfZXxrWhtW6Oj6g/XIeqXXR9yMdrv1jAc3ViIb\r
+ 046GjHgi9UNjlLm7APVdEPUZ+/OhjuD/n/Y9w/Nhp6ROQcR/SRsp7r8vQQckRKA3lLx7\r
+ w0s0WhKovzQgzZqthme1RtM1bvgy196eJX46JSyOd0Vz+3v+hPAMci6rlMv2GUPwXD6M\r
+ JnEGxM5bgH6bxzghuG5p2K4Yy9V2vzZeWAQHtwFTU0qe6pWYbBC4pfbwiW4P1fRdEmap\r
+ e0Vchanefc/abwuPlrv0lQyi/n/G2lGekXodBdJxrLL+p9A5x7uNMJ/5NuyPvDg35185\r
+ AuVw==\r
+X-Gm-Message-State:\r
+ ALoCoQnO80z6rnwuLyBdWVJ8N5ln9pCDPk7vcQJ+VIjCHO0Ke/+nEsiKvVgTQnTe1KqtJKWMjetn\r
+X-Received: by 10.180.89.99 with SMTP id bn3mr9762037wib.61.1440860203417;\r
+ Sat, 29 Aug 2015 07:56:43 -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 yu4sm13137828wjc.43.2015.08.29.07.56.42\r
+ (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Sat, 29 Aug 2015 07:56:42 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [RFC PATCH 2/5] cli: abstract new mailbox creation\r
+Date: Sat, 29 Aug 2015 17:56:33 +0300\r
+Message-Id:\r
+ <cf56a57d13ea2ae8f3115d602a640a11a2b7e5a0.1440859765.git.jani@nikula.org>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <cover.1440859765.git.jani@nikula.org>\r
+References: <cover.1440859765.git.jani@nikula.org>\r
+In-Reply-To: <cover.1440859765.git.jani@nikula.org>\r
+References: <cover.1440859765.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: Sat, 29 Aug 2015 14:56:47 -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