Skip to content

Commit 8e106a0

Browse files
Mail: Change interpolation when logging in ilMailMimeTransportBase
1 parent 4138e12 commit 8e106a0

1 file changed

Lines changed: 42 additions & 42 deletions

File tree

components/ILIAS/Mail/classes/Mime/Transport/class.ilMailMimeTransportBase.php

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ final public function send(ilMimeMail $mail): bool
6262
$recipient_pieces = array_filter(array_map('trim', explode(',', $recipients)));
6363
foreach ($recipient_pieces as $recipient) {
6464
if (!$this->getMailer()->addAddress($recipient)) {
65-
ilLoggerFactory::getLogger('mail')->warning($this->getMailer()->ErrorInfo);
65+
ilLoggerFactory::getLogger('mail')->warning('{error}', ['error' => $this->getMailer()->ErrorInfo]);
6666
}
6767
}
6868
}
@@ -71,7 +71,7 @@ final public function send(ilMimeMail $mail): bool
7171
$cc_pieces = array_filter(array_map('trim', explode(',', $carbon_copies)));
7272
foreach ($cc_pieces as $carbon_copy) {
7373
if (!$this->getMailer()->addCC($carbon_copy)) {
74-
ilLoggerFactory::getLogger('mail')->warning($this->getMailer()->ErrorInfo);
74+
ilLoggerFactory::getLogger('mail')->warning('{error}', ['error' => $this->getMailer()->ErrorInfo]);
7575
}
7676
}
7777
}
@@ -80,7 +80,7 @@ final public function send(ilMimeMail $mail): bool
8080
$bcc_pieces = array_filter(array_map('trim', explode(',', $blind_carbon_copies)));
8181
foreach ($bcc_pieces as $blind_carbon_copy) {
8282
if (!$this->getMailer()->addBCC($blind_carbon_copy)) {
83-
ilLoggerFactory::getLogger('mail')->warning($this->getMailer()->ErrorInfo);
83+
ilLoggerFactory::getLogger('mail')->warning('{error}', ['error' => $this->getMailer()->ErrorInfo]);
8484
}
8585
}
8686
}
@@ -91,25 +91,25 @@ final public function send(ilMimeMail $mail): bool
9191
$mail->getFrom()->getReplyToAddress(),
9292
$mail->getFrom()->getReplyToName()
9393
)) {
94-
ilLoggerFactory::getLogger('mail')->warning($this->getMailer()->ErrorInfo);
94+
ilLoggerFactory::getLogger('mail')->warning('{error}', ['error' => $this->getMailer()->ErrorInfo]);
9595
}
9696
if ($mail->getFrom()->hasEnvelopFromAddress()) {
9797
$this->getMailer()->Sender = $mail->getFrom()->getEnvelopFromAddress();
9898
}
9999

100100
if (!$this->getMailer()->setFrom($mail->getFrom()->getFromAddress(), $mail->getFrom()->getFromName(), false)) {
101-
ilLoggerFactory::getLogger('mail')->warning($this->getMailer()->ErrorInfo);
101+
ilLoggerFactory::getLogger('mail')->warning('{error}', ['error' => $this->getMailer()->ErrorInfo]);
102102
}
103103

104104
foreach ($mail->getAttachments() as $attachment) {
105105
if (!$this->getMailer()->addAttachment($attachment['path'], $attachment['name'])) {
106-
ilLoggerFactory::getLogger('mail')->warning($this->getMailer()->ErrorInfo);
106+
ilLoggerFactory::getLogger('mail')->warning('{error}', ['error' => $this->getMailer()->ErrorInfo]);
107107
}
108108
}
109109

110110
foreach ($mail->getImages() as $image) {
111111
if (!$this->getMailer()->addEmbeddedImage($image['path'], $image['cid'], $image['name'])) {
112-
ilLoggerFactory::getLogger('mail')->warning($this->getMailer()->ErrorInfo);
112+
ilLoggerFactory::getLogger('mail')->warning('{error}', ['error' => $this->getMailer()->ErrorInfo]);
113113
}
114114
}
115115

@@ -123,41 +123,41 @@ final public function send(ilMimeMail $mail): bool
123123
$this->getMailer()->Body = $mail->getFinalBody();
124124
$this->getMailer()->AllowEmpty = true;
125125

