From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 9B23F6DE0352 for ; Fri, 21 Jul 2017 03:59:01 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.001 X-Spam-Level: X-Spam-Status: No, score=-0.001 tagged_above=-999 required=5 tests=[AWL=0.010, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ERcVhSj7DAZU for ; Fri, 21 Jul 2017 03:59:01 -0700 (PDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id 3F47C6DE00C6 for ; Fri, 21 Jul 2017 03:58:54 -0700 (PDT) Received: from remotemail by fethera.tethera.net with local (Exim 4.84_2) (envelope-from ) id 1dYVam-0002yI-PV; Fri, 21 Jul 2017 06:55:32 -0400 Received: (nullmailer pid 4898 invoked by uid 1000); Fri, 21 Jul 2017 10:58:46 -0000 From: David Bremner To: notmuch@notmuchmail.org, notmuch@freelists.org Subject: [Patch v4 02/12] lib/n_d_add_message: refactor test for new/ghost messages Date: Fri, 21 Jul 2017 07:58:30 -0300 Message-Id: <20170721105840.4737-3-david@tethera.net> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170721105840.4737-1-david@tethera.net> References: <20170721105840.4737-1-david@tethera.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.23 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: Fri, 21 Jul 2017 10:59:01 -0000 The switch is easier to understand than the side effects in the if test. It also potentially allows us more flexibility in breaking up this function into smaller pieces, since passing private_status around is icky. --- lib/add-message.cc | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/add-message.cc b/lib/add-message.cc index 5fe2c45b..0f09415e 100644 --- a/lib/add-message.cc +++ b/lib/add-message.cc @@ -570,7 +570,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch, notmuch_message_t *message = NULL; notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS, ret2; notmuch_private_status_t private_status; - notmuch_bool_t is_ghost = false; + notmuch_bool_t is_ghost = FALSE, is_new = FALSE; const char *date, *header; const char *from, *to, *subject; @@ -655,7 +655,17 @@ notmuch_database_add_message (notmuch_database_t *notmuch, talloc_free (message_id); - if (message == NULL) { + /* We cannot call notmuch_message_get_flag for a new message */ + switch (private_status) { + case NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND: + is_ghost = FALSE; + is_new = TRUE; + break; + case NOTMUCH_PRIVATE_STATUS_SUCCESS: + is_ghost = notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_GHOST); + is_new = FALSE; + break; + default: ret = COERCE_STATUS (private_status, "Unexpected status value from _notmuch_message_create_for_message_id"); goto DONE; @@ -663,18 +673,11 @@ notmuch_database_add_message (notmuch_database_t *notmuch, _notmuch_message_add_filename (message, filename); - /* Is this a newly created message object or a ghost - * message? We have to be slightly careful: if this is a - * blank message, it's not safe to call - * notmuch_message_get_flag yet. */ - if (private_status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND || - (is_ghost = notmuch_message_get_flag ( - message, NOTMUCH_MESSAGE_FLAG_GHOST))) { + if (is_new || is_ghost) { _notmuch_message_add_term (message, "type", "mail"); if (is_ghost) /* Convert ghost message to a regular message */ _notmuch_message_remove_term (message, "type", "ghost"); - ret = _notmuch_database_link_message (notmuch, message, message_file, is_ghost); if (ret) -- 2.13.2