From 7b30ef1ee29aa33a9436a6108add5f5ef100f8da Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Mon, 16 Sep 2019 15:45:43 -0700 Subject: changelog: notmuch project shipped but did not install the script Reported-by: David Bremner Signed-off-by: Sean Whitton --- debian/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'debian') diff --git a/debian/changelog b/debian/changelog index aa8c371..ecf6ce2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,7 +1,7 @@ mailscripts (0.11-1) unstable; urgency=medium * New script: email-print-mime-structure (Closes: #939993). - Imported from the notmuch project, which never shipped it in releases. + Imported from the notmuch project, which never installed it. Thanks to Daniel Kahn Gillmor for the patches. * Generate nroff output in UTF-8. Thanks to Daniel Kahn Gillmor for the patch. -- cgit v1.2.3 From 8fde04b7d2743e393e93fd0677ef2fcfc53b351b Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Fri, 1 Nov 2019 20:38:29 -0700 Subject: changelog Signed-off-by: Sean Whitton --- debian/changelog | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'debian') diff --git a/debian/changelog b/debian/changelog index ecf6ce2..4de2082 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +mailscripts (0.12-1) UNRELEASED; urgency=medium + + * email-print-mime-structure: make typesafe. + Thanks to Daniel Kahn Gillmor for the patch. + + -- Sean Whitton Fri, 01 Nov 2019 20:38:07 -0700 + mailscripts (0.11-1) unstable; urgency=medium * New script: email-print-mime-structure (Closes: #939993). -- cgit v1.2.3 From 67a847605769d5e255168a65d780594383569b75 Mon Sep 17 00:00:00 2001 From: Daniel Kahn Gillmor Date: Sat, 2 Nov 2019 01:28:24 -0400 Subject: email-print-mime-structure: add decryption capability MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add simple decryption capability for email-print-mime-structure, so that it can do stuff like this: $ email-print-mime-structure --pgpkey alice@openpgp.example.sec.asc < msg.eml └┬╴multipart/encrypted 2190 bytes ├─╴application/pgp-encrypted 11 bytes └─╴application/octet-stream 1613 bytes ↧ (decrypts to) └─╴text/plain 425 bytes $ At the moment, it only works with keys that can be found in the filesystem, and when the pgpy module is installed. Possible future work: - try using gpg to do the decryption from whatever gpg's system capabilities are I've added python3-pgpy to the list of Recommends, since it is not a hard dependency. Signed-off-by: Daniel Kahn Gillmor --- debian/control | 1 + email-print-mime-structure | 34 ++++++++++++++++++++++++++++++++++ email-print-mime-structure.1.pod | 8 ++++++++ 3 files changed, 43 insertions(+) (limited to 'debian') diff --git a/debian/control b/debian/control index 6d3a54f..fc2bccc 100644 --- a/debian/control +++ b/debian/control @@ -39,6 +39,7 @@ Recommends: devscripts, git, notmuch, + python3-pgpy, Architecture: all Description: collection of scripts for manipulating e-mail on Debian This package provides a collection of scripts for manipulating e-mail diff --git a/email-print-mime-structure b/email-print-mime-structure index 33579a7..eb513b3 100755 --- a/email-print-mime-structure +++ b/email-print-mime-structure @@ -38,6 +38,11 @@ from typing import Optional, Union, List, Tuple, Any from email.charset import Charset from email.message import Message +try: + import pgpy #type: ignore +except ImportError: + pgpy = None + class MimePrinter(object): def __init__(self, args:Namespace): self.args = args @@ -66,6 +71,33 @@ class MimePrinter(object): print(f'{prefix}{z.get_content_type()}{cset}{disposition}{fname} {nbytes:d} bytes') + if self.args.pgpkey and \ + (parent is not None) and \ + (parent.get_content_type().lower() == 'multipart/encrypted') and \ + (str(parent.get_param('protocol')).lower() == 'application/pgp-encrypted') and \ + (num == 2): + if pgpy is None: + logging.warning(f'Python module pgpy is not available, not decrypting (try "apt install python3-pgpy")') + else: + cryptopayload:Optional[Message] = None + keyname:str + for keyname in self.args.pgpkey: + try: + key:pgpy.PGPKey + key, _ = pgpy.PGPKey.from_file(keyname) + msg:pgpy.PGPMessage = pgpy.PGPMessage.from_blob(z.get_payload()) + msg = key.decrypt(msg) + cryptopayload = email.message_from_bytes(msg.message) + break + except: + pass + if cryptopayload is None: + logging.warning(f'Unable to decrypt') + else: + newprefix = prefix[:-3] + ' ' + print(f'{newprefix}↧ (decrypts to)') + self.print_tree(cryptopayload, newprefix + '└', z, 0) + def print_tree(self, z:Message, prefix:str, parent:Optional[Message], num:int) -> None: if (z.is_multipart()): self.print_part(z, prefix+'┬╴', parent, num) @@ -88,6 +120,8 @@ class MimePrinter(object): def main() -> None: parser:ArgumentParser = ArgumentParser(description='Read RFC2822 MIME message from stdin and emit a tree diagram to stdout.', epilog="Example: email-print-mime-structure < message.eml") + parser.add_argument('--pgpkey', metavar='KEYFILE', action='append', + help='OpenPGP Transferable Secret Key for decrypting') args:Namespace = parser.parse_args() msg:Union[Message, str, int, Any] = email.message_from_file(sys.stdin) diff --git a/email-print-mime-structure.1.pod b/email-print-mime-structure.1.pod index 03a8e29..209c725 100644 --- a/email-print-mime-structure.1.pod +++ b/email-print-mime-structure.1.pod @@ -21,6 +21,14 @@ something like "cat -n". =over 4 +=item B<--pgpkey=>I + +I should name an OpenPGP transferable secret key that is not +password-protected. If a PGP/MIME-encrypted message is found on +standard input, this key will be tried for decryption. May be used +multiple times if you want to try decrypting with more than one secret +key. + =item B<--help>, B<-h> Show usage instructions. -- cgit v1.2.3 From c0698086733f24314b4dc170c2c01d0541e50066 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 2 Nov 2019 09:01:58 -0700 Subject: changelog Signed-off-by: Sean Whitton --- debian/changelog | 3 +++ 1 file changed, 3 insertions(+) (limited to 'debian') diff --git a/debian/changelog b/debian/changelog index 4de2082..149b4e1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,6 +2,9 @@ mailscripts (0.12-1) UNRELEASED; urgency=medium * email-print-mime-structure: make typesafe. Thanks to Daniel Kahn Gillmor for the patch. + * email-print-mime-structure: add capability to decrypt message parts + (Closes: #943959). + Thanks to Daniel Kahn Gillmor for the patch series. -- Sean Whitton Fri, 01 Nov 2019 20:38:07 -0700 -- cgit v1.2.3 From 8d2dcb9d14a681c3ba86dc2f67756a5619f4d10d Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 2 Nov 2019 09:52:46 -0700 Subject: mailscripts.el: add mailscripts-extract-patches-branch-prefix Signed-off-by: Sean Whitton --- debian/changelog | 1 + mailscripts.el | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) (limited to 'debian') diff --git a/debian/changelog b/debian/changelog index 149b4e1..6f57add 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,7 @@ mailscripts (0.12-1) UNRELEASED; urgency=medium * email-print-mime-structure: add capability to decrypt message parts (Closes: #943959). Thanks to Daniel Kahn Gillmor for the patch series. + * mailscripts.el: add mailscripts-extract-patches-branch-prefix defcustom. -- Sean Whitton Fri, 01 Nov 2019 20:38:07 -0700 diff --git a/mailscripts.el b/mailscripts.el index 3d3a584..a2ec230 100644 --- a/mailscripts.el +++ b/mailscripts.el @@ -4,7 +4,7 @@ ;; Version: 0.12 ;; Package-Requires: (notmuch) -;; Copyright (C) 2018 Sean Whitton +;; Copyright (C) 2018, 2019 Sean Whitton ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by @@ -23,6 +23,16 @@ (require 'notmuch) +(defgroup mailscripts nil + "Customisation of functions in the mailscripts package.") + +(defcustom mailscripts-extract-patches-branch-prefix nil + "Prefix for git branches created by functions which extract patch series. + +E.g. `mailed/'." + :type 'string + :group 'mailscripts) + ;;;###autoload (defun notmuch-slurp-debbug (bug &optional no-open) "Slurp Debian bug with bug number BUG and open the thread in notmuch. @@ -54,14 +64,20 @@ threads to the notmuch-extract-patch(1) command." (interactive "Dgit repo: \nsnew branch name: ") (let ((thread-id notmuch-show-thread-id) (default-directory (expand-file-name repo))) - (call-process-shell-command - (format "git checkout -b %s" - (shell-quote-argument branch))) + (mailscripts--check-out-branch branch) (shell-command (format "notmuch-extract-patch %s | git am" (shell-quote-argument thread-id)) "*notmuch-apply-thread-series*"))) +(defun mailscripts--check-out-branch (branch) + (call-process-shell-command + (format "git checkout -b %s" + (shell-quote-argument + (if mailscripts-extract-patches-branch-prefix + (concat mailscripts-extract-patches-branch-prefix branch) + branch))))) + (provide 'mailscripts) ;;; mailscripts.el ends here -- cgit v1.2.3 From cb53ee3309fb20492bdb2d43c4596ed507140701 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 2 Nov 2019 10:06:39 -0700 Subject: mailscripts.el: add notmuch-extract-thread-patches-projectile Signed-off-by: Sean Whitton --- debian/changelog | 1 + mailscripts.el | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'debian') diff --git a/debian/changelog b/debian/changelog index 6f57add..52c4282 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,6 +6,7 @@ mailscripts (0.12-1) UNRELEASED; urgency=medium (Closes: #943959). Thanks to Daniel Kahn Gillmor for the patch series. * mailscripts.el: add mailscripts-extract-patches-branch-prefix defcustom. + * mailscripts.el: add notmuch-extract-thread-patches-projectile command. -- Sean Whitton Fri, 01 Nov 2019 20:38:07 -0700 diff --git a/mailscripts.el b/mailscripts.el index a2ec230..bcdc0ad 100644 --- a/mailscripts.el +++ b/mailscripts.el @@ -2,7 +2,7 @@ ;; Author: Sean Whitton ;; Version: 0.12 -;; Package-Requires: (notmuch) +;; Package-Requires: (notmuch projectile) ;; Copyright (C) 2018, 2019 Sean Whitton @@ -22,6 +22,7 @@ ;;; Code: (require 'notmuch) +(require 'projectile) (defgroup mailscripts nil "Customisation of functions in the mailscripts package.") @@ -70,6 +71,12 @@ threads to the notmuch-extract-patch(1) command." (shell-quote-argument thread-id)) "*notmuch-apply-thread-series*"))) +;;;###autoload +(defun notmuch-extract-thread-patches-projectile () + "Like `notmuch-extract-thread-patches', but use projectile to choose the repo." + (interactive) + (mailscripts--projectile-repo-and-branch 'notmuch-extract-thread-patches)) + (defun mailscripts--check-out-branch (branch) (call-process-shell-command (format "git checkout -b %s" @@ -78,6 +85,12 @@ threads to the notmuch-extract-patch(1) command." (concat mailscripts-extract-patches-branch-prefix branch) branch))))) +(defun mailscripts--projectile-repo-and-branch (f) + (let ((repo (projectile-completing-read + "Select projectile project: " projectile-known-projects)) + (branch (completing-read "Branch name: " nil))) + (funcall f repo branch))) + (provide 'mailscripts) ;;; mailscripts.el ends here -- cgit v1.2.3 From 80bf3c2b53d7514b888cec7ca6fdb2f4e579269d Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 2 Nov 2019 12:06:40 -0700 Subject: mailscripts.el: add notmuch-extract-message-patches{,-projectile} Signed-off-by: Sean Whitton --- debian/changelog | 1 + mailscripts.el | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) (limited to 'debian') diff --git a/debian/changelog b/debian/changelog index 52c4282..06e92e6 100644 --- a/debian/changelog +++ b/debian/changelog @@ -7,6 +7,7 @@ mailscripts (0.12-1) UNRELEASED; urgency=medium Thanks to Daniel Kahn Gillmor for the patch series. * mailscripts.el: add mailscripts-extract-patches-branch-prefix defcustom. * mailscripts.el: add notmuch-extract-thread-patches-projectile command. + * mailscripts.el: add notmuch-extract-message-patches{,-projectile} commands. -- Sean Whitton Fri, 01 Nov 2019 20:38:07 -0700 diff --git a/mailscripts.el b/mailscripts.el index bcdc0ad..09d213d 100644 --- a/mailscripts.el +++ b/mailscripts.el @@ -77,6 +77,35 @@ threads to the notmuch-extract-patch(1) command." (interactive) (mailscripts--projectile-repo-and-branch 'notmuch-extract-thread-patches)) +;;;###autoload +(defun notmuch-extract-message-patches (repo branch) + "Extract patches attached to current message to branch BRANCH in repo REPO. + +The target branch may or may not already exist. + +Patches are applied using git-am(1), so we only consider +attachments with filenames which look like they were generated by +git-format-patch(1)." + (interactive "Dgit repo: \nsnew branch name: ") + (with-current-notmuch-show-message + (let ((default-directory (expand-file-name repo)) + (mm-handle (mm-dissect-buffer))) + (mailscripts--check-out-branch branch) + (notmuch-foreach-mime-part + (lambda (p) + (let* ((disposition (mm-handle-disposition p)) + (filename (cdr (assq 'filename disposition)))) + (and filename + (string-match "^[0-9]+-.+\.\\(patch\\|diff\\|txt\\)$" filename) + (mm-pipe-part p "git am")))) + mm-handle)))) + +;;;###autoload +(defun notmuch-extract-message-patches-projectile () + "Like `notmuch-extract-message-patches', but use projectile to choose the repo." + (interactive) + (mailscripts--projectile-repo-and-branch 'notmuch-extract-message-patches)) + (defun mailscripts--check-out-branch (branch) (call-process-shell-command (format "git checkout -b %s" -- cgit v1.2.3 From 294e321dde7219b80d4fd6f831dff8546eab7ba3 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 2 Nov 2019 12:16:37 -0700 Subject: changelog Signed-off-by: Sean Whitton --- debian/changelog | 1 + 1 file changed, 1 insertion(+) (limited to 'debian') diff --git a/debian/changelog b/debian/changelog index 06e92e6..dc13036 100644 --- a/debian/changelog +++ b/debian/changelog @@ -8,6 +8,7 @@ mailscripts (0.12-1) UNRELEASED; urgency=medium * mailscripts.el: add mailscripts-extract-patches-branch-prefix defcustom. * mailscripts.el: add notmuch-extract-thread-patches-projectile command. * mailscripts.el: add notmuch-extract-message-patches{,-projectile} commands. + * elpa-mailscripts now depends on elpa-projectile. -- Sean Whitton Fri, 01 Nov 2019 20:38:07 -0700 -- cgit v1.2.3 From 736064843a60ac1814da71550ae04c9673ed1e89 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Wed, 6 Nov 2019 20:34:53 -0700 Subject: mailscripts.el: if user does not enter a branch name, use HEAD Signed-off-by: Sean Whitton --- debian/changelog | 1 + mailscripts.el | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) (limited to 'debian') diff --git a/debian/changelog b/debian/changelog index dc13036..919eb1a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -7,6 +7,7 @@ mailscripts (0.12-1) UNRELEASED; urgency=medium Thanks to Daniel Kahn Gillmor for the patch series. * mailscripts.el: add mailscripts-extract-patches-branch-prefix defcustom. * mailscripts.el: add notmuch-extract-thread-patches-projectile command. + * mailscripts.el: if user does not enter a branch name, use current HEAD. * mailscripts.el: add notmuch-extract-message-patches{,-projectile} commands. * elpa-mailscripts now depends on elpa-projectile. diff --git a/mailscripts.el b/mailscripts.el index 6bc64bc..db1cf94 100644 --- a/mailscripts.el +++ b/mailscripts.el @@ -65,7 +65,8 @@ The target branch may or may not already exist. See notmuch-extract-patch(1) manpage for limitations: in particular, this Emacs Lisp function supports passing only entire threads to the notmuch-extract-patch(1) command." - (interactive "Dgit repo: \nsnew branch name: \nP") + (interactive + "Dgit repo: \nsbranch name (or leave blank to apply to current HEAD): \nP") (let ((thread-id notmuch-show-thread-id) (default-directory (expand-file-name repo))) (mailscripts--check-out-branch branch no-prefix) @@ -93,7 +94,8 @@ The target branch may or may not already exist. Patches are applied using git-am(1), so we only consider attachments with filenames which look like they were generated by git-format-patch(1)." - (interactive "Dgit repo: \nsnew branch name: \nP") + (interactive + "Dgit repo: \nsbranch name (or leave blank to apply to current HEAD): \nP") (with-current-notmuch-show-message (let ((default-directory (expand-file-name repo)) (mm-handle (mm-dissect-buffer))) @@ -116,17 +118,20 @@ git-format-patch(1)." 'notmuch-extract-message-patches no-prefix)) (defun mailscripts--check-out-branch (branch no-prefix) - (call-process-shell-command - (format "git checkout -b %s" - (shell-quote-argument - (if (and (not no-prefix) mailscripts-extract-patches-branch-prefix) - (concat mailscripts-extract-patches-branch-prefix branch) - branch))))) + (unless (string= branch "") + (call-process-shell-command + (format "git checkout -b %s" + (shell-quote-argument + (if (and (not no-prefix) mailscripts-extract-patches-branch-prefix) + (concat mailscripts-extract-patches-branch-prefix branch) + branch)))))) (defun mailscripts--projectile-repo-and-branch (f &optional no-prefix) (let ((repo (projectile-completing-read "Select projectile project: " projectile-known-projects)) - (branch (completing-read "Branch name: " nil))) + (branch (completing-read + "Branch name (or leave blank to apply to current HEAD): " + nil))) (funcall f repo branch no-prefix))) (provide 'mailscripts) -- cgit v1.2.3 From b29caa46f35789e152fb0182441c33fac3382edb Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Wed, 6 Nov 2019 20:53:57 -0700 Subject: changelog Signed-off-by: Sean Whitton --- debian/changelog | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'debian') diff --git a/debian/changelog b/debian/changelog index 919eb1a..f905ff5 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,10 +5,13 @@ mailscripts (0.12-1) UNRELEASED; urgency=medium * email-print-mime-structure: add capability to decrypt message parts (Closes: #943959). Thanks to Daniel Kahn Gillmor for the patch series. - * mailscripts.el: add mailscripts-extract-patches-branch-prefix defcustom. - * mailscripts.el: add notmuch-extract-thread-patches-projectile command. - * mailscripts.el: if user does not enter a branch name, use current HEAD. - * mailscripts.el: add notmuch-extract-message-patches{,-projectile} commands. + + * mailscripts.el: + - new defcustom: mailscripts-extract-patches-branch-prefix + - new commands: + + notmuch-extract-thread-patches-projectile + + notmuch-extract-message-patches{,-projectile} + - if user does not enter a branch name, use current HEAD. * elpa-mailscripts now depends on elpa-projectile. -- Sean Whitton Fri, 01 Nov 2019 20:38:07 -0700 -- cgit v1.2.3 From fbda073c3d28496a7882c9a261718de65470f40c Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Wed, 6 Nov 2019 20:55:01 -0700 Subject: release mailscript 0.12 (0.12-1 to Debian unstable) Signed-off-by: Sean Whitton --- debian/changelog | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'debian') diff --git a/debian/changelog b/debian/changelog index f905ff5..d5aa2a8 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -mailscripts (0.12-1) UNRELEASED; urgency=medium +mailscripts (0.12-1) unstable; urgency=medium * email-print-mime-structure: make typesafe. Thanks to Daniel Kahn Gillmor for the patch. @@ -14,7 +14,7 @@ mailscripts (0.12-1) UNRELEASED; urgency=medium - if user does not enter a branch name, use current HEAD. * elpa-mailscripts now depends on elpa-projectile. - -- Sean Whitton Fri, 01 Nov 2019 20:38:07 -0700 + -- Sean Whitton Wed, 06 Nov 2019 20:54:56 -0700 mailscripts (0.11-1) unstable; urgency=medium -- cgit v1.2.3 From 4c55ffc5e899e63603c09b0c37898243913e565c Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 9 Nov 2019 15:01:43 -0700 Subject: changelog Signed-off-by: Sean Whitton --- debian/changelog | 6 ++++++ mailscripts.el | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'debian') diff --git a/debian/changelog b/debian/changelog index d5aa2a8..80a9232 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +mailscripts (0.13-1) UNRELEASED; urgency=medium + + * notmuch-extract-patch: add -v/--reroll-count option + + -- Sean Whitton Sat, 09 Nov 2019 15:01:23 -0700 + mailscripts (0.12-1) unstable; urgency=medium * email-print-mime-structure: make typesafe. diff --git a/mailscripts.el b/mailscripts.el index 1e8cf93..ee05cd6 100644 --- a/mailscripts.el +++ b/mailscripts.el @@ -1,7 +1,7 @@ ;;; mailscripts.el --- functions to access tools in the mailscripts package ;; Author: Sean Whitton -;; Version: 0.12 +;; Version: 0.13 ;; Package-Requires: (notmuch projectile) ;; Copyright (C) 2018, 2019 Sean Whitton -- cgit v1.2.3 From fc0576a446b5d9cfee859184498780cce41b112d Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 9 Nov 2019 15:03:53 -0700 Subject: close bug Signed-off-by: Sean Whitton --- debian/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'debian') diff --git a/debian/changelog b/debian/changelog index 80a9232..545e749 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,6 @@ mailscripts (0.13-1) UNRELEASED; urgency=medium - * notmuch-extract-patch: add -v/--reroll-count option + * notmuch-extract-patch: add -v/--reroll-count option (Closes: #944418). -- Sean Whitton Sat, 09 Nov 2019 15:01:23 -0700 -- cgit v1.2.3 From f06554efd870911a275b6e920afb133d0d61e68c Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 9 Nov 2019 15:20:44 -0700 Subject: mailscripts.el: arg to pass --reroll-count to notmuch-extract-patch Signed-off-by: Sean Whitton --- debian/changelog | 2 ++ mailscripts.el | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'debian') diff --git a/debian/changelog b/debian/changelog index 545e749..6787b43 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,8 @@ mailscripts (0.13-1) UNRELEASED; urgency=medium * notmuch-extract-patch: add -v/--reroll-count option (Closes: #944418). + * mailscripts.el: prefix arg to pass -v/--reroll-count to + notmuch-extract-patch. -- Sean Whitton Sat, 09 Nov 2019 15:01:23 -0700 diff --git a/mailscripts.el b/mailscripts.el index ee05cd6..916aec8 100644 --- a/mailscripts.el +++ b/mailscripts.el @@ -54,21 +54,26 @@ If NO-OPEN, don't open the thread." (notmuch-refresh-this-buffer))) ;;;###autoload -(defun notmuch-extract-thread-patches (repo branch) +(defun notmuch-extract-thread-patches (repo branch &optional reroll-count) "Extract patch series in current thread to branch BRANCH in repo REPO. The target branch may or may not already exist. +With an optional prefix numeric argument REROLL-COUNT, try to +extract the nth revision of a series. See the --reroll-count +option detailed in notmuch-extract-patch(1). + See notmuch-extract-patch(1) manpage for limitations: in particular, this Emacs Lisp function supports passing only entire threads to the notmuch-extract-patch(1) command." (interactive - "Dgit repo: \nsbranch name (or leave blank to apply to current HEAD): ") + "Dgit repo: \nsbranch name (or leave blank to apply to current HEAD): \np") (let ((thread-id notmuch-show-thread-id) (default-directory (expand-file-name repo))) (mailscripts--check-out-branch branch) (shell-command - (format "notmuch-extract-patch %s | git am" + (format "notmuch-extract-patch -v%d %s | git am" + (if reroll-count reroll-count 1) (shell-quote-argument thread-id)) "*notmuch-apply-thread-series*"))) @@ -76,7 +81,8 @@ threads to the notmuch-extract-patch(1) command." (defun notmuch-extract-thread-patches-projectile () "Like `notmuch-extract-thread-patches', but use projectile to choose the repo." (interactive) - (mailscripts--projectile-repo-and-branch 'notmuch-extract-thread-patches)) + (mailscripts--projectile-repo-and-branch + 'notmuch-extract-thread-patches (prefix-numeric-value current-prefix-arg))) ;;;###autoload (defun notmuch-extract-message-patches (repo branch) @@ -118,13 +124,13 @@ git-format-patch(1)." (concat mailscripts-extract-patches-branch-prefix branch) branch)))))) -(defun mailscripts--projectile-repo-and-branch (f) +(defun mailscripts--projectile-repo-and-branch (f &rest args) (let ((repo (projectile-completing-read "Select projectile project: " projectile-known-projects)) (branch (completing-read "Branch name (or leave blank to apply to current HEAD): " nil))) - (funcall f repo branch))) + (apply f repo branch args))) (provide 'mailscripts) -- cgit v1.2.3 From 02ef341d2280d168ebe045277e7ea1064b7650dd Mon Sep 17 00:00:00 2001 From: Daniel Kahn Gillmor Date: Sat, 9 Nov 2019 19:14:21 -0500 Subject: wrap-and-sort -ast Signed-off-by: Daniel Kahn Gillmor --- debian/mailscripts.install | 10 +++++----- debian/mailscripts.manpages | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'debian') diff --git a/debian/mailscripts.install b/debian/mailscripts.install index 99216c1..2c060df 100644 --- a/debian/mailscripts.install +++ b/debian/mailscripts.install @@ -1,8 +1,8 @@ +email-extract-openpgp-certs /usr/bin +email-print-mime-structure /usr/bin +maildir-import-patch /usr/bin mbox2maildir /usr/bin mdmv /usr/bin -notmuch-slurp-debbug /usr/bin -maildir-import-patch /usr/bin -notmuch-import-patch /usr/bin notmuch-extract-patch/notmuch-extract-patch /usr/bin -email-extract-openpgp-certs /usr/bin -email-print-mime-structure /usr/bin +notmuch-import-patch /usr/bin +notmuch-slurp-debbug /usr/bin diff --git a/debian/mailscripts.manpages b/debian/mailscripts.manpages index 6d7cb30..1de088f 100644 --- a/debian/mailscripts.manpages +++ b/debian/mailscripts.manpages @@ -1,8 +1,8 @@ +email-extract-openpgp-certs.1 +email-print-mime-structure.1 +maildir-import-patch.1 mbox2maildir.1 mdmv.1 -notmuch-slurp-debbug.1 -maildir-import-patch.1 -notmuch-import-patch.1 notmuch-extract-patch.1 -email-extract-openpgp-certs.1 -email-print-mime-structure.1 +notmuch-import-patch.1 +notmuch-slurp-debbug.1 -- cgit v1.2.3 From e910230a9fb8a5151bede6d043679ec50570290f Mon Sep 17 00:00:00 2001 From: Daniel Kahn Gillmor Date: Sat, 9 Nov 2019 16:48:14 -0500 Subject: email-print-mime-structure: Add --use-gpg-agent for decryption In some cases, the user may want to try to use their own GnuPG secret keys to decrypt encrypted parts of the message. By default it is disabled so that we aren't accidentally triggering the use of user secret key material. Note that gpg(1) says: It is highly recommended to use [--batch] along with the options --status-fd and --with-colons for any unattended use of gpg. I am deliberately choosing to not use either --status-fd or --with-colons for email-print-mime-structure. I'm not using --with-colons because there is no output from GnuPG that we expect to be machine-readable -- we're just looking for the cleartext of whatever ciphertext is in the message part. I'm not using --status-fd because there is nothing actionable we can do with GnuPG status messages, and asking for them would require switching from subprocess.run to subprocess.Popen to take advantage of the pass_fds argument, which in turn would make the script only work in a POSIX environment (I believe, but have not tested, that the script can currently be used on Windows). Signed-off-by: Daniel Kahn Gillmor --- debian/control | 2 ++ email-print-mime-structure | 22 +++++++++++++++++++++- email-print-mime-structure.1.pod | 24 +++++++++++++++++++----- 3 files changed, 42 insertions(+), 6 deletions(-) (limited to 'debian') diff --git a/debian/control b/debian/control index fc2bccc..4c3b956 100644 --- a/debian/control +++ b/debian/control @@ -38,6 +38,8 @@ Depends: Recommends: devscripts, git, + gpg, + gpg-agent, notmuch, python3-pgpy, Architecture: all diff --git a/email-print-mime-structure b/email-print-mime-structure index c22d556..5497597 100755 --- a/email-print-mime-structure +++ b/email-print-mime-structure @@ -29,9 +29,11 @@ Example: If you want to number the parts, i suggest piping the output through something like "cat -n" ''' +import os import sys import email import logging +import subprocess from argparse import ArgumentParser, Namespace from typing import Optional, Union, List, Tuple, Any @@ -70,7 +72,7 @@ class MimePrinter(object): nbytes = len(payload) print(f'{prefix}{z.get_content_type()}{cset}{disposition}{fname} {nbytes:d} bytes') - try_decrypt:bool = True if self.args.pgpkey else False + try_decrypt:bool = self.args.pgpkey or self.args.use_gpg_agent if try_decrypt and \ (parent is not None) and \ @@ -84,6 +86,8 @@ class MimePrinter(object): return if self.args.pgpkey: cryptopayload = self.pgpy_decrypt(self.args.pgpkey, ciphertext) + if cryptopayload is None and self.args.use_gpg_agent: + cryptopayload = self.gpg_decrypt(ciphertext) if cryptopayload is None: logging.warning(f'Unable to decrypt') return @@ -108,6 +112,19 @@ class MimePrinter(object): pass return None + def gpg_decrypt(self, ciphertext:str) -> Optional[Message]: + inp:int + outp:int + inp, outp = os.pipe() + with open(outp, 'w') as outf: + outf.write(ciphertext) + out:subprocess.CompletedProcess[bytes] = subprocess.run(['gpg', '--batch', '--decrypt'], + stdin=inp, + capture_output=True) + if out.returncode == 0: + return email.message_from_bytes(out.stdout) + return None + def print_tree(self, z:Message, prefix:str, parent:Optional[Message], num:int) -> None: if (z.is_multipart()): self.print_part(z, prefix+'┬╴', parent, num) @@ -132,6 +149,9 @@ def main() -> None: epilog="Example: email-print-mime-structure are used ephemerally, and +do not interact with any local GnuPG keyring. + +=item B<--use-gpg-agent=>I|I + +If I, and B encounters a +PGP/MIME-encrypted part, it will try to decrypt the part using the +secret keys found in the local installation of GnuPG. (default: +I) + +If both B<--pgpkey=>I and B<--use-gpg-agent=true> are +supplied, I arguments will be tried before falling back to +GnuPG. + +If B has been asked to decrypt parts with +either B<--pgpkey=>I or with B<--use-gpg-agent=true>, and it +is unable to decrypt an encrypted part, it will emit a warning to +stderr. + =item B<--help>, B<-h> Show usage instructions. @@ -49,11 +68,6 @@ Show usage instructions. =head1 LIMITATIONS -B only decrypts encrypted e-mails using -raw, non-password-protected OpenPGP secret keys (see B<--pgpkey>, -above). If it is unable to decrypt an encrypted part with the -supplied keys, it will warn on stderr. - B's output is not stable, and is not intended to be interpreted by machines, so please do not depend on it in scripts! -- cgit v1.2.3 From d1ac3aa761e03486915c98348206970db80a3352 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 9 Nov 2019 17:07:39 -0700 Subject: changelog Signed-off-by: Sean Whitton --- debian/changelog | 2 ++ 1 file changed, 2 insertions(+) (limited to 'debian') diff --git a/debian/changelog b/debian/changelog index 6787b43..85e3e47 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,6 +3,8 @@ mailscripts (0.13-1) UNRELEASED; urgency=medium * notmuch-extract-patch: add -v/--reroll-count option (Closes: #944418). * mailscripts.el: prefix arg to pass -v/--reroll-count to notmuch-extract-patch. + * email-print-mime-structure: add --use-gpg-agent option (Closes: #944340). + Thanks to Daniel Kahn Gillmor for the patch series. -- Sean Whitton Sat, 09 Nov 2019 15:01:23 -0700 -- cgit v1.2.3 From 92eaaca02a0945e2ede9b54975ed218ece9632c3 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sun, 10 Nov 2019 01:00:47 -0700 Subject: demote gpg, gpg-agent Recommends->Suggests See discussion in #944340. Signed-off-by: Sean Whitton --- debian/changelog | 1 + debian/control | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'debian') diff --git a/debian/changelog b/debian/changelog index 85e3e47..af4030a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,7 @@ mailscripts (0.13-1) UNRELEASED; urgency=medium notmuch-extract-patch. * email-print-mime-structure: add --use-gpg-agent option (Closes: #944340). Thanks to Daniel Kahn Gillmor for the patch series. + - Suggest gpg & gpg-agent. -- Sean Whitton Sat, 09 Nov 2019 15:01:23 -0700 diff --git a/debian/control b/debian/control index 4c3b956..f92f7a1 100644 --- a/debian/control +++ b/debian/control @@ -38,10 +38,11 @@ Depends: Recommends: devscripts, git, - gpg, - gpg-agent, notmuch, python3-pgpy, +Suggests: + gpg, + gpg-agent, Architecture: all Description: collection of scripts for manipulating e-mail on Debian This package provides a collection of scripts for manipulating e-mail -- cgit v1.2.3 From 677d6ed933a073a3bc3b2c461f49a97b0cbefebd Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sun, 10 Nov 2019 01:12:18 -0700 Subject: release mailscript 0.13 (0.13-1 to Debian unstable) Signed-off-by: Sean Whitton --- debian/changelog | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'debian') diff --git a/debian/changelog b/debian/changelog index af4030a..ef96e0e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -mailscripts (0.13-1) UNRELEASED; urgency=medium +mailscripts (0.13-1) unstable; urgency=medium * notmuch-extract-patch: add -v/--reroll-count option (Closes: #944418). * mailscripts.el: prefix arg to pass -v/--reroll-count to @@ -7,7 +7,7 @@ mailscripts (0.13-1) UNRELEASED; urgency=medium Thanks to Daniel Kahn Gillmor for the patch series. - Suggest gpg & gpg-agent. - -- Sean Whitton Sat, 09 Nov 2019 15:01:23 -0700 + -- Sean Whitton Sun, 10 Nov 2019 01:12:04 -0700 mailscripts (0.12-1) unstable; urgency=medium -- cgit v1.2.3 From 818dba1efe67f7b01f6d601c6462a40567c9ed7f Mon Sep 17 00:00:00 2001 From: Daniel Kahn Gillmor Date: Sun, 10 Nov 2019 09:31:58 -0500 Subject: email-print-mime-structure: add tab completion This is modeled after the use of argcomplete in diffoscope, and it should be possible to use it for any other pythonic mailscript that uses argparse. Signed-off-by: Daniel Kahn Gillmor --- Makefile | 9 ++++++++- debian/control | 3 +++ debian/mailscripts.bash-completion | 1 + debian/rules | 2 +- email-print-mime-structure | 15 +++++++++++++++ 5 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 debian/mailscripts.bash-completion (limited to 'debian') diff --git a/Makefile b/Makefile index 352f6f0..0cd06b7 100644 --- a/Makefile +++ b/Makefile @@ -3,14 +3,21 @@ MANPAGES=mdmv.1 mbox2maildir.1 \ email-extract-openpgp-certs.1 \ email-print-mime-structure.1 \ notmuch-import-patch.1 +COMPLETIONS=completions/bash/email-print-mime-structure -all: $(MANPAGES) +all: $(MANPAGES) $(COMPLETIONS) clean: rm -f $(MANPAGES) + rm -rf completions %.1: %.1.pod pod2man --section=1 --date="Debian Project" --center="User Commands" \ --utf8 \ --name=$(subst .1,,$@) \ $^ $@ + +completions/bash/%: + mkdir -p completions/bash + register-python-argcomplete3 $(notdir $@) > $@.tmp + mv $@.tmp $@ diff --git a/debian/control b/debian/control index f92f7a1..782636f 100644 --- a/debian/control +++ b/debian/control @@ -4,9 +4,11 @@ Priority: optional Maintainer: Sean Whitton Standards-Version: 4.1.5 Build-Depends: + bash-completion, debhelper (>= 10), dh-elpa, perl, + python3-argcomplete, Vcs-Git: https://git.spwhitton.name/mailscripts Vcs-Browser: https://git.spwhitton.name/mailscripts @@ -39,6 +41,7 @@ Recommends: devscripts, git, notmuch, + python3-argcomplete, python3-pgpy, Suggests: gpg, diff --git a/debian/mailscripts.bash-completion b/debian/mailscripts.bash-completion new file mode 100644 index 0000000..435576f --- /dev/null +++ b/debian/mailscripts.bash-completion @@ -0,0 +1 @@ +completions/bash/email-print-mime-structure diff --git a/debian/rules b/debian/rules index e8e22ba..6d50bf4 100755 --- a/debian/rules +++ b/debian/rules @@ -1,4 +1,4 @@ #!/usr/bin/make -f %: - dh $@ --with elpa + dh $@ --with elpa --with bash-completion diff --git a/email-print-mime-structure b/email-print-mime-structure index 5497597..aac8194 100755 --- a/email-print-mime-structure +++ b/email-print-mime-structure @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +# PYTHON_ARGCOMPLETE_OK # -*- coding: utf-8 -*- # Copyright (C) 2019 Daniel Kahn Gillmor @@ -45,6 +46,11 @@ try: except ImportError: pgpy = None +try: + import argcomplete #type: ignore +except ImportError: + argcomplete = None + class MimePrinter(object): def __init__(self, args:Namespace): self.args = args @@ -152,6 +158,15 @@ def main() -> None: parser.add_argument('--use-gpg-agent', metavar='true|false', type=bool, default=False, help='Ask local GnuPG installation for decryption') + + if argcomplete: + argcomplete.autocomplete(parser) + elif '_ARGCOMPLETE' in os.environ: + logging.error('Argument completion requested but the "argcomplete" ' + 'module is not installed. ' + 'Maybe you want to "apt install python3-argcomplete"') + sys.exit(1) + args:Namespace = parser.parse_args() msg:Union[Message, str, int, Any] = email.message_from_file(sys.stdin) -- cgit v1.2.3 From 55603ae831d2a50c7b2fb37b7a8cce1690d11b5e Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sun, 10 Nov 2019 09:02:29 -0700 Subject: changelog Signed-off-by: Sean Whitton --- debian/changelog | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'debian') diff --git a/debian/changelog b/debian/changelog index ef96e0e..09441a6 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +mailscripts (0.14-1) UNRELEASED; urgency=medium + + * email-print-mime-structure: add bash completion (Closes: #944434). + Thanks to Daniel Kahn Gillmor for the patch. + + -- Sean Whitton Sun, 10 Nov 2019 09:01:58 -0700 + mailscripts (0.13-1) unstable; urgency=medium * notmuch-extract-patch: add -v/--reroll-count option (Closes: #944418). -- cgit v1.2.3 From 8ef023c49c264bb77f2d1a64a0ba3c0630407de7 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sun, 10 Nov 2019 09:06:44 -0700 Subject: Declare compliance with Debian Policy 4.4.1 Thanks to Daniel Kahn Gillmor for taking the time to verify that no changes are required. Signed-off-by: Sean Whitton --- debian/changelog | 3 +++ debian/control | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'debian') diff --git a/debian/changelog b/debian/changelog index 09441a6..caf14cc 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,6 +2,9 @@ mailscripts (0.14-1) UNRELEASED; urgency=medium * email-print-mime-structure: add bash completion (Closes: #944434). Thanks to Daniel Kahn Gillmor for the patch. + * Declare compliance with Debian Policy 4.4.1. + Thanks to Daniel Kahn Gillmor for taking the time to verify that no + changes are required. -- Sean Whitton Sun, 10 Nov 2019 09:01:58 -0700 diff --git a/debian/control b/debian/control index 782636f..72b57c3 100644 --- a/debian/control +++ b/debian/control @@ -2,7 +2,7 @@ Source: mailscripts Section: mail Priority: optional Maintainer: Sean Whitton -Standards-Version: 4.1.5 +Standards-Version: 4.4.1 Build-Depends: bash-completion, debhelper (>= 10), -- cgit v1.2.3 From bb2eb59ef72b92e598f149d3987f0969386223ab Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Fri, 15 Nov 2019 18:02:48 -0700 Subject: changelog Signed-off-by: Sean Whitton --- debian/changelog | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'debian') diff --git a/debian/changelog b/debian/changelog index caf14cc..2c200f5 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,6 +2,12 @@ mailscripts (0.14-1) UNRELEASED; urgency=medium * email-print-mime-structure: add bash completion (Closes: #944434). Thanks to Daniel Kahn Gillmor for the patch. + - Build-depend on bash-completion, python3-argcomplete. + - Recommend python3-argcomplete. + * email-print-mime-structure: replace --use-gpg-agent=true with + --use-gpg-agent, and add --no-use-gpg-agent (Closes: #944475). + This is due to limitations in Python's argparse library. + Thanks to Daniel Kahn Gillmor for the report and a patch. * Declare compliance with Debian Policy 4.4.1. Thanks to Daniel Kahn Gillmor for taking the time to verify that no changes are required. -- cgit v1.2.3 From 693117551a0e21359ac6dbadba443516c56b04df Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Fri, 15 Nov 2019 18:19:09 -0700 Subject: release mailscripts 0.14 (0.14-1 to Debian unstable) Signed-off-by: Sean Whitton --- debian/changelog | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'debian') diff --git a/debian/changelog b/debian/changelog index 2c200f5..9f6a0d1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -mailscripts (0.14-1) UNRELEASED; urgency=medium +mailscripts (0.14-1) unstable; urgency=medium * email-print-mime-structure: add bash completion (Closes: #944434). Thanks to Daniel Kahn Gillmor for the patch. @@ -12,7 +12,7 @@ mailscripts (0.14-1) UNRELEASED; urgency=medium Thanks to Daniel Kahn Gillmor for taking the time to verify that no changes are required. - -- Sean Whitton Sun, 10 Nov 2019 09:01:58 -0700 + -- Sean Whitton Fri, 15 Nov 2019 18:19:04 -0700 mailscripts (0.13-1) unstable; urgency=medium -- cgit v1.2.3