From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 28665913F9 for ; Fri, 17 Mar 2023 19:45:18 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 12FC41D103 for ; Fri, 17 Mar 2023 19:45:18 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Fri, 17 Mar 2023 19:45:16 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 7801F45216 for ; Fri, 17 Mar 2023 19:45:16 +0100 (CET) From: Stoiko Ivanov To: pmg-devel@lists.proxmox.com Date: Fri, 17 Mar 2023 19:44:52 +0100 Message-Id: <20230317184456.26465-4-s.ivanov@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230317184456.26465-1-s.ivanov@proxmox.com> References: <20230317184456.26465-1-s.ivanov@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.143 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [utils.pm] Subject: [pmg-devel] [PATCH pmg-api v3 3/5] reinject mail: improve error logging X-BeenThere: pmg-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Mar 2023 18:45:18 -0000 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 --- 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