1 Return-Path: <jani@nikula.org>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 2E464431FB6
\r
6 for <notmuch@notmuchmail.org>; Tue, 27 Dec 2011 08:04:56 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"
\r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
13 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id 21siScjjsksS for <notmuch@notmuchmail.org>;
\r
17 Tue, 27 Dec 2011 08:04:54 -0800 (PST)
\r
18 Received: from mail-ee0-f53.google.com (mail-ee0-f53.google.com
\r
19 [74.125.83.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client
\r
20 certificate requested) by olra.theworths.org (Postfix) with ESMTPS id
\r
21 23288429E31 for <notmuch@notmuchmail.org>; Tue, 27 Dec 2011 08:04:54 -0800
\r
23 Received: by mail-ee0-f53.google.com with SMTP id d41so14244908eek.26
\r
24 for <notmuch@notmuchmail.org>; Tue, 27 Dec 2011 08:04:53 -0800 (PST)
\r
25 Received: by 10.213.29.135 with SMTP id q7mr5864043ebc.49.1325001893602;
\r
26 Tue, 27 Dec 2011 08:04:53 -0800 (PST)
\r
27 Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.
\r
29 by mx.google.com with ESMTPS id u53sm60300002eeu.6.2011.12.27.08.04.51
\r
30 (version=SSLv3 cipher=OTHER); Tue, 27 Dec 2011 08:04:52 -0800 (PST)
\r
31 From: Jani Nikula <jani@nikula.org>
\r
32 To: notmuch@notmuchmail.org
\r
33 Subject: [PATCH v3 2/3] emacs: create patch filename from subject for inline
\r
35 Date: Tue, 27 Dec 2011 18:04:39 +0200
\r
37 <1e0858219afccc075268574208c11ec696b649a6.1325001418.git.jani@nikula.org>
\r
38 X-Mailer: git-send-email 1.7.5.4
\r
39 In-Reply-To: <cover.1325001418.git.jani@nikula.org>
\r
40 References: <1321657368-13872-1-git-send-email-jani@nikula.org>
\r
41 <cover.1325001418.git.jani@nikula.org>
\r
42 In-Reply-To: <cover.1325001418.git.jani@nikula.org>
\r
43 References: <cover.1325001418.git.jani@nikula.org>
\r
44 X-BeenThere: notmuch@notmuchmail.org
\r
45 X-Mailman-Version: 2.1.13
\r
47 List-Id: "Use and development of the notmuch mail system."
\r
48 <notmuch.notmuchmail.org>
\r
49 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
50 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
51 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
52 List-Post: <mailto:notmuch@notmuchmail.org>
\r
53 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
54 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
55 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
56 X-List-Received-Date: Tue, 27 Dec 2011 16:04:56 -0000
\r
58 Use the mail subject line for creating a descriptive filename for the wash
\r
59 generated inline patch fake parts. The names are similar to the ones
\r
60 created by 'git format-patch'.
\r
62 If the user has notmuch-wash-convert-inline-patch-to-part hook enabled in
\r
63 notmuch-show-insert-text/plain-hook, this will change the old default
\r
64 filename of "inline patch" in fake parts:
\r
66 [ inline patch: inline patch (as text/x-diff) ]
\r
70 [ 0002-emacs-create-patch-filename-from-subject-for-inline.patch: inline patch (as text/x-diff) ]
\r
72 which is typically the same filename the sender had if he was using 'git
\r
73 format-patch' and 'git send-email'.
\r
75 Signed-off-by: Jani Nikula <jani@nikula.org>
\r
77 emacs/notmuch-wash.el | 43 ++++++++++++++++++++++++++++++++++++++++++-
\r
78 1 files changed, 42 insertions(+), 1 deletions(-)
\r
80 diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
\r
81 index e9f2dba..5c1e830 100644
\r
82 --- a/emacs/notmuch-wash.el
\r
83 +++ b/emacs/notmuch-wash.el
\r
84 @@ -290,6 +290,44 @@ When doing so, maintaining citation leaders in the wrapped text."
\r
86 (defvar diff-file-header-re) ; From `diff-mode.el'.
\r
88 +(defun notmuch-wash-subject-to-filename (subject &optional maxlen)
\r
89 + "Convert a mail SUBJECT into a filename.
\r
91 +The resulting filename is similar to the names generated by \"git
\r
92 +format-patch\", without the leading patch sequence number
\r
93 +\"0001-\" and \".patch\" extension. Any leading \"[PREFIX]\"
\r
94 +style strings are removed prior to conversion.
\r
96 +Optional argument MAXLEN is the maximum length of the resulting
\r
97 +filename, before trimming any trailing . and - characters."
\r
98 + (let* ((s (replace-regexp-in-string "^ *\\(\\[[^]]*\\] *\\)*" "" subject))
\r
99 + (s (replace-regexp-in-string "[^A-Za-z0-9._]+" "-" s))
\r
100 + (s (replace-regexp-in-string "\\.+" "." s))
\r
101 + (s (if maxlen (substring s 0 (min (length s) maxlen)) s))
\r
102 + (s (replace-regexp-in-string "[.-]*$" "" s)))
\r
105 +(defun notmuch-wash-subject-to-patch-sequence-number (subject)
\r
106 + "Convert a patch mail SUBJECT into a patch sequence number.
\r
108 +Return the patch sequence number N from the last \"[PATCH N/M]\"
\r
109 +style prefix in SUBJECT, or nil if such a prefix can't be found."
\r
110 + (when (string-match
\r
111 + "^ *\\(\\[[^]]*\\] *\\)*\\[[^]]*?\\([0-9]+\\)/[0-9]+[^]]*\\].*"
\r
113 + (string-to-number (substring subject (match-beginning 2) (match-end 2)))))
\r
115 +(defun notmuch-wash-subject-to-patch-filename (subject)
\r
116 + "Convert a patch mail SUBJECT into a filename.
\r
118 +The resulting filename is similar to the names generated by \"git
\r
119 +format-patch\". If the patch mail was generated and sent using
\r
120 +\"git format-patch/send-email\", this should re-create the
\r
121 +original filename the sender had."
\r
122 + (format "%04d-%s.patch"
\r
123 + (or (notmuch-wash-subject-to-patch-sequence-number subject) 1)
\r
124 + (notmuch-wash-subject-to-filename subject 52)))
\r
126 (defun notmuch-wash-convert-inline-patch-to-part (msg depth)
\r
127 "Convert an inline patch into a fake 'text/x-diff' attachment.
\r
129 @@ -316,7 +354,10 @@ for error."
\r
130 (setq part (plist-put part :content-type "inline-patch-fake-part"))
\r
131 (setq part (plist-put part :content (buffer-string)))
\r
132 (setq part (plist-put part :id -1))
\r
133 - (setq part (plist-put part :filename "inline patch"))
\r
134 + (setq part (plist-put part :filename
\r
135 + (notmuch-wash-subject-to-patch-filename
\r
137 + (plist-get msg :headers) :Subject))))
\r
138 (delete-region (point-min) (point-max))
\r
139 (notmuch-show-insert-bodypart nil part depth))))))
\r