From 0c21fadd7683629c50d1068106b17e9ac1addc62 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Sat, 5 Mar 2016 19:36:20 +0100 Subject: Terminate the SMTP transmission channel gracefully. --- pullimap | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'pullimap') diff --git a/pullimap b/pullimap index 2c9b45d..40f7f6f 100755 --- a/pullimap +++ b/pullimap @@ -127,7 +127,8 @@ my ($SMTP, $SMTP_PIPELINING); 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; @@ -252,6 +253,10 @@ sub pull(;$) { 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; -- cgit v1.2.3