126-
ilLoggerFactory::getLogger('mail')->info(sprintf(
127-
"Trying to delegate external email delivery:" .
128-
" Initiated by: %s (%s) " .
129-
"| To: %s | CC: %s | BCC: %s | Subject: %s " .
130-
"| From: %s / %s " .
131-
"| ReplyTo: %s / %s " .
132-
"| EnvelopeFrom: %s",
133-
$GLOBALS['DIC']->user()->getLogin(),
134-
$GLOBALS['DIC']->user()->getId(),
135-
implode(', ', $mail->getTo()),
136-
implode(', ', $mail->getCc()),
137-
implode(', ', $mail->getBcc()),
138-
$mail->getSubject(),
139-
$mail->getFrom()->getFromAddress(),
140-
$mail->getFrom()->getFromName(),
141-
$mail->getFrom()->getReplyToAddress(),
142-
$mail->getFrom()->getReplyToName(),
143-
$mail->getFrom()->getEnvelopFromAddress()
144-
));
126+
ilLoggerFactory::getLogger('mail')->info(
127+
'Trying to delegate external email delivery:' .
128+
' Initiated by: {login} ({id}) ' .
129+
'| To: {to} | CC: {cc} | BCC: {bcc} | Subject: {subject} ' .
130+
'| From: {from_address} / {from_name} ' .
131+
'| ReplyTo: {reply_to_address} / {reply_to_name} ' .
132+
'| EnvelopeFrom: {envelope_from}',
133+
[
134+
'login' => $GLOBALS['DIC']->user()->getLogin(),
135+
'id' => $GLOBALS['DIC']->user()->getId(),
136+
'to' => implode(', ', $mail->getTo()),
137+
'cc' => implode(', ', $mail->getCc()),
138+
'bcc' => implode(', ', $mail->getBcc()),
139+
'subject' => $mail->getSubject(),
140+
'from_address' => $mail->getFrom()->getFromAddress(),
141+
'from_name' => $mail->getFrom()->getFromName(),
142+
'reply_to_address' => $mail->getFrom()->getReplyToAddress(),
143+
'reply_to_name' => $mail->getFrom()->getReplyToName(),
144+
'envelope_from' => $mail->getFrom()->getEnvelopFromAddress(),
145+
]
146+
);
145147

146148
ilLoggerFactory::getLogger('mail')
147-
->debug(sprintf("Mail Alternative Body: %s", $this->getMailer()->AltBody));
149+
->debug('Mail Alternative Body: {body}', ['body' => $this->getMailer()->AltBody]);
148150
ilLoggerFactory::getLogger('mail')
149-
->debug(sprintf("Mail Body: %s", $this->getMailer()->Body));
151+
->debug('Mail Body: {body}', ['body' => $this->getMailer()->Body]);
150152

151153
$this->getMailer()->CharSet = 'utf-8';
152154

153155
$this->mailer->Debugoutput = static function (string $message, $level): void {
154-
if (
155-
strpos($message, 'Invalid address') ||
156-
strpos($message, 'Message body empty')
157-
) {
158-
ilLoggerFactory::getLogger('mail')->warning($message);
156+
if (str_contains($message, 'Invalid address') ||
157+
str_contains($message, 'Message body empty')) {
158+
ilLoggerFactory::getLogger('mail')->warning('{message}', ['message' => $message]);
159159
} else {
160-
ilLoggerFactory::getLogger('mail')->debug($message);
160+
ilLoggerFactory::getLogger('mail')->debug('{message}', ['message' => $message]);
161161
}
162162
};
163163

@@ -168,16 +168,16 @@ final public function send(ilMimeMail $mail): bool
168168
->info('Successfully delegated external mail delivery');
169169

170170
if ($this->getMailer()->ErrorInfo !== '') {
171-
ilLoggerFactory::getLogger('mail')->warning(sprintf(
172-
'... with most recent errors: %s',
173-
$this->getMailer()->ErrorInfo
174-
));
171+
ilLoggerFactory::getLogger('mail')->warning(
172+
'... with most recent errors: {error}',
173+
['error' => $this->getMailer()->ErrorInfo]
174+
);
175175
}
176176
} else {
177-
ilLoggerFactory::getLogger('mail')->warning(sprintf(
178-
'Could not deliver external email: %s',
179-
$this->getMailer()->ErrorInfo
180-
));
177+
ilLoggerFactory::getLogger('mail')->warning(
178+
'Could not deliver external email: {error}',
179+
['error' => $this->getMailer()->ErrorInfo]
180+
);
181181
}
182182

183183
$this->event_handler->raise('components/ILIAS/Mail', 'externalEmailDelegated', [

0 commit comments

Comments
 (0)