Sending an E-Mail

Sending an E-Mail

am 10.10.2010 09:25:35 von mark

--------------050908070406060403090708
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi, folks,

I'd like to send a string ($line) as an e-mail from within a script.

I receive regular e-mail forwards from a college I teach at, because I
don't want to use their Outlook webmail. In the process of being
forwarded, each message gets rewritten by Outlook's webmail forwarder.

I've set up an e-mail filter (in HostMonster's cPanel) that pipes these
forwarded messages to a Perl script. The main part of the script
restores as much of the message as possible (given my very limited
knowledge of Perl). The final step I need is to send myself the restored
e-mail, the entirety of which is stored in the variable $line.

So that's my first question: how do I send the string $line -- which is
a multipart MIME message, often with one or more attachments -- as a new
e-mail to myself?

Plus, there might be a complication: three of the things I've restored
are the 'From:', 'To:' and 'Cc:' headers. Often the restored message
will, according to its header, be addressed to several people in
addition to me. How do I e-mail myself the string $line, but make sure
it only gets delivered to me and not to the other recipients in the header?

Below is the entire script for reference. The place where I want to send
$line as an e-mail is the second-to-last line.

(I should say that I have not tested this version of the script yet.
I've only been testing it with text file replicas of raw e-mails on my
computer, reading the text into the string $line, and then concluding by
printing $line in the Terminal. Also, I apologize for all the inelegance
of this code -- repeated sections instead of functions, probably sloppy
regex, and so on. This is rookie stuff.)

- Mark


#!/usr/bin/env perl
use warnings;
use strict;
use Data::Dumper;

####GET THE FULL E-MAIL AS RAW TEXT AND STORE IN $line
while ( $line = )
{
chomp $line;

#We're going to need the following string multiple times
my $atMCC = '@mcc.commnet.edu';

####EXTRACT THE ORIGINAL PLAIN-TEXT HEADER FROM THE MESSAGE BODY:
if ( $line =~ m/(Content-Transfer-Encoding:
quoted-printable\n)(\n\n------------------------------------ -------\n)(.*?)(\nAuto
forwarded by a Rule)/s )
{
$::header = $2 . $3 . $4;
}

####EXTRACT & MASSAGE THE SENDER CONTAINED IN $header.
##Case: \nFrom: First Last[SMTP:addr@domain.ext]
##\nFrom: First \s Last '[SMTP:' E-mail
']'
##($1) ($2) ($3) ($4) ($5) ($6)
($7)
if ( $::header =~ m/(\nFrom:
)(.*?)(\[SMTP:)(\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z] {2,4}\b)(]\n)/s
)
{
my $emailString = $4;
$emailString =~ tr/A-Z/a-z/; # convert to lower case
$::from = $1.$2.' <'.$emailString.'>';
}
##Case: \nFrom: Last , F---irst [M]
## ($1) ($2) ($3) ($4)($5)
elsif ( $::header =~ m/(\nFrom:\s)(.*?)(,\s)(\w)(\w+)/s )
{
$::from = $1.$4.$5.' '.$2.' <'.$4.$2.$atMCC.'>';
##Check for a 'St. Someone' name in e-mail address!
if ( $::from =~ m/St\. / )
{
$::from =~ s/(.*?<.*)(St\. )(.*?)/$1St$3/g;
}##Check for two separate words in last name in e-mail address!
if ( $::from =~ m/(\n.*<\S+) (\S+@\S+)/ )
{
$::from =~ s/(\n.*<\S+)( )(\S+@\S+)/$1$3/g;
}
}

####EXTRACT THE RAW RECIPIENT(S) CONTAINED IN $header.
##Check to see if there's a 'CC: ' header. If so, grab 'To: '
*and* 'CC: '
$::CCswitch = "No";
if ( $::header =~ m/(\nCC:\s)/si )
{
$::CCswitch = "Yes";
##Grab the entire 'To: ' header and store in $::toRaw
if ( $::header =~ m/\n(To: .*?)\nCC:\s/si )
{
$::toRaw = $1;
}
##Grab the entire 'CC: ' header (case insensitive) and store in
$::ccRaw
if ( $::header =~ m/\n(CC:\s)(.*?)\nSubject:\s/si )
{
$::ccRaw = $1.$2;
}
##Populate @::ccHeader
##Do we need to split $::ccRaw?
if ($::ccRaw =~ m/(CC: )(.*;\s.*)/si )
{
my $ccNames = $2;
##Replace all occurrences of '\n' with '\s'
$ccNames =~ s/(\n)(\w)/ $2/g;
$ccNames =~ s/\n//g;
@::ccHeader = split('; ', $ccNames);
}
else
{
$::ccRaw =~ s/Cc: //g;
@::ccHeader = ();
$::ccHeader[0] = $::ccRaw;
}
##Process each item in the array @::ccHeader
foreach $::ccName (@::ccHeader)
{
#If $ccHeader[n] contains "," then convert it
## Last , F...irst [M]
## ($1) ($2)($3)($4)
if ( $::ccName =~ m/(.*?)(, )(\w)(\w+)/s )
{
$::cc = $3.$4.' '.$1.' <'.$3.$1.$atMCC.'>';
##Check for a 'St. Someone' name in e-mail address!
if ( $::cc =~ m/St\. / )
{
$::cc =~ s/(.*?<.*)(St\. )(.*?)/$1St$3/g;
}##Check for two separate words in last name in
e-mail address!
if ( $::cc =~ m/(.*<\S+) (\S+@\S+)/ )
{
$::cc =~ s/(.*<\S+)( )(\S+@\S+)/$1$3/g;
}
$::ccName = $::cc;
}
}
}
##If no 'CC: ' header, just grab the 'To: ' header and store in
$::toRaw
elsif ( $::header =~ m/\n(To: .*?)\nSubject:\s/s )
{
$::toRaw = $1;
#To avoid having to do tests down the road, create a null
@::ccHeader
@::ccHeader = ();
}

####MASSAGE THE RECIPIENT(S) CONTAINED IN $::toRaw (and $::ccRaw,
if it exists).
##Do we need arrays?
if ($::toRaw =~ m/(To: )(.*;\s.*)/s )
{
my $toNames = $2;
##Replace all occurrences of '\n' with '\s'
$toNames =~ s/(\n)(\w)/ $2/g;
$toNames =~ s/\n//g;
@::toHeader = split('; ', $toNames);
}
else
{
$::toRaw =~ s/To: //g;
@::toHeader = ();
$::toHeader[0] = $::toRaw;
}

##Process each item in the array @::toHeader
foreach $::toName (@::toHeader)
{
#If $toHeader[n] contains "," then convert it
## Last , F...irst [M]
## ($1) ($2)($3)($4)
if ( $::toName =~ m/(.*?)(, )(\w)(\w+)/s )
{
$::to = $3.$4.' '.$1.' <'.$3.$1.$atMCC.'>';
##Check for a 'St. Someone' name in e-mail address!
if ( $::to =~ m/St\. / )
{
$::to =~ s/(.*?<.*)(St\. )(.*?)/$1St$3/g;
}##Check for two separate words in last name in e-mail
address!
if ( $::to =~ m/(.*<\S+) (\S+@\S+)/ )
{
$::to =~ s/(.*<\S+)( )(\S+@\S+)/$1$3/g;
}
$::toName = $::to;
}
}

##If more than one element in @::toHeader, add semicolons back in
if ( scalar( @::toHeader ) > 1 )
{
$::toString = join( '; ', @::toHeader );
}
else { $::toString = $::toHeader[0] }
##Repeat: If more than one element in @::ccHeader, put back
semicolons
if ( scalar( @::ccHeader ) > 1 )
{
$::ccString = join( '; ', @::ccHeader );
}
##Concatenate the 'TO' and 'CC' strings into $::recipientString
if ( length ( $::ccString ) > 3 )
{
$::recipientString = $::toString . "\nCc: " . $::ccString;
}
else { $::recipientString = $::toString }

####Replace in $line (i.e. the actual e-mail) the actual message
####header elements From, To, CC, and Subject, as well as the
####annoying header info in the e-mail's body.
if ( $line =~ m/(\n)(From: "myLastname, myFirstname MI"
\n)(To: )\n/s )
{
$::originalFromTo = $1 . "X-Outlook's Original " . $2 .
"X-Outlook's Original " . $3;
$line =~ s/(.*?)(\nFrom: "myLastname, myFirstname MI"
)(\nTo:
)(\n)(.*?)/$1$::from$3$::recipientString\n$5/g;
}

####DELETE "FW: " FROM THE SUBJECT HEADER
$line =~ s/\nSubject: FW: {1}?/\nSubject: /g;

####DELETE INTERPOLATED HEADER SEGMENTS IN THE E-MAIL'S BODY
##Delete the Plain-Text version
$line =~
s/\n\n-------------------------------------------\n.*?\nAuto forwarded
by a Rule//s;
##Delete the HTML version
$line =~
s/\n\n.*?-------------------------------------------.*?Auto
forwarded by a =\nRule.{22}?\n//si;

####Send the new version of the e-mail
#DO SOMETHING TO SEND "$line" TO ONLY MY E-MAIL ADDRESS, WHILE
PRESERVING ALL THE HEADERS;

} #END OF 'WHILE' BLOCK

--------------050908070406060403090708--

Re: Sending an E-Mail

am 10.10.2010 09:50:49 von Shlomi Fish

Hi Mark,

On Sunday 10 October 2010 09:25:35 Mark wrote:
> Hi, folks,
>
> I'd like to send a string ($line) as an e-mail from within a script.
>
> I receive regular e-mail forwards from a college I teach at, because I
> don't want to use their Outlook webmail. In the process of being
> forwarded, each message gets rewritten by Outlook's webmail forwarder.
>
> I've set up an e-mail filter (in HostMonster's cPanel) that pipes these
> forwarded messages to a Perl script. The main part of the script
> restores as much of the message as possible (given my very limited
> knowledge of Perl). The final step I need is to send myself the restored
> e-mail, the entirety of which is stored in the variable $line.
>
> So that's my first question: how do I send the string $line -- which is
> a multipart MIME message, often with one or more attachments -- as a new
> e-mail to myself?
>
> Plus, there might be a complication: three of the things I've restored
> are the 'From:', 'To:' and 'Cc:' headers. Often the restored message
> will, according to its header, be addressed to several people in
> addition to me. How do I e-mail myself the string $line, but make sure
> it only gets delivered to me and not to the other recipients in the header?
>
> Below is the entire script for reference. The place where I want to send
> $line as an e-mail is the second-to-last line.
>
> (I should say that I have not tested this version of the script yet.
> I've only been testing it with text file replicas of raw e-mails on my
> computer, reading the text into the string $line, and then concluding by
> printing $line in the Terminal. Also, I apologize for all the inelegance
> of this code -- repeated sections instead of functions, probably sloppy
> regex, and so on. This is rookie stuff.)
>
> - Mark
>

Looking at your code, I see that you process the E-mail message using regular
expressions. Please don't do that and use a CPAN module. Some options to
investigate are:

* http://search.cpan.org/dist/MIME-Lite/

* http://search.cpan.org/dist/Email-Sender/

* http://search.cpan.org/dist/Mail-Box/

Now some comments about your coding style:

>
> #!/usr/bin/env perl
> use warnings;
> use strict;
> use Data::Dumper;
>
> ####GET THE FULL E-MAIL AS RAW TEXT AND STORE IN $line

1. Include a space after the "#".

2. Don't write your comments in all-capital letters.

3. One "#" instead of a quad "####" should be enough.

Together, they make your comment hard to read and obstruct the flow of the
code.

> while ( $line = )

Because of use strict; this won't compile because $line is used out of the
blue.

> {
> chomp $line;
>
> #We're going to need the following string multiple times
> my $atMCC = '@mcc.commnet.edu';
>
> ####EXTRACT THE ORIGINAL PLAIN-TEXT HEADER FROM THE MESSAGE BODY:
> if ( $line =~ m/(Content-Transfer-Encoding:
> quoted-printable\n)(\n\n------------------------------------ -------\n)(.*?)
> (\nAuto forwarded by a Rule)/s )
> {
> $::header = $2 . $3 . $4;

1. You're making excessive use of package-scope variables using $::var_name.
This defeats the point of using use strict. You should declare these variables
in the scope where they are needed.

2. It would be preferable to write it as:

if (my ($one, $two, $three) = $line =~ m/....))
{
$header = "$one$two$three";
}

3. What are you doing with "$1"? If you don't need it, you can use the
clustering (?:...) instead of the capturing (...).

Regards,

Shlomi Fish

--
------------------------------------------------------------ -----
Shlomi Fish http://www.shlomifish.org/
Stop Using MSIE - http://www.shlomifish.org/no-ie/

She's a hot chick. But she smokes.
She can smoke as long as she's smokin'.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

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

Re: Sending an E-Mail

am 13.10.2010 04:08:13 von mark

--------------050107080109090302040101
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

On 10/10/10 3:50 AM, Shlomi Fish wrote:
> Looking at your code, I see that you process the E-mail message using regular
> expressions. Please don't do that and use a CPAN module.
I'm not sure I understand the admonishment. Is it that, if I use
regex to process the e-mail, then I don't *need* a CPAN module? Is it
that CPAN modules and regex don't like each other?...

> Some options to
> investigate are:
>
> *http://search.cpan.org/dist/MIME-Lite/
>
> *http://search.cpan.org/dist/Email-Sender/
>
> *http://search.cpan.org/dist/Mail-Box/

I've been trying to use the second one: Email-Sender. But I can't
install it on my Macbook Pro in order to test it locally. I've tried to
install several different ways, the latest being a manual compile &
install of 'Bundle-Email'. When I tried 'make test', I got the output
below. What am I doing wrong?

- Mark

$ make test
/usr/bin/perl "-Iinc" Makefile.PL --config=
--installdeps=Email::Address,0,Email::MIME::Encodings,0,Emai l::MIME::ContentType,0,Email::MessageID,0,Email::Simple,0,Em ail::Date,0,Email::Abstract,0,Email::MIME,0,Email::Simple::C reator,0,Email::MIME::Modifier,0,Email::MIME::Creator,0,Emai l::Send,0,Email::Send::Test,0,Email::FolderType,0,Email::Fol derType::Net,0,Email::LocalDelivery,0,Email::Folder,0,File:: Type,0,Email::Stuff,0
CPAN: File::HomeDir loaded ok (v0.93)
*** Installing dependencies...
*** Installing Email::Send...
CPAN: Storable loaded ok (v2.15)
Going to read '/Users/My_White_Plume/Library/Application
Support/.cpan/sources/authors/01mailrc.txt.gz'
gzip: /Users/My_White_Plume/Library/Application.gz: No such file or
directory
gzip: Support/.cpan/sources/authors/01mailrc.txt.gz: No such file or
directory
DONE
Going to read '/Users/My_White_Plume/Library/Application
Support/.cpan/sources/modules/02packages.details.txt.gz'
gzip: /Users/My_White_Plume/Library/Application.gz: No such file or
directory
gzip: Support/.cpan/sources/modules/02packages.details.txt.gz: No such
file or directory
Warning: Your /Users/My_White_Plume/Library/Application
Support/.cpan/sources/modules/02packages.details.txt.gz does not contain
a Line-Count header.
Please check the validity of the index file by comparing it to more
than one CPAN mirror. I'll continue but problems seem likely to
happen.
Warning: Your /Users/My_White_Plume/Library/Application
Support/.cpan/sources/modules/02packages.details.txt.gz does not contain
a Last-Updated header.
Please check the validity of the index file by comparing it to more
than one CPAN mirror. I'll continue but problems seem likely to
happen.
DONE
Going to read '/Users/My_White_Plume/Library/Application
Support/.cpan/sources/modules/03modlist.data.gz'
gzip: /Users/My_White_Plume/Library/Application.gz: No such file or
directory
gzip: Support/.cpan/sources/modules/03modlist.data.gz: No such file or
directory
Can't locate object method "data" via package "CPAN::Modulelist"
(perhaps you forgot to load "CPAN::Modulelist"?) at (eval 69) line 1.
at /Library/Perl/Updates/5.8.8/CPAN/Index.pm line 518
CPAN::Index::rd_modlist('CPAN::Index',
'/Users/My_White_Plume/Library/Application Support/.cpan/sourc...')
called at /Library/Perl/Updates/5.8.8/CPAN/Index.pm line 85
CPAN::Index::reload('CPAN::Index') called at
/Library/Perl/Updates/5.8.8/CPAN.pm line 955
CPAN::exists('CPAN=HASH(0xb11638)', 'CPAN::Module',
'Email::Send') called at /Library/Perl/Updates/5.8.8/CPAN/Shell.pm line 1343
CPAN::Shell::expand_by_method('CPAN::Shell', 'CPAN::Module',
'ARRAY(0xa34cb4)', 'Email::Send') called at
/Library/Perl/Updates/5.8.8/CPAN/Shell.pm line 1260
CPAN::Shell::expand('CPAN::Shell', 'Module', 'Email::Send')
called at inc/Module/AutoInstall.pm line 470
Module::AutoInstall::_install_cpan('ARRAY(0x906260)',
'ARRAY(0x5e51f4)') called at inc/Module/AutoInstall.pm line 318
Module::AutoInstall::install('Module::AutoInstall',
'ARRAY(0x8ffc54)', 'undef', 'undef', 'undef', 'undef', 'undef', 'undef',
'undef', ...) called at inc/Module/AutoInstall.pm line 60
Module::AutoInstall::_init() called at
inc/Module/AutoInstall.pm line 25
require Module/AutoInstall.pm called at
inc/Module/Install/AutoInstall.pm line 37
Module::Install::AutoInstall::auto_install('undef') called at
Makefile.PL line 37
Compilation failed in require at inc/Module/Install/AutoInstall.pm line 37.
make: *** [installdeps] Error 1

--------------050107080109090302040101--

Re: Sending an E-Mail

am 13.10.2010 07:50:58 von Shlomi Fish

Hi Mark,

On Wednesday 13 October 2010 04:08:13 Mark wrote:
> On 10/10/10 3:50 AM, Shlomi Fish wrote:
> > Looking at your code, I see that you process the E-mail message using
> > regular expressions. Please don't do that and use a CPAN module.
>=20
> I'm not sure I understand the admonishment. Is it that, if I use
> regex to process the e-mail, then I don't *need* a CPAN module? Is it
> that CPAN modules and regex don't like each other?...
>=20

No, I meant that you should use a CPAN module with a decent parsing logic,=
=20
which will handle all the edge cases of MIME for you, *instead* of the=20
convulted parsing logic you have using regexes. Regular expressions natural=
ly=20
have many valid uses, but using them to parse and process E-mail messages=20
directly is not one of them. For that, use a module.

> > Some options to
> > investigate are:
> >=20
> > *http://search.cpan.org/dist/MIME-Lite/
> >=20
> > *http://search.cpan.org/dist/Email-Sender/
> >=20
> > *http://search.cpan.org/dist/Mail-Box/
>=20
> I've been trying to use the second one: Email-Sender. But I can't
> install it on my Macbook Pro in order to test it locally. I've tried to
> install several different ways, the latest being a manual compile &
> install of 'Bundle-Email'. When I tried 'make test', I got the output
> below. What am I doing wrong?
>=20
> - Mark
>=20
> $ make test
> /usr/bin/perl "-Iinc" Makefile.PL --config=3D
> --installdeps=3DEmail::Address,0,Email::MIME::Encodings,0,Em ail::MIME::Co=
nten
> tType,0,Email::MessageID,0,Email::Simple,0,Email::Date,0,Ema il::Abstract,=
0,
> Email::MIME,0,Email::Simple::Creator,0,Email::MIME::Modifier ,0,Email::MIM=
E:
> :Creator,0,Email::Send,0,Email::Send::Test,0,Email::FolderTy pe,0,Email::F=
ol
> derType::Net,0,Email::LocalDelivery,0,Email::Folder,0,File:: Type,0,Email:=
:S
> tuff,0 CPAN: File::HomeDir loaded ok (v0.93)
> *** Installing dependencies...
> *** Installing Email::Send...

Seems like Module::AutoInstall is kicking in here. I loath that module. You=
=20
should try installing everything using the CPAN client and let us know of t=
he=20
verdict.

> CPAN: Storable loaded ok (v2.15)
> Going to read '/Users/My_White_Plume/Library/Application
> Support/.cpan/sources/authors/01mailrc.txt.gz'
> gzip: /Users/My_White_Plume/Library/Application.gz: No such file or
> directory
> gzip: Support/.cpan/sources/authors/01mailrc.txt.gz: No such file or
> directory

It seems that your path contains a whitespace, which confuses gzip that is=
=20
called from Perl. There are some solutions here:

http://www.perlmonks.org/?node_id=3D777434

=46rom chatting on IRC about Perl on Mac OS X, I know that many people reco=
mmend=20
not to use the system perl for active development, but instead to install a=
=20
different perl under your home directory, possibly using=20
http://search.cpan.org/dist/local-lib/ and/or=20
http://search.cpan.org/dist/App-perlbrew/ . I'll ask about it more.

Regards,

Shlomi Fish

=2D-=20
=2D--------------------------------------------------------- -------
Shlomi Fish http://www.shlomifish.org/
"Star Trek: We, the Living Dead" - http://shlom.in/st-wtld

She's a hot chick. But she smokes.
She can smoke as long as she's smokin'.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

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

Re: Sending an E-Mail

am 13.10.2010 08:04:40 von Shlomi Fish

On Wednesday 13 October 2010 07:50:58 Shlomi Fish wrote:
> Hi Mark,
>
> On Wednesday 13 October 2010 04:08:13 Mark wrote:
> > On 10/10/10 3:50 AM, Shlomi Fish wrote:
> > > Looking at your code, I see that you process the E-mail message using
> > > regular expressions. Please don't do that and use a CPAN module.
> > >
> > I'm not sure I understand the admonishment. Is it that, if I use
> >
> > regex to process the e-mail, then I don't *need* a CPAN module? Is it
> > that CPAN modules and regex don't like each other?...
>
> No, I meant that you should use a CPAN module with a decent parsing logic,
> which will handle all the edge cases of MIME for you, *instead* of the
> convulted parsing logic you have using regexes. Regular expressions
> naturally have many valid uses, but using them to parse and process E-mail
> messages directly is not one of them. For that, use a module.
>
> > > Some options to
> > > investigate are:
> > >
> > > *http://search.cpan.org/dist/MIME-Lite/
> > >
> > > *http://search.cpan.org/dist/Email-Sender/
> > >
> > > *http://search.cpan.org/dist/Mail-Box/
> >
> > I've been trying to use the second one: Email-Sender. But I can't
> > install it on my Macbook Pro in order to test it locally. I've tried to
> > install several different ways, the latest being a manual compile &
> > install of 'Bundle-Email'. When I tried 'make test', I got the output
> > below. What am I doing wrong?
> >
> > - Mark
> >
> > $ make test
> > /usr/bin/perl "-Iinc" Makefile.PL --config=
> > --installdeps=Email::Address,0,Email::MIME::Encodings,0,Emai l::MIME::Cont
> > en
> > tType,0,Email::MessageID,0,Email::Simple,0,Email::Date,0,Ema il::Abstract
> > ,0,
> >
> >
Email::MIME,0,Email::Simple::Creator,0,Email::MIME::Modifier ,0,Email::MIME:
> > :Creator,0,Email::Send,0,Email::Send::Test,0,Email::FolderTy pe,0,Email::F
> > :ol
> >
> > derType::Net,0,Email::LocalDelivery,0,Email::Folder,0,File:: Type,0,Email:
> > :S tuff,0 CPAN: File::HomeDir loaded ok (v0.93)
> > *** Installing dependencies...
> > *** Installing Email::Send...
>
> Seems like Module::AutoInstall is kicking in here. I loath that module. You
> should try installing everything using the CPAN client and let us know of
> the verdict.
>
> > CPAN: Storable loaded ok (v2.15)
> > Going to read '/Users/My_White_Plume/Library/Application
> > Support/.cpan/sources/authors/01mailrc.txt.gz'
> > gzip: /Users/My_White_Plume/Library/Application.gz: No such file or
> > directory
> > gzip: Support/.cpan/sources/authors/01mailrc.txt.gz: No such file or
> > directory
>
> It seems that your path contains a whitespace, which confuses gzip that is
> called from Perl. There are some solutions here:
>
> http://www.perlmonks.org/?node_id=777434
>
> From chatting on IRC about Perl on Mac OS X, I know that many people
> recommend not to use the system perl for active development, but instead
> to install a different perl under your home directory, possibly using
> http://search.cpan.org/dist/local-lib/ and/or
> http://search.cpan.org/dist/App-perlbrew/ . I'll ask about it more.
>

Here's what the FreeNode #perl people told about it:

[irc]
Hi all. In regards to http://www.perlmonks.org/?node_id=777434 (well
something similar that someone posted on
http://www.nntp.perl.org/group/perl.beginners/ ) - what is considered the best
practice for Perl development on Mac OS X? Should Mac OS X users install their
own perl?
rindolf: i've heard perlbrew works okay
i couldn't get it working because i fucked up my build at one point
rindolf: I usually install a debian VM
OS X is a desktop OS, it's not significantly more suitable than win32
for development IME
rindolf, in all seriousness, macports works fine. The worst thing is
to use the system perl.
macports installed 5.12 alright
rindolf: From what I've heard, perl on MacOS is sort of like perl on
RedHat. It works. but.. Um. use local::lib or perlbrew or something.
[/irc]

Regards,

Shlomi Fish

--
------------------------------------------------------------ -----
Shlomi Fish http://www.shlomifish.org/
Optimising Code for Speed - http://shlom.in/optimise

She's a hot chick. But she smokes.
She can smoke as long as she's smokin'.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

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

Email Filter Script

am 22.10.2010 09:35:19 von mark

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][LastName]@mcc.commnet.edu
...but in the Interpolated Header this gets altered to:
[LastName], [FirstName] [Middle Initial]
So, for example, the college address:
GWillickers@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_WILLICKERS@DOMAIN.COM]
b. While in the "To: " line and (if it exists) the "Cc: "
line, non-college addresses appear literally:
gollygwillickers@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
gstwillickers@mcc.commnet.edu.
- The name Golly G. Willi Kerrs becomes
gwillikerrs@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
(Mark@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"
To:
# [...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_WILLICKERS@DOMAIN.COM]
Sent: Wednesday, September 29, 2010 4:12:46 PM
To: MA-Adjunct Faculty; golly.willickers@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


charset=3Diso-8859-1">






FACE=3D"Arial">-------------------------------------------

From: SIZE=3D2 FACE=3D"Arial">Golly Willickers[SMTP:GOLLY_G_WILLICKERS@DOMAIN.COM]

Sent: SIZE=3D2 FACE=3D"Arial">Wednesday, September 29, 2010 4:12:46 PM

To: SIZE=3D2 FACE=3D"Arial">MA-Adjunct Faculty;


golly.willickers@gmail.com; Vecchio, Mark J

Cc: SIZE=3D2 FACE=3D"Arial">Willickers, Golly G

Subject: SIZE=3D2 FACE=3D"Arial">Outlook Webmail is Fascistic

Auto forwarded by a =
Rule






Greetings, =
Everyone --

 



[Body of message (snipped).]



------_=_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-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Email Filter Script

am 22.10.2010 12:29:26 von Peter Scott

On Fri, 22 Oct 2010 03:35:19 -0400, Mark wrote:
> I have a college e-mail account. The college uses Outlook webmail.
> I hate Outlook webmail.

You are among friends :)

