commit af00eeb4abf0a253a523e61a2b8562d060611752
Author: Christoph Lohmann <20h@r-36.net>
Date:   Sat, 26 Feb 2011 01:03:12 +0100
Initial commit of watch_mdbox.
Diffstat:
3 files changed, 80 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
@@ -0,0 +1,26 @@
+# watch_mdbox
+
+This script is intended to be used in conjunction with mswatch [0]. You
+can see an example ~/.mswatchrc in home/mswatchrc.
+
+You should change the paths according to your your setup.
+
+[0] http://mswatch.sourceforge.net/
+
+## What does it do?
+
+This script checks for changes in a dbox[1], which is a mailbox format
+introduced by the dovecot IMAP server[2] for handling mail storage more
+efficiently.
+
+When new mail is added to the dbox, watch-mdbox receives an event through
+inotify, parses the path and prints out the notification mswatch needs
+for starting the synchronisation specifically on this mailbox.
+
+[1] http://wiki2.dovecot.org/MailboxFormat/dbox 
+[2] http://www.dovecot.org
+
+## Obligatory cheering
+
+Have fun!
+
diff --git a/bin/watch_mdbox b/bin/watch_mdbox
@@ -0,0 +1,43 @@
+#!/bin/bash
+
+delimiter="."
+
+if [ "$1" == "" ];
+then
+	mdboxroot="$HOME/mdbox"
+else
+	mdboxroot="$1"
+fi
+
+mailboxes="${mdboxroot}/mailboxes"
+
+echo
+
+omailbox=""
+otime=`date +%s`
+
+inotifywait -qrm -e modify \
+	--format "%w" \
+	--exclude "^dovecot.index.cache$" \
+	"${mailboxes}" | \
+while read status
+do
+	mailbox=`echo $status | \
+		sed "s,^${mailboxes}/\(.*\)/dbox-Mails/$,\1,g"`;
+	mailbox=`echo $mailbox | sed "s,/,${delimiter},g"`;
+	if [ "$mailbox" == "$omailbox" ];
+	then
+		ntime=`date +%s`
+		difft=$[$ntime - ($otime + 1)]
+		if [ $difft -gt 0 ];
+		then
+			otime=`date +%s`
+			echo $mailbox
+		fi
+	else
+		echo $mailbox
+		omailbox="$mailbox"
+		otime=`date +%s`
+	fi
+done
+
diff --git a/home/mswatchrc b/home/mswatchrc
@@ -0,0 +1,11 @@
+sync syncapp 
+mailbox_prefix mb :
+
+store sshremote {
+	watch ssh user@example.com "inputkill /usr/bin/watch_mdbox" 
+}
+
+store local {
+	watch /usr/bin/watch_mdbox
+}
+