perl as email client

L

Larry Gates

I've used perl as a usenet client before, but now that I have a site out
there with an email address that is supposed to get to me, and I wanted to
look at it through the rubric of perl.

How would a person use perl to simulate what OE does?

What activestate modules are required for a given method? I would have to
think there would be as many ways to do this in perl as building a wall for
a carpenter.
--
larry gates

Chip Salzenberg sent me a complete patch to add System V IPC (msg, sem and
shm calls), so I added them. If that bothers you, you can always undefine
them in config.sh. :) -- Larry Wall in <[email protected]>
 
P

Peter Wyzl

Larry Gates said:
I've used perl as a usenet client before, but now that I have a site out
there with an email address that is supposed to get to me, and I wanted to
look at it through the rubric of perl.

How would a person use perl to simulate what OE does?

What activestate modules are required for a given method? I would have to
think there would be as many ways to do this in perl as building a wall
for
a carpenter.

Anything with POP3 in it would be a starting point. But Perl is a language,
not a usenet client -- you mean you wrote a usenet client in Perl.

You can do POP3 with a telnet client if you wish, which would be a good
place to start how e-mail clients commincate with the servers.

P
 
T

Tim Greer

Larry said:
I've used perl as a usenet client before, but now that I have a site
out there with an email address that is supposed to get to me, and I
wanted to look at it through the rubric of perl.

How would a person use perl to simulate what OE does?

What activestate modules are required for a given method? I would
have to think there would be as many ways to do this in perl as
building a wall for a carpenter.

I believe you mean that you've used a usenet client coded in Perl.
Someone asked a similar question a month or two ago, and then stated
they wanted to actually do something else in the end. I assume you
mean exactly what your subject says, and that you want to use Perl to
code an email client? I don't know of any, but it's certainly
possible. I don't know where to suggest you start for Windows (using
ActiveState) though.
 
L

Larry Gates

I believe you mean that you've used a usenet client coded in Perl.
Someone asked a similar question a month or two ago, and then stated
they wanted to actually do something else in the end. I assume you
mean exactly what your subject says, and that you want to use Perl to
code an email client?
Yeah.
I don't know of any, but it's certainly
possible. I don't know where to suggest you start for Windows (using
ActiveState) though.

Gosh, I would have thought that writing an e-mail client in perl would be
as commonplace as ways to calculate pi with fortran.
 
P

Peter Wyzl

Gosh, I would have thought that writing an e-mail client in perl would be
as commonplace as ways to calculate pi with fortran.

Net::pOP3

From the docs:

SYNOPSIS
use Net::pOP3; # Constructors
$pop = Net::pOP3->new('pop3host');
$pop = Net::pOP3->new('pop3host', Timeout => 60); if
($pop->login($username, $password) > 0) {
my $msgnums = $pop->list; # hashref of msgnum => size
foreach my $msgnum (keys %$msgnums) {
my $msg = $pop->get($msgnum);
print @$msg;
$pop->delete($msgnum);
}
} $pop->quit;

--------------------------------------------------------------------------------

DESCRIPTION
This module implements a client interface to the POP3 protocol, enabling a
perl5 application to talk to POP3 servers. This documentation assumes that
you are familiar with the POP3 protocol described in RFC1939.

A new Net::pOP3 object must be created with the new method. Once this has
been done, all POP3 commands are accessed via method calls on the object.


Surely you can read the rest yourself...

P
 
M

M.O.B. i L.

Larry said:
I've used perl as a usenet client before, but now that I have a site out
there with an email address that is supposed to get to me, and I wanted to
look at it through the rubric of perl.

How would a person use perl to simulate what OE does?

What activestate modules are required for a given method? I would have to
think there would be as many ways to do this in perl as building a wall for
a carpenter.

I would use an IMAP client:
<http://search.cpan.org/search?query=imap&mode=all>.

It would enable me to transfer mails from one account to a GMail account
for backup. GMail uses IMAP with SSL (imap.gmail.com, port 993). I have
not done this myself yet and would also appeciate recommendations of
which modules actually work.
 
M

M.O.B. i L.

M.O.B. i L. said:
I would use an IMAP client:
<http://search.cpan.org/search?query=imap&mode=all>.

It would enable me to transfer mails from one account to a GMail account
for backup. GMail uses IMAP with SSL (imap.gmail.com, port 993). I have
not done this myself yet and would also appeciate recommendations of
which modules actually work.

