sub sendmail($$) {
my ($from, $rfc822) = @_;
unless (defined $SMTP) {
- # XXX we can be logged out while connected, so we need to be able to reconnect
+ # 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'}, 25);
$addr =~ s/^([ls]mtp):// or die;
my $ehlo = $1 eq 'lmtp' ? 'LHO' : $1 eq 'smtp' ? 'EHLO' : die;
writeUID($uid);
}, @$ignore);
+ # terminate the transmission channel gracefully, cf RFC 5321 section 4.5.3.2
+ smtp_send('QUIT' => '221') if defined $SMTP;
+ undef $SMTP;
+
# now that everything has been deliverd, mark @ignore and @uid as \Seen
$IMAP->silent_store(compact_set(@$ignore, @uid), '+', '\Seen') if @$ignore or @uid;