From 12f901918176be62fbe8565f0d5690ee315a5c08 Mon Sep 17 00:00:00 2001 From: Raul Benencia Date: Sun, 31 Jul 2022 15:56:57 -0700 Subject: mail: notmuch-search --- bin/mutt-remember-mail | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'bin/mutt-remember-mail') 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 -# 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}' +]) -- cgit v1.2.3