diff --git a/easy_unsubscribe.php b/easy_unsubscribe.php index a43ed48..1ef296c 100644 --- a/easy_unsubscribe.php +++ b/easy_unsubscribe.php @@ -2,6 +2,9 @@ class easy_unsubscribe extends rcube_plugin { + private $message_headers_done = false; + private $unsubscribe_img; + function init() { $rcmail = rcmail::get_instance(); @@ -21,19 +24,28 @@ class easy_unsubscribe extends rcube_plugin public function message_headers($p) { - $ListUnsubscribe = $p['headers']->others['list-unsubscribe']; - preg_match('/<(.*?)>/', $ListUnsubscribe, $rVal); - if($rVal[1]!='') - $O = 'Unsubscribe'; - else + if($this->message_headers_done===false) { - preg_match('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $ListUnsubscribe, $rVal); - if($rVal[0]!='') - $O = 'Unsubscribe'; + $this->message_headers_done = true; + + $ListUnsubscribe = $p['headers']->others['list-unsubscribe']; + preg_match('/<(.*?)>/', $ListUnsubscribe, $rVal); + + if($rVal[1]!='') + $this->unsubscribe_img = 'Unsubscribe'; + else + { + preg_match('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $ListUnsubscribe, $rVal); + if($rVal[0]!='') + $this->unsubscribe_img = 'Unsubscribe'; + } + } + + if(isset($p['output']['subject'])) + { + $p['output']['subject']['value'] = $p['output']['subject']['value'] . $this->unsubscribe_img; + $p['output']['subject']['html'] = 1; } - - $p['output']['subject']['value'] = $p['output']['subject']['value'] . $O; - $p['output']['subject']['html'] = true; return $p; }