Hey Win,

I did almost exactly this recently...this script takes a folder that you want to search, a folder you want to move processed mail items to, and a regex to search on the subject line.

The datestamping could use work, I was just lazy b/c it was just for me.
#! perl -w use strict; use Win32::OLE qw(in valof with OVERLOAD); my $infolder; my $tstamp = &getDateString; my ($in, $to, $submatch)=@ARGV; my $mail = new Win32::OLE('Outlook.Application'); my $ns = $mail->GetNamespace("MAPI"); my $inbox = $ns->GetDefaultFolder(6); if ($in !~ /inbox/i){ $infolder = $inbox->Folders($in); } else { $infolder = $inbox; } my $tofolder = $inbox->Folders($to); my $count = $infolder->Items->Count; print "There are $count messages in the $in folder\n"; my $i=0; my $result = &saveAttachments($submatch); sub saveAttachments(){ my ($sub) = @_; foreach my $item(in $infolder->Items){ #my $bdy = $item->Body; my $subject = $item->Subject; #print "$subject\n"; #print "$bdy\n"; if ($subject =~ /$sub/i){ foreach my $atm(in $item->Attachments){ my $atmname = $atm->FileName; $tstamp = &getDateString; print "\nSaving $tstamp.$atmname..."; $atm->SaveAsFile("H:\\erepts\\$tstamp.$atmname"); (-e "H:\\erepts\\$tstamp.$atmname") or print "Could not sa +ve $tstamp.$atmname\n"; } $item->Move($tofolder); } } } sub getDateString(){ my @fields=localtime(); $fields[5] += 1900; $fields[4]++; for (@fields){ $_ = sprintf ("%01d", $_) if length($_) gt 2; } my $time_stamp = join "-", reverse @fields[0..5]; return $time_stamp; } #$mail->Quit();

In reply to Re: E.mail interface by SamCG
in thread E.mail interface by Win

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.