mail_sync (974B)
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/.local/var/mbox" 6 log_file="$HOME/.local/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 [ -f ${log_file} || touch ${log_file} 10 [ -d ${mail_dir} || mkdir -p ${mail_dir}/pyratebeard/ 11 log() { 12 echo "$(date +%H:%M:%S): ${1}" >> ${log_file} 13 } 14 15 if [[ "${cached_key}" == "1" ]] ; then 16 log "INFO: gpg key cached, beginning sync" 17 offlineimap -f INBOX >/dev/null 2>&1 18 sleep 5 19 20 for inbox in pyratebeard ; do 21 new_mail=$(ls -l ${mail_dir}/${inbox}/INBOX/new | wc -l) 22 let new_mail=new_mail-1 23 if [ ${new_mail} -gt 0 ] ; then 24 /usr/bin/notify-send -u 'normal' "${new_mail} new mail(s) for ${inbox}" 25 fi 26 done 27 else 28 log "ERROR: no gpg key cached" 29 fi 30 31 [ -d $HOME/__pycache__ ] && rm -rf $HOME/__pycache__