Skip to content

Instantly share code, notes, and snippets.

@tychoish

tychoish/org-mail.md

Created Oct 13, 2014
Embed
What would you like to do?

Org-Mail

These scripts and glue accept email sent to a secret address and convert the body of the email into a file where the subject of the email becomes an org-mode headline with the body of the note as the body of that org-mode item. Using a custom FILE todo keyword, these items are included in the org-agenda (assuming that ~/mail/inbox.org is included on your agenda.) With a deadline of "today," relative to receipt of the email.

There are a few dependencies and assumptions. They are:

  • That you have procmail, mimencode and html2text installed on your machines and that you're using procmail to filter your email prior to it's delivery in your email

  • I've commented this out, but I run an xmpp-notify script that sends me an XMPP message whenever one of these notes arrives, just as a check.

File (excerpt:) ~/.procmailrc:

 ## Change html email to text
 :0
 * ^Content-Type: text/html;
 {
  :0c
  $MAIL/html.a/
  :0fwb
  | `which html2text`
  :0fwh
  | `which formail` -i "Content-Type: text/plain; charset=us-ascii"
  LOG="HTML message found and converted..."
 }

 ## notes filtering

 :0
 * ^TO_.*[SECRET-EMAIL@example\.com.*
 {
   # :0 hc
   # | /opt/xmpp-notify "<org-mode.mail> $SUBJECT"
   :0c
   $MAIL/notes/

   :0 fwh
   |  /opt/org-inbox subject "$SUBJECT"
   :0 fwb
   | /opt/org-inbox body 

   :0:
   /dev/null
   }

File: /opt/org-inbox:

 #!/bin/bash

 touch ~/mail/inbox.org

 if [ "$1" = "body" ]; then 
     html2text | mimencode -u | sed -re '/^-- /,$ d
                                    /\=20$/ d'  >> ~/mail/inbox.org
 elif [ "$1" = "subject" ]; then
     shift
     BODY=$*
     echo \* FILE $BODY >> ~/mail/inbox.org    
     echo "DEADLINE: <`date \"+%Y-%m-%d %a\"`>" >> ~/mail/inbox.org
 else
    echo failure
    LOG="improper command" 
 fi 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.