--- /dev/null
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 2E464431FB6\r
+ for <notmuch@notmuchmail.org>; Tue, 27 Dec 2011 08:04:56 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id 21siScjjsksS for <notmuch@notmuchmail.org>;\r
+ Tue, 27 Dec 2011 08:04:54 -0800 (PST)\r
+Received: from mail-ee0-f53.google.com (mail-ee0-f53.google.com\r
+ [74.125.83.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client\r
+ certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
+ 23288429E31 for <notmuch@notmuchmail.org>; Tue, 27 Dec 2011 08:04:54 -0800\r
+ (PST)\r
+Received: by mail-ee0-f53.google.com with SMTP id d41so14244908eek.26\r
+ for <notmuch@notmuchmail.org>; Tue, 27 Dec 2011 08:04:53 -0800 (PST)\r
+Received: by 10.213.29.135 with SMTP id q7mr5864043ebc.49.1325001893602;\r
+ Tue, 27 Dec 2011 08:04:53 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
+ [80.220.92.23])\r
+ by mx.google.com with ESMTPS id u53sm60300002eeu.6.2011.12.27.08.04.51\r
+ (version=SSLv3 cipher=OTHER); Tue, 27 Dec 2011 08:04:52 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3 2/3] emacs: create patch filename from subject for inline\r
+ patch fake parts\r
+Date: Tue, 27 Dec 2011 18:04:39 +0200\r
+Message-Id:\r
+ <1e0858219afccc075268574208c11ec696b649a6.1325001418.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.5.4\r
+In-Reply-To: <cover.1325001418.git.jani@nikula.org>\r
+References: <1321657368-13872-1-git-send-email-jani@nikula.org>\r
+ <cover.1325001418.git.jani@nikula.org>\r
+In-Reply-To: <cover.1325001418.git.jani@nikula.org>\r
+References: <cover.1325001418.git.jani@nikula.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 27 Dec 2011 16:04:56 -0000\r
+\r
+Use the mail subject line for creating a descriptive filename for the wash\r
+generated inline patch fake parts. The names are similar to the ones\r
+created by 'git format-patch'.\r
+\r
+If the user has notmuch-wash-convert-inline-patch-to-part hook enabled in\r
+notmuch-show-insert-text/plain-hook, this will change the old default\r
+filename of "inline patch" in fake parts:\r
+\r
+[ inline patch: inline patch (as text/x-diff) ]\r
+\r
+into, for example:\r
+\r
+[ 0002-emacs-create-patch-filename-from-subject-for-inline.patch: inline patch (as text/x-diff) ]\r
+\r
+which is typically the same filename the sender had if he was using 'git\r
+format-patch' and 'git send-email'.\r
+\r
+Signed-off-by: Jani Nikula <jani@nikula.org>\r
+---\r
+ emacs/notmuch-wash.el | 43 ++++++++++++++++++++++++++++++++++++++++++-\r
+ 1 files changed, 42 insertions(+), 1 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el\r
+index e9f2dba..5c1e830 100644\r
+--- a/emacs/notmuch-wash.el\r
++++ b/emacs/notmuch-wash.el\r
+@@ -290,6 +290,44 @@ When doing so, maintaining citation leaders in the wrapped text."\r
+ \r
+ (defvar diff-file-header-re) ; From `diff-mode.el'.\r
+ \r
++(defun notmuch-wash-subject-to-filename (subject &optional maxlen)\r
++ "Convert a mail SUBJECT into a filename.\r
++\r
++The resulting filename is similar to the names generated by \"git\r
++format-patch\", without the leading patch sequence number\r
++\"0001-\" and \".patch\" extension. Any leading \"[PREFIX]\"\r
++style strings are removed prior to conversion.\r
++\r
++Optional argument MAXLEN is the maximum length of the resulting\r
++filename, before trimming any trailing . and - characters."\r
++ (let* ((s (replace-regexp-in-string "^ *\\(\\[[^]]*\\] *\\)*" "" subject))\r
++ (s (replace-regexp-in-string "[^A-Za-z0-9._]+" "-" s))\r
++ (s (replace-regexp-in-string "\\.+" "." s))\r
++ (s (if maxlen (substring s 0 (min (length s) maxlen)) s))\r
++ (s (replace-regexp-in-string "[.-]*$" "" s)))\r
++ s))\r
++\r
++(defun notmuch-wash-subject-to-patch-sequence-number (subject)\r
++ "Convert a patch mail SUBJECT into a patch sequence number.\r
++\r
++Return the patch sequence number N from the last \"[PATCH N/M]\"\r
++style prefix in SUBJECT, or nil if such a prefix can't be found."\r
++ (when (string-match\r
++ "^ *\\(\\[[^]]*\\] *\\)*\\[[^]]*?\\([0-9]+\\)/[0-9]+[^]]*\\].*"\r
++ subject)\r
++ (string-to-number (substring subject (match-beginning 2) (match-end 2)))))\r
++\r
++(defun notmuch-wash-subject-to-patch-filename (subject)\r
++ "Convert a patch mail SUBJECT into a filename.\r
++\r
++The resulting filename is similar to the names generated by \"git\r
++format-patch\". If the patch mail was generated and sent using\r
++\"git format-patch/send-email\", this should re-create the\r
++original filename the sender had."\r
++ (format "%04d-%s.patch"\r
++ (or (notmuch-wash-subject-to-patch-sequence-number subject) 1)\r
++ (notmuch-wash-subject-to-filename subject 52)))\r
++\r
+ (defun notmuch-wash-convert-inline-patch-to-part (msg depth)\r
+ "Convert an inline patch into a fake 'text/x-diff' attachment.\r
+ \r
+@@ -316,7 +354,10 @@ for error."\r
+ (setq part (plist-put part :content-type "inline-patch-fake-part"))\r
+ (setq part (plist-put part :content (buffer-string)))\r
+ (setq part (plist-put part :id -1))\r
+- (setq part (plist-put part :filename "inline patch"))\r
++ (setq part (plist-put part :filename\r
++ (notmuch-wash-subject-to-patch-filename\r
++ (plist-get\r
++ (plist-get msg :headers) :Subject))))\r
+ (delete-region (point-min) (point-max))\r
+ (notmuch-show-insert-bodypart nil part depth))))))\r
+ \r
+-- \r
+1.7.5.4\r
+\r