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

In reply to Battling mail timing issues by oko1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.