Skip to content

Instantly share code, notes, and snippets.

@noqqe
Last active December 23, 2015 01:48
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save noqqe/6562350 to your computer and use it in GitHub Desktop.
Save noqqe/6562350 to your computer and use it in GitHub Desktop.
I was running into some encoding errors with internationalized mailheaders in the traditional mutt2task. So this is a improved, more reliable, charset- and limiter-save version of mutt2task from http://www.nixternal.com/mark-e-mails-in-mutt-as-tasks-in-taskwarrior/ written in Python.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
## About
# Add the subject of a mail as task to taskwarrior
#
## Usage
# add this to your .muttrc:
# macro index,pager t "<pipe-message>~/path/to/mutt2task.py<enter>"
# import libraries
import sys
import email
from email.header import decode_header
from subprocess import call
# read from stdin and parse subject
x = sys.stdin.read()
x = email.message_from_string(x)
x = x['Subject']
# decode internationalized subject and transform ascii into utf8
x = decode_header(x)
x = ' '.join([ unicode(t[0], t[1] or 'ASCII' ) for t in x ])
x = x.encode('utf8')
# customize your own taskwarrior line
# use `x' to add the subject
call(['task', 'add', 'pri:L', '+mail', '--', x ])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment