Skip to content

Commit

Permalink
Implementation of nextcloud#12885
Browse files Browse the repository at this point in the history
Signed-off-by: hdijkema <hans@dykema.nl>
  • Loading branch information
hdijkema committed Dec 9, 2018
1 parent 554e7bd commit 546480e
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 5 deletions.
49 changes: 44 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,51 @@ 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 thinderbird Lightning.
# using a plain text text/calendar ics.
# This plain text text/calendar part is needed for
# Microsoft Outlook versions <=2010 to work.

# The attachment base64 text/calendar part is removed from the code
#$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
#);
#$message->attach($attachment);

# The plain text text/calendar part is added to the code, but we need
# to do something more. Outlook (2010 and 2016 tested) has problems with canceled messages
# that contain Time Zone Identifications (e.g. ;TZID=Europe/Amsterdam:).
# A 'not-supported-calendar-message.ics' is shown and the cancellation is not recognized.
#
# See e.g.: https://stackoverflow.com/questions/48550054/icalendar-appointment-is-a-not-supported-calendar-message-ics
#
# To work around this problem, DTSTART and DTEND are converted to UTC.
# UTC date/times work in all situations.

$utc_tz = new \DateTimeZone("UTC");

$cvt_dtstart = $start;
$cvt_dtstart_dt = $cvt_dtstart->getDateTime();
$dtstart_ts = $cvt_dtstart_dt->getTimestamp();
$cvt_dtstart_dt = new \DateTime("now", $utc_tz);
$cvt_dtstart_dt->setTimestamp($dtstart_ts);
$cvt_dtstart->setDateTime($cvt_dtstart_dt, false);

$cvt_dtend = $end;
$cvt_dtend_dt = $cvt_dtend->getDateTime();
$dtend_ts = $cvt_dtend_dt->getTimestamp();
$cvt_dtend_dt = new \DateTime("now", $utc_tz);
$cvt_dtend_dt->setTimestamp($dtend_ts);
$cvt_dtend->setDateTime($cvt_dtend_dt, false);

$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 14.0.4
*/
public function addPart($data, $content_type = 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");
$this->swiftMessage->setEncoder($eightbit_encoder);
$this->swiftMessage->addPart($data, $content_type, $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 14.0.4
*/
public function addPart($body, $content_type = null, $charset = null): IMessage;

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

0 comments on commit 546480e

Please sign in to comment.