aboutsummaryrefslogtreecommitdiffstats
path: root/pullimap
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2016-03-07 17:32:29 +0100
committerGuilhem Moulin <guilhem@fripost.org>2016-03-07 17:32:29 +0100
commit67f7ae7c82263dc3acad7f6b4df586f94f3b5e15 (patch)
tree756ef9a00496e35703810637777177e39371bcfe /pullimap
parent247cc63d7710e1907b114a75125c27de946415aa (diff)
wibble
Diffstat (limited to 'pullimap')
-rwxr-xr-xpullimap16
1 files changed, 9 insertions, 7 deletions
diff --git a/pullimap b/pullimap
index 7e737f2..27226d2 100755
--- a/pullimap
+++ b/pullimap
@@ -1,7 +1,7 @@
#!/usr/bin/perl -T
#----------------------------------------------------------------------
-# Pull mails from an IMAP mailbox and deliver them to an SMTP session
+# Pull mails from an IMAP mailbox and deliver them to a SMTP session
# Copyright © 2016 Guilhem Moulin <guilhem@fripost.org>
#
# This program is free software: you can redistribute it and/or modify
@@ -59,10 +59,10 @@ my $CONF = read_config( delete $CONFIG{config} // $NAME,
, [$ARGV[0]]
, statefile => qr/\A(\P{Control}+)\z/
, mailbox => qr/\A([\x01-\x7F]+)\z/
- , 'deliver-method' => qr/\A((?:[ls]mtp:)?\[.*\](?::\d+)?)\z/
+ , 'deliver-method' => qr/\A([ls]mtp:\[.*\]:\d+)\z/
, 'deliver-ehlo' => qr/\A(\P{Control}+)\z/
, 'deliver-rcpt' => qr/\A(\P{Control}+)\z/
- , 'purge-after' => qr/\A(\d+)d\z/
+ , 'purge-after' => qr/\A(\d+)\z/
)->{$ARGV[0]};
my ($MAILBOX, $STATE);
@@ -122,12 +122,12 @@ sub sendmail($$) {
unless (defined $SMTP) {
# TODO we need to be able to reconnect when the server closes
# the connection due to a timeout (RFC 5321 section 4.5.3.2)
- my ($fam, $addr, $port) = (PF_INET, $CONF->{'deliver-method'} // 'smtp:[127.0.0.1]:10024', 25);
+ my ($fam, $addr) = (PF_INET, $CONF->{'deliver-method'} // 'smtp:[127.0.0.1]:25');
$addr =~ s/^([ls]mtp):// or die;
my $ehlo = $1 eq 'lmtp' ? 'LHO' : $1 eq 'smtp' ? 'EHLO' : die;
$ehlo .= ' '. ($CONF->{'deliver-ehlo'} // 'localhost.localdomain');
- $port = $1 if $addr =~ s/:(\d+)$//;
+ my $port = $addr =~ s/:(\d+)$// ? $1 : die;
$addr =~ s/^\[(.*)\]$/$1/ or die;
$fam = PF_INET6 if $addr =~ /:/;
$addr = Socket::inet_pton($fam, $addr) // die "Invalid address $addr\n";
@@ -226,7 +226,6 @@ my $IMAP = Net::IMAP::InterIMAP::->new( %$CONF, %CONFIG{qw/quiet debug/} );
my $LAST_PURGED;
sub purge() {
my $days = $CONF->{'purge-after'} // return;
- $days =~ s/d$//;
my ($uidnext) = $IMAP->get_cache('UIDNEXT');
return unless 1<$uidnext;
my $set = "1:".($uidnext-1);
@@ -319,7 +318,10 @@ do {
pull($ignore);
purge();
};
-exit 0 unless defined $CONFIG{idle};
+unless (defined $CONFIG{idle}) {
+ $IMAP->logout();
+ exit 0;
+}
$CONFIG{idle} = 1740 if defined $CONFIG{idle} and $CONFIG{idle} == 0; # 29 mins
while(1) {