Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: E.mail interface

by SamCG (Hermit)
on Dec 16, 2005 at 20:48 UTC ( [id://517361]=note: print w/replies, xml ) Need Help??


in reply to E.mail interface

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();

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://517361]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-25 07:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found