Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Hotmail Login/Forwarding Script

by Anonymous Monk
on Aug 30, 2004 at 20:03 UTC ( #387017=sourcecode: print w/ replies, xml ) Need Help??

Category:
Author/Contact Info fockjef@gmail.com
Description: this script will login to hotmail and forward all messages that are unread to whatever email address you want. you need to set your options in hotmail to the advanced view so that there is a link to view the email source. the script requires sendmail so its probably best to run it from a *nix box (i have it run as a cron job every 30 minutes). this also requires the LWP bundle as well as the Crypto::SSLeay module (for the https). You could set it up to use Sockets to talk to the mail server directly and lots of servers are picky about who they allow (i tried but it messed up sometimes). Any improvements are welcome and i hope this helps some people.
#!/usr/bin/perl

$user = 'username';        # hotmail user name
$pass = 'password';        # hotmail password
$addr = 'fwdaddress@foo.com';    # forwarding address
$delay = 30;            # delay (in seconds) between sending messages
$delete_messages = 0;        # 0/1 => don't/do delete messages from th
+e hotmail account

require LWP::UserAgent;
require HTTP::Cookies;

# set up our super cool web browser
$ua = LWP::UserAgent->new;
push @{$ua->requests_redirectable}, 'POST';
$ua->cookie_jar(HTTP::Cookies->new({}));
$ua->agent("yellow rubber ducky");

# let's get some "hot" mail
$html = $ua->get('http://www.hotmail.com')->content;

# we don't need no stinkin' javascript
while( $html =~ s/<input type=hidden name="([^"]*)" value="([^"]*)">//
+ ){
    $form{$1} = $2;
}
$html = $ua->post( 'http://login.passport.net/uilogin.srf?id=2', \%for
+m)->content;

# log on in
$html =~ /<form TARGET="_top" name="hotmail_com" action="([^"]*)"/;
$html = $ua->post( $1, ['login'         => $user,
                        'passwd'        => $pass,
                        'domain'        => 'hotmail.com',
                        'sec'           => '',
                        'mspp_shared'   => '',
                        'padding'       => substr( "xxxxxxxxxxxxxxxx",
+0, 16-length($pass))])->content;

# follow the magic meta
$html =~ /<META HTTP-EQUIV="REFRESH" CONTENT="0; URL=([^"]*)"/;
$html = $ua->get($1)->content;

# we definetly don't need no stinking internet explorer
$html =~ /<form name="cont" action="([^"]*)"/;
$html = $ua->post( $1, ['curmbox'       => 'F000000001', 
                        'HrsTest'       => ''])->content;
$base = $1;
$base =~ s/\/cgi-bin\/.*//;

# find out where we can get our free massages
$html =~ /_UM = "([^"]*)"/;
$UM = $1;
while( $html =~ s/<a href="javascript:G\('(\/cgi-bin\/getmsg?[^']*)'//
+ ){
    if( $1 !~ /msgread/ ){
        push @messes, $1;
    }
}

# get the whole mess
foreach $mess(@messes){
    $html = $ua->get($base.$mess."&".$UM)->content;

    # junk it
    if( $delete_messages ){
        $html =~ /<a href="#" onclick="G\('([^']*)'.*>Delete<\/a>/;
        $ua->get($base.$1."&".$UM);
    }
    
    # go straight to the source (set the options for advanced view)
    $html =~ /<a href="([^"]*)" target="_blank">View E-mail Message So
+urce<\/a>/;
    $html = $ua->get($1)->content;
    $html =~ /<A HREF="([^"]*)">here<\/A>/;
    $html = $ua->get($1)->content;

    # clean up the mess
    $html =~ s/<pre>\s*([\w\W]*)<\/pre>[\w\W]*/$1/;
    $html =~ s/&quot;/"/gi;
    $html =~ s/&lt;/</gi;
    $html =~ s/&gt;/>/gi;
    $html =~ s/&amp;/&/gi;
    $html =~ s/\n\.\n/\n .\n/g;
    $html =~ s/(\s+)To:.*/$1To: $addr/;

    open MAIL, "|/usr/sbin/sendmail -t";
    print MAIL $html;
    close MAIL;

    sleep($delay);
}

Comment on Hotmail Login/Forwarding Script
Download Code

Back to Code Catacombs

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2014-12-27 04:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls