<?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>Butler Press &#187; Python</title>
	<atom:link href="http://butlerpress.com/category/programming/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://butlerpress.com</link>
	<description>Scott Willson&#039;s website. Professional software development and some non-professional bits, too.</description>
	<lastBuildDate>Tue, 15 Dec 2009 19:52:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Ruby on Rails as Mailman External Archiver</title>
		<link>http://butlerpress.com/2006/01/23/hello-world/</link>
		<comments>http://butlerpress.com/2006/01/23/hello-world/#comments</comments>
		<pubDate>Mon, 23 Jan 2006 23:06:10 +0000</pubDate>
		<dc:creator>scott</dc:creator>
				<category><![CDATA[Mailman]]></category>
		<category><![CDATA[OBRA]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[I set up a Mailman mailing list. I want archives. I want these archives to look like other dynamic parts of the site (brought to you by Ruby on Rails). And I want to integrate a couple years&#8217; worth of Topica messages.
At I first, I figured I&#8217;d use MHonArc or something similar. Mailman&#8217;s external interface [...]]]></description>
			<content:encoded><![CDATA[<p>I set up a <a href="http://www.gnu.org/software/mailman/">Mailman</a> mailing list. I want archives. I want these archives to look like other dynamic parts of the site (brought to you by <a href="http://www.rubyonrails.org/">Ruby on Rails</a>). And I want to integrate a couple years&#8217; worth of <a href="http://lists.topica.com/">Topica</a> messages.</p>
<p>At I first, I figured I&#8217;d use <a href="http://www.mhonarc.org/">MHonArc</a> or something similar. Mailman&#8217;s external interface is <a href="http://www.mhonarc.org/archive/html/mhonarc-users/2001-10/msg00021.html">lightly documented</a>, but simple and capable once you figure it out. Looking at the Python code helps in /usr/mailman/Mailman.</p>
<p>I decided to use Rails in the end. Maybe not the best choice, but I like keeping all my UI code in once place as much as possible.</p>
<p>I have an ActionMailer subclass with a delivery method:<br />
<code>
<pre>class MailingListMailer < ActionMailer::Base
  def receive(email)
    post = Post.new()
    post.subject = email.subject
    post.body = email.body
    post.sender = email.friendly_from
    post.date = email.date
    post.save!
  end
end

class Post << ActionRecord::Base ....</pre>
<p></code></p>
<p>I added an entry to PUBLIC_EXTERNAL_ARCHIVER in Mailman's mm_cfg.py file. On Suse 10, it's in /usr/lib/mailman/Mailman. I've add backslash line breaks for legibility here.<br />
<code>PUBLIC_EXTERNAL_ARCHIVER = '/srv/www/rails/obra/current/script/runner \<br />
-e "production" "MailingListMailer.receive(STDIN.read)" \<br />
>> /srv/www/rails/obra/shared/log/production.log'</code></p>
<p>I made several mistakes:</p>
<ul>
<li>You need to restart Mailman for it to pickup your changes: /usr/lib/mailman/bin/mailmanctl restart</li>
<li>The apostrophes need to be around your command: '/srv/www ... production.log' Otherwise, you are trying to execute Python code, not assign a string variable.</li>
<li>Leave out -e "production" and Rails will execute in its development environment.</li>
<li>Ensure your logs are writeable by the mailman user, or nothing will work very well.</li>
</ul>
<p>A typical Mailman error message in /var/lib/mailman/logs/error is "external archiver non-zero exit status: 127." Not very helpful. My shell foo isn't up to the task of redirecting standard error and standard out from the PUBLIC_EXTERNAL_ARCHIVER command. I got better info with Mailman calling a Bash script that then called the Rails runner. I validated that things worked at each small step, and I had to take baby steps because I kept putting a single quote where I needed a double quote, etc.:</p>
<ul>
<li>Unit test for the ActionMailer</li>
<li>Run the ActionMailer in irb</li>
<li>Run the runner: sudo -u mailman /srv/www/rails/obra/current/script/runner -e "production" "MailingListMailer.receive(STDIN.read)"</li>
<li>Write a shell script to call the runner</li>
</ul>
<p>Of course, it's helpful the public Mailman pages point to my new Rails-based archive. Here's how I do it. In Mailman/mm_cfg.py:<br />
<code>PUBLIC_ARCHIVE_URL = 'http://%(hostname)s/mailing_lists/%(listname)s/posts'</code></p>
<p>I like the end result, and it's easy to do once you know how to do it. Next step is to see if Rails can sew a header and footer onto the Mailman list info pages. I am keeping the gnu, of course.</p>
]]></content:encoded>
			<wfw:commentRss>http://butlerpress.com/2006/01/23/hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