> 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:

Can you create a redirection rule instead?

http://office.microsoft.com/en-us/outlook-help/automatically -forward-
messages-to-another-e-mail-account-HA001150201.aspx

--
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
http://www.oreillyschool.com/courses/perl1/

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

Re: Email Filter Script

am 22.10.2010 18:53:05 von mark

--------------060606060106010705090702
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

On 10/22/10 6:29 AM, Peter Scott wrote:
>> 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:
> Can you create a redirection rule instead?

That excellent feature has apparently been disabled, as has any other
set up of rules and filters. Forwarding, with all the server's
alterations, is the only escape route. The Outlook software itself is
not the problem; the college's IT policies are the problem, and the
policy is the commandment, Thou shalt use Outlook webmail. The IT person
I talked to said it is done this way for security reasons: the college's
e-mail activity is isolated from the outside Internet. As far as I can
tell, you even have to be at a specially-enabled workstation in the IT
office itself to set up the automatic forwarding in the first place. I
set it up in the IT office, and since that day have not seen the
forwarding menu option in the webmail interface in any other location
either on or off campus. (Haven't been back to the IT office, as they
had minimal ability to be helpful on this issue).

- Mark

--------------060606060106010705090702--

Re: Email Filter Script

am 22.10.2010 18:53:57 von Brandon McCaig

Hello, Mark.

On Fri, Oct 22, 2010 at 3:35 AM, Mark wrote:
> 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.
*snip*
> 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.

I'm a computer programmer. :) I'm not suggesting you hire me or
anything like that. Just that I'd like to try to write a program for
this and if it works out then maybe you can use it. I need more
information, however.

It seems that the E-mails are piped to the script so I shouldn't need
to worry about file system IO. Correct? So basically, parse the E-mail
message from STDIN, parse the body to extract the original
information, restore the FROM, TO, CC, and SUBJECT fields; then
restore the body by extracting the "inlined headers" and then send it
off. Is that correct?

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

