This is a simple three-step process:
Write a program to commit an email to git.
This is the shell script I use; I named it
~/.bin/commit-an-email . It constructs a commit message with the sender and subject, adds the email to the repo, and commits using that message:
#!/bin/sh MAILDIR=$HOME/Maildir commit_message=`grep '^From: ' $LASTFOLDER; grep '^Subject: ' $LASTFOLDER` cd $MAILDIR && \ git add `echo $LASTFOLDER | sed -e 's|^/home/mike/Maildir/||'` && \ git commit -m "$commit_message"
Set a procmail
TRAP setting points to a shell command which is executed after procmail has finished processing an email; it passes a copy of the email to
stdin. Set this to the
commit-an-email script in
Clean up deletions and moves, and push.
After the email is delivered you may read it, move it to another mailbox, or delete it. It’d be great if these actions were tracked as well. One option is to write a series of mutt macros that redefine
enter, and so on, to do the appropriate git command. Alternatively, you could handle this nightly with this script, meant to be run from
cron. I named it
#!/bin/sh GIT=/usr/local/bin/git MAILDIR=$HOME/Maildir cd $MAILDIR && \ $GIT add . && \ $GIT add -u && \ $GIT commit -m "Nightly maintainance" && \ $GIT push origin master >/dev/null
And this is my
5 1 * * * /usr/home/mike/.bin/commit-email