{"id":39,"date":"2006-10-03T23:27:27","date_gmt":"2006-10-03T21:27:27","guid":{"rendered":"http:\/\/katastrophos.net\/andre\/blog\/2006\/10\/03\/vpopmail-maildrop-sqwebmail-mailfilter-patch\/"},"modified":"2006-10-20T21:27:30","modified_gmt":"2006-10-20T19:27:30","slug":"vpopmail-maildrop-sqwebmail-mailfilter-patch","status":"publish","type":"post","link":"https:\/\/katastrophos.net\/andre\/blog\/2006\/10\/03\/vpopmail-maildrop-sqwebmail-mailfilter-patch\/","title":{"rendered":"vpopmail &#8211; maildrop &#8211; SqWebMail mailfilter patch"},"content":{"rendered":"<p>On our production mail server we&#8217;re using a so called <span>qmail<\/span> toaster setup. It&#8217;s essentially the same setup as described by shupp.org. However, instead of using <a target=\"_blank\" href=\"http:\/\/www.squirrelmail.org\/\">SquirrelMail<\/a> for webmail, we opted for <a target=\"_blank\" href=\"http:\/\/www.courier-mta.org\/sqwebmail\/\">SqWebMail<\/a> and <a target=\"_blank\" href=\"http:\/\/www.courier-mta.org\/maildrop\/\">maildrop<\/a>. The nice thing about SqWebMail is that it offers a web interface for configuring the maildrop mailfilters. That way, every user can configure their filtering rules individually.\n<\/p>\n<p>The problem here is that vdelivermail (of <a target=\"_blank\" href=\"http:\/\/www.inter7.com\/index.php?page=vpopmail\">vpopmail<\/a>) doesn&#8217;t support those mailfilter files. For that to work we need vdelivermail to call maildrop to process those files on an individual basis. However, this requires to setup the processing instructions for every mail account manually. Of course, this is unbearable on a large setup.\n<\/p>\n<p>We came up with a patch for vdelivermail that automatically chain-calls maildrop if it finds a mailfilter file in the domain&#8217;s account directory. Some parts are based on another patch which source I forgot. I mainly extended it to be less strict and to publish certain internal vpopmail\/vdelivermail variables as environment variables that could be used inside the mailfilter &#8211; namely username, userdir, domainname, domaindir.\n<\/p>\n<p>If it finds the file in the domain&#8217;s directory, it will delegate the mail to the domain-wide mailfilter.<br \/>\nThe domain-wide mailfilter will delegate the mail to the users mailfilter if it exists. If not, it will simply do a standard mail delivery to the account&#8217;s INBOX.\n<\/p>\n<p>If vdelivermail can&#8217;t find any domain-wide mailfilter it will simply default to standard mail delivery to the account&#8217;s INBOX.<\/p>\n<p>Here is the patch against vpopmail 5.4.17:<\/p>\n<p><a class=\"downloadlink\" target=\"_blank\" href=\"http:\/\/www.katastrophos.net\/downloads\/qmailtoaster\/vpopmail-5.4.17-vdelivermail.c-maildrop.patch\">vpopmail-5.4.17-vdelivermail.c-maildrop.patch<\/a><\/p>\n<p>If you&#8217;re too lazy to patch the vpopmail sourcecode yourself, here is the already patched vdelivermail.c:<\/p>\n<p><a class=\"downloadlink\" href=\"http:\/\/www.katastrophos.net\/downloads\/qmailtoaster\/vdelivermail-5.4.17-maildrop.c\">vdelivermail-5.4.17-maildrop.c<\/a><\/p>\n<p>(Rename it to vdelivermail.c and place it in the vpopmail source directory and compile.)\n<\/p>\n<p><!--more--><\/p>\n<p><strong>Our current mail server setup goes something like this:<br \/>\n<\/strong><\/p>\n<p><strong>qmail (with SMTP-AUTH + TLS) + vpopmail + <\/strong><strong>SpamAssassin \/ ClamAV<\/strong><strong> + maildrop + custom scripts + SqWebMail (for webmail) + Dovecot (for SSL IMAP)<\/strong>\n<\/p>\n<p>In our setup by default every account has the following hierarchy:<\/p>\n<pre>\r\nINBOX\r\n  Spam\r\n    learn no-spam\r\n    learn spam\r\n<\/pre>\n<p>The Spam subfolder is automatically created by the domain-wide mailfilter once the first email hits the account.\n<\/p>\n<p>We&#8217;re using the following domain-wide filter (\/home\/vpopmail\/domains\/yourdomainname\/mailfilter):<\/p>\n<p><a class=\"downloadlink\" target=\"_blank\" href=\"http:\/\/www.katastrophos.net\/downloads\/qmailtoaster\/mailfilter\">mailfilter<\/a><\/p>\n<p>Again, our modified vdelivermail takes care of checking the domain for that mailfilter as described above.<\/p>\n<p>Here is our script used to create the Spam subfolders in the domain-wide mailfilter above:<\/p>\n<p><a class=\"downloadlink\" href=\"http:\/\/www.katastrophos.net\/downloads\/qmailtoaster\/check-create-spamfolders.sh\">check-create-spamfolders.sh<\/a><\/p>\n<p>If you want to use it, make sure to adjust the paths in the file to your setup.<\/p>\n<p>So, now consider that the Spam subfolders have been created. People can use these folders to instruct what mails are spam and what mails are ham (non-spam). They can use this mechanism to report missed spam mails or to correct mistakenly classified non-spam mails.<\/p>\n<p>Now, we wanted to get information out of those folders and try to educate our SpamAssassin&#8217;s bayes filter. Here is what we start in our crontab every hour:<\/p>\n<p><a class=\"downloadlink\" href=\"http:\/\/www.katastrophos.net\/downloads\/qmailtoaster\/sa-learn.sh\">sa-learn.sh<\/a><\/p>\n<p>This script will make a list of all account&#8217;s spam and ham folders in every domain under \/home\/vpopmail\/domains and feed the mails therein into <a href=\"http:\/\/spamassassin.apache.org\/full\/3.0.x\/dist\/doc\/sa-learn.html\" target=\"_blank\">sa-learn<\/a>. Again, if you want to use the script, make sure to adjust the paths to your setup.\n<\/p>\n<p>Since our server runs Debian installing SpamAssassin is pretty easy. We just had to make sure to start SpamAssassin&#8217;s <a href=\"http:\/\/spamassassin.apache.org\/full\/3.0.x\/dist\/doc\/spamd.html\" target=\"_blank\">spamd<\/a> with the following adjusted settings in \/etc\/default\/spamd.conf:<\/p>\n<pre>\r\n# Change to one to enable spamd\r\nENABLED=1\r\n\r\n# Options\r\n# See man spamd for possible options. The -d option is automatically added.\r\nOPTIONS=\"-m 2 -H -u vpopmail --vpopmail --nouser-config\"\r\n\r\n# Set nice level of spamd\r\nNICE=\"--nicelevel 10\"\r\n<\/pre>\n<p>This will launch spamd globally for all vpopmail accounts. The bayes database is shared among all accounts and is stored in \/home\/vpopmail\/.spamassassin\/ with the following local.cf in \/etc\/spamassassin\/local.cf:<\/p>\n<p><a class=\"downloadlink\" href=\"http:\/\/www.katastrophos.net\/downloads\/qmailtoaster\/local.cf\">local.cf<\/a><\/p>\n<p>Having a global shared bayes database for your SpamAssassin is controversial. I won&#8217;t go into detail on why it&#8217;s good or bad to do so. All I can say is it&#8217;s working pretty well for us.<\/p>\n<p>Currently, in our setup the SpamAssassin and ClamAV scanning is integrated into qmail via <a target=\"_blank\" href=\"http:\/\/qmail-scanner.sourceforge.net\/\">Qmail-Scanner<\/a>. This has the disadvantage that antivirus filtering is done pretty deep down the processing chain. I plan to migrate this to <a target=\"_blank\" href=\"http:\/\/inter7.com\/?page=simscan\">simscan<\/a>, which stops and rejects any virus mail at SMTP level and thus prevents them from entering the queue, i.e. nothing will get onto your box. Qmail-Scanner on the other hand puts virus mails into a global quarantine directory.\n<\/p>\n<p>As for IMAP access to mail accounts, we&#8217;ve previously used <a target=\"_blank\" href=\"http:\/\/www.inter7.com\/courierimap\/\">Courier IMAP<\/a> and just recently migrated all accounts to <a target=\"_blank\" href=\"http:\/\/www.dovecot.org\/\">Dovecot<\/a>. Both servers are proven and very reliable. However, we found Dovecot to be more secure and way faster. This is especially noticeable when doing searches and threading on mailboxes. Also, Dovecot is easier to set up as there are fewer external dependencies than with Courier IMAP.<br \/>\nDovecot offers support for vpopmail. If you want to give it a try in your setup, make sure to enable this support via the &#8220;&#8211;with-vpopmail&#8221; switch when running configure.<\/p>\n<p>As already stated above, we chose to use SqWebMail for webmail and mail filter configuration. By default the latter is disabled. You&#8217;ll have to explicitly enable the mail filter interface. Check the documentation on how to do that.<\/p>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>On our production mail server we&#8217;re using a so called qmail toaster setup. It&#8217;s essentially the same setup as described by shupp.org. However, instead of using SquirrelMail for webmail, we opted for SqWebMail and maildrop. The nice thing about SqWebMail is that it offers a web interface for configuring the maildrop mailfilters. That way, every [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[12,11,14,13],"class_list":["post-39","post","type-post","status-publish","format-standard","hentry","tag-debian","tag-linux","tag-mail","tag-server"],"_links":{"self":[{"href":"https:\/\/katastrophos.net\/andre\/blog\/wp-json\/wp\/v2\/posts\/39"}],"collection":[{"href":"https:\/\/katastrophos.net\/andre\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/katastrophos.net\/andre\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/katastrophos.net\/andre\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/katastrophos.net\/andre\/blog\/wp-json\/wp\/v2\/comments?post=39"}],"version-history":[{"count":0,"href":"https:\/\/katastrophos.net\/andre\/blog\/wp-json\/wp\/v2\/posts\/39\/revisions"}],"wp:attachment":[{"href":"https:\/\/katastrophos.net\/andre\/blog\/wp-json\/wp\/v2\/media?parent=39"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/katastrophos.net\/andre\/blog\/wp-json\/wp\/v2\/categories?post=39"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/katastrophos.net\/andre\/blog\/wp-json\/wp\/v2\/tags?post=39"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}