Chinaunix首页 | 论坛 | 博客
  • 博客访问: 466690
  • 博文数量: 279
  • 博客积分: 4467
  • 博客等级: 上校
  • 技术积分: 2830
  • 用 户 组: 普通用户
  • 注册时间: 2007-04-03 14:43
文章分类

全部博文(279)

文章存档

2013年(1)

2012年(39)

2011年(35)

2009年(29)

2008年(131)

2007年(44)

分类:

2008-04-22 11:03:25


#!/use/bin/perl


use strict;
use warnings;
use IO::Socket;

if( @ARGV != 3 )
{
    print "imail_subscribe.pl \n";
    exit( -1 );
}

my $host = $ARGV[0];
my $user = $ARGV[1];
my $pass = $ARGV[2];

my $sock = IO::Socket::INET->new( PeerHost=>$host, PeerPort=>"143", proto=>"tcp" ) || die "Connect error.\n";

my $res = <$sock>;
print $res;
if( $res !~ /OK/ )
{
    exit( -1 );
}

# login

print $sock "0 LOGIN $user $pass\r\n";
$res = <$sock>;
if( ! defined($res) )
{
    exit(-1);
}

print $res;
if( $res !~ /OK/ )
{
    exit(-1);
}

# select

print $sock "2 SELECT INBOX\r\n";
while( <$sock> )
{
    print $_;
    if( $_ =~ /2 OK/ || $_ =~ /2 BAD/ )
    {
        last;
    }
}

my $test_code = "AB" x 800;
print $sock "3 UNSUBSCRIBE $test_code\r\n";

$res = <$sock>;
if( ! defined($res) )
{
    exit(-1);
}
print $res;

#exit

print $sock "4 LOGOUT\r\n";
print <$sock>;

$sock->close();

阅读(471) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~