2009-10-21 2 views

답변

6

나는 어쌔신이 전환의 ISP 전에 이메일을 플래그 필터링 할 following script을 사용하는 데 사용 :

#!/usr/bin/perl 

use strict; 
use warnings; 

$| = 1; 

use constant SEVERITY => 5; 

use Mail::POP3Client; 
use Term::ReadKey; 

my $user = shift; 

my $pop = Mail::POP3Client->new(
    HOST => '127.0.0.1', 
    PORT => 9999 
); 

my $pass = prompt_password(); 
print "\n"; 

$pop->User($user); 
$pop->Pass($pass); 
$pop->Connect or die $pop->Message; 

my $count = $pop->Count; 

$count >= 0 or die "Failed to get message count.\n"; 
$count > 0 or die "No messages in mailbox.\n"; 

my @to_delete; 

print "Scanning messages: "; 

my $to_delete = 0; 
for my $msg_num (1 .. $count) { 
    my @headers = $pop->Head($msg_num); 

    for my $h (@headers) { 
     if($h =~ /^X-Spam-Level: (\*+)/) { 
      if(SEVERITY <= length $1) { 
       $to_delete += 1; 
       $pop->Delete($msg_num); 
       print "\b*>"; 
      } else { 
       print "\b->"; 
      } 
     } 
    } 
} 

print "\b ... done\n"; 

use Lingua::EN::Inflect qw(PL); 

if($to_delete) { 
    printf "%d %s will be deleted. Commit: [Y/N]?\n", 
     $to_delete, PL('message', $to_delete); 
    $pop->Reset unless yes(); 
} 

$pop->Close; 

print "OK\n"; 

sub yes { 
    while(my $r = <STDIN>) { 
     $r = lc substr $r, 0, 1; 
     return 1 if $r eq 'y'; 
     next unless $r eq 'n'; 
     last; 
    } 
    0; 
} 

sub prompt_password { 
    print 'Password: '; 
    ReadMode 2; 
    my $pass = ReadLine 0; 
    ReadMode 0; 
    chomp $pass; 
    return $pass; 
} 

메시지를 절약 할 수 있도록이를 변경하는 간단하다. Mail::POP3Client을 참조하십시오.

+0

대단히 고마워, 나는이 코드를 연구 할 것이다! –

3

거의 이러한 질문에 대한 답변은 "CPAN Search에 적합한 모듈 찾기"입니다.

대부분의 모듈에는 설명서 및 테스트의 예제가 있습니다.

행운을 빕니다 :)

+0

대단히 감사합니다! –

+1

나는 '대답'에 동의하는 반면 실제로 대답은 무엇입니까? 그는 CPAN을 수색해야 했음에 틀림없지 만, 우리는 SO를 완벽하게 만들고 popper를 고용 할 수 있어야하며, 그가 고용 할 수있는 작업 모듈을 적어도 제공해야합니까? 방금 검색 엔진에 연결하지 않는 것이 그것이 규칙이라고 생각 했습니까? 나는 틀릴 수 있었다. –

+0

나는 좀 더 공손한 "RTFM"으로 읽었습니다. RTFM이 명백하기는하지만 모든 사람이 CPAN에 대해 (또는 단지 얼마나 광대한지) 잘 압니다. – Ether

관련 문제