Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id E65C1431FAF for ; Fri, 26 Oct 2012 13:54:21 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fqWq7snfVdtz for ; Fri, 26 Oct 2012 13:54:21 -0700 (PDT) Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU [18.7.68.34]) by olra.theworths.org (Postfix) with ESMTP id 60051431FAE for ; Fri, 26 Oct 2012 13:54:21 -0700 (PDT) X-AuditID: 12074422-b7f746d0000008cc-56-508af87cd561 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP id 93.CB.02252.C78FA805; Fri, 26 Oct 2012 16:54:20 -0400 (EDT) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q9QKsJkW014430; Fri, 26 Oct 2012 16:54:19 -0400 Received: from drake.dyndns.org (26-4-172.dynamic.csail.mit.edu [18.26.4.172]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q9QKsFNM019236 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Fri, 26 Oct 2012 16:54:18 -0400 (EDT) Received: from amthrax by drake.dyndns.org with local (Exim 4.77) (envelope-from ) id 1TRqv1-0006Sm-4F; Fri, 26 Oct 2012 16:54:15 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 1/2] tag: Disallow adding malformed tags to messages Date: Fri, 26 Oct 2012 16:54:12 -0400 Message-Id: <1351284853-24809-1-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.10 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprJIsWRmVeSWpSXmKPExsUixCmqrVvzoyvAYOV1a4vrN2cyOzB6PFt1 izmAMYrLJiU1J7MstUjfLoEr4/PZtIJ3fBW/znQzNTDe4O5i5OSQEDCRWLvtBRuELSZx4d56 IJuLQ0hgH6PE9nnzGSGcDYwSh05PZQapEhI4xSRxcJ80RGIuo8T326dYQRJsAhoS2/YvZwSx RQSkJXbenQ0U5+BgFlCT+NOlAhIWFnCRaJl8mQnEZhFQlXjSdxVsM6+Ag8T+WzfZIa6Ql3h6 v49tAiPvAkaGVYyyKblVurmJmTnFqcm6xcmJeXmpRbqmermZJXqpKaWbGEEhwO6itIPx50Gl Q4wCHIxKPLw7nnQFCLEmlhVX5h5ilORgUhLlnfQdKMSXlJ9SmZFYnBFfVJqTWnyIUYKDWUmE t+gYUI43JbGyKrUoHyYlzcGiJM57LeWmv5BAemJJanZqakFqEUxWhoNDSYJ3BshQwaLU9NSK tMycEoQ0EwcnyHAeoOFgi3mLCxJzizPTIfKnGBWlxHk7QBICIImM0jy4XliMvmIUB3pFmLcX pIoHGN9w3a+ABjMBDRZj7QQZXJKIkJJqYGRqfDz56KNpV47Ilibfqmmb2BWw9r1ndp2B7f60 VzlRRc4GyklCf37xNtdlC/ZInFb3SNsdJjXBOO/fGsYLb66G5m85H3yWW4ShxV95h9zUX5Pv GvtFqYRZ35RPnbd634o3SqVuAbc8GwKCeD45F+4NXOoz/3CAysu+XfFTpNmv/FplcnzKfyWW 4oxEQy3mouJEANXW17ysAgAA X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 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, 26 Oct 2012 20:54:22 -0000 This disallows adding empty tags, since nothing but confusion follows in their wake, and disallows adding tags that begin with "-" because they are also confusing, the tag "-" is impossible to remove using the CLI, and because the syntax for removing such tags conflicts with long argument syntax. This does not place any restrictions on what tags can be removed, as that would make it difficult for people who have the misfortune of already having malformed tags to remove these tags. --- notmuch-tag.c | 11 +++++++++++ test/tagging | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/notmuch-tag.c b/notmuch-tag.c index 7d18639..d15f1ed 100644 --- a/notmuch-tag.c +++ b/notmuch-tag.c @@ -203,6 +203,17 @@ notmuch_tag_command (void *ctx, int argc, char *argv[]) break; } if (argv[i][0] == '+' || argv[i][0] == '-') { + if (argv[i][0] == '+' && argv[i][1] == '\0') { + fprintf(stderr, "Error: tag names cannot be empty.\n"); + return 1; + } + if (argv[i][0] == '+' && argv[i][1] == '-') { + /* This disallows adding the non-removable tag "-" and + * enables notmuch tag to take long options in the + * future. */ + fprintf(stderr, "Error: tag names must not start with '-'.\n"); + return 1; + } tag_ops[tag_ops_count].tag = argv[i] + 1; tag_ops[tag_ops_count].remove = (argv[i][0] == '-'); tag_ops_count++; diff --git a/test/tagging b/test/tagging index e4782ed..980ff92 100755 --- a/test/tagging +++ b/test/tagging @@ -46,4 +46,8 @@ test_expect_equal "$output" "\ thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; One (:\" inbox tag1 unread) thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag1 tag4 unread)" +test_expect_code 1 "Empty tag names" 'notmuch tag + One' + +test_expect_code 1 "Tag name beginning with -" 'notmuch tag +- One' + test_done -- 1.7.10