aboutsummaryrefslogtreecommitdiff
path: root/bin/mutt-remember-mail
diff options
context:
space:
mode:
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