mail_sync (868B)
1 #!/usr/bin/env bash 2 3 export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus 4 export PYTHONDONTWRITEBYTECODE=1 5 mail_dir="$HOME/var/mbox" 6 log_file="$HOME/var/log/mail_sync.log" 7 cached_key=$(gpg-connect-agent 'keyinfo --list' /bye 2>/dev/null | awk 'BEGIN{CACHED=0} /^S/ {if($7==1){CACHED=1}} END{if($0!=""){print CACHED} else {print "none"}}') 8 9 log() { 10 echo "$(date +%H:%M:%S): ${1}" >> ${log_file} 11 } 12 13 if [[ "${cached_key}" == "1" ]] ; then 14 log "INFO: gpg key cached, beginning sync" 15 offlineimap -f INBOX >/dev/null 2>&1 16 sleep 5 17 18 for inbox in pyratebeard ; do 19 new_mail=$(ls -l ${mail_dir}/${inbox}/INBOX/new | wc -l) 20 let new_mail=new_mail-1 21 if [ ${new_mail} -gt 0 ] ; then 22 /usr/bin/notify-send -u 'normal' "${new_mail} new mail(s) for ${inbox}" 23 fi 24 done 25 else 26 log "ERROR: no gpg key cached" 27 fi 28 29 [ -d $HOME/__pycache__ ] && rm -rf $HOME/__pycache__