Skip to content
Merged
Changes from 1 commit
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
Next Next commit
Add iMIP parsing
Signed-off-by: Anna Larch <[email protected]>
  • Loading branch information
miaulalala committed Jul 14, 2022
commit ee4ddff53ba5c5078703cca9697a43c327fd46e2
54 changes: 40 additions & 14 deletions lib/Model/IMAPMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public function __construct($conn,
public $plainMessage = '';
public $attachments = [];
public $inlineAttachments = [];
public $scheduling = [];
private $loadHtmlMessage = false;
private $hasHtmlMessage = false;

Expand Down Expand Up @@ -398,6 +399,44 @@ private function loadMessageBodies(): void {
* @return void
*/
private function getPart(Horde_Mime_Part $p, $partNo): void {
// iMIP messages
// Handle text/calendar parts first because they might be attachments at the same time.
// Otherwise, some of the following if-conditions might break the handling and treat iMIP
// data like regular attachments.
$allContentTypeParameters = $p->getAllContentTypeParameters();
if ($p->getType() === 'text/calendar') {
// Handle event data like a regular attachment
// Outlook doesn't set a content disposition
// We work around this by checking for the name only
if ($p->getName() !== null) {
$this->attachments[] = [
'id' => $p->getMimeId(),
'messageId' => $this->messageId,
'fileName' => $p->getName(),
'mime' => $p->getType(),
'size' => $p->getBytes(),
'cid' => $p->getContentId(),
'disposition' => $p->getDisposition()
];
}

// return if this is an event attachment only
// the method parameter determines if this is a iMIP message
if (!isset($allContentTypeParameters['method'])) {
return;
}

if (in_array(strtoupper($allContentTypeParameters['method']), ['REQUEST', 'REPLY', 'CANCEL'])) {
$this->scheduling[] = [
'id' => $p->getMimeId(),
'messageId' => $this->messageId,
'method' => strtoupper($allContentTypeParameters['method']),
'contents' => $this->loadBodyData($p, $partNo),
];
return;
}
}

// Regular attachments
if ($p->isAttachment() || $p->getType() === 'message/rfc822') {
$this->attachments[] = [
Expand Down Expand Up @@ -442,19 +481,6 @@ private function getPart(Horde_Mime_Part $p, $partNo): void {
return;
}

if ($p->getType() === 'text/calendar') {
$this->attachments[] = [
'id' => $p->getMimeId(),
'messageId' => $this->messageId,
'fileName' => $p->getName() ?? 'calendar.ics',
'mime' => $p->getType(),
'size' => $p->getBytes(),
'cid' => $p->getContentId(),
'disposition' => $p->getDisposition()
];
return;
}

if ($p->getType() === 'text/html') {
$this->handleHtmlMessage($p, $partNo);
return;
Expand All @@ -478,7 +504,6 @@ private function getPart(Horde_Mime_Part $p, $partNo): void {
*/
public function getFullMessage(int $id): array {
$mailBody = $this->plainMessage;

$data = $this->jsonSerialize();
if ($this->hasHtmlMessage) {
$data['hasHtmlBody'] = true;
Expand Down Expand Up @@ -509,6 +534,7 @@ public function jsonSerialize() {
'flags' => $this->getFlags(),
'hasHtmlBody' => $this->hasHtmlMessage,
'dispositionNotificationTo' => $this->getDispositionNotificationTo(),
'scheduling' => $this->scheduling,
];
}

Expand Down