Next week, I have to be away from my computer. For an entire week. To Liverpool, NY (near Syracuse), of all places. Ugh. I tried pretty hard to avoid this, but it's just not something I can (responsibly) squirm out of.

So, my life is chaos for the next three weeks.

One of the largest problems I had to solve was that my mail, for several reasons, *CANNOT* go that long without being checked.

After about two days, so many messages accumulate that it is in practice very hard to retrieve them, because in the middle of doing so the dialup connection will probably die, causing a lack-of-graceful-exit condition, so the mail server will think I did not get those messages, and will offer them to me again. And again. If it's been a couple of days since the last successful mail pull, it can take four or five tries to finally clear out the mailbox on the server. A couple of days more, and the mailbox will fill up to the quota, resulting in (hopefully) temporary failures on incoming messages, which at *BEST* will result in my eventually getting things all very badly mixed up and out of order, and at worst can result in my being silently unsubscribed from mailing lists.

So I want to avoid that. So I downloaded fetchmail and experimented with that, but I couldn't get it to work right. At first I wasn't sure where it was putting the messages it was fetching; I thought maybe it was swallowing them. (I had it set up to not delete them from the server, of course, so I didn't lose mail, but I couldn't get the copies that fetchmail had fetched...) Then I discovered it was attempting to deliver them remotely back to my ISP's mail server. I do NOT have time to debug that between now and Saturday.

So I went back to my old standby, the CPAN. Hey, here's this module on there called Mail::POP3Client. Didn't that thing get me out of a jam once before, when my real mail client wasn't working due to filesystem failure or something? Yeah...

So I wrote a quick script to use that to grab my mail off the server and store it on disk in directories that I can later fetch using the "directory group" facility in Gnus, respool them so they get sorted, and Bob is my uncle. Whole thing took me less time to write than it took to download, install, and configure fetchmail. It's under 40 lines and worked *correctly* the first time I tested it.

I love the CPAN.

#!/usr/bin/perl -w # Okay, nothin' fancy, just grab my mail and store it on disk: use Mail::POP3Client; use DateTime; use DateTime::Format::Mail; use File::Spec::Functions; my $basedir = '/home/jonadab/mail-proxy/store'; my $EOL = "\015\012"; my $pop = new Mail::POP3Client( USER => "jonadab", PASSWORD => "[secret]", HOST => "mail.bright.net" ); $pop->Connect(); my $cnt = $pop->Count(); if ($cnt) { print "The server has $cnt messages for me.\n"; my $now = DateTime->now(); my $nowdir = catfile($basedir, $now->ymd() . '_' . $now->hour() . $n +ow->minute() . $now->second()); my $nowrcvd = DateTime::Format::Mail->new()->format_datetime($now); while (-e $nowdir) { my @c = qw(hai lou qan xi cho nau); $nowdir .= +$c[rand @c]; } mkdir $nowdir; for my $num (1..$cnt) { print "."; print "\n" if not $cnt % 60; my $file = catfile($nowdir, $num); my $content = $pop->Retrieve($num); if ($content and (open MAIL, '>', $file)) { print MAIL "Received: from mail.bright.net by $0; $now$EOL"; print MAIL $content; close MAIL; $pop->Delete($num); } } $pop->Close(); }

Caveat: the above does not attempt to handle Unicode correctly, because I do not need that functionality. The only language I get non-spam mail in is English. YMMV.

Update: no, that's not my real password.


"In adjectives, with the addition of inflectional endings, a changeable long vowel (Qamets or Tsere) in an open, propretonic syllable will reduce to Vocal Shewa. This type of change occurs when the open, pretonic syllable of the masculine singular adjective becomes propretonic with the addition of inflectional endings."  — Pratico & Van Pelt, BBHG, p68

Replies are listed 'Best First'.
Re: the CPAN saves me from a huge mess with my mail
by GrandFather (Saint) on Sep 07, 2005 at 22:50 UTC

    Why the random dir?


    Perl is Huffman encoded by design.
      Why the random dir?

      Just being paranoid. The random part only gets called if the directory that is about to be created already exists. In principle, this should never happen, but if it ever _does_ happen, random stuff is appended to the directory name until it's unique.

Re: the CPAN saves me from a huge mess with my mail
by jonadab (Parson) on Sep 10, 2005 at 17:16 UTC