Link to home
Start Free TrialLog in
Avatar of sharpmail
sharpmail

asked on

email piped to script... BCC?

Hi,

I have email piped to a perl script which grabs who the email was sent to and from etc

I need to know who the email was intended for (To) but when an email is sent BCC the To field is not the address the email was delivered to. How can I get the address the email was delivered to?
Avatar of Tintin
Tintin

Short answer; you can't.

Longer answer; you can only obtain this information by having access to the mail server the originating mail was sent from.
Avatar of sharpmail

ASKER

I have managed to sort the problem out, posfix an dpossibly other mail programs adds

received from [xxx.xxx.xxx.xxx]
for <email@address.com> on dd mmm timezone yyyy hh:mm:ss

looping over the lines i simply lokked for a string match of  $line=~ m/for </i; when I had this line split it by the < and split the right eliment by the > leaving the left eliment the email address

when to, from, subject and for lines were found stopped the loop.


@email = <STDIN>;   # read the email from STDIN

foreach $line (@email){ # loop over the email to find the lines we want
if($line=~m/^From: /){$from = "$line";}
if($line=~m/^To: /){$to = "$line";}
if($line=~m/^Subject: /){$subject = "$line";}
if($line=~m/for </ && $forwho eq ""){$forwho = "$line";}      # if BCC then this is the real delivered to?
last if($from ne "" && $to ne "" && $subject ne "" && $forwho ne ""); # end the loop if we have what we wanted
}
@foraddy= split(/</ ,$forwho);
$forwho = $foraddy[1];    # cut garbage from the leff
@foraddy= split(/>/ ,$forwho);
$forwho = $foraddy[0];   # cut garbage off the right and leave the address
ASKER CERTIFIED SOLUTION
Avatar of GranMod
GranMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial