Manipulating ANY type of email



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@xxxxxxxxxxxxxxxxxxxxxxx', 'passwsord');

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


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



.



Relevant Pages

  • Re: JMSs Spotlight at SDCC
    ... Jan of rec.arts.sf.tv.babylon5.moderated make plain: ... If deadlines conspire to gang up on him, the script books can be ... postponed as needed as can Book of Lost Souls, ... To be determined are 'Borrowed Lives'-the script for the pilot is ...
    (rec.arts.sf.tv.babylon5.moderated)
  • Save the contents of a message to a file.
    ... I really don't know if this is more an entourage question or an applescript ... From there another shell script will ... pick it up and go from there, but the data has to be in plain text. ...
    (microsoft.public.mac.office.entourage)
  • Re: Replacing Adium
    ... Open a *plain* text editor (TextWrangler, ... Paste the script into a *plain* text document. ...
    (comp.sys.mac.apps)
  • Re: Optimizing a string manipulation script.
    ... of comp.lang.php make plain: ... The main problem is that the script currently takes about 20 ... Phorm PHP Form Processor ...
    (comp.lang.php)