diff options
| author | Thibaut Horel <thibaut.horel@gmail.com> | 2014-08-17 20:27:44 -0400 |
|---|---|---|
| committer | Thibaut Horel <thibaut.horel@gmail.com> | 2014-08-17 20:27:44 -0400 |
| commit | cb2e7c09daefafad97618763f43c991baf8e9365 (patch) | |
| tree | 339bec874ce6b0b6efec33943b93325db63de153 | |
| download | mutt-helpers-cb2e7c09daefafad97618763f43c991baf8e9365.tar.gz | |
Initial commit
| -rwxr-xr-x | attach.py | 18 | ||||
| -rwxr-xr-x | filter.py | 17 | ||||
| -rwxr-xr-x | mutt-notmuch.py | 66 |
3 files changed, 101 insertions, 0 deletions
diff --git a/attach.py b/attach.py new file mode 100755 index 0000000..5750537 --- /dev/null +++ b/attach.py @@ -0,0 +1,18 @@ +#! /usr/bin/python2 +from glob import glob +from os.path import expanduser, join, basename +from os import remove, devnull +from shutil import copy +from sys import argv +from subprocess import Popen, STDOUT + +tmp_dir = expanduser(join("~", ".mutt", "temp", "attachments")) + +for f in glob(join(tmp_dir, "*")): + remove(f) + +basename = basename(argv[1]) +copy(argv[1], tmp_dir) +Popen(["xdg-open", join(tmp_dir, basename)], + stderr=STDOUT, + stdout=open(devnull, "wb")) diff --git a/filter.py b/filter.py new file mode 100755 index 0000000..59f27fe --- /dev/null +++ b/filter.py @@ -0,0 +1,17 @@ +#! /usr/bin/python2 +import os +import sys +from subprocess import PIPE, Popen + +os.environ["PARINIT"] = "85rTbgqR0d1 B=.,?!_A_a Q=_s>|+" + +for line in sys.stdin: + line = line.strip() + print line + if not line: + break +sys.stdout.flush() + +p = Popen("par", stdin=PIPE) +for line in sys.stdin: + p.stdin.write(line) diff --git a/mutt-notmuch.py b/mutt-notmuch.py new file mode 100755 index 0000000..fbfbd19 --- /dev/null +++ b/mutt-notmuch.py @@ -0,0 +1,66 @@ +#! /usr/bin/python2 +import sys +import email +import readline +from mailbox import Maildir +import os +from os.path import basename, join, expanduser +from ConfigParser import RawConfigParser, NoSectionError, NoOptionError + +from notmuch import Database, Query + +CONFIG_FILE = expanduser(os.getenv("NOTMUCH_CONFIG") or "~/.notmuch-config") +HIST_FILE = expanduser(os.getenv("MUTT_NM_HIST") or "~/.mutt-notmuch-history") + + +def make_query(query): + parser = RawConfigParser() + parser.read(CONFIG_FILE) + try: + tags = parser.get("search", "exclude_tags").split(";") + except (NoSectionError, NoOptionError): + tags = [] + q = Database().create_query(query) + map(q.exclude_tag, tags) + return q + + +def search(query): + q = make_query(query) + q.set_sort(Query.SORT.NEWEST_FIRST) + for message in q.search_messages(): + yield message.get_filename() + + +def thread(id): + q = make_query("id:" + id) + for message in q.search_messages(): + q2 = make_query("thread:" + message.get_thread_id()) + for m in q2.search_messages(): + yield m.get_filename() + + +def process(gen, output): + box = Maildir(output) + box.clear() + for filename in gen: + os.symlink(filename, join(box._path, "cur", basename(filename))) + + +def main(): + output = sys.argv[1] + if sys.argv[2] == "search": + try: + readline.read_history_file(HIST_FILE) + except IOError: + open(HIST_FILE, "a").close() + query = raw_input("Query: ") + readline.write_history_file(HIST_FILE) + process(search(query), output) + elif sys.argv[2] == "thread": + message = email.message_from_file(sys.stdin) + process(thread(message["message-id"][1:-1]), output) + + +if __name__ == "__main__": + main() |
