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 21C6E6DE1154 for ; Sat, 12 Aug 2017 09:47:49 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.494 X-Spam-Level: X-Spam-Status: No, score=0.494 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_WEB=0.614, SPF_PASS=-0.001] 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 JcXYBlJaBHfG for ; Sat, 12 Aug 2017 09:47:48 -0700 (PDT) Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by arlo.cworth.org (Postfix) with ESMTPS id 42A766DE115C for ; Sat, 12 Aug 2017 09:47:48 -0700 (PDT) Received: by mail-wm0-f65.google.com with SMTP id t138so9731893wmt.4 for ; Sat, 12 Aug 2017 09:47:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=jL2pOp5TD7AIxvp+jLRfG7FAlqWeiUhEyJfFcJ6vyGE=; b=KiOHzPH/+bzjgDmLeNb8KBYOfSNnyGXWA4Dzb0NO1tKC/R8WEPt/QSgoQGnly07Jel z8SIWyE3J5BpvflUl29XlrkfvnK03iOanKW+BTVpC/zA0mfB/2A66RQ5KIAEc6tWa/vM 1syZrdHfIfGhywKxckIFmHpMK/FvbWIk4fU7yJfj8oo8KPjtj8RQ+Y7QoJR8ypdZhnlM 9qstMHDc8QiZcxApBITTvufKtONie7HwJXYoSqMozZdxWrC0+j8HZgUzDZrMFL2WhyWd Yry0fu8x0oJ3tpfkrWB9bCcUkbQk0de+ziK2NAwPyHPU1K1qfhip8JAc5l2rc007vaC/ TRRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=jL2pOp5TD7AIxvp+jLRfG7FAlqWeiUhEyJfFcJ6vyGE=; b=hb/btKXVJHExbydmrqDID+2GeexiRtkguilfWixnu9Szy/a3KlPH3VeyMGqtrv/y3U 1G74+GE2/LtvL8I1Rr4mkW/b8fcp14By5nSH//TLewrerVELFa4NqQhvSaME4lGmoh5i aTB6ioaWfVVWy9LZwCAndwjNzzyYH9KxlY2FGqTyP8buHN+CUnfrt4Q1MzhD+ssTir+B 0dnF/zCLt9fRLaNBAWTFsUNkf20n/68EeQYtznUmri3C22xj93ltyS/yhSw/H2SjLGF9 WV/H+78Qh5pSSqn0jUI0mk8koraTslbaqWDuGePl9PS7EL0k1nqejfv17qn/NhHWpgS3 eeFA== X-Gm-Message-State: AHYfb5j9KqT0L4/fYhwpl5ZXSottEVxBBRyggViTyciZ6Y86RrF+KTX+ h+zcAp5hDkk5D088zrQ= X-Received: by 10.28.62.134 with SMTP id l128mr1147380wma.87.1502556466549; Sat, 12 Aug 2017 09:47:46 -0700 (PDT) Received: from localhost (HSI-KBW-046-005-019-096.hsi8.kabel-badenwuerttemberg.de. [46.5.19.96]) by smtp.gmail.com with ESMTPSA id 52sm5514905wrt.38.2017.08.12.09.47.45 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 12 Aug 2017 09:47:46 -0700 (PDT) From: Yuri Volchkov To: notmuch@notmuchmail.org Subject: [PATCH 2/4] insert: strip trailing / in folder path Date: Sat, 12 Aug 2017 18:47:31 +0200 Message-Id: <1502556453-11609-3-git-send-email-yuri.volchkov@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502556453-11609-1-git-send-email-yuri.volchkov@gmail.com> References: <1502556453-11609-1-git-send-email-yuri.volchkov@gmail.com> X-Mailman-Approved-At: Sat, 12 Aug 2017 13:16:46 -0700 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: Sat, 12 Aug 2017 16:47:49 -0000 I have faced a problem, that messages sent by emacs could not be shown or found later. The "notmuch show id:" says "no such file or directory". The reason of this behavior is the following chain of events: 1) While sending a message, emacs calls notmuch insert --folder=maildir/Sent/ < test.msg From database's point of view, "Sent" and "Sent/" are different folders, and the separate record is created for the "Sent/". For the sake of simplicity let's assume inserted message will be stored as "maildir/Sent//new/msg_file_orig" (note the double slash) 2) During next sync, offlineimap uploads this message to the server, renames the source file according to his or servers naming convention. Let's say it is renamed to "maildir/Sent/new/msg_file_renamed" 3) The "notmuch new" command, composes a list of folders which has been modified. Obviously, the "Sent" dir is going to be in this list, but not the "Sent/". When notmuch scans the "Sent" folder, it finds the new file "maildir/Sent/new/msg_file_renamed", and adds it to the database as a duplicated of the message inserted in the step 1. But, notmuch does not notice that the file "maildir/Sent//new/msg_file_orig" has been deleted. So it erroneously stays in the database. 4) Next time, the user wants to see this email, the command "notmuch show id:" picks the first message file, stored in the database record, which happens to be the non-existing "maildir/Sent//new/msg_file_orig". The solution is simple, we have to strip trailing '/' from the insert path. Signed-off-by: Yuri Volchkov --- lib/database.cc | 3 +-- notmuch-insert.c | 4 +++- util/string-util.c | 13 +++++++++++++ util/string-util.h | 2 ++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index 8f0e22a..79eb3d6 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -858,8 +858,7 @@ notmuch_database_open_verbose (const char *path, notmuch->status_string = NULL; notmuch->path = talloc_strdup (notmuch, path); - if (notmuch->path[strlen (notmuch->path) - 1] == '/') - notmuch->path[strlen (notmuch->path) - 1] = '\0'; + strip_trailing(notmuch->path, '/'); notmuch->mode = mode; notmuch->atomic_nesting = 0; diff --git a/notmuch-insert.c b/notmuch-insert.c index bc96af0..2590e83 100644 --- a/notmuch-insert.c +++ b/notmuch-insert.c @@ -27,6 +27,7 @@ #include #include #include +#include "string-util.h" static volatile sig_atomic_t interrupted; @@ -451,7 +452,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[]) size_t new_tags_length; tag_op_list_t *tag_ops; char *query_string = NULL; - const char *folder = NULL; + char *folder = NULL; notmuch_bool_t create_folder = FALSE; notmuch_bool_t keep = FALSE; notmuch_bool_t no_hooks = FALSE; @@ -511,6 +512,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[]) if (folder == NULL) { maildir = db_path; } else { + strip_trailing (folder, '/'); if (! is_valid_folder_name (folder)) { fprintf (stderr, "Error: invalid folder name: '%s'\n", folder); return EXIT_FAILURE; diff --git a/util/string-util.c b/util/string-util.c index 1812530..b010881 100644 --- a/util/string-util.c +++ b/util/string-util.c @@ -255,3 +255,16 @@ strcase_hash (const void *ptr) return hash; } + +void +strip_trailing (char *str, char ch) +{ + int i; + + for (i = strlen (str) - 1; i >= 0; i--) { + if (str[i] == ch) + str[i] = '\0'; + else + break; + } +} diff --git a/util/string-util.h b/util/string-util.h index 87917b8..9777061 100644 --- a/util/string-util.h +++ b/util/string-util.h @@ -75,6 +75,8 @@ int strcase_equal (const void *a, const void *b); /* GLib GHashFunc compatible case insensitive hash function */ unsigned int strcase_hash (const void *ptr); +void strip_trailing (char *str, char ch); + #ifdef __cplusplus } #endif -- 2.7.4