From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 8DBCE429E25 for ; Fri, 18 Nov 2011 15:03:00 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GnjpMmTGyb7S for ; Fri, 18 Nov 2011 15:03:00 -0800 (PST) Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id CFF4B431FD0 for ; Fri, 18 Nov 2011 15:02:59 -0800 (PST) Received: by bkaq10 with SMTP id q10so4364388bka.26 for ; Fri, 18 Nov 2011 15:02:57 -0800 (PST) Received: by 10.204.132.78 with SMTP id a14mr1791062bkt.15.1321657376511; Fri, 18 Nov 2011 15:02:56 -0800 (PST) Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi. [80.220.92.23]) by mx.google.com with ESMTPS id b2sm271100fao.1.2011.11.18.15.02.50 (version=SSLv3 cipher=OTHER); Fri, 18 Nov 2011 15:02:51 -0800 (PST) From: Jani Nikula To: notmuch@notmuchmail.org Subject: [PATCH] emacs: create patch filename from subject for inline patch fake parts Date: Sat, 19 Nov 2011 01:02:48 +0200 Message-Id: <1321657368-13872-1-git-send-email-jani@nikula.org> X-Mailer: git-send-email 1.7.5.4 X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 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, 18 Nov 2011 23:03:00 -0000 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 --- 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