update of mailsync script with dunst support
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -5,3 +5,4 @@ accounts/
 | 
				
			|||||||
personal.muttrc
 | 
					personal.muttrc
 | 
				
			||||||
thunderbird/
 | 
					thunderbird/
 | 
				
			||||||
autoconf/log
 | 
					autoconf/log
 | 
				
			||||||
 | 
					etc/mailsynclastrun
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										
											BIN
										
									
								
								etc/email.gif
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								etc/email.gif
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 7.4 KiB  | 
@@ -7,39 +7,32 @@
 | 
				
			|||||||
#
 | 
					#
 | 
				
			||||||
# I have this run as a cronjob every 5 minutes.
 | 
					# I have this run as a cronjob every 5 minutes.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Check for internet connection. Exit script if none. (timeout in mac is `-t`)
 | 
					export DISPLAY=:0.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Checks for internet connection and set notification script.
 | 
				
			||||||
 | 
					# Settings are different for MacOS (Darwin) systems.
 | 
				
			||||||
if [ "$(uname)" == "Darwin" ]
 | 
					if [ "$(uname)" == "Darwin" ]
 | 
				
			||||||
then
 | 
					then
 | 
				
			||||||
	ping -q -t 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` >/dev/null || exit
 | 
						ping -q -t 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` >/dev/null || exit
 | 
				
			||||||
 | 
						notify() { osascript -e "display notification \"$2 in $1\" with title \"Youve got Mail\" subtitle \"Account: $account\"" && sleep 2 ;}
 | 
				
			||||||
else
 | 
					else
 | 
				
			||||||
	ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` >/dev/null || exit
 | 
						ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` >/dev/null || exit
 | 
				
			||||||
 | 
						notify() { pgrep -x dunst && notify-send -i ~/.config/mutt/etc/email.gif "$2 new mail(s) in \`$1\` account." ;}
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Get current number of new mail, then begin sync.
 | 
					# Run offlineimap. You can feed this script different settings.
 | 
				
			||||||
ori=$(find ~/.mail -wholename '*/new/*' | grep -vi "spam\|trash\|junk" | wc -l)
 | 
					 | 
				
			||||||
offlineimap -o "$@"
 | 
					offlineimap -o "$@"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Recount new mail.
 | 
					# Check all accounts/mailboxes for new mail. Notify if there is new content.
 | 
				
			||||||
new=$(find ~/.mail -wholename '*/new/*' | grep -vi "spam\|trash\|junk" | wc -l)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# If new mail has grown, play a notification.
 | 
					 | 
				
			||||||
if [ "$new" -gt "$ori" ]; then
 | 
					 | 
				
			||||||
	mpv --quiet ~/.config/mutt/etc/notify.opus
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
for account in $(ls ~/.mail)
 | 
					for account in $(ls ~/.mail)
 | 
				
			||||||
do
 | 
					do
 | 
				
			||||||
        for mailbox in $(ls ~/.mail/$account/)
 | 
						#List unread messages newer than last mailsync and count them
 | 
				
			||||||
        do
 | 
						newcount=$(find ~/.mail/$account/INBOX/new/ -type f -newer ~/.config/mutt/etc/mailsynclastrun 2> /dev/null | wc -l)
 | 
				
			||||||
                #List unread messages newer than last mailsync and count them
 | 
						if [ "$newcount" -gt "0" ]
 | 
				
			||||||
                newcount=$(find ~/.mail/$account/$mailbox/new/ -type f -newer ~/.config/mutt/etc/mailsynclastrun 2> /dev/null | wc -l)
 | 
						then
 | 
				
			||||||
                #Pop a Mac style notification with the count for that mailbox
 | 
							notify "$account" "$newcount" & disown
 | 
				
			||||||
                if [ "$(uname)" == "Darwin" -a "$newcount" -gt "0" ]
 | 
							mpv --quiet ~/.config/mutt/etc/notify.opus
 | 
				
			||||||
                then
 | 
						fi
 | 
				
			||||||
                        osascript -e "display notification \"$newcount in $mailbox\" with title \"Youve got Mail\" subtitle \"Account: $account\""
 | 
					 | 
				
			||||||
                        sleep 2
 | 
					 | 
				
			||||||
                fi
 | 
					 | 
				
			||||||
        done
 | 
					 | 
				
			||||||
done
 | 
					done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#Create a touch file that indicates the time of the last run of mailsync
 | 
					#Create a touch file that indicates the time of the last run of mailsync
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user