Manipulating ANY type of email

Manipulating ANY type of email

am 03.01.2006 23:03:32 von DFS

Hi all,

I have this script, and it works, that takes any email, and changes the
addresses (think anonymous email systems)

But what I need to do is to create a function within my script that will add
a body of plain text to any type of email. Whether it be MIME, HTML/TEXT,
Plain Text, has an atachment, whatever.

So that in the end, the same email is forwarded off, but at the top, there
is a new paragraph of text.

At the end of this post am placing my code, not that it makes a difference,
but just to make sure I am getting the idea across.

I have tried just adding my text at the top of the body, but that doesn't
work.

So is there some module out there that handles this type of situation for
me?

Thanks ahead,

Daniel


Here is the code of that module, it's a little sloppier as I whittled it
down for the purpose of posting it here to get some help.

To make the code work on your machine (for your email accounts) all you have
to do is to fill in this part:

################# FILL THESE IN WITH REAL VALUES

And this all does work.

What I am looking for is a fucntion to go here:

#######################
# need a function to add text here
#######################

that will manipulate the body by adding a PLAIN TEXT MESSAGE to the TOP of
the email before forwarding it. REGARDLESS OF THE FORMAT OF THE EMAIL (Mime,
Plain Text, HTML, etc.).

#!/usr/bin/perl -w

use warnings;
use strict;

use CGI;

use Net::POP3;
use Mail::Internet;
use Mail::Header;
use Net::SMTP;
use Mail::Mailer;
my $q = new CGI;


my $deletemail = 0;

my $debug = 1;

################# FILL THESE IN WITHREAL VALUES
# use these to log on to your mailserver
my ($host, $user, $pass) = ('mail.yourownemailaccount.com',
'you@yourownemailaccount.com', 'passwsord');

#where to send all emails, and from who
my ($send_to, $send_from) = ('thewTO@yourownemailaccount.com',
'thenewfrom@yourownemailaccount.com');


CHECKEMAILS:

my $array_ref = &FetchMailGetMails;
if($array_ref == 0 || $#{$array_ref} == -1)
{
zPrintOut("no emails");
}


my $yy = @$array_ref;
for(my $y = 0; $y < $yy; $y++)
{
my %Old_Headers;
my %New_Headers;
my $IsErr;
my $tag;
my $mailer;
my $sent_to;
my @new_body = ();

$Old_Headers{From} = ();
$Old_Headers{To} = ();
$New_Headers{From} = ();
$New_Headers{To} = ();
$Old_Headers{ToType} = ();

my $IMobj = Mail::Internet->new($$array_ref[$y]);
my $SMTPobj = Net::SMTP->new($host);
$SMTPobj->auth ($user, $pass);
my $IMhead = $IMobj->head();
my @tags = $IMhead->tags();


$Old_Headers{From} = $IMhead->get("From");
$Old_Headers{To} = $IMhead->get("To");


my $body_ref = $IMobj->body();

#######################
# need a function to add text here
#######################

#$IMobj->body(\@new_body);
#$body_ref = $IMobj->body();


$IMhead->replace("From", $send_from);
$IMhead->replace("To", $send_to);

my @sentto = $IMobj->smtpsend(Host=>$SMTPobj,
MailFrom=>$IMobj->get("From"),
To=>$IMobj->get("To"));
$SMTPobj->quit;

#goto CHECKEMAILS;
zPrintOut(@sentto);
}


sub FetchMailGetMails
{
my ($pop, $conn, $list, $list1, $list2, $num_msgs, @array, $tot_msgs,
@all_msgs, $all_msgs);

$pop = Net::POP3->new($host);
$conn = $pop->login($user, $pass);
$list = $pop->list();
$num_msgs = keys %$list;
my @emsg = keys %$list;

if($num_msgs < 1)
{
$pop->quit();
return 0;
}
my $msgnum = $emsg[0];

# foreach my $msgnum (keys %$list)
#{
my $size = $pop->list($msgnum);
my $array_temp = $pop->get($msgnum);
push @array, $array_temp;
$pop->delete($msgnum) if ($deletemail);
#}
$pop->quit();
return \@array;
}


sub zPrintOut
{
my ($msg) = @_;
print $q->header();
print $msg;
exit (0);
}