oko1 has asked for the wisdom of the Perl Monks concerning the following question:
Greetings, Earthlings! Take me to your... um, never mind, those guys don't speak Perl anyway. So - greetings, fellow Monks! :) I'd appreciate some advice on a problem that I've run into (*no*, it does not involve UFOs; that would be too much fun.) I will confess that it's not specifically a Perl problem - although I am using Perl to code the relevant bits.
I have an email account on a system where the sysadmin does not want to run a POP server (understandable, given the security issues around POP); this means that my access to the mail on that server is restricted to actually logging in and reading it there. Well... kinda. What I actually do is run a script that uses 'ssh' to 'cat' the contents of that remote mailbox to my local system, then pipes the contents into 'formail -s procmail' (which splits the box into individual messages and processes each of them via 'procmail', which in turn filters it for spam, distributes it to the appropriate mailboxes, etc.) Note that has a possible problem built in: if I do this while the remote mailbox is getting updated, I'm going to get a partial message... but this isn't going to result in anything horrible ('procmail' may complain), so I'm willing to live with that possibility.
The real problem comes when I want to "flush" the content of that remote mailbox after getting its contents. I could just execute a command (via 'ssh') to empty out the file - but that would be a really stupid thing to do. What if the remote SMTP server is writing another email to that box just as I flush it? Bad stuff, that's what.
I've read up on various bits of SMTP server operation (Exim, specifically, since that's what's being used on that remote machine.) I've also noodled on various ideas like copying the remote box to a temp file, then checking for a size difference and deleting/emptying as appropriate if they're the same size (nope, still a possible race condition there). I've also wondered if the SMTP server uses any sort of a lock file to write to the mailbox (it doesn't, as far as I can tell.) It would also be Really Nice (obviously) to eliminate that first problem, where reading the box may result in a partial message.
Unfortunately, at this point, I'm stuck - no new ideas about this problem have hit the old brainbox in more than a week. If anyone has any Wisdom(™) to share, I'd be very grateful.
Update: Apologies about the slow response time, folks - I live on a sailboat, and I've spent the last couple of days preparing for Tropical Storm Fay (which is slowly grinding through us right now.) Perl has not been the top issue on my priority list lately.
-- Human history becomes more and more a race between education and catastrophe. -- HG Wells
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Battling mail timing issues
by jhourcle (Prior) on Aug 18, 2008 at 01:52 UTC | |
by oko1 (Deacon) on Aug 21, 2008 at 19:54 UTC | |
|
Re: Battling mail timing issues
by jethro (Monsignor) on Aug 18, 2008 at 01:45 UTC | |
|
Re: Battling mail timing issues
by Krambambuli (Curate) on Aug 18, 2008 at 07:33 UTC | |
by oko1 (Deacon) on Aug 21, 2008 at 20:06 UTC | |
by Krambambuli (Curate) on Aug 22, 2008 at 12:16 UTC | |
|
Re: Battling mail timing issues
by NiJo (Friar) on Aug 18, 2008 at 19:56 UTC | |
by oko1 (Deacon) on Aug 21, 2008 at 20:15 UTC |