Click to See Complete Forum and Search --> : [perl] Isolating "To" field from mail header using Mail::POP3Client


Broxtor
08-08-2003, 11:22 AM
I want to do some mail filtering before I download messages from my ISP's mail server. Since I haven't found a already working solution to do this, I am trying to write a perl script for this using the Mail::POP3Client module. However, I can't retrieve one single field from the header. I have searched everywhere on the internet, but I didn't find what I'm looking for. The script below gets the headers and displays the From, To, CC and Subject fields of the mail header.


use Mail::POP3Client;

$pop = new Mail::POP3Client("username", "password", "isp.server.com");
for ($i = 1; $i <= $pop->Count; $i++) {
foreach ($pop->Head($i)) {
/^(From|To|Cc|Subject): / and print $_, "\n";
}
print "\n";
}

This works fine. But I want to check the "To" field for certain persons. (My mailbox has an alias, so there can be two different things in the "To" field)
Can anyone tell me how I get the contents of the "To" field in an variable??

chrism01
08-11-2003, 04:51 AM
how about something like


if ( $_ =~ /^(To):/ )
{
$mytemp =$_;
# .. and do whatever with $mytemp
}

Broxtor
08-16-2003, 01:47 PM
Thanks a lot for this. Sorry for the late reply, but I have been away for a week.....

Hayl
08-16-2003, 02:17 PM
don't reinvent the wheel ;)

http://mailfilter.sourceforge.net/

Broxtor
08-16-2003, 05:04 PM
I'm not trying to reinvent the wheel. I'd rather have a ready made solution to my problem. But since I haven't been able to find one, I'm forced to create one myself. If you're interested in what I'm trying to do, check out the following post.
http://justlinux.com/forum/showthread.php?s=&threadid=106248

I don't think mailfilter is the solutions I'm looking for.
But thanks anyway.

Broxtor

[edit]
Removed a huge typo
[edit]