Triggers do sound interesting, however i'd rather see the effort put into server-side filters for sorting purposes then special execution of other applications. As far as getting what your want done, I would suggest using a script driven via cron every half hour or so. I have SpamAssassin's sa-learn doing much the same thing that you wish to accomplish. Keep in mind here that this setup is based upon multiple users sharing the same public folder, but that shouldn't matter much as you could have it read the messages out of any mailbox as long as you specify the correct ID. This script marks the message as deleted and will get purged by a dbmail-util purge run.

Here is my train.sh:

#!/bin/sh
export PATH=$PATH:/usr/local/bin

MYSQL_CMD="/usr/local/bin/mysql -h database_server_ip_here -udbmail -pdbma1l dbmail -B -N -r"
#Grab Messages
HAM_MSG_UIDS=`$MYSQL_CMD -e "SELECT dbmail_messages.message_idnr FROM dbmail_messages WHERE dbmail_messages.mailbox_idnr='59' and status='0'"` SPAM_MSG_UIDS=`$MYSQL_CMD -e "SELECT dbmail_messages.message_idnr FROM dbmail_messages WHERE dbmail_messages.mailbox_idnr='58' and status='0'"`

cd /usr/sa_train/mail/ham
for MSG_UID in $HAM_MSG_UIDS
do
{
$MYSQL_CMD -e "SELECT GROUP_CONCAT(dbmail_messageblks.messageblk ORDER BY dbmail_messageblks.is_header DESC SEPARATOR '') FROM dbmail_messages JOIN dbmail_messageblks ON (dbmail_messages.physmessage_id=dbmail_messageblks.physmessage_id) WHERE dbmail_messages.message_idnr='${MSG_UID}' GROUP BY dbmail_messages.message_idnr" > $MSG_UID $MYSQL_CMD -e "UPDATE dbmail_messages SET deleted_flag='1', status='2' WHERE message_idnr='${MSG_UID}'";
}
done

cd /usr/sa_train/mail/spam
for MSG_UID in $SPAM_MSG_UIDS
do
{
$MYSQL_CMD -e "SELECT GROUP_CONCAT(dbmail_messageblks.messageblk ORDER BY dbmail_messageblks.is_header DESC SEPARATOR '') FROM dbmail_messages JOIN dbmail_messageblks ON (dbmail_messages.physmessage_id=dbmail_messageblks.physmessage_id) WHERE dbmail_messages.message_idnr='${MSG_UID}' GROUP BY dbmail_messages.message_idnr" > $MSG_UID $MYSQL_CMD -e "UPDATE dbmail_messages SET deleted_flag='1', status='2' WHERE message_idnr='${MSG_UID}'";
}
done

#Train SPAM
if [ ! -z "`ls -1 /usr/sa_train/mail/spam`" ]; then
       echo -n "SPAM: "
/usr/local/bin/sa-learn -p /usr/local/etc/MailScanner/spam.assassin.prefs.conf --spam /usr/sa_train/mail/spam
       rm /usr/sa_train/mail/spam/*
fi

#Train HAM
if [ ! -z "`ls -1 /usr/sa_train/mail/ham`" ]; then
       echo -n "HAM: "
/usr/local/bin/sa-learn -p /usr/local/etc/MailScanner/spam.assassin.prefs.conf --ham /usr/sa_train/mail/ham
       rm /usr/sa_train/mail/ham/*
fi

/usr/local/bin/sa-learn -p /usr/local/MailScanner/spam.assassin.prefs.conf --sync

--------------------------------------------
It basically reads the headers and body of each message into its own file, then sa-learm runs on the spam or ham folder. When its done, the temporary copies of the messages are rm'ed from the filesystem and the messages in the db are marked deleted as if somebody deleted them via IMAP.
Don't forget to get the correct mailbox_idnr for each folder!
You could probably easily modify this script to pipe the message to dspamc and probably even skip making the temporary files. If you don't want the email deleted then you do an update on dbmail_messages.mailbox_idnr and changed it to another folder instead of setting the status as deleted. I think this solution will probably work just fine and will accomplish what you want. I would not have cron run this at any less than a 5 minute interval. I have no issues with 50 users using a #Public/spam mailbox running the script every half hour.

-Jon

Aleksander wrote:

I'm interested in the following feature.

A trigger mechanism for IMAP folders. If a message is moved to folder X, specified (external) command is executed. Likewise when message is moved from folder X. If required, dbmail-imap would give the whole msg to the program executed too.


Example.

Using DSpam antispam software. DSpam learns what is spam and what's not spam from the individual user (and is probably the best antispam solution!). In my implementation, postfix delivers mail to dspam, and dspam to dbmail-smtp. If dspam thinks a message is spam, it delivers directly to a user's spam folder. Usually the user forwards a spam message that passed the filter to a specified email address. Or a message that was categorised incorretly as spam to another email aadress. This, is not user friendly.

An alternative could be a triggering mechanism in dbmail-imap. When an email is moved to folder spam, then the command " | dspamc --user [EMAIL PROTECTED] --class=spam --source error" is executed (the whole email is piped to it). That way, DSpam is told the email is spam. (dspamc is a dspam client, that communicates with the dspam daemon.)

When a message is moved from the spam folder, the same command but with --class=innocent is executed. DSpam relearns the message and now knows, that it's not spam at all.

A more user friendly solution is hard to think of. I understand that moving in dbmail means only changing a number in a table and this would require to "compose" a mail that essentially will be piped, but it's done anyway when a user views an email. I understand that is only possible for IMAP, not POP3.


I'm not a develepor and lack the knowledge to do this, but my users and probably all dbmail-imap+dspam users/admins would really appreciate this. Surely this could be used with other applications too. I understand that it's not too hard to implement, or is it?

Have there been similar feature requests or does anyone have additional ideas about the subject. I would like to add this as a feature request in the dbmail docuwiki, but ask for feedback first.

Thanks,
      Alex

DSpam's homepage, worth checking out: http://dspam.nuclearelephant.com/
_______________________________________________
Dbmail mailing list
Dbmail@dbmail.org
https://mailman.fastxs.nl/mailman/listinfo/dbmail


Reply via email to