Skip to content

Commit f7ff552

Browse files
committed
fix(imip): set charset for imip attachment
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
1 parent 25a00b4 commit f7ff552

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
@@ -263,7 +263,6 @@ public function schedule(Message $iTipMessage) {
263263
// convert iTip Message to string
264264
$itip_msg = $iTipMessage->message->serialize();
265265

266-
$user = null;
267266
$mailService = null;
268267

269268
try {
@@ -275,8 +274,14 @@ public function schedule(Message $iTipMessage) {
275274
$mailService = $this->mailManager->findServiceByAddress($user->getUID(), $sender);
276275
}
277276
}
277+
278+
// The display name in Nextcloud can use utf-8.
279+
// As the default charset for text/* is us-ascii, it's important to explicitly define it.
280+
// See https://www.rfc-editor.org/rfc/rfc6047.html#section-2.4.
281+
$contentType = 'text/calendar; method=' . $iTipMessage->method . '; charset="utf-8"';
282+
278283
// evaluate if a mail service was found and has sending capabilities
279-
if ($mailService !== null && $mailService instanceof IMessageSend) {
284+
if ($mailService instanceof IMessageSend) {
280285
// construct mail message and set required parameters
281286
$message = $mailService->initiateMessage();
282287
$message->setFrom(
@@ -288,10 +293,12 @@ public function schedule(Message $iTipMessage) {
288293
$message->setSubject($template->renderSubject());
289294
$message->setBodyPlain($template->renderText());
290295
$message->setBodyHtml($template->renderHtml());
296+
// Adding name=event.ics is a trick to make the invitation also appear
297+
// as a file attachment in mail clients like Thunderbird or Evolution.
291298
$message->setAttachments((new \OCP\Mail\Provider\Attachment(
292299
$itip_msg,
293300
null,
294-
'text/calendar; name=event.ics; method=' . $iTipMessage->method,
301+
$contentType . '; name=event.ics',
295302
true
296303
)));
297304
// send message
@@ -307,10 +314,12 @@ public function schedule(Message $iTipMessage) {
307314
(($senderName !== null) ? [$sender => $senderName] : [$sender])
308315
);
309316
$message->useTemplate($template);
317+
// Using a different content type because Symfony Mailer/Mime will append the name to
318+
// the content type header and attachInline does not allow null.
310319
$message->attachInline(
311320
$itip_msg,
312321
'event.ics',
313-
'text/calendar; method=' . $iTipMessage->method
322+
$contentType,
314323
);
315324
$failed = $this->mailer->send($message);
316325
}

0 commit comments

Comments
 (0)