Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use Net::POP3;
  4. use DBI;
  5.  
  6. my $pop = Net::POP3->new('mail.server.com') or
  7. die "shit, I can't connectn";
  8.  
  9. my $dbh = DBI->connect('DBI:mysql:databasename', 'username', 'password'
  10. ) || die "Could not connect to database: $DBI::errstr";
  11.  
  12.  
  13. if ($pop->login( 'username' , 'pass' ) > 0) {
  14. my $msgnums = $pop->list;
  15. MESSAGE: foreach my $msgnum (keys %$msgnums) {
  16. my $msg = $pop->get($msgnum);
  17.  
  18. my ( $firstName, $lastName, $idNum );
  19.  
  20. if( $msg =~ /^Name:s+([a-zA-Z]+)s+([a-zA-Z]+)/){
  21. $firstName = $1;
  22. $lastName = $2;
  23. }
  24. if ( $msg =~ /^ID Number:s+([0-9]+)/ ){
  25. $idNum = $1;
  26. }
  27.  
  28. $dbh->do('INSERT INTO exmpl_tbl VALUES( ? , ? , ?)', undef, ($firstName, $lastName, $idNum));
  29.  
  30. $pop->delete($msgnum);
  31. next MESSAGE;
  32.  
  33. }
  34. }
  35.  
  36. $pop->quit;
  37. exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement