Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kizashi1122
Created February 25, 2019 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kizashi1122/6fe04fbdd803ef9f05d76c9b433ac000 to your computer and use it in GitHub Desktop.
Save kizashi1122/6fe04fbdd803ef9f05d76c9b433ac000 to your computer and use it in GitHub Desktop.
IMAP経由でメール(eml)をアップロードするスクリプト
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