Skip to content

Commit

Permalink
Provide pgp/mime-encrypted messages to Mailvelope
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Zmdl <[email protected]>
  • Loading branch information
pabzm committed Sep 27, 2024
1 parent 8c802f5 commit ca90728
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
9 changes: 9 additions & 0 deletions lib/IMAP/ImapMessageFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class ImapMessageFetcher {
private ?string $unsubscribeUrl = null;
private bool $isOneClickUnsubscribe = false;
private ?string $unsubscribeMailto = null;
private bool $isPgpMimeEncrypted = false;

public function __construct(int $uid,
string $mailbox,
Expand Down Expand Up @@ -148,6 +149,13 @@ public function fetchMessage(?Horde_Imap_Client_Data_Fetch $fetch = null): IMAPM
// analyse the body part
$structure = $fetch->getStructure();

$this->isPgpMimeEncrypted = ($structure->getType() === 'multipart/encrypted'
&& $structure->getContentTypeParameter('protocol') === 'application/pgp-encrypted');
if ($this->isPgpMimeEncrypted) {
$this->plainMessage = $this->loadBodyData($structure, "2", false);
$this->attachmentsToIgnore[] = $structure->getPartByIndex(1)->getName();
}

$this->hasAnyAttachment = $this->hasAttachments($structure);

$isEncrypted = $this->smimeService->isEncrypted($fetch);
Expand Down Expand Up @@ -267,6 +275,7 @@ public function fetchMessage(?Horde_Imap_Client_Data_Fetch $fetch = null): IMAPM
$isSigned,
$signatureIsValid,
$this->htmlService, // TODO: drop the html service dependency
$this->isPgpMimeEncrypted,
);
}

Expand Down
10 changes: 9 additions & 1 deletion lib/Model/IMAPMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class IMAPMessage implements IMessage, JsonSerializable {
private bool $isEncrypted;
private bool $isSigned;
private bool $signatureIsValid;
private bool $isPgpMimeEncrypted;

public function __construct(int $uid,
string $messageId,
Expand Down Expand Up @@ -98,7 +99,8 @@ public function __construct(int $uid,
bool $isEncrypted,
bool $isSigned,
bool $signatureIsValid,
Html $htmlService) {
Html $htmlService,
bool $isPgpMimeEncrypted) {
$this->messageId = $uid;
$this->realMessageId = $messageId;
$this->flags = $flags;
Expand Down Expand Up @@ -128,6 +130,7 @@ public function __construct(int $uid,
$this->isSigned = $isSigned;
$this->signatureIsValid = $signatureIsValid;
$this->htmlService = $htmlService;
$this->isPgpMimeEncrypted = $isPgpMimeEncrypted;
}

public static function generateMessageId(): string {
Expand Down Expand Up @@ -317,6 +320,7 @@ public function jsonSerialize() {
'isOneClickUnsubscribe' => $this->isOneClickUnsubscribe,
'unsubscribeMailto' => $this->unsubscribeMailto,
'scheduling' => $this->scheduling,
'isPgpMimeEncrypted' => $this->isPgpMimeEncrypted,
];
}

Expand Down Expand Up @@ -459,6 +463,10 @@ public function isOneClickUnsubscribe(): bool {
return $this->isOneClickUnsubscribe;
}

public function isPgpMimeEncrypted(): bool {
return $this->isPgpMimeEncrypted;
}

/**
* Cast all values from an IMAP message into the correct DB format
*
Expand Down
5 changes: 4 additions & 1 deletion src/components/Message.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
:message="message"
:full-height="fullHeight"
@load="$emit('load', $event)" />
<MessageEncryptedBody v-else-if="isEncrypted"
<MessageEncryptedBody v-else-if="isEncrypted || isPgpMimeEncrypted"
:body="message.body"
:from="from"
:message="message" />
Expand Down Expand Up @@ -128,6 +128,9 @@ export default {
isEncrypted() {
return isPgpgMessage(this.message.hasHtmlBody ? html(this.message.body) : plain(this.message.body))
},
isPgpMimeEncrypted() {
return this.message.isPgpMimeEncrypted
},
itineraries() {
return this.message.itineraries ?? []
},
Expand Down

0 comments on commit ca90728

Please sign in to comment.