#!/usr/bin/perl # # # Yahoo!-Ripper Version 1.2 # # # Be sure to define the $popuser/pass/server variables # Change $mainfolder to where you want the main folder of the downloads to be. # or the root directory u want subfolders to be created for the attachments of the Yahoo! # Groups to be stored. # # # v1.0 [ Known Bugs ] # Username was asked for and stored in $username, when program uses $popuser. # # [ Features ] # Downloads emails from a pop server # Stores attachments from groups into proper group folders [KeyHack-Fan-Club], a zip from this group # would be stored in the directory specified, with a subdirectory titled "KeyHack-Fan-Club" # Creates the group directories if they dont exist already. # # [ Features To Come in 1.1 ] # Deletion of emails from server when done downloading. # All new email are stored into group folders, sub folder titled "NEW" and remain in there until # midnight then moved into the proper folders, and the next 24 hours all new email are # stored in the NEW folder. # Runs in the background. # # # v1.1 [ Never Released ] # # Version 1.1 was never released because I worked on 1.2 right after and found out that # 1.2 works a lot better than 1.1 with less bugs, so I never released 1.1 # (if u want version 1.1, email me at keyhack@users.sourceforge.net and I can email it to you) # # v1.2 [ Known Bugs ] # No known bugs. # # [ Features ] # Removes emails from sever onces ALL emails have been successfully downloaded. (asks user) # If the file exists, then it appends a "(1)" to it, if THAT exists, then "(2)"... etc... # Cleaner forefront (colors and status). [Console version] # # [ Features To Come in 1.3 ] # Heavy commentation on the perl code so you can learn from my project. # The "New" folder method stated in [Features to come in 1.1] above. # # # # # How to run v1.2: # # perl yahoo-ripper-1.2.pl <-C> # # If you do not specify the -C flag then the program will run as a console application, not the GUI version. # If you specify the -C flag then the program will run in Xwindows. [WILL BE DONE IN 1.3!] # # Author - KeyHack $popuser = "username"; $poppass = "password"; $popserver = "pop.mail.yahoo.com"; $mainfolder = "/home/user/yahoogroups/"; #make sure to have the / at the end!!!! # set $deleteemails to "a" to have the program ask the user # set $deleteemails to "n" to have the program leave emails on server # set $deleteemails to "y" to have the program remove emails from server $deleteemails = 'a'; # DO NOT MODIFY PAST THIS POINT UNLESS YOU KNOW WHAT YOU ARE DOING # Load the modules for this program and initiate required variables. use Term::ANSIColor; use MIME::Base64; use Net::POP3; $false = 0; $true = 1; # In console mode, display data and receive data via console system("clear"); print color 'white'; print "Yahoo-Ripper version 1.2 created by "; print color 'bold blue'; print "KeyHack (keyhack\@users.sourceforge.net)\n"; print color 'reset'; if ($popuser eq '') { print ("Please enter the username of the POP server.\n"); $popuser = ; chop ($popuser); } if ($poppass eq '') { print ("Please enter the password of the POP server.\n"); system ("stty -echo"); $poppass = ; system ("stty echo"); chop ($poppass); } if ($popserver eq ''){ print ("Please enter the server address of the POP server.\n"); $popserver = ; chop ($popserver); } print color 'bold green'; print "Connecting to POP server -> "; print color 'reset'; print $popserver, "\n"; my $pop = Net::POP3->new($popserver); #initiates the connection to the POP server print color 'bold green'; print "Logging into POP server -> "; print color 'reset'; print $popuser, "\n"; my $numofmess = $pop->login($popuser,$poppass); #sends login information, returns value of # of messages on server if ($numofmess eq '0E0') { # OEO means there are no messages (bool. for false I believe, and scalar for 0) # an error in login $numofmess will be eq ''!!! print color 'bold red'; print "There are no new emails.\n"; print color 'reset'; exit; } if ($numofmess eq '') { # Bad login print color 'bold red'; print "INVALID USERNAME PASSWORD COMBINATION.\n"; print color 'reset'; exit; } print "You have ", $numofmess, " emails on your server. Now downloading...\n"; my $counter = 1; while ($counter <= $numofmess){ my $messagearray = $pop->get($counter); foreach my $liner (@$messagearray) { if ($writingfile == 1) { if ($liner =~ /^\/9j\//) { $writingfile = 2; if (open(FILE1, $mainfolder . $subject . "/" . $filename)) { # We cannot open the file for writing because a file in this directory # already exists with this name, so we append a number to the filename # until it doesnt exist, then we use that to write out data. close(FILE1); $filecount = 1; $dotpoint = index($filename,".",0); $prefilename = substr($filename,0,$dotpoint); $postfilename = substr($filename,$dotpoint+1,length($filename)-$dotpoint-1); while (open(FILE1, $mainfolder . $subject . "/" . $prefilename . "(" . $filecount . ")." . $postfilename)) { close(FILE1); $filecount++; } $filename = $prefilename . "(" . $filecount . ")." . $postfilename; } open(FILE1,">" . $mainfolder . $subject . "/" . $filename); $sizesetter = length($liner); } } if ($writingfile == 2) { if (length($liner) < $sizesetter) { print FILE1 $liner; close (FILE1); $writingfile = 0; open(FILE1, $mainfolder . $subject . "/" . $filename); my @thefile = ; close(FILE1); $todecode = join "", @thefile; $decoded = decode_base64($todecode); open(FILE1,">" . $mainfolder . $subject . "/" . $filename); print FILE1 $decoded; close(FILE1); print color 'green'; print "Wrote the file --> "; print color 'reset'; print $mainfolder . $subject . "/" . $filename . "\n"; goto SKIPPER; } print FILE1 $liner; } if ($liner =~ /^ name=/) { if ($findname == 1) { $filename = substr($liner,7,length($liner)-9); $writingfile = 1; } } if ($liner =~ /^Subject:/) { my @list = split(/ /, $liner); if (substr($list[1],0,1) eq '[') { $subject = substr($list[1],1,length($list[1])-1); $subject = substr($subject,0,length($subject)-1); } else { my $subject = $list[1] } if (opendir(DIR, $mainfolder . $subject)) { } else { mkdir ($mainfolder . $subject, 0770); } } if ($liner =~ /^Content-Type:/) { my @list = split(/ /,$liner); if (substr($list[2],0,5) eq 'name=') { $filename = substr($list[2],6,length($list[2])-7); $filename = substr($filename,0,length($filename)-1); $findname = 0; $writingfile = 1; #print $filename, "\n"; } else { $findname = 1; } } SKIPPER: } $pop->delete($counter); $counter++; } print "Successfully extracted attachments.\n"; if ($deleteemails eq 'a') { print "Do you wish to remove the emails from the server? (y/n) -> "; $yesorno = ; chop ($yesorno); if ($yesorno eq 'y') { print color 'bold green'; print "Emails deleted.\n"; print color 'reset'; $pop->quit; exit; } else { print color 'bold red'; print "Emails saved.\n"; print color 'reset'; $pop->reset; exit; } } if ($deleteemails eq 'y') { print color 'bold green'; print "Emails deleted.\n"; print color 'reset'; $pop->quit; exit; } else { print color 'bold red'; print "Emails saved.\n"; print color 'reset'; $pop->reset; exit; } die "ERROR: Line executed but should not have been reached. [YahooConsole]"; sub YahooGtk { # This is the GTK Version of the program $window = new Gtk::Window("toplevel"); $window->signal_connect("destroy",sub { Gtk->exit(0); } ); $window->set_title("Yahoo-Ripper v1.2"); $window->border_width(15); $statuslabel = new Gtk::Label("Connecting to server -> " . $popserver); $window->add($statuslabel); $window->show_all(); main Gtk(); # die "No GTK support yet."; }