It would be nice if you could send me a complete copy (without all of
the snips) of an example E-mail, preferably with a little HTML
formatting and a meaningless attachment or two just so that I can use
it to test with. I'm not personally familiar with E-mail message
formats, etc., so I'll be relying on existing modules to do all of the
heavy lifting. ;) Perhaps you could have a colleague or student or
whatever send you a sample message (one that doesn't mind their E-mail
address being shared randomly over the Internet :P) and then send me a
full copy of that? That way I'll have an input in the correct format
to feed my script while I write it.


--
Brandon McCaig
V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl.
Castopulence Software

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

Re: Email Filter Script

am 22.10.2010 21:52:40 von HerrPoetry

Brendon -

Did you get the following e-mail (with the attachment intact) at your
gmail address? I'm resending it to the list with the attachment snipped,
because apparently this list has a 50k limit.

- Mark

On 10/22/10 12:53 PM, Brandon McCaig wrote:

>
> Hello, Mark.
>
> I'm a computer programmer. :) I'm not suggesting you hire me or
> anything like that. Just that I'd like to try to write a program for
> this and if it works out then maybe you can use it. I need more
> information, however.
>
> It seems that the E-mails are piped to the script so I shouldn't need
> to worry about file system IO. Correct? So basically, parse the E-mail
> message from STDIN, parse the body to extract the original
> information, restore the FROM, TO, CC, and SUBJECT fields; then
> restore the body by extracting the "inlined headers" and then send it
> off. Is that correct?


That's it.

Re: sending the final product off -- it should only be sent to my
forward-to address, not to any other recipients named in the restored
header.

The tech support guys at HostMonster.com said to use this:

while ( $line = )
{
chomp $line;

# Do stuff to $line...
)

>> Below is a sample Outlook-forwarded e-mail, which shows the egregious
>> alterations in action.
> It would be nice if you could send me a complete copy (without all of
> the snips) of an example E-mail, preferably with a little HTML
> formatting and a meaningless attachment or two just so that I can use
> it to test with. I'm not personally familiar with E-mail message
> formats, etc., so I'll be relying on existing modules to do all of the
> heavy lifting. ;) Perhaps you could have a colleague or student or
> whatever send you a sample message (one that doesn't mind their E-mail
> address being shared randomly over the Internet :P) and then send me a
> full copy of that? That way I'll have an input in the correct format
> to feed my script while I write it.


