Nach einem Posting von <tmohr AT s.netic.de>:

Der Autor verwendet fetchmail

KPPP bietet den Schalter "Ausführen nach Login..."

Gewünscht wären:

use Mail::POP3Client;
use Tk;

$user = "tmohr+s.netic.de";
$pass = "";
$host = "mail.s.netic.de";
$port = 110;
$debug = 0;
$time = 20;

$annoy_size = 100000;

$fetchmail = "/usr/bin/fetchmail";
$zsatz = "-adobe-courier-medium-r-normal--12-100-100-100-m-90-iso8859-1";
$width = 80;

$subj_text = "Subject: ";
$from_text = "From: ";
$to_text = "To: ";
$date_text = "Date: ";
$size_text = "Size: ";

$subj_no = "No Subject line";
$from_no = "No From line";
$to_no = "No To line";
$date_no = "No Date line";
$size_no = "No Size ?!?";

$connected = 0;

$old_id = -1;

$subj_label = $subj_text;
$from_label = $from_text;
$to_label = $to_text;
$date_label = $date_text;
$size_label = $size_text;


$mw = MainWindow->new();
$mw->title("Kill incoming mail");
$up = $mw->Frame();
$dn = $mw->Frame();
$info = $mw->Frame();

$pw_label = $up->Label(-text => "Password:");
$pw_label->pack(-side => "left", -fill => "x", -expand => "yes");

$pw_entry = $up->Entry(-show => '*', -width => 16, -font => $zsatz,
        -textvariable => \$pass, -takefocus => 1);
$pw_entry->pack(-side => "left", -fill => "x", -expand => "yes");
$pw_entry->focus();


$up->pack(-side => "top", -anchor => "w");

$read_bn = $dn->Button(-text => "Look up", -command => \&readmsg_in);
$read_bn->pack(-side => "left", -fill => "x", -expand => "yes");

$kill_bn = $dn->Button(-text => "Kill", -command => \&delete_msg);
$kill_bn->pack(-side => "left", -fill => "x", -expand => "yes");

$go_bn = $dn->Button(-text => "Fetch", -command => \&go);
$go_bn->pack(-side => "left", -fill => "x", -expand => "yes");

$quit_bn = $dn->Button(-text => "Quit", -command => \&ex );
$quit_bn->pack(-side => "left", -fill => "x", -expand => "yes");



#$debug_bn = $dn->Button( -text => "Debug", -command => \&dbg);
#$debug_bn->pack(-side => "left", -fill => "x", -expand => "yes");

$dn->pack(-side => "bottom", -fill => "x", -expand => "no");

$subj_lb = $info->Label(-textvariable => \$subj_label, -font => $zsatz);
$subj_lb->pack(-side => "top", -anchor => "w");

$from_lb = $info->Label(-textvariable => \$from_label, -font => $zsatz);
$from_lb->pack(-side => "top", -anchor => "w");

$to_lb = $info->Label(-textvariable => \$to_label, -font => $zsatz);
$to_lb->pack(-side => "top", -anchor => "w");

$date_lb = $info->Label(-textvariable => \$date_label, -font => $zsatz);
$date_lb->pack(-side => "top", -anchor => "w");

$size_lb = $info->Label(-textvariable => \$size_label, -font => $zsatz);
$size_lb->pack(-side => "top", -anchor => "w");

$info->pack(-side => "bottom", -anchor => "w");

$lb = $mw->Listbox(-selectmode => "multiple",
        -font => $zsatz,
        -selectforeground => "red",
        -selectbackground => "grey90");
$lb->pack(-side => "left", -fill => "both", -expand => "yes");

$sc = $mw->Scrollbar();
$sc->pack(-side => "right", -fill => "y");

$sc->configure(-command => ['yview', $lb]);

$lb->configure(-width => $width, # -height => $height,
                -yscrollcommand => ['set', $sc]);

$lb->bind("<Motion>", [ \&motion, Ev("y") ]);
BindMouseWheel($lb);


MainLoop;


sub dnect {
        if($connected) {
                $pop->Close();
                $connected = 0;
        }
}

sub cnect {
        if(!$connected) {
                $pop = new Mail::POP3Client(
                        USER => $user,
                        PASSWORD => $pass,
                        HOST => $host,
                        PORT => $port,
                        DEBUG => $debug,
                        TIMEOUT => $time);

                if($pop->Connect()) {
                        $connected = 1;
                        print "connected\n";
                }
                else {
                        $connected = 0;
                        print "can't connect :'$pop->Message()'\n";
                }
        }
}

sub motion {
        $id = $lb->nearest($_[1]);
        if($old_id != $id) {
                $old_id = $id;

                $subj_label = $subj_text . $subj[$id];
                $from_label = $from_text . $from[$id];
                $to_label = $to_text . $to[$id];
                $date_label = $date_text . $date[$id];
                $size_label = $size_text . $size[$id];
        }
}

sub ex {
        if($connected) {
                $pop->Reset();
        }
        dnect();
        exit;
}

sub delete_msg {
        del_msg();
        dnect();
        cnect();
        read_in();
}

sub del_msg {
        @list = $lb->curselection();
        foreach $i (@list) {
                $pop->Delete($i+1);
        }
}

sub go {
#       del_msg();
        dnect();
        system($fetchmail);
        exit;
}

sub dbg {
        print "\n####\n$list\n####\n";
        for($i = 0; $i < $n; $i++) {
                print "SUBJ: $subj[$i]\n";
                print "FROM: $from[$i]\n";
                print "TO:   $to[$i]\n";
                print "DATE: $date[$i]\n";
                print "SIZE: $size[$i]\n\n";
        }
}

sub readmsg_in {
        cnect();
        read_in();
}

sub read_in {
        $lb->delete(0, 'end');

        $n = $pop->Count();
        print "$n messages on server\n";

        # the list of the sizes of each mail
        $list = $pop->List();

        for($i = 0; $i < $n; $i++) {
                print "\r";
                $head[$i] = $pop->Head($i+1);
                $tmp = $i+1;
                print "read $tmp of $n messages";
        }
        print "\n";

        @sizes = split(/\n/, $list);
        foreach $line (@sizes) {
                if($line =~ /([0-9]*)[^0-9]+([0-9]*)/) {
                        $size[$1-1] = $2;
                }
        }

        for($i = 0; $i < $n; $i++) {
                # Subjekt
                if($head[$i] =~ /$subj_text(.*)/) {
                        $subj[$i] = $1;
                        $has_subj = 1;
                }
                else {
                        $subj[$i] = $subj_no;
                        $has_subj = 0;
                }

                # From
                if($head[$i] =~ /$from_text(.*)/) {
                        $from[$i] = $1;
                        $has_from = 1;
                }
                else {
                        $from[$i] = $from_no;
                        $has_from = 0;
                }

                # To
                if($head[$i] =~ /$to_text(.*)/) {
                        $to[$i] = $1;
                }
                else {
                        $to[$i] = $to_no;
                }

                # Date
                if($head[$i] =~ /$date_text(.*)/) {
                        $date[$i] = $1;
                }
                else {
                        $date[$i] = $date_no;
                }

                # Size
                if(!defined $size[$i]) {
                        $size[$i] = $size_no;
                        $sz = 0;
                }
                else {
                        $sz = $size[$i];
                }

                $subj[$i] =~ s/\n$//;
                $from[$i] =~ s/\n$//;
                $to[$i] =~ s/\n$//;
                $date[$i] =~ s/\n$//;
                $size[$i] =~ s/\n$//;

                $subj[$i] =~ s/\r$//;
                $from[$i] =~ s/\r$//;
                $to[$i] =~ s/\r$//;
                $date[$i] =~ s/\r$//;
                $size[$i] =~ s/\r$//;

                $current = sprintf("%10s  %-50s  %-30s  %-30s",
                        $size[$i],
                        $subj[$i],
                        $from[$i],
                        $date[$i]);

                $lb->insert('end', "$current");

                if(!$has_subj and !$has_from) {
                        $lb->selectionSet('end');
                }

                if(!$has_subj and $sz > $annoy_size) {
                        $lb->selectionSet('end');
                }

                if(!$has_from and $sz > $annoy_size) {
                        $lb->selectionSet('end');
                }

        }
}

sub BindMouseWheel {
        my($w) = @_;

        $w->bind('<4>' => sub {
                $_[0]->yview('scroll', -3, 'units');
        });

        $w->bind('<5>' => sub {
                $_[0]->yview('scroll', +3, 'units');
        });
}

fetchmail/SpamFilter (zuletzt geändert am 2007-12-23 22:45:22 durch localhost)