Updated 2023

Works in newer RC.
This commit is contained in:
Steven Sullivan 2023-11-29 12:41:51 -05:00 committed by GitHub
parent 3a10b296f3
commit f783ff59ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 70 additions and 48 deletions

9
easy_unsubscribe.js Normal file

@ -0,0 +1,9 @@
function easy_unsubscribe_click(link) {
if(confirm(rcmail.get_label('confirm', 'easy_unsubscribe'))) {
if(link.dataset.href) window.open(link.dataset.href, '_blank');
}
}

@ -1,49 +1,62 @@
<?php <?php
class easy_unsubscribe extends rcube_plugin class easy_unsubscribe extends rcube_plugin {
{
private $message_headers_done = false; public $task = 'mail';
private $unsubscribe_img; private $message_headers_done = false;
private $unsubscribe_img;
function init()
{ function init() {
$rcmail = rcmail::get_instance();
$layout = $rcmail->config->get('layout'); $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->add_hook('message_headers_output', array($this, 'message_headers'));
$this->add_hook('storage_init', array($this, 'storage_init'));
$this->include_stylesheet('easy_unsubscribe.css');
$this->include_stylesheet('easy_unsubscribe.css');
$this->add_texts('localization/'); $this->include_script('easy_unsubscribe.js');
}
$this->add_texts('localization/');
public function storage_init($p)
{ $rcmail->output->add_label('easy_unsubscribe.confirm');
$p['fetch_headers'] = trim($p['fetch_headers'] . ' ' . strtoupper('List-Unsubscribe'));
return $p; }
}
public function storage_init($p) {
public function message_headers($p)
{ $p['fetch_headers'] = trim($p['fetch_headers'] . ' ' . strtoupper('List-Unsubscribe'));
if($this->message_headers_done===false) return $p;
{
$this->message_headers_done = true; }
$ListUnsubscribe = $p['headers']->others['list-unsubscribe']; public function message_headers($p) {
if ( preg_match_all('/<(.+)>/mU', $ListUnsubscribe, $items, PREG_PATTERN_ORDER) ) {
foreach ( $items[1] as $uri ) { if($this->message_headers_done===false) {
$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>';
} $this->message_headers_done = true;
} $ListUnsubscribe = $p['headers']->others['list-unsubscribe'];
}
if (preg_match_all('/<(.+)>/mU', $ListUnsubscribe, $items, PREG_PATTERN_ORDER)) {
if(isset($p['output']['subject']))
{ foreach ( $items[1] as $uri ) {
$p['output']['subject']['value'] = $p['output']['subject']['value'] . $this->unsubscribe_img;
$p['output']['subject']['html'] = 1; $this->unsubscribe_img .= '<a class="easy_unsubscribe_link tooltip-right" data-tooltip="' . $this->gettext('click_to_unsubscribe') . '" data-href="'. htmlentities($uri) .'" target="_blank" onclick="easy_unsubscribe_click(this);"><img src="plugins/easy_unsubscribe/icon.png" alt="' . $this->gettext('unsubscribe') . '" /></a>';
}
}
return $p; }
}
}
if(isset($p['output']['subject'])) {
$p['output']['subject']['value'] = $p['output']['subject']['value'] . $this->unsubscribe_img;
$p['output']['subject']['html'] = 1;
}
return $p;
}
} }