From 25b947edf445a96db335fe285a8b253b214649ff Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Wed, 6 Jan 2016 22:59:26 +0800 Subject: Rename .* => _*; Move out private contents. --- _offlineimap/offlineimap.py | 68 +++++++++++++++++++++++++++++++++++++++++++++ _offlineimap/postsync.sh | 26 +++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100755 _offlineimap/offlineimap.py create mode 100755 _offlineimap/postsync.sh (limited to '_offlineimap') diff --git a/_offlineimap/offlineimap.py b/_offlineimap/offlineimap.py new file mode 100755 index 0000000..e3ae422 --- /dev/null +++ b/_offlineimap/offlineimap.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python +# +# Add support of encrypting password with gpg2 for OfflineIMAP. +# Provide function 'mailpasswd' to decrypt the password. +# +# Configurations: +# [general] +# pythonfile = ~/.offlineimap/offlineimap.py +# ... +# [Repository ] +# remotepasseval = mailpasswd("") +# ... +# +# Reference: +# [1] Encrypt OfflineIMAP Password +# http://unix.stackexchange.com/questions/44214/encrypt-offlineimap-password +# +# Updated: 2015/02/02 +# + +import os +import subprocess + +def mailpasswd(account): + account = os.path.basename(account) + path = '{0}/.offlineimap/{1}.gpg'.format(os.environ['HOME'], account) + args = ['gpg2', '--for-your-eyes-only', '--no-tty', + '--quiet', '--batch', '--decrypt', path] + try: + return subprocess.check_output(args).strip() + except subprocess.CalledProcessError: + return '' + +# subprocess.check_output() only introduced in python 2.7 +# this version of 'mailpasswd' works with older version of python +#def mailpasswd(account): +# account = os.path.basename(account) +# path = '{0}/.offlineimap/{1}.gpg'.format(os.environ['HOME'], account) +# args = ['gpg2', '--for-your-eyes-only', '--no-tty', +# '--quiet', '--batch', '--decrypt', path] +# proc = subprocess.Popen(args, stdout=subprocess.PIPE) +# output = proc.communicate()[0].strip() +# retcode = proc.wait() +# if retcode == 0: +# return output +# else: +# return '' + + +# If you have several accounts that get checked simultaneously, and you +# use 'gpg-agent', then it will ask for you passphrase for each account. +# I prime the agent by creating a file, and priming the gpg-agent by +# decrypting this file on launch of offlineimap. +def prime_gpg_agent(): + # echo "prime" | gpg -e -r > ~/.offlineimap/prime.gpg + ret = False + i = 1 + while not ret: + ret = (mailpasswd("prime") == "prime") + if i > 2: + from offlineimap.ui import getglobalui + sys.stderr.write("Error reading in passwords. Terminating.\n") + getglobalui().terminate() + i += 1 + return ret + +prime_gpg_agent() + diff --git a/_offlineimap/postsync.sh b/_offlineimap/postsync.sh new file mode 100755 index 0000000..c5a3985 --- /dev/null +++ b/_offlineimap/postsync.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# +# OfflineIMAP postsynchook +# +# Weitian LI +# 2015/02/02 +# + +## Check new mails & send notification +MAILDIR="${HOME}/Mail/" +newmails=0 +for d in `find ${MAILDIR} -maxdepth 2 -type d -iname '*inbox'`; do + n=`ls ${d}/new/ | wc -l` + newmails=`expr ${newmails} + ${n}` +done + +if [ ${newmails} -gt 0 ] && which notify-send >/dev/null 2>&1; then + export DISPLAY=":0" + export XAUTHORITY="${HOME}/.Xauthority" + notify-send -i 'mail-unread' -a "OfflineIMAP" \ + "OfflineIMAP: Received ${newmails} new mail(s)!" +fi + +## Invoke notmuch to index mails +notmuch new + -- cgit v1.2.2