Skip to content

Commit 209ad4e

Browse files
committed
fix(imip): set charset for imip attachment
Signed-off-by: Daniel Kesselberg <[email protected]>
1 parent ae4bbbf commit 209ad4e

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

apps/dav/lib/CalDAV/Schedule/IMipPlugin.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ public function schedule(Message $iTipMessage) {
249249
// convert iTip Message to string
250250
$itip_msg = $iTipMessage->message->serialize();
251251

252-
$user = null;
253252
$mailService = null;
254253

255254
try {
@@ -261,8 +260,14 @@ public function schedule(Message $iTipMessage) {
261260
$mailService = $this->mailManager->findServiceByAddress($user->getUID(), $sender);
262261
}
263262
}
263+
264+
// The display name in Nextcloud can use utf-8.
265+
// As the default charset for text/* is us-ascii, it's important to explicitly define it.
266+
// See https://www.rfc-editor.org/rfc/rfc6047.html#section-2.4.
267+
$contentType = 'text/calendar; method=' . $iTipMessage->method . '; charset="utf-8"';
268+
264269
// evaluate if a mail service was found and has sending capabilities
265-
if ($mailService !== null && $mailService instanceof IMessageSend) {
270+
if ($mailService instanceof IMessageSend) {
266271
// construct mail message and set required parameters
267272
$message = $mailService->initiateMessage();
268273
$message->setFrom(
@@ -274,10 +279,12 @@ public function schedule(Message $iTipMessage) {
274279
$message->setSubject($template->renderSubject());
275280
$message->setBodyPlain($template->renderText());
276281
$message->setBodyHtml($template->renderHtml());
282+
// Adding name=event.ics is a trick to make the invitation also appear
283+
// as a file attachment in mail clients like Thunderbird or Evolution.
277284
$message->setAttachments((new Attachment(
278285
$itip_msg,
279286
null,
280-
'text/calendar; name=event.ics; method=' . $iTipMessage->method,
287+
$contentType . '; name=event.ics',
281288
true
282289
)));
283290
// send message
@@ -293,10 +300,12 @@ public function schedule(Message $iTipMessage) {
293300
(($senderName !== null) ? [$sender => $senderName] : [$sender])
294301
);
295302
$message->useTemplate($template);
303+
// Using a different content type because Symfony Mailer/Mime will append the name to
304+
// the content type header and attachInline does not allow null.
296305
$message->attachInline(
297306
$itip_msg,
298307
'event.ics',
299-
'text/calendar; method=' . $iTipMessage->method
308+
$contentType,
300309
);
301310
$failed = $this->mailer->send($message);
302311
}

0 commit comments

Comments
 (0)