[Dovecot] How to notify dovecot that maildir contents is changed by
third-party helper ?
Илья Евсеев
ilya_evseev at mail.ru
Sat Apr 29 03:39:09 EEST 2006
Hi, folks!
How to notify dovecot that maildir contents
is changed by third-party helper?
My script performs spam cleanup,
but all index/cache files (dovecot-uidlist, dovecot.index,
dovecot.index.cache and dovecot.index.log) still unchanged,
so, Web-frontend (IlohaMail over IMAP)
displays taht mailbox contents isn't refreshed.
Dovecot 1.0-alpha5 under FreeBSD 4.11.
mail = maildir:/var/vmail/default/%1n/%n
WBR, Ilya
-------------------------------------------------
#!/bin/bash
#
# CleanupMailboxSpam
#
# Tracks mail directories of Dovecot IMAP server
# and moves/removes all messages marked as spam by SpamAssassin:
#
# * When mailbox contains "KillSpam.<number>" subfolder,
# all spam messages with score >= <number> are removed.
# * When mailbox contains "Spam" subfolder,
# all remaining spam messages are moved to this subfolder.
# * When mailbox contains "KillSpam" subfolder,
# all remaining spam messages are removed.
#
# TODO: update indexes and caches on altered mail folders!!!
#
# Only for testing: doit=echo; export doit; ...
# This prints all modification commands instead of executing them.
#
# Written at Apr 2006 by evseev at sertolovo.ru
#
VMAIL_TOPDIR=/var/vmail
FIND_DEPTH=4
# Debugging values
VMAIL_TOPDIR=/var/vmail/default/e/evseev
FIND_DEPTH=1
INBOX_DIRNAME=cur
KILLSPAM_DIRNAME='.KillSpam'
SPAM_DIRNAME='.Spam'
MSGHEADLEN=30
RM="/bin/rm -f"
MV="/bin/mv -f"
#========= Routines ==========================================#
IsSpamFile() {
local msgfile="$1" score2clean="$2"
local spamstatus=$(head -$MSGHEADLEN "$msgfile" | egrep '^X-Spam-Status: Yes')
test -z "$spamstatus" && return 1
if [ -n "$score2clean" ]; then
local spamscore=${spamstatus##*score=}
spamscore=${spamscore%%.*}
test "$spamscore" -lt "$score2clean" && return 1
fi
return 0
}
KillSpamInFolder() # $1 = kill-label folder to check
{
local dir2clean=$(dirname $1)/$INBOX_DIRNAME
local score2clean=$(basename $1)
score2clean=${score2clean##${KILLSPAM_DIRNAME}.}
test "$score2clean" -ge 1 -a "$score2clean" -le 50000 > /dev/null 2>&1 || score2clean=
find "$dir2clean" -type f | while read f; do
IsSpamFile "$f" "$score2clean" && $doit $RM "$f"
done
}
MoveSpamToFolder() # $1 = spam folder to consume spam
{
local dir2check=$(dirname $1)/$INBOX_DIRNAME
find "$dir2check" -type f | while read f; do
IsSpamFile "$f" && $doit $MV "$f" "${1}/$INBOX_DIRNAME"
done
}
DoOnSubFolders() # $1 = dirmask to find, $2 = action to apply
{
find $VMAIL_TOPDIR/ -mindepth $FIND_DEPTH -maxdepth $FIND_DEPTH \
-type d -iname "$1" \
| while read d; do
"$2" "$d"
done
}
#========= Main ==============================================#
DoOnSubFolders "${KILLSPAM_DIRNAME}?*" KillSpamInFolder
DoOnSubFolders "${SPAM_DIRNAME}" MoveSpamToFolder
DoOnSubFolders "${KILLSPAM_DIRNAME}" KillSpamInFolder
## EOF ##
More information about the dovecot
mailing list