@@ -263,7 +263,6 @@ public function schedule(Message $iTipMessage) {
263263		// convert iTip Message to string 
264264		$ itip_msg$ iTipMessagemessage ->serialize ();
265265
266- 		$ usernull ;
267266		$ mailServicenull ;
268267
269268		try  {
@@ -275,8 +274,14 @@ public function schedule(Message $iTipMessage) {
275274					$ mailService$ this mailManager ->findServiceByAddress ($ usergetUID (), $ 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= '  . $ iTipMessagemethod  . '; 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  ($ mailServiceinstanceof  IMessageSend) {
280285				// construct mail message and set required parameters 
281286				$ message$ mailServiceinitiateMessage ();
282287				$ messagesetFrom (
@@ -288,10 +293,12 @@ public function schedule(Message $iTipMessage) {
288293				$ messagesetSubject ($ templaterenderSubject ());
289294				$ messagesetBodyPlain ($ templaterenderText ());
290295				$ messagesetBodyHtml ($ templaterenderHtml ());
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				$ messagesetAttachments ((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					(($ senderNamenull ) ? [$ sender$ senderName$ sender
308315				);
309316				$ messageuseTemplate ($ 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				$ messageattachInline (
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