public inbox for pmg-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [PATCH pmg-api v2 3/4] reinject mail: improve error logging
Date: Wed,  8 Mar 2023 15:52:33 +0100	[thread overview]
Message-ID: <20230308145235.37342-5-s.ivanov@proxmox.com> (raw)
In-Reply-To: <20230308145235.37342-1-s.ivanov@proxmox.com>

this patch unifies the error handling for mail and rcpt with
the data command: all now die with sensible error (which gets logged
in the error-handling of the eval), and it sets the respose message
and code for those commands as well.

additionally it adds a '\n' to all die statements.

this makes it possible to provide information what went wrong at
call-sites (instead of only having it in syslog)

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
 src/PMG/Utils.pm | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/PMG/Utils.pm b/src/PMG/Utils.pm
index 37e76aa..6405934 100644
--- a/src/PMG/Utils.pm
+++ b/src/PMG/Utils.pm
@@ -288,8 +288,10 @@ sub reinject_mail {
 	}
 
 	if (!$smtp->_MAIL("FROM:" . $sender_addr . $mail_opts)) {
-	    syslog('err', "smtp error - got: %s %s", $smtp->code, scalar ($smtp->message));
-	    die "smtp from: ERROR";
+	    my @msgs = $smtp->message;
+	    $resmess = $msgs[$#msgs];
+	    $rescode = $smtp->code;
+	    die sprintf("smtp from error - got: %s %s\n", $rescode, $resmess);
 	}
 
 	foreach my $target (@$targets) {
@@ -304,8 +306,10 @@ sub reinject_mail {
 	    $rcpt_addr = encode('UTF-8', $smtp->_addr($target));
 
 	    if (!$smtp->_RCPT("TO:" . $rcpt_addr . $rcpt_opts)) {
-		syslog ('err', "smtp error - got: %s %s", $smtp->code, scalar($smtp->message));
-		die "smtp to: ERROR";
+		my @msgs = $smtp->message;
+		$resmess = $msgs[$#msgs];
+		$rescode = $smtp->code;
+		die sprintf("smtp to error - got: %s %s\n", $rescode, $resmess);
 	    }
 	}
 
@@ -326,13 +330,13 @@ sub reinject_mail {
 	    ($resid) = $resmess =~ m/Ok: queued as ([0-9A-Z]+)/;
 	    $rescode = $smtp->code;
 	    if (!$resid) {
-		die sprintf("unexpected SMTP result - got: %s %s : WARNING", $smtp->code, $resmess);
+		die sprintf("unexpected SMTP result - got: %s %s : WARNING\n", $smtp->code, $resmess);
 	    }
 	} else {
 	    my @msgs = $smtp->message;
 	    $resmess = $msgs[$#msgs];
 	    $rescode = $smtp->code;
-	    die sprintf("sending data failed - got: %s %s : ERROR", $smtp->code, $resmess);
+	    die sprintf("sending data failed - got: %s %s : ERROR\n", $smtp->code, $resmess);
 	}
     };
     my $err = $@;
-- 
2.30.2





  parent reply	other threads:[~2023-03-08 14:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-08 14:52 [pmg-devel] [PATCH pmg-api v2 0/4] improve local mail injection and add smtputf8 support Stoiko Ivanov
2023-03-08 14:52 ` [pmg-devel] [PATCH pmg-docs v2 1/1] doc-generator: add new option smtputf8 Stoiko Ivanov
2023-03-08 14:52 ` [pmg-devel] [PATCH pmg-api v2 1/4] smtputf8: keep smtputf8 from incoming postfix, detect for local mail Stoiko Ivanov
2023-03-08 14:52 ` [pmg-devel] [PATCH pmg-api v2 2/4] config: make smtputf8 configurable through the API Stoiko Ivanov
2023-03-08 14:52 ` Stoiko Ivanov [this message]
2023-03-08 14:52 ` [pmg-devel] [PATCH pmg-api v2 4/4] quarantine: use reinject_local_mail to deliver quarantined mail Stoiko Ivanov
2023-03-08 14:52 ` [pmg-devel] [PATCH pmg-gui v2 1/1] mail proxy options: add smtputf8 checkbox Stoiko Ivanov
2023-03-16 12:52 ` [pmg-devel] [PATCH pmg-api v2 0/4] improve local mail injection and add smtputf8 support Dominik Csapak
2023-03-16 12:58   ` Dominik Csapak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230308145235.37342-5-s.ivanov@proxmox.com \
    --to=s.ivanov@proxmox.com \
    --cc=pmg-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal