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 B4DDC4196F2 for ; Mon, 26 Apr 2010 18:33:16 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -4.2 X-Spam-Level: X-Spam-Status: No, score=-4.2 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3] 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 j2N7u-591vep for ; Mon, 26 Apr 2010 18:33:15 -0700 (PDT) Received: from ipex4.johnshopkins.edu (ipex4.johnshopkins.edu [128.220.161.141]) by olra.theworths.org (Postfix) with ESMTP id 97697431FC1 for ; Mon, 26 Apr 2010 18:33:15 -0700 (PDT) X-IronPort-AV: E=Sophos;i="4.52,276,1270440000"; d="scan'208";a="359678433" Received: from c-69-255-36-229.hsd1.md.comcast.net (HELO lucky) ([69.255.36.229]) by ipex4.johnshopkins.edu with ESMTP/TLS/AES256-SHA; 26 Apr 2010 21:33:14 -0400 Received: from jkr by lucky with local (Exim 4.69) (envelope-from ) id 1O6Zfl-00084k-AD; Mon, 26 Apr 2010 21:33:13 -0400 From: Jesse Rosenthal To: Sebastian Spaeth , Notmuch developer list Subject: [PATCH] emacs: add prompt to create maildir for fcc if it does not exist. In-Reply-To: <87mxwpd9g8.fsf@jhu.edu> References: <1272270198-28357-4-git-send-email-Sebastian@SSpaeth.de> <87mxwpd9g8.fsf@jhu.edu> User-Agent: Notmuch/0.2-151-gec6d78a (http://notmuchmail.org) Emacs/23.1.1 (i486-pc-linux-gnu) Date: Mon, 26 Apr 2010 21:33:13 -0400 Message-ID: <87wrvtvfvq.fsf@jhu.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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: Tue, 27 Apr 2010 01:33:16 -0000 If the user specifies a maildir that does not exist, prompt the user to see whether a maildir should be created. This will fail, with the relevant explanation, if the location is not writable, or if a file already exists in that location. If the location is a dir, but not a maildir, this will add /tmp/cur/new to it. --- NB. This builds on the patch in the parent email: id:87mxwpd9g8.fsf@jhu.edu emacs/notmuch-maildir-fcc.el | 26 ++++++++++++++++++++++---- 1 files changed, 22 insertions(+), 4 deletions(-) diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el index 34b1915..6d75b11 100644 --- a/emacs/notmuch-maildir-fcc.el +++ b/emacs/notmuch-maildir-fcc.el @@ -72,10 +72,16 @@ (if (eq subdir nil) (setq subdir (car (car notmuch-fcc-dirs)))) (unless (message-fetch-field "fcc") (message-add-header (concat "Fcc: " message-directory subdir))) - (unless (notmuch-maildir-fcc-dir-is-maildir-p - (message-fetch-field "fcc")) - (error (format "%s is not a maildir." (message-fetch-field "fcc"))))))) - + (let ((fcc-header (message-fetch-field "fcc"))) + (unless (notmuch-maildir-fcc-dir-is-maildir-p fcc-header) + (cond ((not (file-writable-p fcc-header)) + (error (format "%s is not a maildir, but you don't have permission to create one." fcc-header))) + ((y-or-n-p (format "%s is not a maildir. Create it? " + fcc-header)) + (notmuch-maildir-fcc-create-maildir fcc-header)) + (t + (error "Not sending message.")))))))) + (defun notmuch-maildir-fcc-host-fixer (hostname) (replace-regexp-in-string "/\\|:" '(lambda (s) @@ -104,6 +110,18 @@ (file-exists-p (concat dir "/new/")) (file-exists-p (concat dir "/tmp/")))) +(defun notmuch-maildir-fcc-create-maildir (path) + (cond ((or (not (file-exists-p path)) (file-directory-p path)) + (make-directory (concat path "/cur/") t) + (make-directory (concat path "/new/") t) + (make-directory (concat path "/tmp/") t)) + ((file-regular-p path) + (error "%s is a file. Can't creat maildir." path)) + (t + (error "I don't know how to create a maildir here")))) + + + (defun notmuch-maildir-fcc-save-buffer-to-tmp (destdir) "Returns the msg id of the message written to the temp directory if successful, nil if not." -- 1.6.3.3