This Space for Rent

Supertrivial code hack of the day

At work, I've been getting my mail from a M*cr*s*ft *xc*ng* server for the past couple of years, and have been dealing, reluctantly, with the terrible pop3 support that Mutt provides and with the nonstop series of service "enhancements" (all of which make the process of fetching my mail from Windowsland slower and more painful, even when the pop3 server doesn't do something that makes mutt collapse into a foetal position under the desk) coming from IT. Today, after going into the office, restarting mutt, and waiting for fifteen minutes while it s-l-o-w-l-y dragged 500 or so mail messages across the wire, then checked them to make sure they were the sort of message that mutt would want to receive, I snapped and wrote a quick and dirty pop3 mail retriever.

"But", you might say, "there are already mail retrieval programs out there. And they get your mail, sort and shuffle it, and do all sorts of other fun things, and you don't have to write any code!" Yes, true, there are buckets of them, ranging from some programs that are written in Perl to some programs that are written in Python to some programs that are written in C, but in a manner that might make you want to pluck your eyes out and run, screaming, from the room.

But all of them are longer programs (ever look at the guts of poppy? The actual code where it connects to the pop3 server is fairly small, but it's all written in Perl, which is the Language That Defies Readability now that APL has been banished to the museum of esoteric languages) which are wildly general purpose, and I just want something that talks to a pop3 server and moves all of the messages from that pop3 server to my Unix mailbox (NOT my Unix maildir; if I wanted qmail, I'd know where to find it, and I don't want qmail) and which can do that in a fairly small program.

Thus retr, which simply takes messages from the pop server and puts them into a local mailbox. It has a few features in it, which I will leave as an exercise to the reader (hint: no locking! no locking!), but it's actually got a manual page, as a radical change from my traditional scheme of just publishing the code and letting you guess what it does.


retr - retrieve mail from a POP3 server


retr [flags] [pop3-userid] [[pop3-passwd]]


retr moves mail messages from a pop3 server into a local mailbox. After moving the messages, it deletes them from the pop3 server.

Flags are:

Be chattery.

Be more chattery, and don't delete the messages from the pop3 server.

-m mbox
Write messages to mbox, instead of your system mailbox in /var/mail.

-S server
Retrieve messages from the pop3 server at server, instead of the default server pop3.

If a pop3 password is not provided on the command line, retr will prompt for it before attempting to connect to the pop3 server


/var/mail The system mailbox directory

At work, I've stuffed retr into a crontab entry that runs it all the days and all the nights on 5 minute headways, just the same way that mutt was doing it for the past 23 months. I figure it can't be much more unreliable than the way mutt does it, and this has the advantage that it doesn't completely lock up the mail reader when the *xch*ng* pop3 server ages messages away (or just looks at mutt crosseyed.)


If you're popping mail off an exchange server you should check the 'leave mail on server' checkbox on the farthest leftward tab at the end of the setup. Unless, you really do get five hundred e-mails at a time which is, unless your IT system is completely broken down (not unlikely, considering your 'dots'), a statistical improbibility. I've got something like 500 units across a district larger than Vermont: I live e-mail, and at best I get 100 a day with perhaps 20% crap.

Your other alternative, of course, is to use the OWA web interface in conjuction with Firefox (as I do as raely as possible)... oh, didn't think so.

I can't see the same thing as I am fully networked, but from memory: go Start/Settings/ControlPanel/Mail; click E-mail Accounts, Change existing..., Change, More Settings, and it should be the leftmost tab - either Advanced or Remote Mail - in the resulting dialog box. (Caveat: depends on your version of Outlook)

Hmmmm... interesting: an asterik immediately preceding a alpha/num char results in bolding the paragraph, and an underscore results in italicks... wow

Thomas Ware Sun Nov 27 12:10:28 2005

The way mutt works is that it leaves the mail on the exchange server unless you manually delete it off. So, my traditional approach was to just leave the mail on the server. Which used to work, before IT (a) "upgraded" to a new version of exchange and (b) moved it to the other side of North America, on the other side of three ganged t-1s which serve to carry all the traffic from our 600+ person office out to anywhere else in the world.

I'm not sure how the stupid Mutt pop code works (if "works" is a good way to describe it; mutt allows you to READ from a pop server, but doesn't have any corresponding way to WRITE mail to remote smtp servers) but when the exchange server expires articles, mutt comes along, does a LIST, then freaks out because some of the articles it thinks it has AREN'T! THERE! ANY! MORE! And the way mutt freaks out is that it does into an infinite loop of doing sleeping a second, then redoing the LIST command in the hopes that this deleted article will magically reappear.

I use mutt because it allows me to use vi to edit mail messages. The nasty context-free editor that's imbedded in outlook drives me nuts, so I was using mutt 18 months before IT finally proposed the Grand Renaming Scheme for windows machines that made me immediately load Centos onto the box (killing two birds with one stone; I needed a RHEL3 compatable server to play with and I needed a machine with a name that mortals could have a fighting chance to remember.) So there's no really good context menu that I can click, because mutt is Open Source®™© and having easy access to configuration options would be unmanly.

I do occasionally use the outlook web interface (which I think does work with firewombat; my corporate masters lard up their website with checks to make sure you're running one of the Microsoft big bag of security violation browsers, but I don't think that Microsoft does the same with exchange) for when I need to accept a meeting that's been offered up in the exchange calender module, but I won't use it for reading mail because editing from the web makes editing from outlook look easy.

Yes, there are some special things for fonts: *[alphanumeric] boldfaces until the next *, and _[alphanumeric] italicizes until the next _. It's not markdown, but it does the job in its own halfassed way.

David Parsons Sun Nov 27 21:55:26 2005

Comments are closed