Skip to content

Commit

Permalink
fixup! feat: One-click unsubscribe
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Kesselberg <[email protected]>
  • Loading branch information
kesselb committed May 4, 2023
1 parent 90721d2 commit efebc54
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions lib/IMAP/ImapMessageFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,24 +515,29 @@ private function parseHeaders(Horde_Imap_Client_Data_Fetch $fetch): void {
$this->dispositionNotificationTo = $dispositionNotificationTo->value_single;
}

$listUnsubscribeHeader = $parsedHeaders->getHeader('list-unsubscribe');
if ($listUnsubscribeHeader !== null) {
$listHeaders = new Horde_ListHeaders();
/** @var Horde_ListHeaders_Base[] $headers */
$headers = $listHeaders->parse($listUnsubscribeHeader->name, $listUnsubscribeHeader->value_single);
foreach ($headers as $header) {
if (str_starts_with($header->url, 'http')) {
$this->unsubscribeUrl = $header->url;

$unsubscribePostHeader = $parsedHeaders->getHeader('List-Unsubscribe-Post');
if ($unsubscribePostHeader !== null) {
$this->isOneClickUnsubscribe = strtolower($unsubscribePostHeader->value_single) === 'list-unsubscribe=one-click';
$dkimSignatureHeader = $parsedHeaders->getHeader('dkim-signature');
$hasDkimSignature = $dkimSignatureHeader !== null;

if ($hasDkimSignature) {
$listUnsubscribeHeader = $parsedHeaders->getHeader('list-unsubscribe');
if ($listUnsubscribeHeader !== null) {
$listHeaders = new Horde_ListHeaders();
/** @var Horde_ListHeaders_Base[] $headers */
$headers = $listHeaders->parse($listUnsubscribeHeader->name, $listUnsubscribeHeader->value_single);
foreach ($headers as $header) {
if (str_starts_with($header->url, 'http')) {
$this->unsubscribeUrl = $header->url;

$unsubscribePostHeader = $parsedHeaders->getHeader('List-Unsubscribe-Post');
if ($unsubscribePostHeader !== null) {
$this->isOneClickUnsubscribe = strtolower($unsubscribePostHeader->value_single) === 'list-unsubscribe=one-click';
}
break;
}
if (str_starts_with($header->url, 'mailto')) {
$this->unsubscribeMailto = $header->url;
break;
}
break;
}
if (str_starts_with($header->url, 'mailto')) {
$this->unsubscribeMailto = $header->url;
break;
}
}
}
Expand Down

0 comments on commit efebc54

Please sign in to comment.