Created
February 25, 2019 08:51
-
-
Save kizashi1122/6fe04fbdd803ef9f05d76c9b433ac000 to your computer and use it in GitHub Desktop.
IMAP経由でメール(eml)をアップロードするスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v5.18; | |
use Mail::IMAPClient; | |
use File::Slurp; | |
# nohup perl imap-client.pl imap.example.com username password eml_dir 1> importx.log & | |
my $imap_host = $ARGV[0] or die $!; | |
my $user = $ARGV[1] or die $!; | |
my $pass = $ARGV[2] or die $!; | |
my $eml_dir = $ARGV[3] or die $!; | |
my $imap = Mail::IMAPClient->new( | |
Server => $imap_host, | |
User => $user, | |
Password => $pass, | |
Ssl => 1, | |
Uid => 1, | |
); | |
my $count = 0; | |
opendir my $dh, $eml_dir or die $!; | |
for my $eml ( readdir $dh ) { | |
if ($eml =~ /\.eml$/) { | |
my $path = "$eml_dir/$eml"; | |
say "[" . $count++ . "] $path"; | |
my $uidort = $imap->append_file('INBOX', $path) or die "Could not append_file: ", $imap->LastError; | |
} | |
} | |
closedir $dh; | |
# Mark all unread emls as read | |
$imap->select('INBOX'); | |
$imap->see( $imap->unseen ); | |
$imap->logout or die "Logout error: ", $imap->LastError, "\n"; | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment