[Perl Tk] Gmail Inbox 0.1

Iniciado por BigBear, Abril 28, 2012, 11:47:05 AM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Abril 28, 2012, 11:47:05 AM Ultima modificación: Marzo 14, 2015, 10:20:48 AM por Expermicid
Un simple programa en Perl para leer el correo usando Gmail.

Una imagen



El codigo

Código: perl

#!usr/bin/perl
#Gmail Inbox 0.1
#Version Tk
#Coded By Doddy H
#Modules
#ppm install http://www.open.com.au/radiator/free-downloads/Net-SSLeay.ppd
#http://search.cpan.org/~sullr/IO-Socket-SSL-1.54/SSL.pm
#http://search.cpan.org/~fays/GMail-Checker-1.04/Checker.pm

use Tk;
use Tk::HList;
use Tk::ROText;
use GMail::Checker;
use HTML::Strip;

if ( $^O eq 'MSWin32' ) {
    use Win32::Console;
    Win32::Console::Free();
}

my $yeahfucktk = MainWindow->new();
$yeahfucktk->title(
    "Gmail Inbox 0.1 || Coded by Doddy H || [+] Status : <None>");
$yeahfucktk->geometry("870x220+20+20");
$yeahfucktk->resizable( 0, 0 );

my $agen = $yeahfucktk->Scrolled( HList,
    -columns    => 4,
    -header     => 1,
    -width      => 80,
    -scrollbars => "se"
)->place( -x => 20, -y => 20 );

$agen->headerCreate( 0, -text => "ID" );
$agen->headerCreate( 1, -text => "From" );
$agen->headerCreate( 2, -text => "Subject" );
$agen->headerCreate( 3, -text => "Date" );

$agen->bind( "<Double-1>", [ \&yeah ] );

$yeahfucktk->Label( -text => "Gmail Login", -font => "Impact" )
  ->place( -x => 650, -y => 20 );
$yeahfucktk->Label( -text => "Username : ", -font => "Impact1" )
  ->place( -x => 565, -y => 68 );
my $username = $yeahfucktk->Entry( -width => 30 )->place( -x => 653, -y => 73 );
$yeahfucktk->Label( -text => "Password : ", -font => "Impact1" )
  ->place( -x => 565, -y => 100 );
my $password =
  $yeahfucktk->Entry( -width => 30, -show => "*" )
  ->place( -x => 653, -y => 103 );
$yeahfucktk->Button(
    -text    => "Messages list",
    -width   => 20,
    -command => \&startnow
)->place( -x => 640, -y => 150 );

MainLoop;

sub startnow {
    $agen->delete( "all", 0 );
    my $total = total( $username->get, $password->get );
    $yeahfucktk->title(
"Gmail Inbox 0.1 || Coded by Doddy H || [+] Status : $total messages found"
    );

    for ( reverse 1 .. $total ) {
        $yeahfucktk->update;
        $yeahfucktk->title(
"Gmail Inbox 0.1 || Coded by Doddy H || [+] Status : Getting message $_"
        );
        my ( $from, $asunto, $date ) =
          getdata( $username->get, $password->get, $_ );

        $agen->add($_);
        $agen->itemCreate( $_, 0, -text => $_ );
        $agen->itemCreate( $_, 1, -text => $from );
        $agen->itemCreate( $_, 2, -text => $asunto );
        $agen->itemCreate( $_, 3, -text => $date );

    }
    $yeahfucktk->title(
        "Gmail Inbox 0.1 || Coded by Doddy H || [+] Status : <None>");
}

sub total {
    my $mod_total = new GMail::Checker( USERNAME => $_[0], PASSWORD => $_[1] );
    my ( $a, $b ) = $mod_total->get_msg_nb_size("TOTAL_MSG");
    return $a;
}

sub getdata {

    my $mod_msg = new GMail::Checker( USERNAME => $_[0], PASSWORD => $_[1] );
    my @msg = $mod_msg->get_msg( MSG => $_[2] );

    my $mas = $msg[0]->{headers};

    if ( $mas =~ /From: (.*)/ig ) {
        $from = $1;
    }

    if ( $mas =~ /Subject: (.*)/ig ) {
        $asunto = $1;
    }

    if ( $mas =~ /Date: (.*)/ig ) {
        $date = $1;
    }
    return ( $from, $asunto, $date );
}

sub yeah {
    my @ar = $agen->selectionGet();
    openmessage( $username->get, $password->get, $ar[0] );
}

sub openmessage {

    my $cons = MainWindow->new();
    $cons->geometry("500x350+20+20");
    $cons->resizable( 0, 0 );
    $cons->title("Reading message");

    my $conso = $cons->Scrolled(
        "ROText",
        -width      => 70,
        -height     => 40,
        -scrollbars => "e"
    )->pack();

    my $mod_msg = new GMail::Checker( USERNAME => $_[0], PASSWORD => $_[1] );

    my @msg = $mod_msg->get_msg( MSG => $_[2] );

    $conso->insert( "end", "[+] ID : $_[2]\n" );

    my $mas = $msg[0]->{headers};

    if ( $mas =~ /From: (.*)/ig ) {
        my $from = $1;
        $conso->insert( "end", "[+] From : $from\n" );
    }

    if ( $mas =~ /To: (.*)/ig ) {
        my $to = $1;
        $conso->insert( "end", "[+] To : $to\n" );
    }

    if ( $mas =~ /Subject: (.*)/ig ) {
        my $asunto = $1;
        $conso->insert( "end", "[+] Subject : $asunto\n" );
    }

    if ( $mas =~ /Date: (.*)/ig ) {
        my $date = $1;
        $conso->insert( "end", "[+] Date : $date\n\n" );
    }

    my $text = $msg[0]->{body};
    if ( $text =~
        /<body class=3D'hmmessage'><div dir=3D'ltr'>(.*?)<\/div><\/body>/sig )
    {
        my $body = $1;
        $body =~ s/<br>/\n/g;

        my $uno = HTML::Strip->new( emit_spaces => 1 );
        my $body = $uno->parse($body);
        $conso->insert( "end", $body );
    }
}

#The End ?