Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Read Gmail Through A Proxy[Solved-ish]

by varneraa (Initiate)
on Aug 05, 2013 at 22:58 UTC ( #1048009=perlquestion: print w/ replies, xml ) Need Help??
varneraa has asked for the wisdom of the Perl Monks concerning the following question:

Update: Looks like the issue is likely with the proxy server. I posted this question in reddit, and someone tested my code. After digging into the proxy settings it looks like the gmail imap port(993) doesn't have a mapping. Thanks to anyone that took a look.

I've been trying to develop a simple script that will search through my email to parse the body of email status updates I get every few hours. The long term goal of which is to automatically load the data to a spreadsheet for some trend analysis. I found what I was hoping would be a good example on CPAN in Net::IMAP::Simple. I've taken the example from that module and started to adapt it to my situation. The specific issue being the proxy server I am trying to execute the script from behind. I wasn't able to find an example of someone else doing this, but my google-fu may have been weak today. What I did end up finding was IO::Socket::Socks::Wrapper, which I thought would wrap all traffic and thus abstract the proxy from the rest of the script. With all that in place I get a "Broken Pipe" and the script exits while trying to authenticate my username/password.

#!/usr/intel/bin/perl use strict; use warnings; # fill in your details here my $username = 'username@gmail.com'; my $password = 'password'; my $mailhost = 'imap.gmail.com'; my $mailport = 993; my $proxyhost = 'proxy-address'; my $proxyport = 1080; print "Proxy...\n"; use IO::Socket::Socks::Wrapper( { ProxyAddr => $proxyhost, ProxyPort => $proxyport, SocksDebug => 1, Timeout => 100 } ); # required modules use Net::IMAP::Simple; use Email::Simple; use IO::Socket::SSL; print "Proxy...\n"; use IO::Socket::Socks::Wrapper( { ProxyAddr => $proxyhost, ProxyPort => $proxyport, SocksDebug => 1, Timeout => 100 } ); # required modules use Net::IMAP::Simple; use Email::Simple; use IO::Socket::SSL; print "Connecting...\n"; # Connect my $imap = Net::IMAP::Simple->new( $mailhost, port => $mailport, use_ssl => 1 ) || die "Unable to connect to IMAP: $Net::IMAP::Simple::errstr\n"; print "Logging In...\n"; # Log in if ( !$imap->login( $username, $password ) ) { print STDERR "Login failed: " . $imap->errstr . "\n"; exit(64); } print "Selecting Folder...\n"; # Look in the the INBOX my $nm = $imap->select('Archive'); print "How Many Messages Are There...\n"; # How many messages are there? my ($unseen, $recent, $num_messages) = $imap->status(); print "unseen: $unseen, recent: $recent, total: $num_messages\n\n"; print "Quickly Look for unseen messages...\n"; ## Iterate through unseen messages for ( my $i = 1 ; $i <= $nm ; $i++ ) { if ( $imap->seen($i) ) { next; } else { my $es = Email::Simple->new( join '', @{ $imap->top($i) } ); printf( "[%03d] %s\n\t%s\n", $i, $es->header('From'), $es->header( +'Subject') ); } } print "Disconnect...\n"; # Disconnect $imap->quit; print "Exit...\n"; exit;

Here is what I see:

[131]% ~/gmail.pl Useless use of hash element in void context at lib/Net-IMAP-Simple-1.1 +7/lib/Net/IMAP/Simple.pm lin e 903. Proxy... Connecting... Logging In... Broken pipe [132]%

Comment on Read Gmail Through A Proxy[Solved-ish]
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1048009]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2015-07-28 01:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (251 votes), past polls