Skip to content

Commit

Permalink
recreating pull request nextcloud#12946
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinwoff committed Sep 29, 2022
1 parent a880f79 commit 185dcc4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
16 changes: 11 additions & 5 deletions apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
Expand Up @@ -279,12 +279,18 @@ public function schedule(Message $iTipMessage) {

$message->useTemplate($template);

$attachment = $this->mailer->createAttachment(
$iTipMessage->message->serialize(),
'event.ics',// TODO(leon): Make file name unique, e.g. add event id
'text/calendar; method=' . $iTipMessage->method
/*
** We choose to work like Thunderbird Lightning.
** using a plain text text/calendar ics.
** This plain text text/calendar part is needed for
** Microsoft Outlook versions <= 2010 to work.
*/
$itip_msg = $iTipMessage->message->serialize();
$message->attachInline(
$itip_msg,
'text/calendar; method=' . $iTipMessage->method,
'UTF-8'
);
$message->attach($attachment);

try {
$failed = $this->mailer->send($message);
Expand Down
20 changes: 20 additions & 0 deletions lib/private/Mail/Message.php
Expand Up @@ -63,6 +63,26 @@ public function attach(IAttachment $attachment): IMessage {
return $this;
}

/**
* @param $body: body of the mime part
* @param $content-type = null: Mime Content-Type (e.g. text/plain or text/calendar)
* @param $charset = null: Character Set (e.g. UTF-8)
* @return $this
* @since 24.0.6
*/
public function attachInline($data, $contentType = null, $charset = null): IMessage {
# To be sure this works with iCalendar messages, we encode with 8bit instead of
# quoted-printable encoding. We save the current encoder, replace the current
# encoder with an 8bit encoder and after we've finished, we reset the encoder
# to the previous one.
$encoder = $this->swiftMessage->getEncoder();
$eightbitEncoder = new \Swift_Mime_ContentEncoder_PlainContentEncoder('8bit');
$this->swiftMessage->setEncoder($eightbitEncoder);
$this->swiftMessage->addPart($data, $contentType, $charset);
$this->swiftMessage->setEncoder($encoder);
return $this;
}

/**
* SwiftMailer does currently not work with IDN domains, this function therefore converts the domains
* FIXME: Remove this once SwiftMailer supports IDN
Expand Down
9 changes: 9 additions & 0 deletions lib/public/Mail/IMessage.php
Expand Up @@ -40,6 +40,15 @@ interface IMessage {
*/
public function attach(IAttachment $attachment): IMessage;

/**
* @param $body: body of the mime part
* @param $content-type = null: Mime Content-Type (e.g. text/plain or text/calendar)
* @param $charset = null: Character Set (e.g. UTF-8)
* @return IMessage
* @since 24.0.6
*/
public function attachInline($body, $content_type = null, $charset = null): IMessage;

/**
* Set the from address of this message.
*
Expand Down

0 comments on commit 185dcc4

Please sign in to comment.