POP3收信的perl客户端

来源:互联网 发布:生活服务淘宝店铺 编辑:程序博客网 时间:2024/05/16 08:38
看advprog里面的Perl代码,自己试验了一下,很好用。主要是把新浪邮箱里我不关心的邮件统统删除。

#!/usr/local/bin/perl
use Net::POP3;
$m = Net::POP3->new('pop.sina.com.cn'); # Name of POP server
die "Could not open account" unless $m;
$n = $m->login('xxxx', 'xxxx');    # Login, passwd
print "Number of msgs received: $n/n";
$r_msgs = $m->list();                  # Returns a ref-to-hash mapping

# msg_id to msg_size
foreach $msg_id (keys %$r_msgs) {
  $rl_msg = $m->top($msg_id);  # Get top three lines from message
  foreach my $line (@$rl_msg) {
    unless ($line =~ /@163/.com/is) {   #只要不是从163来的信件,统统删除
      $m->delete($msg_id) or warn "can't  delete mail/n";
      print $line;
    }
  }
}
$m->quit();
原创粉丝点击