aboutsummaryrefslogtreecommitdiff
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
parent5193da11b7bd93ce6e4f57555c661e99f5ce4321 (diff)
mail: notmuch-search
-rw-r--r--.emacs1
-rw-r--r--.emacs.local.d/general.el4
-rw-r--r--.emacs.local.d/mail.el13
-rw-r--r--.emacs.local.d/modes/org.el1
-rwxr-xr-xbin/mutt-open76
-rwxr-xr-xbin/mutt-remember-mail37
6 files changed, 32 insertions, 100 deletions
diff --git a/.emacs b/.emacs
index 39ca5da..4fd46f7 100644
--- a/.emacs
+++ b/.emacs
@@ -1,6 +1,7 @@
;; Load up the general config
(load-file "~/.emacs.local.d/config.el")
(load-file "~/.emacs.local.d/general.el")
+(load-file "~/.emacs.local.d/mail.el")
(load-file "~/.emacs.local.d/modes/fonts.el")
(load-file "~/.emacs.local.d/modes/themes.el")
diff --git a/.emacs.local.d/general.el b/.emacs.local.d/general.el
index 76efd12..250c6bc 100644
--- a/.emacs.local.d/general.el
+++ b/.emacs.local.d/general.el
@@ -163,10 +163,6 @@
;; Use default brwoser
;;(setq browse-url-browser-function 'browse-url-generic browse-url-generic-program "chromium")
-;; Mutt support.
-(setq auto-mode-alist (append '((".*tmp/mutt.*" . message-mode)) auto-mode-alist))
-(setq auto-mode-alist (append '((".*tmp/neomutt.*" . message-mode)) auto-mode-alist))
-
;; Save what you enter into minibuffer prompts
(setq history-length 25)
(savehist-mode 1)
diff --git a/.emacs.local.d/mail.el b/.emacs.local.d/mail.el
new file mode 100644
index 0000000..da011cd
--- /dev/null
+++ b/.emacs.local.d/mail.el
@@ -0,0 +1,13 @@
+;; Mutt support.
+(setq auto-mode-alist (append '((".*tmp/mutt.*" . message-mode)) auto-mode-alist))
+(setq auto-mode-alist (append '((".*tmp/neomutt.*" . message-mode)) auto-mode-alist))
+
+;; Hook up `mutt:...` style URLs
+(require 'ol-notmuch)
+(org-add-link-type "message" 'org-notmuch-open)
+
+(setq send-mail-function 'sendmail-send-it
+ sendmail-program "/usr/bin/msmtp"
+ mail-specify-envelope-from t
+ message-sendmail-envelope-from 'header
+ mail-envelope-from 'header)
diff --git a/.emacs.local.d/modes/org.el b/.emacs.local.d/modes/org.el
index d504491..d1939f9 100644
--- a/.emacs.local.d/modes/org.el
+++ b/.emacs.local.d/modes/org.el
@@ -27,7 +27,6 @@
org-fontify-done-headline t
org-fontify-quote-and-verse-blocks t)
-
;; ORG BINDINGS ;;
(global-set-key (kbd "C-c l") #'org-store-link)
(global-set-key (kbd "C-c a") #'org-agenda)
diff --git a/bin/mutt-open b/bin/mutt-open
deleted file mode 100755
index 0b21261..0000000
--- a/bin/mutt-open
+++ /dev/null
@@ -1,76 +0,0 @@
-#!/bin/bash
-#
-# Fire up mutt on a given mail, located in some Maildir
-# Mail can be specified either by path or by Messsage-ID; in the latter case
-# file lookup is performed using some mail indexing tool.
-#
-# Copyright: © 2009-2014 Stefano Zacchiroli <zack@upsilon.cc>
-# License: GNU General Public License (GPL), version 3 or above
-
-# requires: notmuch | maildir-utils >= 0.7
-
-MUTT="neomutt"
-MAIL_INDEXER="notmuch" # one of "notmuch", "mu"
-export NOTMUCH_CONFIG=$HOME/te/etc/notmuch-config
-
-MUTT_FLAGS="-R -F ~/te/etc/muttrc"
-HIDE_SIDEBAR_CMD="B" # set to empty string if sidebar is not used
-
-# Sample output of lookup command, which gets passed to mutt-open
-# /home/zack/Maildir/INBOX/cur/1256673179_0.8700.usha,U=37420,FMD5=7e33429f656f1e6e9d79b29c3f82c57e:2,S
-
-die_usage () {
- echo "Usage: mutt-open FILE" 1>&2
- echo " mutt-open MESSAGE-ID" 1>&2
- echo 'E.g.: mutt-open `notmuch search --output=files id:MESSAGE-ID`' 1>&2
- echo ' mutt-open `mu find -f l i:MESSAGE-ID`' 1>&2
- echo ' mutt-open 20091030112543.GA4230@usha.takhisis.invalid' 1>&2
- exit 3
-}
-
-# Lookup: Message-ID -> mail path. Store results in global $fname
-lookup_msgid () {
- msgid_query="$1"
- case "$MAIL_INDEXER" in
- notmuch)
- fname=$(notmuch search --output=files id:"$msgid_query" | head -n 1)
- ;;
- mu)
- fname=$(mu find -f l i:"$msgid_query" | head -n 1)
- ;;
- esac
-}
-
-dump_info () {
- echo "fname: $fname"
- echo "msgid: $msgid"
-}
-
-if [ -z "$1" -o "$1" = "-h" -o "$1" = "-help" -o "$1" = "--help" ] ; then
- die_usage
-fi
-if (echo "$1" | grep -q /) && test -f "$1" ; then # arg is a file
- fname="$1"
- msgid=$(egrep -i '^message-id:' "$fname" | cut -f 2 -d':' | sed 's/[ <>]//g')
-elif ! (echo "$1" | grep -q /) ; then # arg is a Message-ID
- msgid="$1"
- lookup_msgid "$msgid" # side-effect: set $fname
-fi
-# dump_info ; exit 3
-if ! dirname "$fname" | egrep -q '/(cur|new|tmp)$' ; then
- echo "Path not pointing inside a maildir: $fname" 1>&2
- exit 2
-fi
-maildir=$(dirname $(dirname "$fname"))
-
-if ! [ -d "$maildir" ] ; then
- echo "Not a (mail)dir: $maildir" 1>&1
- exit 2
-fi
-
-# UGLY HACK: without sleep, push keys do not reach mutt, I _guess_ that there
-# might be some terminal-related issue here, since also waiting for an input
-# with "read" similarly "solves" the problem
-sleep 0.5
-mutt_keys="/=i$msgid\n\n$HIDE_SIDEBAR_CMD"
-exec $MUTT $MUTT_FLAGS -f "$maildir/" -e "push $mutt_keys"
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