watch_mdbox

A script to check for changes in dovecot (m)dbox folders.
git clone git://r-36.net/watch_mdbox
Log | Files | Refs | README | LICENSE

watch_mdbox (665B)


      1 #!/bin/sh
      2 
      3 delimiter="."
      4 
      5 if [ "$1" = "" ];
      6 then
      7 	mdboxroot="$HOME/mdbox"
      8 else
      9 	mdboxroot="$1"
     10 fi
     11 
     12 mailboxes="${mdboxroot}/mailboxes"
     13 
     14 echo
     15 
     16 omailbox=""
     17 otime=`date +%s`
     18 
     19 inotifywait -qrm -e modify \
     20 	--format "%w" \
     21 	--exclude "^dovecot.index.cache$" \
     22 	"${mailboxes}" | \
     23 while read status
     24 do
     25 	mailbox=`echo $status | \
     26 		sed "s,^${mailboxes}/\(.*\)/dbox-Mails/$,\1,g"`;
     27 	mailbox=`echo $mailbox | sed "s,/,${delimiter},g"`;
     28 	if [ "$mailbox" = "$omailbox" ];
     29 	then
     30 		ntime=`date +%s`
     31 		difft=$(($ntime - ($otime + 1)))
     32 		if [ $difft -gt 0 ];
     33 		then
     34 			otime=`date +%s`
     35 			echo $mailbox
     36 		fi
     37 	else
     38 		echo $mailbox
     39 		omailbox="$mailbox"
     40 		otime=`date +%s`
     41 	fi
     42 done
     43