IMAPする (module)Mail-IMAPClient
back
Mail::IMAPClient を使って、IMAP サーバへアクセス
use Mail::IMAPClient;
my $serv = "IMAPサーバの指定";
my $user = "ログインユーザ名の指定";
my $pass = "ログインパスワードの指定";
my $auth = "認証の種類 ("CRAM-MD5"とか"PLAIN"とか)";
my $o_imap = Mail::IMAPClient->new(
Server => $serv,
User => $user,
Password => $pass,
Authmechanism => $auth,
) or die "Cannot connect to server: $@";
while (1) {
my @sub_folders = $o_imap->subscribed or warn "could not get subscribed folders: $@\n";
foreach (@sub_folders) {
print $_, "\n";
}
my $dir = "サブディレクトリの指定";
unless ($o_imap->exists($dir)) {
print "could not found $dir: $@\n";
last
}
unless ($o_imap->select($dir)) {
print "could not select $dir: $@\n";
last;
}
my @uid;
@uid = $o_imap->search("ALL");
@uid = $o_imap->unseen;
@uid = $o_imap->seen;
foreach (@uid) {
print $_, "\n";
}
my $uid = "@uid からどれか選ぶ";
my $data;
unless ($data = $o_imap->message_string($uid)) {
print "could not fetch $uid: $@\n";
last;
}
print $data, "\n";
unless ($o_imap->set_flag("seen", @uid)) {
print "could not set flag: $@\n";
last;
}
last;
}
$o_imap->disconnect;
back