diff --git a/easy_unsubscribe.php b/easy_unsubscribe.php index 2246f73..c1231f9 100644 --- a/easy_unsubscribe.php +++ b/easy_unsubscribe.php @@ -44,13 +44,13 @@ class easy_unsubscribe extends rcube_plugin { // Array to store all patterns we want to match $patterns = [ // Standard tag pattern - '/]*?\s+)?href=(["\'])((?:https?:)?\/\/[^"\']*?(?:unsubscribe|dummy-esclick)[^"\']*)\1/i', + '/]*?\s+)?href=(["\'])((?:https?:)?\/\/[^"\']*?(?:unsubscribe)[^"\']*)\1/i', // Square bracket pattern [URL] common in email templates - '/\[\s*((?:https?:)?\/\/[^\]]*?(?:unsubscribe|dummy-esclick)[^\]]*)\s*\]/i', + '/\[\s*((?:https?:)?\/\/[^\]]*?(?:unsubscribe)[^\]]*)\s*\]/i', // Bare URLs with unsubscribe/esclick - '/((?:https?:)?\/\/[^\s<>\[\]"\']*?(?:unsubscribe|dummy-esclick)[^\s<>\[\]"\']*)/i' + '/((?:https?:)?\/\/[^\s<>\[\]"\']*?(?:unsubscribe)[^\s<>\[\]"\']*)/i' ]; $allUrls = []; @@ -80,7 +80,6 @@ class easy_unsubscribe extends rcube_plugin { if($this->message_headers_done === false) { $this->message_headers_done = true; - if(!isset($p['headers']->others['list-unsubscribe'])) return $p; $urls = []; @@ -89,7 +88,7 @@ class easy_unsubscribe extends rcube_plugin { $urls = array_merge($urls, $this->extractUnsubscribeUrls($body)); - $ListUnsubscribe = $this->decodeMimeHeader($p['headers']->others['list-unsubscribe']); + $ListUnsubscribe = $this->decodeMimeHeader($p['headers']->others['list-unsubscribe'] ?? ''); if (preg_match_all('/<(.+)>/mU', $ListUnsubscribe, $items, PREG_PATTERN_ORDER)) { foreach ( $items[1] as $uri ) { $urls[] = $uri; @@ -98,9 +97,20 @@ class easy_unsubscribe extends rcube_plugin { $urls = array_unique($urls); + $exclude_strings = ['?', 'esputnik', 'unsubscribe/']; + foreach ($urls as $uri) { if (str_contains($uri, 'mailto')) continue; - if (!str_contains($uri, '?') && !str_contains($uri, 'esputnik')) continue; + + $should_continue = false; + foreach ($exclude_strings as $exclude_string) { + if (str_contains($uri, $exclude_string)) { + $should_continue = true; + break; + } + } + if (!$should_continue) continue; + $this->unsubscribe_img .= '' . $this->gettext('unsubscribe') . ''; }