Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix calendar emails to be outlook compatible #12946

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,17 @@ public function schedule(Message $iTipMessage) {
$template->addFooter();
$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->addPart(
$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
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,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 16.0.0
*/
public function addPart($data, $content_type = null, $charset = null): IMessage {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method here works different than addPart https://github.com/nextcloud/3rdparty/blob/da8e24b48079cec2f9c8be950f7b996bce172190/swiftmailer/swiftmailer/lib/classes/Swift/Message.php#L72 (from swiftmailer). I would prefer another name than because addPart from swiftmailer add a part with the current encoder while these method always uses 8bit encoder. I would add getEncoder and setEncoder and set the encoding from IMipPlugin but lets ask @nickvergessen first.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function addPart($data, $content_type = null, $charset = null): IMessage {
public function addPart($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();
$eightbit_encoder = new \Swift_Mime_ContentEncoder_PlainContentEncoder("8bit");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$eightbit_encoder = new \Swift_Mime_ContentEncoder_PlainContentEncoder("8bit");
$eightbitEncoder = new \Swift_Mime_ContentEncoder_PlainContentEncoder('8bit');

$this->swiftMessage->setEncoder($eightbit_encoder);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->swiftMessage->setEncoder($eightbit_encoder);
$this->swiftMessage->setEncoder($eightbitEncoder);

$this->swiftMessage->addPart($data, $content_type, $charset);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->swiftMessage->addPart($data, $content_type, $charset);
$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
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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 16.0.0
*/
public function addPart($body, $content_type = null, $charset = null): IMessage;

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