Below is a sample e-mail. This is my first semester at this
college, so I don't really know anyone yet, and I don't think I can
share anyone's actual e-mail address other than mine. However, in the
below sample I have only changed some letters in each name (each one
that isn't mine, that is), so that the format is absolutely precise.
I've also added a couple of non-college addresses that belong to me, so
that the message will contain three real, live addresses, including my
college address. In addition, I've added a "St. Paul" last name, as well
as a "Della Casa" last name, as these name patterns will crop up in some
e-mails. There is one .pdf attachment. Let me know if all this will
suffice for testing.

After the sample e-mail, I've included my original test script.
This did use I/O to read a sample e-mail text file on my local machine.
I never got to the stage of testing the script on my HostMonster server.
In this test script, all the regex processing seems to work fine,
convoluted though it may be. I include it to show you how I was working
with the consistent reformatting Outlook is imposing, plus the logic of
the altered e-mail addresses.

Enjoy!

- Mark


===== BEGIN SAMPLE E-MAIL =====
Return-path:
Envelope-to: Mark@OCaptain.org
Delivery-date: Wed, 29 Sep 2010 14:13:44 -0600
Received: from freevers by host222.hostmonster.com with local-bsmtp
(Exim 4.69)
(envelope-from )
id 1P1327-0006Mv-Fm
for Mark@OCaptain.org; Wed, 29 Sep 2010 14:13:44 -0600
X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on
host222.hostmonster.com
X-Spam-Level:
X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,HTML_MESSAGE
shortcircuit=no autolearn=ham version=3.2.5
Received: from emerald2.commnet.edu ([155.43.4.222])
by host222.hostmonster.com with esmtp (Exim 4.69)
(envelope-from )
id 1P1326-0006MG-5d
for Mark@OCaptain.org; Wed, 29 Sep 2010 14:13:43 -0600
Received: from SYSPYRITE2.sys.commnet.edu (sysgold2.sys.commnet.edu
[155.43.129.124])
by emerald2.commnet.edu (8.14.3/8.14.3) with ESMTP id o8TKDbF8020659
for ; Wed, 29 Sep 2010 16:13:39 -0400
Received: from mask2.mcc.commnet.edu ([155.43.61.3]) by
SYSPYRITE2.sys.commnet.edu with Microsoft SMTPSVC(6.0.3790.4675);
Wed, 29 Sep 2010 16:13:38 -0400
X-MimeOLE: Produced By Microsoft Exchange V6.5
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----_=_NextPart_001_01CB6012.B007C0A4"
Subject: FW: Writing Center, Fall 2010
Date: Wed, 29 Sep 2010 16:12:48 -0400
Message-ID: <3CE9AAA797EE884B8CD374AC1848BDC0024B6996@mask2.mcc.commnet.edu>
X-MS-Has-Attach: yes
X-MS-TNEF-Correlator:
Thread-Topic: Writing Center, Fall 2010
Thread-Index: ActgDFVH71t2HQrhQaqUwJApnHIZ4gABlq1R
From: "Vecchio, Mark J"
To:
X-OriginalArrivalTime: 29 Sep 2010 20:13:38.0559 (UTC)
FILETIME=[CD9E90F0:01CB6012]
X-Proofpoint-Virus-Version: vendor=fsecure
engine=2.50.10432:5.0.10011,1.0.148,0.0.0000
definitions=2010-09-29_10:2010-09-29,2010-09-29,1970-01-01 signatures=0
X-Proofpoint-Spam-Details: rule=senddigest_notspam policy=senddigest
score=0 spamscore=0 ipscore=0
phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx
engine=5.0.0-1005130000 definitions=main-1009290144
X-Identified-User: {1073:host222.hostmonster.com:freevers:freeverse.net}
{sentby:spamassassin for local delivery to identified user}

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: Finermann, Karen
Sent: Wednesday, September 29, 2010 4:12:46 PM
To: anne.malevski@gmail.com; Whiteman, Catherine R; Vecchio, Mark J;
Coursel, Patrick C; fpalston@hotmail.com; nschweitzel@live.com;
Dorrett, Simon; Waldman, Daniel R; herrpoetry@gmail.com; Della Casa, Lisa
Cc: Geeson, Robert; herrpoetry@hailmail.net; St. Paul, Brian
Subject: Writing Center, Fall 2010
Auto forwarded by a Rule

Greetings, Everyone --
=20
With the semester now underway, Brian and I would like to extend our =
most sincere thanks to you all for your commitment to the MCC Writing =
Center; the students who strive to live up to their potential with the =
aid of your expertise will continually benefit from the support you =
offer. It is truly exciting to see a diverse group of professionals, =
peer tutors, and faculty united by a common goal as we move into our =
second year of operation!=20
=20
We hope that those of you already established in the Writing Center will =
give a warm welcome to Anna Nalitov, Mark Vecchio and Michael Schiessl, =
our newest hires, who bring talent and enthusiasm to our table. For =
those of you who are returning, seasoned staffers, please know that we =
are also grateful for the consistency of experience you give to our =
student population. In the weeks to come, I will be stopping by for a =
brief visit with each of you so that you can relay to me any feedback =
you might have concerning your interactions in the Center thus far. =
Ultimately, Brian and I would like to hold a social/summit meeting, as =
we did last year, an opportunity to exchange stories and ideas which =
will help us all as we move forward. The semester has gotten off to a =
flying start, it seems, with an unusually swift flow of traffic -- in =
light of this fact, perhaps there is much to discuss!
=20
In the meantime, please feel free to contact me with any matters which =
you feel to be of importance: my office is Lowe 249, around the corner =
to the right, and I welcome your emails or calls at any time. The =
working schedule has been attached for reference, should you have need =
of this information.
=20
Let me close by thanking you all once more for giving your knowledge, =
patience and dedication to the Writing Center enterprise -- this =
endeavor could not succeed without you!
=20
Best,
=20
Karen=20
=20
Karen finermann
Assistant Professor of English
Writing Center Coordinator
Great Path, M.S. # 19
Manchester, CT 06045 - 0146
Phone: (860) 512 - 2664
Fax: (860) 512 - 2661
Email: kfinermann@mcc.commnet.edu
=20
"Everyman's death diminishes me."=20
-- John Donne
=20

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


charset=3Diso-8859-1">






FACE=3D"Arial">-------------------------------------------

From: SIZE=3D2 FACE=3D"Arial">finermann, Karen

Sent: SIZE=3D2 FACE=3D"Arial">Wednesday, September 29, 2010 4:12:46 PM

To: SIZE=3D2 FACE=3D"Arial">anne.malevski@gmail.com; Whiteman, Catherine R; =
Vecchio, Mark J;

Coursel, Patrick C; =
fpalston@hotmail.com; nschweitzel@live.com;

Dorrett, Simon; =
Waldman, Daniel R; herrpoetry@gmail.com; Della Casa, Lisa

Cc: SIZE=3D2 FACE=3D"Arial">Geeson, Robert; herrpoetry@hailmail.net; St.
Paul, Brian

Subject: SIZE=3D2 FACE=3D"Arial">Writing Center, Fall 2010

Auto forwarded by a =
Rule






Greetings, =
Everyone --

 

With the semester now =
underway, Brian and I would like to extend our most sincere thanks =
to you all for your commitment to the MCC Writing Center; the =
students who strive to live up to their potential with the aid of your =
expertise will continually benefit from the support you offer. It is =
truly exciting to see a diverse group of professionals, peer =
tutors, and faculty united by a common goal as we move into our second =
year of operation!

 

We hope that those of you =
already established in the Writing Center will give a warm welcome to =
Anna Nalitov, Mark Vecchio and Michael Schiessl, our newest hires, =
who bring talent and enthusiasm to our table. For those of you =
who are returning, seasoned staffers, please know that we are =
also grateful for the consistency of experience you give to our =
student population. In the weeks to come, I will be stopping =
by for a brief visit with each of you so that you can relay to me =
any feedback you might have concerning your interactions in the Center =
thus far. Ultimately, Brian and I would like to hold a social/summit =
meeting, as we did last year, an opportunity to exchange stories and =
ideas which will help us all as we move forward. The semester has gotten =
off to a flying start, it seems, with an unusually swift flow of =
traffic -- in light of this fact, perhaps there is much to =
discuss!

 

In the meantime, please feel =
free to contact me with any matters which you feel to be of importance: =
my office is Lowe 249, around the corner to the right, and I welcome =
your emails or calls at any time. The working schedule has been =
attached for reference, should you have need of this =
information.

 

Let me close by thanking you =
all once more for giving your knowledge, patience and dedication to the =
Writing Center enterprise -- this endeavor could not succeed without =
you!

 

Best,

 

Karen 

size=3D2> 


Karen =
finermann

Assistant Professor of =
English

Writing Center Coordinator

Great Path, M.S. # 19

Manchester, CT  06045 - =
0146

Phone: (860) 512 - 2664

Fax: (860) 512 - 2661

Email: href=3D"mailto:kfinermann@mcc.commnet.edu">kfinermann@mcc.co mmnet.edu NT>

 

"Everyman's death diminishes me." =

size=3D2>          &nbs=
p;            =
;        -- John Donne

 

------_=_NextPart_002_01CB6012.B007C0A4--

------_=_NextPart_001_01CB6012.B007C0A4
Content-Type: application/pdf;
name="Writing Center Fall 2010.pdf"
Content-Transfer-Encoding: base64
Content-Description: Writing Center Fall 2010.pdf
Content-Disposition: attachment;
filename="Writing Center Fall 2010.pdf"

{SNIPPED, because of this list's file size limit of 50k}

------_=_NextPart_001_01CB6012.B007C0A4--
===== END SAMPLE E-MAIL =====

===== BEGIN MY ORIGINAL TEST SCRIPT =====
#!/usr/bin/env perl
use warnings;
use strict;
use Data::Dumper;
use Email::Sender::Simple qw(sendmail);
use Email::Simple;
use Email::Simple::Creator;

# This is what I'll have to use for the HostMonster filter script
# while ( $line = ) {
# chomp $line;
# now do something with $line...
# }

#For testing purposes in the meantime, I'll instantiate a filehandle
'$fh' and read it into the scalar '$line'
# On OS X:
#open(my $fh, '/Users/My_White_Plume/My White
Plume/Workshop/Programs/Perl/MCC_Sample_E-mail2.txt')
# or die "OOPS. Could not open the file";
# On Debian-Lenny vbox:
open(my $fh,
'/media/My_White_Plume/Workshop/Programs/Perl/MCC_Sample_E-m ail2.txt')
or die "OOPS. Could not open the file";
$/ = undef;
my $line = <$fh>;

#We're going to need the following string multiple times
my $atMCC = '@mcc.commnet.edu';

# EXTRACT THE ORIGINAL PLAIN-TEXT HEADER FROM THE MESSAGE BODY:
if ( $line =~ m/(Content-Transfer-Encoding:
quoted-printable\n)(\n\n------------------------------------ -------\n)(.*?)(\nAuto
forwarded by a Rule)/s )
{
$::header = $2 . $3 . $4;
}

# EXTRACT & MASSAGE THE SENDER CONTAINED IN $header.
# Case: \nFrom: First Last[SMTP:addr@domain.ext]
# \nFrom: First \s Last '[SMTP:' E-mail
']'
# ($1) ($2) ($3) ($4) ($5) ($6)
($7)
if ( $::header =~ m/(\nFrom:
)(.*?)(\[SMTP:)(\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z] {2,4}\b)(]\n)/s
)
{
my $emailString = $4;
$emailString =~ tr/A-Z/a-z/; # convert to lower case
$::from = $1.$2.' <'.$emailString.'>';
}
# Case: \nFrom: Last , F---irst [M]
# ($1) ($2) ($3) ($4)($5)
elsif ( $::header =~ m/(\nFrom:\s)(.*?)(,\s)(\w)(\w+)/s )
{
$::from = $1.$4.$5.' '.$2.' <'.$4.$2.$atMCC.'>';
# Check for a 'St. Someone' name in e-mail address!
if ( $::from =~ m/St\. / )
{
$::from =~ s/(.*?<.*)(St\. )(.*?)/$1St$3/g;
}# Check for two separate words in last name in e-mail address!
if ( $::from =~ m/(\n.*<\S+) (\S+@\S+)/ )
{
$::from =~ s/(\n.*<\S+)( )(\S+@\S+)/$1$3/g;
}
}

# EXTRACT THE RAW RECIPIENT(S) CONTAINED IN $header.
# Check to see if there's a 'CC: ' header. If so, grab 'To: ' *and*
'CC: '
$::CCswitch = "No";
if ( $::header =~ m/(\nCC:\s)/si )
{
$::CCswitch = "Yes";
# Grab the entire 'To: ' header and store in $::toRaw
if ( $::header =~ m/\n(To: .*?)\nCC:\s/si )
{
$::toRaw = $1;
}
# Grab the entire 'CC: ' header (case insensitive) and store in
$::ccRaw
if ( $::header =~ m/\n(CC:\s)(.*?)\nSubject:\s/si )
{
$::ccRaw = $1.$2;
}
# Populate @::ccHeader
# Do we need to split $::ccRaw?
if ($::ccRaw =~ m/(CC: )(.*;\s.*)/si )
{
my $ccNames = $2;
# Replace all occurrences of '\n' with '\s'
$ccNames =~ s/(\n)(\w)/ $2/g;
$ccNames =~ s/\n//g;
@::ccHeader = split('; ', $ccNames);
}
else
{
$::ccRaw =~ s/Cc: //g;
@::ccHeader = ();
$::ccHeader[0] = $::ccRaw;
}
# Process each item in the array @::ccHeader
foreach $::ccName (@::ccHeader)
{
#If $ccHeader[n] contains "," then convert it
# Last , F...irst [M]
# ($1) ($2)($3)($4)
if ( $::ccName =~ m/(.*?)(, )(\w)(\w+)/s )
{
$::cc = $3.$4.' '.$1.' <'.$3.$1.$atMCC.'>';
# Check for a 'St. Someone' name in e-mail address!
if ( $::cc =~ m/St\. / )
{
$::cc =~ s/(.*?<.*)(St\. )(.*?)/$1St$3/g;
}# Check for two separate words in last name in e-mail
address!
if ( $::cc =~ m/(.*<\S+) (\S+@\S+)/ )
{
$::cc =~ s/(.*<\S+)( )(\S+@\S+)/$1$3/g;
}
$::ccName = $::cc;
}
}
}
# If no 'CC: ' header, just grab the 'To: ' header and store in
$::toRaw
elsif ( $::header =~ m/\n(To: .*?)\nSubject:\s/s )
{
$::toRaw = $1;
#To avoid having to do tests down the road, create a null
@::ccHeader
@::ccHeader = ();
}

# MASSAGE THE RECIPIENT(S) CONTAINED IN $::toRaw (and $::ccRaw, if it
exists).
# Do we need arrays?
if ($::toRaw =~ m/(To: )(.*;\s.*)/s )
{
my $toNames = $2;
# Replace all occurrences of '\n' with '\s'
$toNames =~ s/(\n)(\w)/ $2/g;
$toNames =~ s/\n//g;
@::toHeader = split('; ', $toNames);
}
else
{
$::toRaw =~ s/To: //g;
@::toHeader = ();
$::toHeader[0] = $::toRaw;
}

