Click here to get back home

Manipulating ANY type of email

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Manipulating ANY type of email Daniel Kaplan 01-03-2006
Posted by Daniel Kaplan on January 3, 2006, 5:03 pm
Please log in for more thread options


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 || $# == -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 = ();
$Old_Headers = ();
$New_Headers = ();
$New_Headers = ();
$Old_Headers = ();

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 = $IMhead->get("From");
$Old_Headers = $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);
}





Similar ThreadsPosted
Module for manipulating JPEG image January 4, 2007, 12:53 pm
Modules for hash functions? (ie, common algorithms for computing hash keys, not manipulating perl hashes) August 26, 2006, 7:08 pm
Ip address Data Type DBI May 10, 2006, 4:38 pm
How to detect an image type with GD November 8, 2006, 12:10 pm
GD: How to know image type? (JPEG, PNG, ..) January 15, 2008, 6:36 am
Term::Cap -- Setting terminal type under Windows XP May 24, 2006, 1:46 pm
Term::Cap -- Setting terminal type under Windows XP May 29, 2006, 9:22 pm
HTTP::Request::Form - Problem pressing input type=image button February 1, 2005, 7:56 am
Converting email December 21, 2004, 6:14 pm
Attaching to an email May 18, 2006, 5:59 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap