Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
# Procmail.pl # Monitors a directory for new saved emails # Emails are in text format saved from Outlook # Other progs may save in slightly different format - YMMV # Required fields in email are - # From: xxxxx [xxxxx@xxxx.xxxx] # Subject: xxxxx xxxxx xxxxx # File name is year-mo-da-hhmmss.txt - used for determining # time of +email use Strict; use Win32::ChangeNotify; $indir = "x:/xxx/xxx"; #dir for saved messages $status = "procstat.txt"; #status file $notify = Win32::ChangeNotify->new($indir, 0, FILE_NAME); open(STATUS, ">>".$status) or die "Error opening stats file: $!\n"; my $now = localtime; #start time print STATUS "Procmail started: $now\n"; my $nummail = 0; #number of mails processed my $done = 0; #done processing (back at desk)? while (!($done)) { $notify->wait or warn "Problem waiting: $!\n"; #wait for files if (-e $indir . "/.stopmail") # file created to signal stop { $done = 1; unlink($indir . "/.stopmail"); } opendir(INDIR, $indir) or die "Error opening directory: $!\n"; my @mail = grep { $_ ne '.' and $_ ne '..' } readdir INDIR; foreach (@mail) { my $from = ""; my $subject = ""; my $time; open(INFILE, "<". $indir . "/" . $_) or die "Could not open file: +$!\n"; while ($next = <INFILE>) { chomp($next); if ($next =~ /^From:/) { if ($from eq "") # Only set from if empty to avoid problems +with forwards { $next =~ /.*\[(.*)\].*/; $from = $1; $from = (split(/:/,$from))[1]; } } elsif ($next =~ /^Subject:/) { if ($subject eq "") # Set subject if empty to avoid probs wi +th forwards { $next =~ /^Subject: *(.*)/; $subject = $1; for ($subject) { s/^\s+//; } } } } /(.*)\.txt/; # Get time from file name $time = $1; # Compose message info # My phone is limited, so only the facts my $msg = "From: $from\nSubject: $subject\nTime: $time\n"; # Blat works best using a file if (open(OUTMP, ">" . $time . ".tmp")) { print OUTMP $msg; close(OUTMP); my $blatcmd = "c:\\blat\\blat.exe " . $time . ".tmp -s \"New Emai +l\" -t xxxxxxxx\@xxxx.xxx.com"; print STATUS "Blatted:\n"; my $blatres = `$blatcmd`; print STATUS "$blatres\n"; unlink($time . ".tmp"); $nummail ++; } close(INFILE); unlink($indir . "/" . $_); } undef(@mail); sleep(1); closedir(INDIR); $notify->reset; # Wait for next file(s) } $notify->close; $now = localtime; print STATUS "Caught stop message: $now.\n"; print STATUS "$nummail messages processed\n\n"; close(STATUS);

In reply to Win32/Outlook Mail Forwarder by Guildenstern

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!
  • 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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (10)
    As of 2015-07-31 11:21 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (276 votes), past polls