<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>edeca.net &#187; dspam</title>
	<atom:link href="http://edeca.net/wp/tag/dspam/feed/" rel="self" type="application/rss+xml" />
	<link>http://edeca.net/wp</link>
	<description>Musings of a geek</description>
	<lastBuildDate>Tue, 14 Feb 2012 00:18:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Training dspam from Thunderbird junk messages</title>
		<link>http://edeca.net/wp/2010/02/training-dspam-from-thunderbird-junk-messages/</link>
		<comments>http://edeca.net/wp/2010/02/training-dspam-from-thunderbird-junk-messages/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 14:53:20 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[dspam]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://edeca.net/wp/?p=347</guid>
		<description><![CDATA[Recently I have installed and configured dspam on my mailserver. It seems to work nicely but needs occasional training. I wanted to integrate this with Thunderbird so that users could automatically train dspam from their mail client. Based on this code I knocked together a few lines of bash script which will scan junk mail [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I have installed and configured <a href="http://www.nuclearelephant.com">dspam</a> on my mailserver.  It seems to work nicely but needs occasional training.  I wanted to integrate this with Thunderbird so that users could automatically train dspam from their mail client.<br />
<span id="more-347"></span><br />
Based on <a href="http://www.ghidinelli.com/2006/10/01/combining-thunderbird-junk-mail-filtering-and-dspam">this code</a> I knocked together a few lines of bash script which will scan junk mail directories on the server and automatically train dspam.  This means that an end-user can click the &#8220;Junk&#8221; button in Thunderbird (or Mail.app, etc) and dspam will be trained for them automagically.  The user could even just move the messages there manually, or use some sort of filtering or an extension.</p>
<p>The best bit is that it is completely transparent to the end user and doesn&#8217;t require them to forward messages with headers intact to a weird <tt>user-spam@example.net</tt> address in order to conduct training.</p>
<p>If you find it useful or make changes, please let me know in the comments below.</p>
<h3>The code</h3>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/bin/bash</span><br />
<br />
<span style="color: #666666; font-style: italic;">########</span><br />
<span style="color: #666666; font-style: italic;"># TrainDspam.sh</span><br />
<span style="color: #666666; font-style: italic;">#</span><br />
<span style="color: #666666; font-style: italic;">#   Author: David Cannings &lt;david @edeca.net&gt;</span><br />
<span style="color: #666666; font-style: italic;">#     Date: 21/02/2010</span><br />
<span style="color: #666666; font-style: italic;"># Based on: http://tinyurl.com/yhky5w9</span><br />
<span style="color: #666666; font-style: italic;">#</span><br />
<span style="color: #666666; font-style: italic;"># This script scans mail directories for the Thunderbird &quot;Junk&quot; folder</span><br />
<span style="color: #666666; font-style: italic;"># (or any other folder with the same name) and trains dspam with the</span><br />
<span style="color: #666666; font-style: italic;"># messages contained within it.</span><br />
<span style="color: #666666; font-style: italic;">#</span><br />
<span style="color: #666666; font-style: italic;"># It can be used for periodic (e.g. daily) training of spam messages which</span><br />
<span style="color: #666666; font-style: italic;"># a user has flagged as junk in their mail client.</span><br />
<span style="color: #666666; font-style: italic;">#</span><br />
<span style="color: #666666; font-style: italic;"># It will only train for accounts which appear to be using dspam.</span><br />
<span style="color: #666666; font-style: italic;">########</span><br />
<br />
<span style="color: #666666; font-style: italic;">########</span><br />
<span style="color: #666666; font-style: italic;"># Configuration</span><br />
<br />
<span style="color: #666666; font-style: italic;"># Path to mail directory, which should contain folders per domain and</span><br />
<span style="color: #666666; font-style: italic;"># user e.g. /home/mail/&lt;domain&gt;/&lt;user1&gt;/</span><br />
<span style="color: #007800;">MAIL_PATH</span>=<span style="color: #ff0000;">&quot;/home/mail&quot;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># Path to the directory containing 'dspam'</span><br />
<span style="color: #007800;">DSPAM_BIN_DIR</span>=<span style="color: #ff0000;">&quot;/usr/bin&quot;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># Path to the directory containing the dspam user data files</span><br />
<span style="color: #007800;">DSPAM_DATA_DIR</span>=<span style="color: #ff0000;">&quot;/var/spool/dspam&quot;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># If you want this script to delete messages from the Junk folder</span><br />
<span style="color: #666666; font-style: italic;"># after training, set this to 1.</span><br />
<span style="color: #007800;">DELETE_MAIL</span>=<span style="color: #000000;">0</span><br />
<br />
<span style="color: #666666; font-style: italic;"># DON'T EDIT BELOW THIS LINE</span><br />
<span style="color: #666666; font-style: italic;">########</span><br />
<br />
<span style="color: #000000; font-weight: bold;">for</span> FOLDER <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #007800;">$MAIL_PATH</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'.Junk'</span> <span style="color: #660033;">-type</span> d -print<span style="color: #000000; font-weight: bold;">`</span>; <span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp;<span style="color: #007800;">DOMAIN</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$FOLDER</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> -F<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #ff0000;">'{print $(NF-3)}'</span><span style="color: #000000; font-weight: bold;">`</span><br />
&nbsp;<span style="color: #007800;">USER</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$FOLDER</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> -F<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #ff0000;">'{print $(NF-2)}'</span><span style="color: #000000; font-weight: bold;">`</span><br />
<br />
&nbsp;<span style="color: #666666; font-style: italic;"># We only want to train for accounts that are dspam users,</span><br />
&nbsp;<span style="color: #666666; font-style: italic;"># so check the data directory</span><br />
&nbsp;<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-d</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${DSPAM_DATA_DIR}</span>/data/<span style="color: #007800;">${DOMAIN}</span>/<span style="color: #007800;">${USER}</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp;<span style="color: #007800;">TRAINED_MESSAGES</span>=<span style="color: #000000;">0</span><br />
&nbsp;<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$FOLDER</span><span style="color: #000000; font-weight: bold;">/</span>cur<span style="color: #000000; font-weight: bold;">/</span><br />
&nbsp;<span style="color: #000000; font-weight: bold;">for</span> MESSAGE <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ls</span> -<span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">`</span>; <span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp; &nbsp;<span style="color: #007800;">TRAINED_MESSAGES</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$TRAINED_MESSAGES</span> + <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">`</span><br />
&nbsp; &nbsp;<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$MESSAGE</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #007800;">$DSPAM_BIN_DIR</span><span style="color: #000000; font-weight: bold;">/</span>dspam <span style="color: #660033;">--user</span> <span style="color: #800000;">${USER}</span><span style="color: #000000; font-weight: bold;">@</span><span style="color: #800000;">${DOMAIN}</span> <span style="color: #660033;">--class</span>=spam <span style="color: #660033;">--source</span>=error<br />
&nbsp; &nbsp;<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$DELETE_MAIL</span> <span style="color: #660033;">-gt</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$NAME</span><br />
&nbsp;<span style="color: #000000; font-weight: bold;">done</span><br />
&nbsp;<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;- Trained <span style="color: #007800;">$TRAINED_MESSAGES</span> messages for <span style="color: #007800;">${USER}</span>@<span style="color: #007800;">${DOMAIN}</span>&quot;</span><br />
&nbsp;<span style="color: #000000; font-weight: bold;">fi</span><br />
<span style="color: #000000; font-weight: bold;">done</span></div></td></tr></tbody></table></div>
<p></user1></domain></david></p>
]]></content:encoded>
			<wfw:commentRss>http://edeca.net/wp/2010/02/training-dspam-from-thunderbird-junk-messages/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

