Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -w
- use strict;
- use Net::POP3;
- use DBI;
- my $pop = Net::POP3->new('mail.server.com') or
- die "shit, I can't connectn";
- my $dbh = DBI->connect('DBI:mysql:databasename', 'username', 'password'
- ) || die "Could not connect to database: $DBI::errstr";
- if ($pop->login( 'username' , 'pass' ) > 0) {
- my $msgnums = $pop->list;
- MESSAGE: foreach my $msgnum (keys %$msgnums) {
- my $msg = $pop->get($msgnum);
- my ( $firstName, $lastName, $idNum );
- if( $msg =~ /^Name:s+([a-zA-Z]+)s+([a-zA-Z]+)/){
- $firstName = $1;
- $lastName = $2;
- }
- if ( $msg =~ /^ID Number:s+([0-9]+)/ ){
- $idNum = $1;
- }
- $dbh->do('INSERT INTO exmpl_tbl VALUES( ? , ? , ?)', undef, ($firstName, $lastName, $idNum));
- $pop->delete($msgnum);
- next MESSAGE;
- }
- }
- $pop->quit;
- exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement