aboutsummaryrefslogtreecommitdiffstats
path: root/archiveIMAP.pl
diff options
context:
space:
mode:
Diffstat (limited to 'archiveIMAP.pl')
-rw-r--r--archiveIMAP.pl56
1 files changed, 39 insertions, 17 deletions
diff --git a/archiveIMAP.pl b/archiveIMAP.pl
index c432443..35d4ea8 100644
--- a/archiveIMAP.pl
+++ b/archiveIMAP.pl
@@ -3,22 +3,25 @@
use strict;
use warnings;
use Mail::IMAPClient;
+use IO::Socket::SSL;
use Data::Dumper;
use DateTime;
use DateTime::Format::Strptime;
+use Config::IniFiles;
-my $hostname = "localhost";
-my $login = "matej";
-my $passwd = "lubdkc";
+# possible values are currently -- zimbra, localhost, pobox
+my $account = "zimbra";
# How many months before today the cut date should be?
my $howManyMonths = 3;
-my $folder;
-my $msg;
-my $msgYear;
-my $msgDateStr;
-my $targetFolder;
+# get configuration for the account
+my $conf = new Config::IniFiles ( -file => "/home/matej/.bugzillarc");
+die "No configuration for account $account" unless $conf->SectionExists($account);
+my $hostname = $conf->val($account,'host');
+my $login = $conf->val($account,'name');
+my $password = $conf->val($account,'password');
+my $ssl= $conf->val($account,'ssl');
sub getTargetFolder {
my $source = shift;
@@ -40,7 +43,7 @@ sub getMessageYear {
my $msgDt = $Strp->parse_datetime($msgStr);
if (!$msgDt) {
- $msgDt = $StrpNoTZ->parse_datetime($msgDateStr);
+ $msgDt = $StrpNoTZ->parse_datetime($msgStr);
}
if (!$msgDt) {
print "Date EMPTY.\n";
@@ -56,25 +59,44 @@ sub getMessageYear {
}
my $imap = Mail::IMAPClient->new();
-$imap = Mail::IMAPClient->new(
- Server => $hostname,
- User => $login,
- Password => $passwd,
- UID => 1
-) or die "Cannot connect to localhost as matej: $@";
+if ($ssl) {
+ my $sslSocket=new IO::Socket::SSL("$hostname:imaps");
+ die ("Error connecting - $@") unless defined $sslSocket;
+ $sslSocket->autoflush(1);
+
+ $imap = Mail::IMAPClient->new(
+ Server => $hostname,
+ Socket => $sslSocket,
+ User => $login,
+ Debug => 1,
+ Password => $password,
+ UID => 1
+ ) or die "Cannot connect to localhost as matej: $@";
+} else {
+ $imap = Mail::IMAPClient->new(
+ Server => $hostname,
+ User => $login,
+ Debug => 1,
+ Password => $password,
+ UID => 1
+ ) or die "Cannot connect to localhost as matej: $@";
+}
my $cutDate = DateTime->now();
$cutDate->add( months => -$howManyMonths );
my @sourceFolders = grep(!/^INBOX\/Archiv/,$imap->folders());
my $msgDateInStr;
+my $msgYear;
+my $msgDateStr;
+my $targetFolder;
-LINE: foreach $folder (@sourceFolders) {
+foreach my $folder (@sourceFolders) {
$imap->select($folder);
my @msgsProc = $imap->search(" UNDELETED BEFORE " . $cutDate->strftime("%d-%b-%Y"));
if ($#msgsProc > 0) {
print "Move $#msgsProc in $folder.\n";
- foreach $msg (@msgsProc) {
+ foreach my $msg (@msgsProc) {
$msgDateInStr = $imap->date($msg);
$msgYear = getMessageYear($msgDateInStr);
if ($msgYear !~ /^\s*$/) {