Skip to content

Commit

Permalink
fix: retrieve body structure and process parts on mailbox sync
Browse files Browse the repository at this point in the history
Signed-off-by: SebastianKrupinski <[email protected]>
  • Loading branch information
SebastianKrupinski committed Aug 25, 2024
1 parent 364202d commit 701de26
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
4 changes: 3 additions & 1 deletion lib/Db/MessageMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,9 @@ public function insertBulk(Account $account, Message ...$messages): void {
$qb1->setValue('flag_notjunk', $qb1->createParameter('flag_notjunk'));
$qb1->setValue('flag_important', $qb1->createParameter('flag_important'));
$qb1->setValue('flag_mdnsent', $qb1->createParameter('flag_mdnsent'));
$qb2 = $this->db->getQueryBuilder();
$qb1->setValue('imip_message', $qb1->createParameter('imip_message'));

$qb2 = $this->db->getQueryBuilder();
$qb2->insert('mail_recipients')
->setValue('message_id', $qb2->createParameter('message_id'))
->setValue('type', $qb2->createParameter('type'))
Expand Down Expand Up @@ -309,6 +310,7 @@ public function insertBulk(Account $account, Message ...$messages): void {
$qb1->setParameter('flag_notjunk', $message->getFlagNotjunk(), IQueryBuilder::PARAM_BOOL);
$qb1->setParameter('flag_important', $message->getFlagImportant(), IQueryBuilder::PARAM_BOOL);
$qb1->setParameter('flag_mdnsent', $message->getFlagMdnsent(), IQueryBuilder::PARAM_BOOL);
$qb1->setParameter('imip_message', $message->isImipMessage(), IQueryBuilder::PARAM_BOOL);
$qb1->executeStatement();

$message->setId($qb1->getLastInsertId());
Expand Down
38 changes: 24 additions & 14 deletions lib/IMAP/ImapMessageFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,24 +203,11 @@ public function fetchMessage(?Horde_Imap_Client_Data_Fetch $fetch = null): IMAPM
'forcemime' => true,
]);
}

// debugging below
$structure_type = $structure->getPrimaryType();
if ($structure_type === 'multipart') {
$i = 1;
foreach ($structure->getParts() as $p) {
$this->getPart($p, (string)$i++, $isEncrypted || $isSigned);
}
} else {
$bodyPartId = $structure->findBody();
if (!is_null($bodyPartId)) {
$this->getPart($structure[$bodyPartId], $bodyPartId, $isEncrypted || $isSigned);
}
}
} elseif (is_null($fetch)) {
// Reuse given query or construct a new minimal one
$query = new Horde_Imap_Client_Fetch_Query();
$query->envelope();
$query->structure();
$query->flags();
$query->imapDate();
$query->headerText([
Expand All @@ -234,6 +221,29 @@ public function fetchMessage(?Horde_Imap_Client_Data_Fetch $fetch = null): IMAPM
}
}

// determine if message structure was already extracted
if (!isset($structure)) {
// extract message structure
$structure = $fetch->getStructure();
}
// determine if we finally have a message structure
// and process the message parts if structure exists
if ($structure !== null) {
// debugging below
$structure_type = $structure->getPrimaryType();
if ($structure_type === 'multipart') {
$i = 1;
foreach ($structure->getParts() as $p) {
$this->getPart($p, (string)$i++, $isEncrypted || $isSigned);
}
} else {
$bodyPartId = $structure->findBody();
if (!is_null($bodyPartId)) {
$this->getPart($structure[$bodyPartId], $bodyPartId, $isEncrypted || $isSigned);
}
}
}

$this->parseHeaders($fetch);

$envelope = $fetch->getEnvelope();
Expand Down
1 change: 1 addition & 0 deletions lib/IMAP/MessageMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ public function findByIds(Horde_Imap_Client_Base $client,
bool $runPhishingCheck = false): array {
$query = new Horde_Imap_Client_Fetch_Query();
$query->envelope();
$query->structure();
$query->flags();
$query->uid();
$query->imapDate();
Expand Down

0 comments on commit 701de26

Please sign in to comment.