aboutsummaryrefslogtreecommitdiff
path: root/bin/mutt-remember-mail
diff options
context:
space:
mode:
authorRaul Benencia <id@rbenencia.name>2022-07-31 15:56:57 -0700
committerRaul Benencia <id@rbenencia.name>2022-07-31 15:58:42 -0700
commit12f901918176be62fbe8565f0d5690ee315a5c08 (patch)
treec22acab0658a4681640751588286cb5dad6a71f4 /bin/mutt-remember-mail
parent5193da11b7bd93ce6e4f57555c661e99f5ce4321 (diff)
mail: notmuch-search
Diffstat (limited to 'bin/mutt-remember-mail')
-rwxr-xr-xbin/mutt-remember-mail37
1 files changed, 18 insertions, 19 deletions
diff --git a/bin/mutt-remember-mail b/bin/mutt-remember-mail
index ba5b322..6113e7a 100755
--- a/bin/mutt-remember-mail
+++ b/bin/mutt-remember-mail
@@ -1,22 +1,21 @@
-#!/usr/bin/perl -w
-#
-# Helper for mutt to remember mails in Emacs' Org mode
-#
-# Copyright: © 2009-2010 Stefano Zacchiroli <zack@upsilon.cc>
-# License: GNU General Public License (GPL), version 3 or above
-#
-# Example of mutt macro to invoke this hitting ESC-R (to be put in ~/.muttrc):
-# macro index \eR "|~/bin/mutt-remember-mail\n"
+#!/usr/bin/env python3
-use strict;
-use Mail::Internet;
-use URI::Escape;
+import sys
+import email
+import subprocess
+import urllib.parse
-my $msg = Mail::Internet->new(\*STDIN);
-$msg->head->get('message-id') =~ /^<(.*)>$/;
-my $mid = $1;
-my $subject = $msg->head->get('subject') || "";
-my $from = $msg->head->get('from') || "";
-chomp ($subject, $from);
+# Parse the email from standard input
+message_bytes = sys.stdin.buffer.read()
+message = email.message_from_bytes(message_bytes)
-exec "emacsclient", "-c", "org-protocol://capture?template=m&url=mutt://$mid&title=$subject from $from";
+# Grab the relevant message headers
+message_id = urllib.parse.quote(message['message-id'][1:-1])
+subject = message['subject']
+h_from = message['from']
+
+# Ask emacsclient to save a link to the message
+subprocess.Popen([
+ 'emacsclient', '-c',
+ f'org-protocol://capture?template=m&url=message://id:{message_id}&title={subject} from {h_from}'
+])
nihil fit ex nihilo