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]%

In reply to Read Gmail Through A Proxy[Solved-ish] by varneraa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.