Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 848C06DE0319 for ; Fri, 10 Jun 2016 16:03:18 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.335 X-Spam-Level: X-Spam-Status: No, score=-0.335 tagged_above=-999 required=5 tests=[AWL=0.235, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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 0DZc6Jm-rST1 for ; Fri, 10 Jun 2016 16:03:10 -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 7EDBF6DE00DF for ; Fri, 10 Jun 2016 16:03:05 -0700 (PDT) Received: by mail-wm0-f65.google.com with SMTP id n184so1713859wmn.1 for ; Fri, 10 Jun 2016 16:03:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IndlDcsn9t+LchHWSRIMysZ6P5+h3eusanbeUDDJETU=; b=WRzaZUkb6hIMvZ8TmgIQen70et+FxJ9A3ajToNCnsyWPlg/5zziV62JqrdfaDg4b/2 wm7XEmIzQBkImozpB9wzBXIUNbLcHxsKOL39Z8qGFHji6ymBhHcSPFCsYTQgkF/LEfxr l/8/Y1FhSLrShVWaEBwLSpT6fmcxHVFErzZBta/neJb10zNJiTaR+I0YLVUoW94+gMFm BSk5KTH76EzKhu5xSVNnufJbZQdhoxwTF3p50SyDmkwInwVRDkRXOOZnanf99qVHayc7 D0P4rESxwCMfv7oPN3SLw5Otg37CuZ5VX3VjfBTtQ/hSX57LARlzhHuxFs1lqCgSuEIq ZAoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IndlDcsn9t+LchHWSRIMysZ6P5+h3eusanbeUDDJETU=; b=OkRXeiAQp5b1Nx76TOdhzUn+iVWdheGYImw4CgjdWMe/pLccFHewPcjvkYxhBEiLik yxaVNiNjz9xF4E+ttb4dFC2Qi3KiD6K7879BSrGoUSIN+LEXlKFBSTeEldwzoNExOJI5 BSGB+d8DPYRQ++3s/n58FIvndWlmECB1KgrzSDvFND8tsBBOb63IIf3z4WZ49NHBkE3B cAv7BfifOZKhLzrGNfDYvdgNKT4y0vnKOSie02jQqUeU6atej74u5ysOr+UqUymjLNZB s/XR5ENc0ehlQve6Go8nnfn6c8xFY+obPln06lMHX7fWhMpI7OusPFIOax1hbZKja7uz mqig== X-Gm-Message-State: ALyK8tIVz1j7mEJu97Su1Lh3juS5h9m6JlJRVLS0xqH2qm0Qn1B4ffLDExJgUAijrErrjg== X-Received: by 10.194.192.193 with SMTP id hi1mr4081178wjc.4.1465599784031; Fri, 10 Jun 2016 16:03:04 -0700 (PDT) Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162]) by smtp.gmail.com with ESMTPSA id 124sm1266181wml.12.2016.06.10.16.03.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Jun 2016 16:03:03 -0700 (PDT) From: Mark Walters To: notmuch@notmuchmail.org Subject: [PATCH 2/6] emacs: maildir-fcc: prepare for use of notmuch insert Date: Sat, 11 Jun 2016 00:02:48 +0100 Message-Id: <1465599772-10297-3-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1465599772-10297-1-git-send-email-markwalters1009@gmail.com> References: <1465599772-10297-1-git-send-email-markwalters1009@gmail.com> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.20 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, 10 Jun 2016 23:03:18 -0000 We move some code around in preparation for the use of notmuch insert. In particular, we move the check for a valid maildir for the fcc to when the message is sent rather than when the fcc header is inserted. The main motivation is consistency with the insert version (coming later) where we cannot check the validity until send. We allow the user some chance to correct the header; the choice here is intended to be consistent with the insert version to come. --- emacs/notmuch-maildir-fcc.el | 69 ++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el index bbf6132..835258f 100644 --- a/emacs/notmuch-maildir-fcc.el +++ b/emacs/notmuch-maildir-fcc.el @@ -65,11 +65,9 @@ yet when sending a mail." :require 'notmuch-fcc-initialization :group 'notmuch-send) -(defun notmuch-fcc-handler (destdir) - "Write buffer to `destdir', marking it as sent -Intended to be dynamically bound to `message-fcc-handler-function'" - (notmuch-maildir-fcc-write-buffer-to-maildir destdir t)) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Functions which set up the fcc header in the message buffer. (defun notmuch-fcc-header-setup () "Add an Fcc header to the current message buffer. @@ -110,27 +108,25 @@ by notmuch-mua-mail" (error "Invalid `notmuch-fcc-dirs' setting (neither string nor list)"))))) (when subdir - (message-add-header - (concat "Fcc: " - (file-truename - ;; If the resulting directory is not an absolute path, - ;; prepend the standard notmuch database path. - (if (= (elt subdir 0) ?/) - subdir - (concat (notmuch-database-path) "/" subdir))))) - - ;; finally test if fcc points to a valid maildir - (let ((fcc-header (message-field-value "Fcc"))) - (unless (notmuch-maildir-fcc-dir-is-maildir-p fcc-header) - (cond ((not (file-writable-p fcc-header)) - (error (format "No permission to create %s, which does not exist" - 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 "Message not sent")))))))) - + (notmuch-maildir-add-file-style-fcc-header subdir)))) + +(defun notmuch-maildir-add-file-style-fcc-header (subdir) + (message-add-header + (concat "Fcc: " + (file-truename + ;; If the resulting directory is not an absolute path, + ;; prepend the standard notmuch database path. + (if (= (elt subdir 0) ?/) + subdir + (concat (notmuch-database-path) "/" subdir)))))) + +(defun notmuch-fcc-handler (fcc-header) + "Store message with file fcc." + (notmuch-maildir-fcc-file-fcc fcc-header)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Functions for saving a message using file fcc. + (defun notmuch-maildir-fcc-host-fixer (hostname) (replace-regexp-in-string "/\\|:" (lambda (s) @@ -192,6 +188,29 @@ if successful, nil if not." (concat destdir "/tmp/" msg-id) (concat destdir "/cur/" msg-id ":2," (when mark-seen "S")))) +(defun notmuch-maildir-fcc-file-fcc (fcc-header) + "Write the message to the file specified by FCC-HEADER. + +It offers the user a chance to correct the header, or filesystem, +if needed." + (if (notmuch-maildir-fcc-dir-is-maildir-p fcc-header) + (notmuch-maildir-fcc-write-buffer-to-maildir fcc-header 't) + ;; The fcc-header is not a valid maildir see if the user wants to + ;; fix it in some way. + (let* ((prompt (format "Fcc %s is not a maildir: (r)etry, (c)reate folder, (i)gnore, or (e)dit the header? " + fcc-header)) + (response (read-char-choice prompt '(?r ?c ?i ?e)))) + (case response + (?r (notmuch-maildir-fcc-file-fcc fcc-header)) + (?c (if (file-writable-p fcc-header) + (notmuch-maildir-fcc-create-maildir fcc-header) + (message "No permission to create %s." fcc-header) + (sit-for 2)) + (notmuch-maildir-fcc-file-fcc fcc-header)) + (?i 't) + (?e (notmuch-maildir-fcc-file-fcc + (read-from-minibuffer "Fcc header: " fcc-header))))))) + (defun notmuch-maildir-fcc-write-buffer-to-maildir (destdir &optional mark-seen) "Writes the current buffer to maildir destdir. If mark-seen is non-nil, it will write it to cur/, and mark it as read. It should -- 2.1.4