I found one start to this:

#!/usr/bin/perl

# Based on a script on <http://www.perlmonks.org/?node_id=649742>.

use strict;
use warnings;
use Mail::IMAPClient;
use IO::Socket::SSL;

my %settings = (
IMAP => 'imap.gmail.com',
PORT => 993,
);
@ARGV == 2
or die 'Provide username and password for the IMAP server,'
. " on the command line.\n";
@settings{qw( USER PASS )} = @ARGV;

my $socket = IO::Socket::SSL->new(
PeerAddr => $settings{IMAP},
PeerPort => $settings{PORT},
) or die "socket(): $@";

my $client = Mail::IMAPClient->new(
Socket => $socket,
User => $settings{USER},
Password => $settings{PASS},
) or die "new(): $@";

print "Logged in\n" if $client->IsAuthenticated();
my @folders = $client->folders();
print join( "\n* ", 'Folders:', @folders ), "\n";

$client->logout();
 
L

Larry Gates

use strict;
use warnings;
use Mail::IMAPClient;
use IO::Socket::SSL;

Thanks for your response, mo. One of the hardest parts of getting one of
these projects rolling is figuring out how you're going to imitate the
modules that others use.

The trick for me is to get what I read here on usenet and my actual choices
with activestate to gybe.

When I google for "cpan email pop3" I can't get away from this page
http://kobesearch.cpan.org/htdocs/Email-Folder-POP3/Email/Folder/POP3.html

I do not have this module:

C:\MinGW\source> perl eml1.pl
Can't locate Email/Folder.pm in @INC (@INC contains: C:/Perl/site/lib
C:/Perl/li
b .) at eml1.pl line 1.
BEGIN failed--compilation aborted at eml1.pl line 1.

C:\MinGW\source>type eml1.pl
use Email::Folder;
use Email::FolderType::Net;

my $folder = Email::Folder->new('pop://user:p[email protected]:110');

print $_->header('Subject') for $folder->messages;

# perl eml1.pl
C:\MinGW\source>

What I do have is Mail::pOP3Client

http://lomas-assault.net/usenet/z10.jpg

I do now have POP3Client.pm in /site/lib/mail/.

Does anyone have experience with mail::pOP3Client? It's 42 k long as a .pm
file. If I'm trying to figure out how to use it without any better
documentation, how would I determine the methods?
--
larry gates

...sometimes collections of stupid utterances can be rather clever. If
my writings are ever published posthumously, they should probably be
called "A Collection of Stupid Utterances", or some such... :)
-- Larry Wall in <[email protected]>
 
L

Larry Gates

Net::pOP3

From the docs:

SYNOPSIS
use Net::pOP3; # Constructors
$pop = Net::pOP3->new('pop3host');
$pop = Net::pOP3->new('pop3host', Timeout => 60); if
($pop->login($username, $password) > 0) {
my $msgnums = $pop->list; # hashref of msgnum => size
foreach my $msgnum (keys %$msgnums) {
my $msg = $pop->get($msgnum);
print @$msg;
$pop->delete($msgnum);
}
} $pop->quit;

I had to download the Email::Folder::pOP3, but now I've got it and we're
rolling:

C:\MinGW\source>perl eml2.pl
Can't call method "login" on an undefined value at eml2.pl line 3.

C:\MinGW\source>

--------------------------------------------------------------------------------

DESCRIPTION
This module implements a client interface to the POP3 protocol, enabling a
perl5 application to talk to POP3 servers. This documentation assumes that
you are familiar with the POP3 protocol described in RFC1939.


What is Perl5?
A new Net::pOP3 object must be created with the new method. Once this has
been done, all POP3 commands are accessed via method calls on the object.


Surely you can read the rest yourself...

I'll get on it.
--
larry gates

And other operators aren't so special syntactically, but weird
in other ways, like "scalar", and "goto".
-- Larry Wall in <[email protected]>
 
L

Larry Gates


It certainly does:

C:\MinGW\source>perl eml3.pl
Can't locate Lingua/EN/Inflect.pm in @INC (@INC contains: C:/Perl/site/lib
C:/Pe
rl/lib .) at eml3.pl line 52.
BEGIN failed--compilation aborted at eml3.pl line 52.

C:\MinGW\source>type eml3.pl
#!/usr/bin/perl