# Process each item in the array @::toHeader
foreach $::toName (@::toHeader)
{
#If $toHeader[n] contains "," then convert it
# Last , F...irst [M]
# ($1) ($2)($3)($4)
if ( $::toName =~ m/(.*?)(, )(\w)(\w+)/s )
{
$::to = $3.$4.' '.$1.' <'.$3.$1.$atMCC.'>';
# Check for a 'St. Someone' name in e-mail address!
if ( $::to =~ m/St\. / )
{
$::to =~ s/(.*?<.*)(St\. )(.*?)/$1St$3/g;
}# Check for two separate words in last name in e-mail address!
if ( $::to =~ m/(.*<\S+) (\S+@\S+)/ )
{
$::to =~ s/(.*<\S+)( )(\S+@\S+)/$1$3/g;
}
$::toName = $::to;
}
}

# If more than one element in @::toHeader, add semicolons back in
if ( scalar( @::toHeader ) > 1 )
{
$::toString = join( '; ', @::toHeader );
}
else { $::toString = $::toHeader[0] }
# Repeat: If more than one element in @::ccHeader, add semicolons
back in
if ( scalar( @::ccHeader ) > 1 )
{
$::ccString = join( '; ', @::ccHeader );
}
# Concatenate the 'TO' and 'CC' strings into $::recipientString
if ( length ( $::ccString ) > 3 )
{
$::recipientString = $::toString . "\nCc: " . $::ccString;
}
else { $::recipientString = $::toString }

# Replace in $line (i.e. the actual e-mail) the actual message
# header elements From, To, CC, and Subject, as well as the
# annoying header info in the e-mail's body.
if ( $line =~ m/(\n)(From: "Vecchio, Mark J"
\n)(To: )\n/s )
{
# $::originalFromTo = $1 . "X-Outlook's Original " . $2 .
"X-Outlook's Original " . $3;
$line =~ s/(.*?)(\nFrom: "Vecchio, Mark J"
)(\nTo:
)(\n)(.*?)/$1$::from$3$::recipientString\n$5/g;
}

# DELETE "FW: " FROM THE SUBJECT HEADER
$line =~ s/\nSubject: FW: {1}?/\nSubject: /g;

# DELETE INTERPOLATED HEADER SEGMENTS IN THE E-MAIL'S BODY
# Delete the Plain-Text version
$line =~
s/\n\n-------------------------------------------\n.*?\nAuto forwarded
by a Rule//s;
# Delete the HTML version
$line =~
s/\n\n.*?-------------------------------------------.*?Auto
forwarded by a =\nRule.{22}?\n//si;

# Send the new version of the e-mail
my $recipient = 'Mark Vecchio ';
Email::Sender::Simple->send($line, { to => $recipient }); # This
ain't working

# Print the restored e-mail in the Terminal for review
print "\n\n$line\n\nE-mail sent . . . perhaps.\n\n";

# DEBUGGING: SHOW OUTPUT
#print "\n\n\n # DEBUGGING: SHOW OUTPUT:\n\n";
#print "\n" . ' HEY! $ccNames = ' . "\n$ccNames\n\n";
#print " THE EXTRACTED PLAIN TEXT HEADER IS:
\n$::header \n\n";
#print " THE EXTRACTED HTML HEADER IS:
\n$::html_header \n";
#print " THE EXTRACTED 'FROM' HEADER IS: \n$::from
\n\n";
#print " THE EXTRACTED RAW 'TO' HEADER IS:
\n$::toRaw \n\n";
#print " THE EXTRACTED 'TO' ARRAY IS: \n@::toHeader
\n\n";
#print " THE FINISHED 'TO' STRING IS: \n$::toString
\n\n";
#print '$CCswitch = ' . "$::CCswitch \n\n";
#print " THE EXTRACTED RAW 'CC' HEADER IS:
\n$::ccRaw\n\n";
#print " THE EXTRACTED 'CC' ARRAY IS: \n@::ccHeader
\n\n";
#print " THE FINISHED 'CC' STRING IS: \n$::ccString
\n\n";
===== END MY ORIGINAL TEST SCRIPT =====

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

a Loop constructing the URLs to use LWP::UserAgent repeatedly up to10 thousand times

am 23.10.2010 07:16:04 von Floobee

Hello dear list good morning



I am trying to use LWP::UserAgent on the same URLs see below with different query arguments, and i am wondering if LWP::UserAgent provides a way for us to loop through the query arguments?
I am not sure that LWP::UserAgent has a method for us to do that.
I tried to figure it out. And i digged deeper in the Manpages and Howtos: we can have a loop constructing the URLs and use LWP::UserAgent repeatedly:


