I've been trying (and failing) to write a script that takes a forwarded e-mail that has been altered in the forwarding process, restores that e-mail, and then delivers the restored version to me by e-mail. I've never programmed in Perl before this, and I'm not a professional programmer to begin with -- have just dabbled -- and I need help.

Statement of the Problem:

I have a college e-mail account. The college uses Outlook webmail. I hate Outlook webmail. I have multiple e-mail accounts and use one IMAP e-mail client (Tbird) to manage them all; can't be chasing down individual webmail accounts. However, the college Outlook account in question is not accessible via IMAP. So I set up the Outlook account to automatically forward all messages to one of my personal accounts. The college's Outlook server does forward all messages, but in the process it severely alters the messages in the following ways: 1. Replaces the Sender's address with the e-mail address assigned to me at the college, so that the forwarded message is now from my college Outlook address instead of from the original sender. 2. Strips out all the recipient addresses from the header (both To: and Cc:) and replaces them with the forward-to address I provided in the forward rule. (By the way, there are no other filter rules possible; forwarding is my only option.)
    3.    Inserts "FW: " into the Subject header.
4. At the top of the message's body (both the plain text and HTML MIME parts), the server writes the message's original header info, presumably for my reference, in the following format:
            -------------------------------------------
            From: [Name of Sender]
            Sent: [Date]
            To: [Recipients (various formats -- see below)]
            Cc: [Recipients (various formats -- see below)]
            Subject: [Original Subject]
            Auto forwarded by a Rule
(In the HTML part of the message, this interpolated section includes a bunch of markup tags.)
    I'll call this written-in section the Interpolated Header.
5. In the Interpolated Header, any official college e-mail addresses are masked. A college address is normally in the form:
            [Initial of firstname][lastna...@mcc.commnet.edu
    ...but in the Interpolated Header this gets altered to:
            [LastName], [FirstName] [Middle Initial]
    So, for example, the college address:
            gwillick...@mcc.commnet.edu
    gets altered to:
            Willickers, Golly G
    6.    Other address alterations:
a. In the Interpolated Header's "From: " line, a non-college address is rewritten this way:
            Golly Willickers[SMTP:golly_g_willick...@domain.com]
b. While in the "To: " line and (if it exists) the "Cc: " line, non-college addresses appear literally:
            gollygwillick...@domain.com
c. Sometimes the "To: " and/or "Cc: " lines include a college listserv name, in this form:
            MA-[Listserv Name]

That's all the damage. Thus, when I receive the forwarded message, if I hit "Reply" or "Reply to All," I am composing a reply message to myself (because the From: header has been stuffed by Outlook with my college address) instead of to the sender and other recipients.

With my own web host (HostMonster.com), I can set up a user-level filter that pipes these forwarded e-mails to a script.

Objectives of the Script:
I.    Restore the forwarded e-mail.
a. Using the data in the Interpolated Header, restore the original header info (i.e. the sender and the recipients).
        1.    Convert altered addresses into proper e-mail address format.
i. Properly interpret problematic names during the conversion; for example, a last name of "St. Something", or a two-word last name. Here are the rules applied by the college's IT dept.: - The name Golly G. St. Willickers becomes gstwillick...@mcc.commnet.edu. - The name Golly G. Willi Kerrs becomes gwillike...@mcc.commnet.edu. 2. Leave listserv names (e.g. "MA-Adjunct Faculty") unrestored: I don't care about them, and will never need to include them in my replies. I'd just as soon *not* remove them entirely, as that could conceivably empty out the To: header entirely. 2. Remove the Interpolated Header from both the plain text and HTML parts of the message body.
    3.    Remove the "FW: " from the Subject: header.
II. Deliver the restored e-mail to my forwarding address (m...@ocaptain.org).

I posted my first attempt at this script to this list on 10/10/10 (the Subject was "Sending an E-mail"). It used regex indiscriminately to parse everything, and I had no idea how to deliver the restored e-mail (which was contained in a single string) to my forward-to e-mail account.

I still have no idea how to do this. And, much as I'm interested in learning Perl, my non-computer work life (teaching and theatre arts) won't give me enough time to do so sufficiently to accomplish this task. Is there anyone who can help me with this script? If such a request is beyond the pale for this forum, any estimate on how much it would cost me to hire a programmer to do it, and where I'd go to do that? (That's how much I hate using Outlook webmail.) Any advice will be dearly appreciated.

Incidentally -- Shlomi, thank you for your replies on 10/13/10. In fact I have a Debian-Lenny installation on VirtualBox, and was able to use the CPAN client in there to install the Email modules. However, as you can see, I didn't get far after that. I've also browsed the web a bit, looking at parsing modules, as you suggested (to replace the clumsy regex), but I just don't have the experience to be able to understand how to use them without more serious study of the language.

- Mark


Below is a sample Outlook-forwarded e-mail, which shows the egregious alterations in action.


# [...Various Headers (snipped)...]
Subject: FW: [Original Subject] # 'FW: ' has been interpolated by Outlook
# [...More Headers (snipped)...]
# [The next two headers always appear as follows:]
From: "Vecchio, Mark J" <mvecc...@mcc.commnet.edu>
To: <m...@ocaptain.org>
# [...Final Headers (snipped)...]

This is a multi-part message in MIME format.

------_=_NextPart_001_01CB6012.B007C0A4
Content-Type: multipart/alternative;
    boundary="----_=_NextPart_002_01CB6012.B007C0A4"


------_=_NextPart_002_01CB6012.B007C0A4
Content-Type: text/plain;
    charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


-------------------------------------------
From: Golly Willickers[SMTP:golly_g_willick...@domain.com]
Sent: Wednesday, September 29, 2010 4:12:46 PM
To: MA-Adjunct Faculty; golly.willick...@gmail.com; Vecchio, Mark J
Cc: Willickers, Golly G
Subject: Outlook Webmail is Fascistic
Auto forwarded by a Rule

[Body of message (snipped).]

------_=_NextPart_002_01CB6012.B007C0A4
Content-Type: text/html;
    charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<HTML dir=3Dltr><HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">


<META content=3D"MSHTML 6.00.6000.17080" name=3DGENERATOR></HEAD>
<BODY>
<P><SPAN LANG=3D"en-us"><FONT SIZE=3D2 FACE=3D"Arial">
<BR></FONT><FONT SIZE=3D2 =
FACE=3D"Arial">-------------------------------------------
<BR></FONT><B><FONT SIZE=3D2 FACE=3D"Arial">From:</FONT></B> <FONT =
SIZE=3D2 FACE=3D"Arial">Golly Willickers[SMTP:golly_g_willick...@domain.com]
<BR></FONT><B><FONT SIZE=3D2 FACE=3D"Arial">Sent:</FONT></B> <FONT =
SIZE=3D2 FACE=3D"Arial">Wednesday, September 29, 2010 4:12:46 PM
<BR></FONT><B><FONT SIZE=3D2 FACE=3D"Arial">To:</FONT></B> <FONT =
SIZE=3D2 FACE=3D"Arial">MA-Adjunct Faculty;
<BR></FONT><B></B><FONT SIZE=3D2 FACE=3D"Arial"> golly.willick...@gmail.com; Vecchio, Mark J
<BR></FONT><B><FONT SIZE=3D2 FACE=3D"Arial">Cc:</FONT></B> <FONT =
SIZE=3D2 FACE=3D"Arial">Willickers, Golly G
<BR></FONT><B><FONT SIZE=3D2 FACE=3D"Arial">Subject:</FONT></B> <FONT =
SIZE=3D2 FACE=3D"Arial">Outlook Webmail is Fascistic
<BR></FONT><B><FONT SIZE=3D2 FACE=3D"Arial">Auto forwarded by a =
Rule</FONT></B></SPAN></P>
<BR>

<DIV id=3DidOWAReplyText29867 dir=3Dltr>
<DIV dir=3Dltr><FONT face=3DArial color=3D#000000 size=3D2>Greetings, =
Everyone --</FONT></DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>

[Body of message (snipped).]

</FONT></DIV>
</BODY></HTML>
------_=_NextPart_002_01CB6012.B007C0A4--

------_=_NextPart_001_01CB6012.B007C0A4
Content-Type: application/pdf;
    name="Some File.pdf"
Content-Transfer-Encoding: base64
Content-Description: Some File.pdf
Content-Disposition: attachment;
    filename="Some File.pdf"

[Embedded attachment (snipped).]

------_=_NextPart_001_01CB6012.B007C0A4--


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to