use strict;
use warnings;

$| = 1;

use constant SEVERITY => 5;

use Mail::pOP3Client;
use Term::ReadKey;

my $user = shift;

my $pop = Mail::pOP3Client->new(HOST => '127.0.0.1', PORT => 9999);

my $pass = prompt_password();
print "\n";

$pop->User($user);
$pop->Pass($pass);
$pop->Connect or die $pop->Message;

my $count = $pop->Count;

$count >= 0 or die "Failed to get message count.\n";
$count > 0 or die "No messages in mailbox.\n";

my @to_delete;

print "Scanning messages: ";

my $to_delete = 0;
for my $msg_num (1 .. $count) {
my @headers = $pop->Head($msg_num);

for my $h (@headers) {
if($h =~ /^X-Spam-Level: (\*+)/) {
if(SEVERITY <= scalar ($1 =~ tr/*/*/)) {
$to_delete += 1;
$pop->Delete($msg_num);
print "\b*>";
} else {
print "\b->";
}
}
}
}

print "\b ... done\n";

use Lingua::EN::Inflect qw( PL );

if( $to_delete ) {
printf "%d %s will be deleted. Commit: [Y/N]?\n",
$to_delete, PL('message', $to_delete);
$pop->Reset unless yes();
}

$pop->Close;

print "OK\n";

sub yes {
while(my $r = <STDIN>) {
$r = lc substr $r, 0, 1;
return 1 if $r eq 'y';
next unless $r eq 'n';
last;
}
0;
}

sub prompt_password {
print 'Password: ';
ReadMode 2;
my $pass = ReadLine 0;
ReadMode 0;
chomp $pass;
return $pass;
}

__END__
# perl eml3.pl
C:\MinGW\source>

The good news here is that I see a bunch of goodies as far as POP3's
methods, and I don't fail until I get to:

use Lingua::EN::Inflect qw( PL );

What does this module do to filter out spam?
--
larry gates

Randal can write one-liners again. Everyone is happy, and peace spreads
over the whole Earth.
-- Larry Wall in <[email protected]>
 
T

Tad J McClellan

Larry Gates said:
What is Perl5?


The version of perl that came after version 4 of perl (perldoc perlhist).

Perl5 was a huge change to Perl, it introduced references and
lexical variables to the language for example.

For quite some time folks said "Perl5" rather than just "Perl" so that
readers would know not to try the code with "Perl4".
 
A

A. Sinan Unur

C:\MinGW\source>perl eml3.pl
Can't locate Lingua/EN/Inflect.pm in @INC (@INC contains:
C:/Perl/site/lib C:/Pe
rl/lib .) at eml3.pl line 52.
BEGIN failed--compilation aborted at eml3.pl line 52.

....

use Lingua::EN::Inflect qw( PL );

if( $to_delete ) {
printf "%d %s will be deleted. Commit: [Y/N]?\n",
$to_delete, PL('message', $to_delete);
$pop->Reset unless yes();
}
....

use Lingua::EN::Inflect qw( PL );

What does this module do to filter out spam?

Note that the only place the module is used is where I choose between
message/messages on the basis of the number of messages to delete.

It is unnecessary to pull in a whole module to do this just once
(obviously) but this code was meant as a demonstration.

Sinan
--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
L

Larry Gates

C:\MinGW\source>perl eml3.pl
Can't locate Lingua/EN/Inflect.pm in @INC (@INC contains:
C:/Perl/site/lib C:/Pe
rl/lib .) at eml3.pl line 52.
BEGIN failed--compilation aborted at eml3.pl line 52.

...

use Lingua::EN::Inflect qw( PL );

if( $to_delete ) {
printf "%d %s will be deleted. Commit: [Y/N]?\n",
$to_delete, PL('message', $to_delete);
$pop->Reset unless yes();
}
...

use Lingua::EN::Inflect qw( PL );

What does this module do to filter out spam?

Note that the only place the module is used is where I choose between
message/messages on the basis of the number of messages to delete.

It is unnecessary to pull in a whole module to do this just once
(obviously) but this code was meant as a demonstration.

Sinan

I see. I thought it was a means to characterize the dialect of spam:
tennis shoes, cheap flights, and so on.

So it says, message nixed? message hits the bitbucket? message adiosed?
--
larry gates

