mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-17 14:37:02 +00:00
maillog: Support logging to stdout and stderr
This patch adds support for writing maillog to stdout and stderr, which can be desirable in certain environments. Thanks to Denys Vitali <denys@denv.it> who sent an alternative patch for this functionality.
This commit is contained in:
@@ -216,9 +216,14 @@ func loadAddresses(srv *smtpsrv.Server, addrs []string, ls []net.Listener, mode
|
|||||||
func initMailLog(path string) {
|
func initMailLog(path string) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if path == "<syslog>" {
|
switch path {
|
||||||
|
case "<syslog>":
|
||||||
maillog.Default, err = maillog.NewSyslog()
|
maillog.Default, err = maillog.NewSyslog()
|
||||||
} else {
|
case "<stdout>":
|
||||||
|
maillog.Default = maillog.New(os.Stdout)
|
||||||
|
case "<stderr>":
|
||||||
|
maillog.Default = maillog.New(os.Stderr)
|
||||||
|
default:
|
||||||
_ = os.MkdirAll(filepath.Dir(path), 0775)
|
_ = os.MkdirAll(filepath.Dir(path), 0775)
|
||||||
maillog.Default, err = maillog.NewFile(path)
|
maillog.Default, err = maillog.NewFile(path)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,7 +133,7 @@
|
|||||||
.\" ========================================================================
|
.\" ========================================================================
|
||||||
.\"
|
.\"
|
||||||
.IX Title "chasquid.conf 5"
|
.IX Title "chasquid.conf 5"
|
||||||
.TH chasquid.conf 5 "2020-05-13" "" ""
|
.TH chasquid.conf 5 "2020-05-24" "" ""
|
||||||
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
||||||
.\" way too many mistakes in technical documents.
|
.\" way too many mistakes in technical documents.
|
||||||
.if n .ad l
|
.if n .ad l
|
||||||
@@ -224,7 +224,8 @@ you set this to \f(CW\*(C`._\*(C'\fR, email to local user \f(CW\*(C`u.se_r\*(C'\
|
|||||||
.IP "\fBmail_log_path\fR (string):" 8
|
.IP "\fBmail_log_path\fR (string):" 8
|
||||||
.IX Item "mail_log_path (string):"
|
.IX Item "mail_log_path (string):"
|
||||||
Path where to write the mail log to. If \f(CW\*(C`<syslog>\*(C'\fR, log using the
|
Path where to write the mail log to. If \f(CW\*(C`<syslog>\*(C'\fR, log using the
|
||||||
syslog (at \f(CW\*(C`MAIL|INFO\*(C'\fR priority). Default: \f(CW\*(C`<syslog>\*(C'\fR.
|
syslog (at \f(CW\*(C`MAIL|INFO\*(C'\fR priority). If \f(CW\*(C`<stdout>\*(C'\fR, log to stdout; if
|
||||||
|
\&\f(CW\*(C`<stderr>\*(C'\fR, log to stderr. Default: \f(CW\*(C`<syslog>\*(C'\fR.
|
||||||
.IP "\fBdovecot_auth\fR (bool):" 8
|
.IP "\fBdovecot_auth\fR (bool):" 8
|
||||||
.IX Item "dovecot_auth (bool):"
|
.IX Item "dovecot_auth (bool):"
|
||||||
Enable dovecot authentication. If true, users that are not found in chasquid's
|
Enable dovecot authentication. If true, users that are not found in chasquid's
|
||||||
|
|||||||
@@ -101,7 +101,8 @@ C<user>. Default: C<.>.
|
|||||||
=item B<mail_log_path> (string):
|
=item B<mail_log_path> (string):
|
||||||
|
|
||||||
Path where to write the mail log to. If C<< <syslog> >>, log using the
|
Path where to write the mail log to. If C<< <syslog> >>, log using the
|
||||||
syslog (at C<MAIL|INFO> priority). Default: C<< <syslog> >>.
|
syslog (at C<MAIL|INFO> priority). If C<< <stdout> >>, log to stdout; if
|
||||||
|
C<< <stderr> >>, log to stderr. Default: C<< <syslog> >>.
|
||||||
|
|
||||||
=item B<dovecot_auth> (bool):
|
=item B<dovecot_auth> (bool):
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,7 @@
|
|||||||
|
|
||||||
# Path where to write the mail log to.
|
# Path where to write the mail log to.
|
||||||
# If "<syslog>", log using the syslog (at MAIL|INFO priority).
|
# If "<syslog>", log using the syslog (at MAIL|INFO priority).
|
||||||
|
# If "<stdout>", log to stdout; if "<stderr>", log to stderr.
|
||||||
# Default: <syslog>
|
# Default: <syslog>
|
||||||
#mail_log_path: "<syslog>"
|
#mail_log_path: "<syslog>"
|
||||||
|
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ type Config struct {
|
|||||||
DropCharacters string `protobuf:"bytes,11,opt,name=drop_characters,json=dropCharacters,proto3" json:"drop_characters,omitempty"`
|
DropCharacters string `protobuf:"bytes,11,opt,name=drop_characters,json=dropCharacters,proto3" json:"drop_characters,omitempty"`
|
||||||
// Path where to write the mail log to.
|
// Path where to write the mail log to.
|
||||||
// If "<syslog>", log using the syslog (at MAIL|INFO priority).
|
// If "<syslog>", log using the syslog (at MAIL|INFO priority).
|
||||||
|
// If "<stdout>", log to stdout; if "<stderr>", log to stderr.
|
||||||
// Default: <syslog>
|
// Default: <syslog>
|
||||||
MailLogPath string `protobuf:"bytes,12,opt,name=mail_log_path,json=mailLogPath,proto3" json:"mail_log_path,omitempty"`
|
MailLogPath string `protobuf:"bytes,12,opt,name=mail_log_path,json=mailLogPath,proto3" json:"mail_log_path,omitempty"`
|
||||||
// Enable dovecot authentication.
|
// Enable dovecot authentication.
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ message Config {
|
|||||||
|
|
||||||
// Path where to write the mail log to.
|
// Path where to write the mail log to.
|
||||||
// If "<syslog>", log using the syslog (at MAIL|INFO priority).
|
// If "<syslog>", log using the syslog (at MAIL|INFO priority).
|
||||||
|
// If "<stdout>", log to stdout; if "<stderr>", log to stderr.
|
||||||
// Default: <syslog>
|
// Default: <syslog>
|
||||||
string mail_log_path = 12;
|
string mail_log_path = 12;
|
||||||
|
|
||||||
|
|||||||
1
test/t-17-maillog/.gitignore
vendored
Normal file
1
test/t-17-maillog/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
config/chasquid.conf
|
||||||
10
test/t-17-maillog/config/chasquid.conf.in
Normal file
10
test/t-17-maillog/config/chasquid.conf.in
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
smtp_address: ":1025"
|
||||||
|
submission_address: ":1587"
|
||||||
|
submission_over_tls_address: ":1465"
|
||||||
|
monitoring_address: ":1099"
|
||||||
|
|
||||||
|
mail_delivery_agent_bin: "test-mda"
|
||||||
|
mail_delivery_agent_args: "%to%"
|
||||||
|
|
||||||
|
data_dir: "../.data"
|
||||||
|
mail_log_path: "$MAIL_LOG_PATH"
|
||||||
4
test/t-17-maillog/content
Normal file
4
test/t-17-maillog/content
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
Subject: Prueba desde el test
|
||||||
|
|
||||||
|
Crece desde el test el futuro
|
||||||
|
Crece desde el test
|
||||||
1
test/t-17-maillog/hosts
Normal file
1
test/t-17-maillog/hosts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
testserver localhost
|
||||||
28
test/t-17-maillog/msmtprc
Normal file
28
test/t-17-maillog/msmtprc
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
account default
|
||||||
|
|
||||||
|
host testserver
|
||||||
|
port 1587
|
||||||
|
|
||||||
|
tls on
|
||||||
|
tls_trust_file config/certs/testserver/fullchain.pem
|
||||||
|
|
||||||
|
from user@testserver
|
||||||
|
|
||||||
|
auth on
|
||||||
|
user user@testserver
|
||||||
|
password secretpassword
|
||||||
|
|
||||||
|
account smtpport : default
|
||||||
|
port 1025
|
||||||
|
|
||||||
|
account subm_tls : default
|
||||||
|
port 1465
|
||||||
|
tls_starttls off
|
||||||
|
|
||||||
|
account baduser : default
|
||||||
|
user unknownuser@testserver
|
||||||
|
password secretpassword
|
||||||
|
|
||||||
|
account badpasswd : default
|
||||||
|
user user@testserver
|
||||||
|
password badsecretpassword
|
||||||
48
test/t-17-maillog/run.sh
Executable file
48
test/t-17-maillog/run.sh
Executable file
@@ -0,0 +1,48 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
. $(dirname ${0})/../util/lib.sh
|
||||||
|
|
||||||
|
init
|
||||||
|
|
||||||
|
mkdir -p .logs
|
||||||
|
|
||||||
|
generate_certs_for testserver
|
||||||
|
add_user user@testserver secretpassword
|
||||||
|
add_user someone@testserver secretpassword
|
||||||
|
|
||||||
|
function send_one() {
|
||||||
|
rm -f .logs/mail_log .logs/stdout .logs/stderr
|
||||||
|
envsubst < config/chasquid.conf.in > config/chasquid.conf
|
||||||
|
|
||||||
|
chasquid -v=2 --logfile=.logs/chasquid.log --config_dir=config \
|
||||||
|
> .logs/stdout 2> .logs/stderr &
|
||||||
|
wait_until_ready 1025
|
||||||
|
|
||||||
|
run_msmtp someone@testserver < content
|
||||||
|
wait_for_file .mail/someone@testserver
|
||||||
|
mail_diff content .mail/someone@testserver
|
||||||
|
|
||||||
|
pkill -s 0 chasquid
|
||||||
|
sleep 0.2
|
||||||
|
}
|
||||||
|
|
||||||
|
export MAIL_LOG_PATH="../.logs/mail_log"
|
||||||
|
send_one
|
||||||
|
if ! grep -q "from=user@testserver all done" .logs/mail_log; then
|
||||||
|
fail "entries not found in .logs/mail_log"
|
||||||
|
fi
|
||||||
|
|
||||||
|
export MAIL_LOG_PATH="<stdout>"
|
||||||
|
send_one
|
||||||
|
if ! grep -q "from=user@testserver all done" .logs/stdout; then
|
||||||
|
fail "entries not found in .logs/stdout"
|
||||||
|
fi
|
||||||
|
|
||||||
|
export MAIL_LOG_PATH="<stderr>"
|
||||||
|
send_one
|
||||||
|
if ! grep -q "from=user@testserver all done" .logs/stderr; then
|
||||||
|
fail "entries not found in .logs/stderr"
|
||||||
|
fi
|
||||||
|
|
||||||
|
success
|
||||||
Reference in New Issue
Block a user