#!c:\perl\bin #Author: James Williamson #Date: 14/09/2010 #Purpose: Downloads all PMs from an Instructables.com inbox and saves them as files appropriate to open in Thunderbird #Required: Mechanize, LWP use WWW::Mechanize; #available free from cpan.org ########## Settings ########## #### fill these in please #### my $username = "Jayefuu"; my $password = "password"; my $directory = 'C:/messages/'; #Where would you like your new emails dumped? ############################## print "Ignore this line:\n"; #log in to your instructables account to access pro features my $url = "http://www.instructables.com/account/login"; my $mech = WWW::Mechanize->new(); $mech->get($url); $mech->form_name('LoginFORM'); #tells Mechanize which form to fill in $mech->field(u => $username); #tells Mechanize which field to fill in and what to put in it $mech->field (p => $password); #as above, but for the password $mech->click(); #DO IT!!! #check you're logged in $url = "http://www.instructables.com/you"; $mech->get($url); $contents = $mech->content(); if ($contents =~ m:welcome $nickname:){ print "Successfully logged in.\n\n"; } else{ print "Login failed!"; die; } #visit your inbox $url = "http://www.instructables.com/you/inbox/"; $mech->get($url); $contents = $mech->content(); #find the total number of PMs in the inbox my $total_pms=0; if ($contents =~ m:1-10 of ([0-9]*)<\/span>:){ $total_pms = $1; } #an array to hold all of the URLs to PMs my @msgs_urls; print "Searching your inbox...\n"; #iterate through all of the pages in your inbox grabbing the URLs and stuffing them into the array for ($i=0;$i<=$total_pms;$i+=10){ if ($i%100==0){ print "$i messages found... searching...\n"; } $url="http://www.instructables.com/you/inbox?sort=&limit=10&offset=$i"; $mech->get($url); $contents = $mech->content(); @templist = ($contents =~ m: name=\"messagesIds\" value=\"(.*)\" \/><\/span>:g); #pushes each element of the temporary array into the permanent list of the user's ibles foreach (@templist){ push (@msgs_urls,$_); } undef(@templist); #get the first 10 PM links then start iterating through the pages grabbing more } print "$total_pms messages found\n"; print "Downloading messages... this could take a while... (2 secs per message)\n"; my $sender; my $subject; my $date; my $body; $j=0; # now iterate through the list of links# foreach (@msgs_urls){ $url="http://www.instructables.com/you/inbox?view=$_"; $mech->get($url); $contents = $mech->content(); if ($contents =~ m:class=\"bright\" href=\"/member/.*/\">(.*)<\/a><\/b><\/div>:){ $sender = $1; } if ($contents =~ m:<\/div>
(.*)<\/b><\/div>
:){ $subject = $1; } if ($contents =~ m:<\/div>
(\w{3} [0-9]{1,2}, [0-9]{4}. [0-9]{1,2}\:[0-9]{2} \w{2})<\/div>
:){ $date = $1; } #
if ($contents =~ m:<\/div>
(.*)<\/b><\/div>
((.*\n)*.*)
$file"); #Opens the file #paste in bits print INFO "Received:\n"; print INFO "Return-Path:\n"; print INFO "Return-path: \n"; print INFO "Envelope-to: \n"; print INFO "Delivery-date: \n"; print INFO "Received: \n"; print INFO "Received: \n"; print INFO "Received:\n"; print INFO "DKIM-Signature:\n"; print INFO "DomainKey-Signature:\n"; print INFO "MIME-Version: 1.0\n"; print INFO "Received: \n"; print INFO "Received:\n"; print INFO "Date: $date\n"; print INFO "Message-ID: \n"; print INFO "Subject: $subject\n"; print INFO "From: $sender <$sender\@notinstructables.com>\n"; print INFO "To: $username <$username\@notinstructables.com>\n"; print INFO "Content-Type: multipart/alternative; boundary=0016e6464ec464c295048fbe77c3\n"; print INFO "X-ZenAWL-Match: false\n"; print INFO "X-Zen-Test-Spam-Score: 10\n"; print INFO "X-Zen-Test-Spam-Bar: (+)\n"; print INFO "X-Originating-Bastion02-IP:]\n"; print INFO "X-Envelope-From: \n"; print INFO "X-Envelope-To: \n"; print INFO "X-Apparently-To: \n"; print INFO "X-Zen-Loop2: e70170adfabfe217f93891ad66215081\n"; print INFO "X-Rcpt-To: \n"; print INFO "\n"; print INFO "--0016e6464ec464c295048fbe77c3\n"; print INFO "Content-Type: text/plain; charset=ISO-8859-1\n"; print INFO "\n"; print INFO "\n"; print INFO "\n"; print INFO "--0016e6464ec464c295048fbe77c3\n"; print INFO "Content-Type: text/html; charset=ISO-8859-1\n"; print INFO "\n"; print INFO "$body\n"; print INFO "Reply\n"; print INFO "\n"; print INFO "--0016e6464ec464c295048fbe77c3--\n"; print INFO "\n"; #close file close INFO; $j++; if ($j%10==0){ print "$j of $total_pms downloaded..."; } }