Personally, Rorschach blots always look like butterflies to me. Or
pelvis bones, I admit it.
-- Larry Wall, 8th State of the Onion
 
S

sln

On Sat, 07 Mar 2009 15:51:25 GMT, A. Sinan Unur wrote:
[cut the crap]
What does this module do to filter out spam?

Note that the only place the module is used is where I choose between
message/messages on the basis of the number of messages to delete.

It is unnecessary to pull in a whole module to do this just once
(obviously) but this code was meant as a demonstration.

Sinan

I see. I thought it was a means to characterize the dialect of spam:
tennis shoes, cheap flights, and so on.

So it says, message nixed? message hits the bitbucket? message adiosed?

You are indeed insane and have no job and are worthless worker with no
talent or skilz. If you had anything going for you, you wouldn't post here!
I know I do, but what are you?

-sln
 
L

Larry Gates

DESCRIPTION
This module implements a client interface to the POP3 protocol, enabling a
perl5 application to talk to POP3 servers. This documentation assumes that
you are familiar with the POP3 protocol described in RFC1939.

A new Net::pOP3 object must be created with the new method. Once this has
been done, all POP3 commands are accessed via method calls on the object.


Surely you can read the rest yourself...

It took me till now to realize that if you know a module's name, you can
get documentation on it by typing
perldoc Net ::pOP3

I tried to adapt their source snippet there, but I've hit on an error
that's got the better of me:

C:\MinGW\source> perl html5.pl
Use of uninitialized value in numeric gt (>) at html5.pl line 18.

C:\MinGW\source>type html5.pl
use strict;
use warnings;

use LWP::Simple;
use HTML::TreeBuilder;
use HTML::FormatText;
use Net::pOP3;

my $t = "http://www.lomas-assault.net";


my $host = 'pop.secureserver.net';
my $username = '(e-mail address removed)';
my $password = '';

my $pop = Net::pOP3->new( $host);

if ($pop->login($username, $password) > 0) {
my $msgnums = $pop->list; # hashref of msgnum => size
foreach my $msgnum (keys %$msgnums) {
my $msg = $pop->get($msgnum);
print @$msg;
#$pop->delete($msgnum);
}
}

$pop->quit;
# perl html5.pl

C:\MinGW\source>

Line 18 is
if ($pop->login($username, $password) > 0) {

I think of the error as usually having omitted a "my", but I think I've got
that base covered. ??
--
larry gates

Part of language design is purturbing the proposed feature in various
directions to see how it might generalize in the future.
-- Larry Wall in <[email protected]>
 
T

Tad J McClellan

Larry Gates said:
It took me till now to realize that if you know a module's name, you can
get documentation on it by typing
perldoc Net ::pOP3

I tried to adapt their source snippet there, but I've hit on an error
that's got the better of me:


That is not an error message.

It is a warning message.

C:\MinGW\source> perl html5.pl
Use of uninitialized value in numeric gt (>) at html5.pl line 18.


You can also use perldoc to look up messages that perl issues.


perldoc perldiag

Use of uninitialized value%s

(W uninitialized) An undefined value was used as if it were already
defined. It was interpreted as a "" or a 0, but maybe it was a mistake.
To suppress this warning assign a defined value to your variables.

To help you figure out what was undefined, perl tells you what operation
you used the undefined value in. Note, however, that perl optimizes your
program and the operation displayed in the warning may not necessarily
appear literally in your program. For example, C<"that $foo"> is
usually optimized into C<"that " . $foo>, and the warning will refer to
the C<concatenation (.)> operator, even though there is no C<.> in your
program.

I think of the error as usually having omitted a "my",


No, the message you get for violating "use strict" like that is:

Global symbol "%s" requires explicit package name

(F) You've said "use strict vars", which indicates that all variables
must either be lexically scoped (using "my"), declared beforehand using
"our", or explicitly qualified to say which package the global variable
is in (using "::").
 
T

Todd Wade

Gosh, I would have thought that writing an e-mail client in perl would be
as commonplace as ways to calculate pi with fortran.

Great! Because it is. Your OP dosen't give enough information to tell
us what it is that you want to do (generate a .csv file based on
emails in an IMAP folder? Call the police when your security system
emails you that someone has broke in?) so you are getting very little
feedback and the feedback you are getting is very general.

I would have thought that someone posting general questions in a
technical newsgroup wouldn't be surprised when they get general
responses :0)

trwww
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top