aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2008-09-30 22:36:13 +0200
committerMatej Cepl <mcepl@redhat.com>2008-09-30 22:36:13 +0200
commit6a84a24aa748517bb2a798f6035cdebe8d85c5f5 (patch)
treedf50dc94eae167c257781e1d90fbe231bbed9a69
parentb2c450c288c44189cd839ffc33fb900f15d980c9 (diff)
downloadimapArch-6a84a24aa748517bb2a798f6035cdebe8d85c5f5.tar.gz
Přiděláno čtení konfiguračního souboru a připojení přes SSL socket.
-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*$/) {