in reply to Re: Removing Signature from Email
in thread Removing Signature from Email

this is the code i have that's doesn't work it downloads all mail and then saves as XML file
use Mail::POP3Client; $pop = new Mail::POP3Client( USER => "*****", PASSWORD => "*****", HOST => "127.0.0.1" ); open(OUTPUT,">mail.xml") or die; $id=0; for( $i = 1; $i <= $pop->Count(); $i++ ) { $id++; print OUTPUT "<message>\n"; $header=$pop->Head( $i ); $body=$pop->Body($i); $header =~ m#^From: (.*?)$#m; $from=$1; $header =~ m#^To: (.*?)$#m; $to=$1; $header =~ m#^Subject: (.*?)$#m; $subject=$1; $header =~ m#^Date: (.*?)$#m; $date=$1; #print "$header\n"; print OUTPUT "<from>$from</from>\n"; print OUTPUT "<to>$to</to>\n"; print OUTPUT "<subject>$subject</subject>\n"; print OUTPUT "<date>$date</date>\n"; print "Msg ID: $id\n"; #have to edit here if ($body=~/^--$/) { next; } else { print OUTPUT "<body>\n$body\n<\body>\n"; } #ends print OUTPUT "</message>\n"; } $pop->Close();
could any1 help me plz

Replies are listed 'Best First'.
Re: Re: Re: Removing Signature from Email
by Wodin (Acolyte) on Apr 08, 2001 at 14:10 UTC

    Looking at the docs for Mail::POP3Client, I think you want to get the body as an array of lines and then iterate over that array, keeping only those lines which are not the signature and the line immediately following it. Right now, you're saying  $body = $pop->Body($i); which would be in a scalar context and force Mail::POP3Client to return the body as one big string.

    Hopefully, the following code will clear up your problem. Be warned that this is untested.

    my @lines = $pop->Body($i); ## Some code passes, not much, not a little, what am I, a watch? ## iterate over @lines, checking if we want to keep it. print OUTPUT "<body>\n"; foreach $line (@lines) { if ($line =~ /^--$/) { # Everything else is signature, # so we break the foreach loop last; } else { print OUTPUT $line; } } print OUTPUT "\n<\body>\n";
    Hope this works.