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 2003D40DEEC for ; Fri, 19 Nov 2010 00:25:40 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -1.9 X-Spam-Level: X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001] autolearn=ham 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 pfN-UtADjoTZ for ; Fri, 19 Nov 2010 00:25:30 -0800 (PST) Received: from mail-wy0-f181.google.com (mail-wy0-f181.google.com [74.125.82.181]) by olra.theworths.org (Postfix) with ESMTP id D25E540DEEB for ; Fri, 19 Nov 2010 00:25:29 -0800 (PST) Received: by wyb40 with SMTP id 40so4389198wyb.26 for ; Fri, 19 Nov 2010 00:25:26 -0800 (PST) Received: by 10.216.27.20 with SMTP id d20mr1412900wea.99.1290155126226; Fri, 19 Nov 2010 00:25:26 -0800 (PST) Received: from ut.hh.sledj.net (host81-149-164-25.in-addr.btopenworld.com [81.149.164.25]) by mx.google.com with ESMTPS id y80sm643235weq.3.2010.11.19.00.25.23 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 19 Nov 2010 00:25:24 -0800 (PST) Received: by ut.hh.sledj.net (Postfix, from userid 1000) id A16B8594058; Fri, 19 Nov 2010 08:22:28 +0000 (GMT) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH] emacs: Avoid attempts to add invalid tags. Date: Fri, 19 Nov 2010 08:22:25 +0000 Message-Id: <1290154945-2460-1-git-send-email-dme@dme.org> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <878w0pai83.fsf@SSpaeth.de> References: <878w0pai83.fsf@SSpaeth.de> 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, 19 Nov 2010 08:25:40 -0000 Add a (probably incomplete) function to validate a tag specified by the user. Use the function to avoid adding invalid tags. --- emacs/notmuch.el | 17 ++++++++++++----- 1 files changed, 12 insertions(+), 5 deletions(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 3d82f0d..b003cd6 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -72,12 +72,19 @@ For example: :type '(alist :key-type (string) :value-type (string)) :group 'notmuch) +(defun notmuch-valid-tag (tag) + (not (string= "" tag))) + (defun notmuch-select-tag-with-completion (prompt &rest search-terms) - (let ((tag-list - (with-output-to-string - (with-current-buffer standard-output - (apply 'call-process notmuch-command nil t nil "search-tags" search-terms))))) - (completing-read prompt (split-string tag-list "\n+" t) nil nil nil))) + (let* ((tag-list + (with-output-to-string + (with-current-buffer standard-output + (apply 'call-process notmuch-command nil t nil "search-tags" search-terms)))) + (tag (completing-read prompt (split-string tag-list "\n+" t) + nil nil nil))) + (if (notmuch-valid-tag tag) + tag + (error "Invalid tag")))) (defun notmuch-foreach-mime-part (function mm-handle) (cond ((stringp (car mm-handle)) -- 1.7.2.3