Guest User

Untitled

a guest
May 30th, 2018
1,005
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. # Put this in ~/.gmail/ and use "crontab -e" to add something like
  4. # "* * * * * ~/.gmail/gmail.pl > /dev/null" to run it every minute.
  5. # ${exec cat ~/.gmail/.gmail_top} shows your inbox in Conky.
  6. # Note that this was intended to be used with Gmail or any other
  7. # ssl-enabled pop3 server.
  8.  
  9. # beginning of configuration
  10.  
  11. # pop3 host
  12. $pop_host = "pop.gmail.com";
  13.  
  14. # pop3 username (for Gmail, I didn't have to put @gmail.com at the end)
  15. $pop_user = "user";
  16.  
  17. # pop3 password
  18. $pop_pass = "Password";
  19.  
  20. # ssl port number (995 is what Gmail uses)
  21. $ssl_port = "995";
  22.  
  23. # ssl protocol
  24. $ssl_prot = "tcp";
  25.  
  26. # number of emails to show
  27. $dis_numb = "6";
  28.  
  29. # end of configuration
  30.  
  31. use Mail::POP3Client;
  32. use IO::Socket::SSL;
  33.  
  34. my $socket = IO::Socket::SSL->new( PeerAddr => $pop_host,
  35. PeerPort => $ssl_port,
  36. Proto => $ssl_prot);
  37. my $pop = Mail::POP3Client->new();
  38. $pop->User($pop_user);
  39. $pop->Pass($pop_pass);
  40. $pop->Socket($socket);
  41. $pop->Connect();
  42.  
  43. $msg_count = $pop->Count();
  44.  
  45. for ($i = $msg_count, $j = 0; $i >= $msg_count-($dis_numb-1); $i--, $j++) {
  46. foreach ( $pop->Head( $i ) ) {
  47. #/^(From|Subject):\s+/i and print $_, "\n";
  48. if ($_ =~ m/^From:/) {
  49. ($from) = ($_ =~ m#^From: .*<(.*)>#);
  50. $from = substr($from, 0, 30);
  51. $out .= "$j = $from\n";
  52. }
  53. }
  54. #chop $out;
  55. `echo -e "$out"> ~/.gmail/.gmail_top`;
  56. }
  57.  
  58. $pop->Close();
Add Comment
Please, Sign In to add comment