summaryrefslogtreecommitdiffstats
path: root/.local/bin/fetch_mail.sh
blob: 0375f412dc10f3a80322844d09074a3f3b2b6b58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/sh

set -f
set +f
set -m

export GNUPGHOME=/home/jozan/.local/share/gnupg
export PASSWORD_STORE_DIR=/home/jozan/.local/share/pass 

mc_file="/tmp/newmailcount"
if [ -f $mc_file ]; then
	pre_count=$(cat $mc_file)
else
	pre_count="$(ls "${MAIL:-/var/mail/jozan}"/main/INBOX/new | wc -l 2>/dev/null)"
	mb1="$(ls "${MAIL:-/var/mail/jozan}"/gmail_br/INBOX/new | wc -l 2>/dev/null)"
	mb2="$(ls "${MAIL:-/var/mail/jozan}"/gmail_oon/INBOX/new | wc -l 2>/dev/null)"
	mb3="$(ls "${MAIL:-/var/mail/jozan}"/gmail_tos/INBOX/new | wc -l 2>/dev/null)"
	pre_count="$((pre_count + mb1 + mb2 + mb3))"
fi
killall mbsync >/dev/null 2>&1
# notify-send -u low -t 3000 'mbsync' '  fetching mail...' >/dev/null 2>&1
{
	mbsync -a -c /usr/home/jozan/.config/mbsync/mbsyncrc ||
		notify-send -u low -t 6000 'mbsync' '  failed to fetch mail' >/dev/null 2>&1
}&
gsleep 0.2
kill -74 $(pidof dwmblocks) >/dev/null 2>&1
fg
post_count="$(ls "${MAIL:-/var/mail/jozan}"/main/INBOX/new | wc -l 2>/dev/null)"
mb1="$(ls "${MAIL:-/var/mail/jozan}"/gmail_br/INBOX/new | wc -l 2>/dev/null)"
mb2="$(ls "${MAIL:-/var/mail/jozan}"/gmail_oon/INBOX/new | wc -l 2>/dev/null)"
mb3="$(ls "${MAIL:-/var/mail/jozan}"/gmail_tos/INBOX/new | wc -l 2>/dev/null)"
post_count="$((post_count + mb1 + mb2 + mb3))"
if [ $post_count -gt $pre_count ]; then
	notify-send -u normal 'NeoMutt' '  '$post_count' new mail(s)'
fi
echo $post_count >$mc_file
sleep 1
kill -74 $(pidof dwmblocks) >/dev/null 2>&1