[notmuch] Rework of attachment saving

2009-12-14 Thread camalot
I think I've reworked the attachment savings to behave as we've been
discussing.  I don't know anything about the button handling so I
haven't attempted to implement the direct manipulation approach of of
saving using the buttons.  That would certainly be nice to have
however and I belive this change should make it easy for someone who
knows how buttons work to implement it.

 --- Keith

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[notmuch] [PATCH] Rework saving of attachments.

2009-12-14 Thread camalot
From: Keith Amidon ke...@nicira.com

With this commit notmuch-show-mode supports saving a single attachment
from a message (bound to 'w') and saving all attachments to the
message (bound to 'W').  The new variable notmuch-default-save-dir
allows the user to specify a directory within which attachments should
be saved by default.  The user can modify this default path, even
specifying a non-existent directory path, in which case he or she will
be prompted to create the path.  Reporting of the actions taken is
also improved.
---
 notmuch.el |   93 ++-
 1 files changed, 72 insertions(+), 21 deletions(-)

diff --git a/notmuch.el b/notmuch.el
index 97914f2..b72548d 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -64,7 +64,8 @@
 (define-key map f 'notmuch-show-forward-current)
 (define-key map r 'notmuch-show-reply)
 (define-key map | 'notmuch-show-pipe-message)
-(define-key map w 'notmuch-show-save-attachments)
+(define-key map w 'notmuch-show-save-attachment)
+(define-key map W 'notmuch-show-save-all-attachments)
 (define-key map V 'notmuch-show-view-raw-message)
 (define-key map v 'notmuch-show-view-all-mime-parts)
 (define-key map - 'notmuch-show-remove-tag)
@@ -98,6 +99,9 @@ pattern can still test against the entire line).)
 (defvar notmuch-command notmuch
   Command to run the notmuch binary.)
 
+(defvar notmuch-default-save-dir (file-name-as-directory (getenv HOME ))
+  Default directory in which attachments are saved.)
+
 (defvar notmuch-show-message-begin-regexp\fmessage{)
 (defvar notmuch-show-message-end-regexp  \fmessage})
 (defvar notmuch-show-header-begin-regexp \fheader{)
@@ -329,28 +333,75 @@ buffer.
  mm-handle)
 count))
 
-(defun notmuch-save-attachments (mm-handle optional queryp)
-  (notmuch-foreach-mime-part
-   (lambda (p)
- (let ((disposition (mm-handle-disposition p)))
-   (and (listp disposition)
-(or (equal (car disposition) attachment)
-(and (equal (car disposition) inline)
- (assq 'filename disposition)))
-(or (not queryp)
-(y-or-n-p
- (concat Save ' (cdr (assq 'filename disposition)) ' )))
-(mm-save-part p
-   mm-handle))
-
-(defun notmuch-show-save-attachments ()
-  Save all attachments from the current message.
-  (interactive)
+(defun notmuch-attachment-q (mm-handle)
+  (let ((disposition (mm-handle-disposition p)))
+(and (listp disposition)
+ (assq 'filename disposition
+
+(defun notmuch-get-save-path (filename default-dir)
+  (let ((savepath nil))
+(while (not savepath)
+  (let* ((ddir (file-name-as-directory default-dir))
+ (fn (read-file-name Save to:  ddir nil nil filename))
+ (efn (expand-file-name fn))
+ (dir (file-name-directory efn)))
+(when (not (file-accessible-directory-p dir))
+  (when (y-or-n-p (concat Create directory  dir  ))
+(make-directory dir t)))
+(if (file-accessible-directory-p dir)
+(setq savepath fn)
+  (setq default-dir (file-name-directory fn)
+savepath))
+
+(defun notmuch-save-attachment (mm-handle default-dir)
+  Save the current attachment part to a file.
+  (cond ((not (notmuch-attachment-q mm-handle))
+ (message Current part is not an attachment.)
+ nil)
+(t
+ (let* ((fn (cdr (assq 'filename (mm-handle-disposition mm-handle
+(savepath (notmuch-get-save-path fn default-dir)))
+   (mm-save-part-to-file mm-handle savepath)
+   savepath
+
+(defun notmuch-save-attachment-num (mm-handle part-num)
+  Save the nth part number
+  (let ((nfound 0)
+(nsaved 0))
+(notmuch-foreach-mime-part
+ (lambda (p)
+   (when (notmuch-attachment-q p)
+ (cond ((equal (+ 1 nfound) part-num)
+(when (notmuch-save-attachment p notmuch-default-save-dir)
+  (incf nsaved
+ (incf nfound))) mm-handle)
+(equal nsaved 1)))
+
+(defun notmuch-show-save-attachment (num)
+  Save a single attachment.
+  (interactive p)
   (with-current-notmuch-show-message
(let ((mm-handle (mm-dissect-buffer)))
- (notmuch-save-attachments
-  mm-handle ( (notmuch-count-attachments mm-handle) 1
-  (message Done))
+ (if (notmuch-save-attachment-num mm-handle num)
+ (message Attachment %d saved. num)
+   (message Failed to save attachment.)
+
+(defun notmuch-show-save-all-attachments ()
+  Save all attachments of a message to a directory.
+  (interactive)
+  (with-current-notmuch-show-message
+   (let ((nfound 0)
+ (nsaved 0)
+ (default-dir notmuch-default-save-dir)
+ (mm-handle (mm-dissect-buffer)))
+ (notmuch-foreach-mime-part
+  (lambda (p)
+(when (notmuch-attachment-q p)
+  (incf nfound)
+  (let ((savepath 

[notmuch] [PATCH 1/9] Explicitly require the message library

2009-11-27 Thread camalot
From: Keith Amidon ke...@nicira.com

Functions provided by the message library were being used without
ensuring it was loaded.
---
 notmuch.el |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/notmuch.el b/notmuch.el
index d7c973c..a1efa4f 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -49,6 +49,7 @@
 
 (require 'cl)
 (require 'mm-view)
+(require 'message)
 
 (defvar notmuch-show-mode-map
   (let ((map (make-sparse-keymap)))
-- 
1.6.5.3

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[notmuch] [PATCH 2/9] Adjust autoload comments

2009-11-27 Thread camalot
From: Keith Amidon ke...@nicira.com

The previous location of autoload comments didn't seem to correspond
with the functions most likely to be the entry points for using
notmuch.  This change adjusts them to match those likely entry points.
---
 notmuch.el |6 --
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/notmuch.el b/notmuch.el
index a1efa4f..6400199 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -707,8 +707,6 @@ view, (remove the \inbox\ tag from each), with
mode-name notmuch-show)
   (setq buffer-read-only t))
 
-;;;###autoload
-
 (defgroup notmuch nil
   Notmuch mail reader for Emacs.
   :group 'mail)
@@ -1002,6 +1000,7 @@ This function advances point to the next line when 
finished.
  (set 'more nil))
   (delete-process proc
 
+;;;###autoload
 (defun notmuch-search (query optional oldest-first)
   Run \notmuch search\ with the given query string and display results.
   (interactive sNotmuch search: )
@@ -1081,6 +1080,8 @@ current search results AND that are tagged with the given 
tag.
(list (notmuch-select-tag-with-completion Filter by tag: )))
   (notmuch-search (concat notmuch-search-query-string  and tag: tag) 
notmuch-search-oldest-first))
 
+
+;;;###autoload
 (defun notmuch ()
   Run notmuch to display all mail with tag of 'inbox'
   (interactive)
@@ -1156,6 +1157,7 @@ results for the search terms in that line.
 (if search
(notmuch-search (cdr search) notmuch-search-oldest-first
 
+;;;###autoload
 (defun notmuch-folder ()
   Show the notmuch folder view and update the displayed counts.
   (interactive)
-- 
1.6.5.3

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[notmuch] [PATCH 3/9] Add key binding for notmuch-search in show-mode

2009-11-27 Thread camalot
From: Keith Amidon ke...@nicira.com

It's not uncommon to want to start a search as a result of something
read in a message so this is convenient.
---
 notmuch.el |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/notmuch.el b/notmuch.el
index 6400199..cd6609d 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -70,6 +70,7 @@
 (define-key map (kbd C-p) 'notmuch-show-previous-line)
 (define-key map q 'kill-this-buffer)
 (define-key map r 'notmuch-show-reply)
+(define-key map s 'notmuch-search)
 (define-key map v 'notmuch-show-view-all-mime-parts)
 (define-key map w 'notmuch-show-view-raw-message)
 (define-key map x 'kill-this-buffer)
-- 
1.6.5.3

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[notmuch] [PATCH 9/9] Key binding rearrangement for save attachments in show mode

2009-11-27 Thread camalot
From: Keith Amidon ke...@nicira.com

The most obvious bindings for save attachments are already taken.  The
existing 'w' binding was bound to view the raw message.  This commit
moves it to 'V' which still seems somewhat mnemonic and uses 'w' for
save (write) attachments.
---
 notmuch.el |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/notmuch.el b/notmuch.el
index 0c6b527..f0e8d65 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -76,7 +76,8 @@
 (define-key map r 'notmuch-show-reply)
 (define-key map s 'notmuch-search)
 (define-key map v 'notmuch-show-view-all-mime-parts)
-(define-key map w 'notmuch-show-view-raw-message)
+(define-key map V 'notmuch-show-view-raw-message)
+(define-key map w 'notmuch-show-save-attachments)
 (define-key map x 'kill-this-buffer)
 (define-key map + 'notmuch-show-add-tag)
 (define-key map - 'notmuch-show-remove-tag)
-- 
1.6.5.3

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch