unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] emacs: create patch filename from subject for inline patch fake parts
@ 2011-11-18 23:02 Jani Nikula
  2011-12-20 20:05 ` Jani Nikula
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Jani Nikula @ 2011-11-18 23:02 UTC (permalink / raw)
  To: notmuch

Use the mail subject line for creating a descriptive filename for the wash
generated inline patch fake parts. The names are similar to the ones
created by 'git format-patch', just without the leading numbers.

Signed-off-by: Jani Nikula <jani@nikula.org>

---

I know notmuch-subject-to-patch-filename is totally un-lispy. Suggestions
welcome on how to make it lispy and keep it somewhat readable.

If we later want to have a '>' counterpart to '|' to save messages to files
rather than pipe, then this could be generalized and re-used for creating
the suggested filename for that.

I don't even use the notmuch-wash-convert-inline-patch-to-part option that
much, but having it suggest "inline patch" as filename is just ugly...
---
 emacs/notmuch-wash.el |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
index 1f420b2..755d64a 100644
--- a/emacs/notmuch-wash.el
+++ b/emacs/notmuch-wash.el
@@ -290,6 +290,17 @@ When doing so, maintaining citation leaders in the wrapped text."
 
 (defvar diff-file-header-re) ; From `diff-mode.el'.
 
+(defun notmuch-subject-to-patch-filename (str)
+  "Convert a typical patch mail subject line into a suitable filename."
+  (let ((s str))
+    (setq s (replace-regexp-in-string "^ *\\(\\[[^]]*\\]\\)? *" "" s))
+    (setq s (replace-regexp-in-string "[. ]*$" "" s))
+    (setq s (replace-regexp-in-string "[^A-Za-z0-9._-]+" "-" s))
+    (setq s (replace-regexp-in-string "\\.+" "." s))
+    (when (> (length s) 52)
+      (setq s (substring s 0 52)))
+    (concat s ".patch")))
+
 (defun notmuch-wash-convert-inline-patch-to-part (msg depth)
   "Convert an inline patch into a fake 'text/x-diff' attachment.
 
@@ -316,7 +327,10 @@ for error."
 	    (setq part (plist-put part :content-type "text/x-diff"))
 	    (setq part (plist-put part :content (buffer-string)))
 	    (setq part (plist-put part :id -1))
-	    (setq part (plist-put part :filename "inline patch"))
+	    (setq part (plist-put part :filename
+				  (notmuch-subject-to-patch-filename
+				   (plist-get
+				    (plist-get msg :headers) :Subject))))
 	    (delete-region (point-min) (point-max))
 	    (notmuch-show-insert-bodypart nil part depth))))))
 
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2011-12-28 12:22 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-18 23:02 [PATCH] emacs: create patch filename from subject for inline patch fake parts Jani Nikula
2011-12-20 20:05 ` Jani Nikula
2011-12-20 20:11   ` Dmitry Kurochkin
2011-12-20 21:52   ` Austin Clements
2011-12-21  9:21     ` David Edmondson
2011-12-21 14:40       ` Austin Clements
2011-12-21 20:21         ` Jani Nikula
2011-12-25 22:00 ` [PATCH v2 0/2] emacs: patch filename from subject Jani Nikula
2011-12-25 22:00   ` [PATCH v2 1/2] emacs: create patch filename from subject for inline patch fake parts Jani Nikula
2011-12-26 12:06     ` David Edmondson
2011-12-26 12:24       ` Jani Nikula
2011-12-26 20:38         ` Jameson Graef Rollins
2011-12-26 21:52           ` Jani Nikula
2011-12-26 22:05             ` David Edmondson
2011-12-25 22:00   ` [PATCH v2 2/2] test: emacs: test notmuch-wash-subject-to-* functions Jani Nikula
2011-12-27 16:04 ` [PATCH v3 0/3] emacs: patch filename from subject Jani Nikula
2011-12-27 16:04   ` [PATCH v3 1/3] emacs: add inline patch fake parts through a special handler Jani Nikula
2011-12-27 16:04   ` [PATCH v3 2/3] emacs: create patch filename from subject for inline patch fake parts Jani Nikula
2011-12-27 16:04   ` [PATCH v3 3/3] test: emacs: test notmuch-wash-subject-to-* functions Jani Nikula
2011-12-28 12:22   ` [PATCH v3 0/3] emacs: patch filename from subject David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).