<?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>A Blog by Tim Bishop &#187; SRS</title>
	<atom:link href="http://www.bishnet.net/tim/blog/tag/srs/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bishnet.net/tim/blog</link>
	<description>"For a moment, nothing happened. Then, after a second or so, nothing continued to happen." -- HHGTTG</description>
	<lastBuildDate>Wed, 02 Nov 2011 15:21:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Implementing SRS with Exim and SQLite</title>
		<link>http://www.bishnet.net/tim/blog/2009/07/29/implementing-srs-with-exim-and-sqlite/</link>
		<comments>http://www.bishnet.net/tim/blog/2009/07/29/implementing-srs-with-exim-and-sqlite/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 23:09:18 +0000</pubDate>
		<dc:creator>Tim Bishop</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[Exim]]></category>
		<category><![CDATA[Sender Rewriting Scheme]]></category>
		<category><![CDATA[SPF]]></category>
		<category><![CDATA[SQLite]]></category>
		<category><![CDATA[SRS]]></category>

		<guid isPermaLink="false">http://www.bishnet.net/tim/blog/?p=265</guid>
		<description><![CDATA[In this post I look at implemeting SRS using Exim and SQLite.


Related posts:<ol><li><a href='http://www.bishnet.net/tim/blog/2007/11/26/ebay-customer-support/' rel='bookmark' title='Permanent Link: eBay &#8220;Customer Support&#8221;'>eBay &#8220;Customer Support&#8221;</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Due to issues with SPF-style restrictions I decided I&#8217;d take a look at implementing SRS (the Sender Rewriting Scheme, a good description of which is <a href="http://www.openspf.org/SRS">over here</a>) with <a href="http://www.exim.org/">Exim</a>. I thought it&#8217;d be fairly straightforward and well documented, but it wasn&#8217;t. I&#8217;m left wondering if anybody actually does it like this?</p>
<p>To start with I built Exim on <a href="http://www.freebsd.org/">FreeBSD</a> with the SPF and SRS libraries (I used <a href="http://srs.mirtol.com/">libsrs_alt</a>). This was straightforward enough &#8211; although where are the options in the FreeBSD port? &#8211; and would be standard across most operating systems.</p>
<p>Since this was a trial run I thought I&#8217;d take the lightweight approach and use <a href="http://www.sqlite.org/">SQLite</a> rather than set up a full database like MySQL. This again was a straightforward install.</p>
<p>Lets look quickly and the SQLite tables. The <a href="http://srs.mirtol.com/exim.php">instructions on the libsrs_alt site</a> don&#8217;t talk about creating these, so I just figured it out for myself. This is what I ended up with:</p>
<pre># sqlite3 /var/tmp/srs.db .dump
BEGIN TRANSACTION;
CREATE TABLE SRS(Key TEXT, Address TEXT, Time INTEGER);
COMMIT;
#</pre>
<p>That&#8217;s pretty simple. The database should probably live somewhere a bit more permanent though <img src='http://www.bishnet.net/tim/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .</p>
<p>Right, back to the instructions. Basically we need to add a bit of config and a new router to the exim configuration. Starting with the default configuration I added the following option in the global section:</p>
<pre>hide srs_secrets = asecurestringofareasonablelength</pre>
<p>And then the following routers:</p>
<pre>srs_reverse:
  driver = redirect
  domains = +local_domains
  srs = reverseandforward
  srs_dbinsert = ${lookup sqlite{/var/tmp/srs.db \
    INSERT INTO SRS ('Key', 'Address', 'Time') \
    VALUES ('${srs_db_key}', '${srs_db_address}', \
    strftime('%s','now'))}}
  srs_dbselect = ${lookup sqlite{/var/tmp/srs.db \
    SELECT Address FROM SRS \
    WHERE Key = '${srs_db_key}' \
    AND Time &gt; strftime('%s','now','-30 days') \
    LIMIT 1}}
  data = ${srs_recipient}</pre>
<pre>srs_forward:
  driver = redirect
  domains = +local_domains
  srs = forward
  srs_dbinsert = ${lookup sqlite{/var/tmp/srs.db \
    INSERT INTO 'SRS' ('Key', 'Address', 'Time') \
    VALUES ('${srs_db_key}', '${srs_db_address}', \
    strftime('%s','now'))}}
  data = $local_part@example.org</pre>
<p>As you can see in this case, I&#8217;m simply forwarding all email to another domain. That&#8217;s not the most useful setup, but again I&#8217;m just testing.</p>
<p>Note that I had to put these in the opposite order to <a href="http://srs.mirtol.com/exim.php">the instructions</a>. The first router is looking for addresses that are already SRS encoded (so bounces for forwarded messages, etc). If it doesn&#8217;t find one, it just passes on to the next one. So this way round work best for me.</p>
<p>That&#8217;s it really. At a simple level this works. I&#8217;ve not looking at proper integration in to the forwarding setup or any kind of database maintenance yet. But given the lack of useful documentation online I thought I&#8217;d post my findings.</p>
<p>If you&#8217;re reading this and thinking &#8220;why on earth is he doing it like that?&#8221; please drop me a comment below and enlighten me <img src='http://www.bishnet.net/tim/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .</p>


<p>Related posts:<ol><li><a href='http://www.bishnet.net/tim/blog/2007/11/26/ebay-customer-support/' rel='bookmark' title='Permanent Link: eBay &#8220;Customer Support&#8221;'>eBay &#8220;Customer Support&#8221;</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.bishnet.net/tim/blog/2009/07/29/implementing-srs-with-exim-and-sqlite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

