2018-02-12 11:23:51 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class easy_unsubscribe extends rcube_plugin
|
|
|
|
{
|
2018-02-14 12:15:54 -05:00
|
|
|
private $message_headers_done = false;
|
|
|
|
private $unsubscribe_img;
|
|
|
|
|
2018-02-12 11:23:51 -05:00
|
|
|
function init()
|
|
|
|
{
|
|
|
|
$rcmail = rcmail::get_instance();
|
|
|
|
$layout = $rcmail->config->get('layout');
|
|
|
|
|
|
|
|
$this->add_hook('message_headers_output', array($this, 'message_headers'));
|
|
|
|
$this->add_hook('storage_init', array($this, 'storage_init'));
|
|
|
|
|
|
|
|
$this->include_stylesheet('easy_unsubscribe.css');
|
2021-07-12 17:53:49 +07:00
|
|
|
|
|
|
|
$this->add_texts('localization/');
|
2018-02-12 11:23:51 -05:00
|
|
|
}
|
|
|
|
|
2018-02-14 12:26:03 -05:00
|
|
|
public function storage_init($p)
|
|
|
|
{
|
|
|
|
$p['fetch_headers'] = trim($p['fetch_headers'] . ' ' . strtoupper('List-Unsubscribe'));
|
|
|
|
return $p;
|
|
|
|
}
|
2018-02-12 11:23:51 -05:00
|
|
|
|
2018-02-14 12:26:03 -05:00
|
|
|
public function message_headers($p)
|
|
|
|
{
|
|
|
|
if($this->message_headers_done===false)
|
2018-02-12 11:23:51 -05:00
|
|
|
{
|
2018-02-14 12:15:54 -05:00
|
|
|
$this->message_headers_done = true;
|
2018-02-14 12:26:03 -05:00
|
|
|
|
2018-02-14 12:15:54 -05:00
|
|
|
$ListUnsubscribe = $p['headers']->others['list-unsubscribe'];
|
2019-08-25 13:27:58 +02:00
|
|
|
if ( preg_match_all('/<(.+)>/mU', $ListUnsubscribe, $items, PREG_PATTERN_ORDER) ) {
|
|
|
|
foreach ( $items[1] as $uri ) {
|
2021-07-12 17:53:49 +07:00
|
|
|
$this->unsubscribe_img .= '<a class="easy_unsubscribe_link tooltip-right" data-tooltip="' . $this->gettext('click_to_unsubscribe') . '" href="'. htmlentities($uri) .'" target="_blank" onclick="return confirm(\'' . $this->gettext('confirm') . '\');"><img src="plugins/easy_unsubscribe/icon.png" alt="' . $this->gettext('unsubscribe') . '" /></a>';
|
2019-08-25 13:27:58 +02:00
|
|
|
}
|
|
|
|
}
|
2018-02-14 12:15:54 -05:00
|
|
|
}
|
2018-02-14 12:26:03 -05:00
|
|
|
|
2018-02-14 12:15:54 -05:00
|
|
|
if(isset($p['output']['subject']))
|
|
|
|
{
|
|
|
|
$p['output']['subject']['value'] = $p['output']['subject']['value'] . $this->unsubscribe_img;
|
|
|
|
$p['output']['subject']['html'] = 1;
|
2018-02-12 11:23:51 -05:00
|
|
|
}
|
|
|
|
|
2018-02-14 12:26:03 -05:00
|
|
|
return $p;
|
|
|
|
}
|
2021-07-12 17:53:49 +07:00
|
|
|
}
|