for my $id (0 .. 100000) { $ua->get($url."?id=21&extern_eid=".(09-$id)) //rest of the code }


Well, alternatively we can add a request_prepare handler that computes and add the query arguments before we send out the request.

Do you think that this fits the needs? look forward to your review of this issue!
greetings


What is aimed: Here on this following site we find a list of many schools: see the page with the subsequent results - approx more than 1000 sites

http://www-db.sn.schule.de/index.php?id=25


i want to fetch all the sites that are listet on this page - and therefore i want to use LWP::UserAgent; - and subesquently i want to parse them.

the sites can be reached directly - by constructing in other words the subsites of the overview can be reached via direct links... see the following.

http://www-db.sn.schule.de/index.php?id=21&extern_eid=1543
http://www-db.sn.schule.de/index.php?id=21&extern_eid=709
http://www-db.sn.schule.de/index.php?id=21&extern_eid=789
http://www-db.sn.schule.de/index.php?id=21&extern_eid=1297
___________________________________________________________
WEB.DE DSL Doppel-Flat ab 19,99 €/mtl.! Jetzt auch mit
gratis Notebook-Flat! http://produkte.web.de/go/DSL_Doppel_Flatrate/2

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

Re: a Loop constructing the URLs to use LWP::UserAgent repeatedly up to 10 thousand times

am 23.10.2010 11:09:51 von Shlomi Fish

Hi jobst,

On Saturday 23 October 2010 07:16:04 jobst müller wrote:
> Hello dear list good morning
>=20

Please don't start a new thread by replying to an existing message (you als=
o=20
CCed the previous correspondents.) Instead send a new message to=20
beginners@perl.org.

> I am trying to use LWP::UserAgent on the same URLs see below with differe=
nt
> query arguments, and i am wondering if LWP::UserAgent provides a way for
> us to loop through the query arguments? I am not sure that LWP::UserAgent
> has a method for us to do that.
> I tried to figure it out. And i digged deeper in the Manpages and Howtos:
> we can have a loop constructing the URLs and use LWP::UserAgent
> repeatedly:
>=20
>=20
> for my $id (0 .. 100000) { $ua->get($url."?id=3D21&extern_eid=3D".(09-$id=
))
> //rest of the code }

{{{
shlomif:~$ perl -e 'print 09'
Illegal octal digit '9' at -e line 1, at end of line
Execution of -e aborted due to compilation errors.
}}}

So (09-$id) is wrong. What are you trying to do.

In any case, using a loop like this for that is exactly the way to do it. T=
he=20
LWP APIs do not aim to replace the functionality of the core Perl, and you =
can=20
use Perl loops to query multiple URLs. What are your reservations from usin=
g a=20
loop for that?

Regards,

Shlomi Fish

=2D-=20
=2D--------------------------------------------------------- -------
Shlomi Fish http://www.shlomifish.org/
My Favourite FOSS - http://www.shlomifish.org/open-source/favourite/

She's a hot chick. But she smokes.
She can smoke as long as she's smokin'.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

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

Re: Email Filter Script

am 23.10.2010 18:34:45 von Brandon McCaig

On Fri, Oct 22, 2010 at 3:52 PM, wrote:
> Brendon -
>
> Did you get the following e-mail (with the attachment intact) at your gmail
> address? I'm resending it to the list with the attachment snipped, because
> apparently this list has a 50k limit.

Yes I did. :) It just kept going and going. :P

--
Brandon McCaig
V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl.
Castopulence Software

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

Re: Email Filter Script

am 24.10.2010 03:37:44 von Brandon McCaig

I give up. My head hurts. D:


--
Brandon McCaig
V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl.
Castopulence Software

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

Re: a Loop constructing the URLs to use LWP::UserAgent repeatedly up to 10 thousand times

am 24.10.2010 09:08:51 von merlyn

>>>>> ""jobst" == "jobst müller" writes:

"jobst> I am trying to use LWP::UserAgent on the same URLs see below
with different query arguments, and i am wondering if LWP::UserAgent
provides a way for us to loop through the query arguments?

Why are you hitting this website to scrape it? Do you have their
permission? Can't you get the data some other way other than generating
an entire web page (with likely a lot of common elements) just so you
can pick out the juicy bits?

This is almost always the *wrong* way to do this task, on many levels.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095

Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.posterous.com/ for Smalltalk discussion

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

Re: Email Filter Script

am 24.10.2010 23:11:29 von mark

--------------020909020809060508050002
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Thank you, Brendon, for taking a look at the script. I'd like to narrow
down the problem so I can finish some working version of this thing.

I have logic that gets the job of restoring the e-mail done, albeit
using regex in a brute force kind of way rather than parsing the message
elegantly with modules. To get a minimally working, if ugly, script I
just have to e-mail myself the resulting string ('$line'), which
contains the entire multipart MIME message as raw text, attachments
included. After looking at the online Quickstart web page for
Email::Sender (the hyperlink to the more complete manual goes nowhere),
this is what I wrote:

my $recipient = 'Mark Vecchio ';
Email::Sender::Simple->send($line, { to => $recipient });

It doesn't work, I hope for reasons that are obvious to some of you out
there. The script does run without throwing any errors in the Terminal
I'm testing it in, but no e-mail gets sent.Toward the top of the script
I've included the lines:

use Email::Sender::Simple qw(sendmail);
use Email::Simple;
use Email::Simple::Creator;

I have no idea where to go from here. I want to e-mail the string
'$line' with all its headers -- i.e. From:, To:, Cc:, and Subject: --
intact. The To: and Cc: headers will often contain addresses other than
my own, and I don't want to send the e-mail to anyone else but me.
Anyone who can give me a snippet of code to jump start me in this final
phase will become a god in my pantheon.

- Mark

--------------020909020809060508050002--

Re: Email Filter Script

am 25.10.2010 05:30:15 von Jim Gibson

At 5:11 PM -0400 10/24/10, Mark wrote:
>Thank you, Brendon, for taking a look at the script. I'd like to
>narrow down the problem so I can finish some working version of this
>thing.
>
>I have logic that gets the job of restoring the e-mail done, albeit
>using regex in a brute force kind of way rather than parsing the
>message elegantly with modules. To get a minimally working, if ugly,
>script I just have to e-mail myself the resulting string ('$line'),
>which contains the entire multipart MIME message as raw text,
>attachments included. After looking at the online Quickstart web
>page for Email::Sender (the hyperlink to the more complete manual
>goes nowhere), this is what I wrote:
>
>my $recipient = 'Mark Vecchio ';
>Email::Sender::Simple->send($line, { to => $recipient });
>
>It doesn't work, I hope for reasons that are obvious to some of you
>out there. The script does run without throwing any errors in the
>Terminal I'm testing it in, but no e-mail gets sent.Toward the top
>of the script I've included the lines:
>
>use Email::Sender::Simple qw(sendmail);
>use Email::Simple;
>use Email::Simple::Creator;
>
>I have no idea where to go from here. I want to e-mail the string
>'$line' with all its headers -- i.e. From:, To:, Cc:, and Subject:
>-- intact. The To: and Cc: headers will often contain addresses
>other than my own, and I don't want to send the e-mail to anyone
>else but me. Anyone who can give me a snippet of code to jump start
>me in this final phase will become a god in my pantheon.

Have you looked at the documentation for Email::Sender::Simple? The
CPAN page for Email::Sender::Simple refers you to here:



Following the sample code on that page will lead you to the following
(untested):

my $email = Email::Simple->create(
header => [ To => 'MVecchio@mcc.commnet.edu' ],
body => $line
);
sendmail($email);

Try that instead. Note that sendmail returns a true value on success
or dies on failure.



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