You've already forked roundcube-easy-unsubscribe
Compare commits
16 Commits
5acfc11b48
...
master
Author | SHA1 | Date | |
---|---|---|---|
e3f841af59
|
|||
8df9a270ae
|
|||
5b2945686f
|
|||
f80acac49b
|
|||
2a89cac244
|
|||
636d43e97e
|
|||
4f84f7c31c | |||
0da7ce2a12 | |||
39483b56ef | |||
3970c082f6 | |||
6154d87a89 | |||
f783ff59ec | |||
3a10b296f3 | |||
e50726b58a | |||
c3ae9edb7c | |||
9a72724a02 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.idea
|
22
README.md
22
README.md
@ -1,4 +1,22 @@
|
|||||||
# Roundcube Easy Unsubscribe
|
# Roundcube Easy Unsubscribe
|
||||||
Displays a small icon after the subject line when viewing an email, so you can very quickly unsubscribe.
|
Displays a small icon after the subject line when viewing an email, so you can very quickly unsubscribe. Multiple icons may show as the plugin is reliant upon the `List-Unsubscribe` header. Sometimes emails use multiple i.e. one mailto: and one URL.
|
||||||
|
|
||||||

|
|
||||||
|
## Demo Visual
|
||||||
|

|
||||||
|
|
||||||
|
## Deployment
|
||||||
|
|
||||||
|
Download a copy of this repo and upload the contents to:
|
||||||
|
```
|
||||||
|
/path/to/roundcube/plugins/easy_unsubscribe
|
||||||
|
```
|
||||||
|
|
||||||
|
Edit your `/path/to/roundcube/config/config.inc.php` file and add `easy_unsubscribe` to the `$config['plugins']` variable. It should look something like the following:
|
||||||
|
|
||||||
|
```
|
||||||
|
$config['plugins'] = array(
|
||||||
|
'password',
|
||||||
|
'easy_unsubscribe'
|
||||||
|
);
|
||||||
|
```
|
||||||
|
@ -1,16 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "ss88/easy_unsubscribe",
|
"name": "stuzer05/roundcube-easy-unsubscribe",
|
||||||
"type": "roundcube-plugin",
|
"type": "roundcube-plugin",
|
||||||
"description": "Displays a small icon after the subject line when viewing an email, so you can very quickly unsubscribe.",
|
"description": "Displays a small icon after the subject line when viewing an email, so you can very quickly unsubscribe.",
|
||||||
"license": "GPL-3.0+",
|
"license": "GPL-3.0+",
|
||||||
"keywords": ["unsubscribe","subscription", "newsletter", "mailer"],
|
"keywords": ["unsubscribe","subscription", "newsletter", "mailer"],
|
||||||
"homepage": "https://github.com/SS88UK/roundcube-easy-unsubscribe",
|
"homepage": "https://gitea.stuzer.link/stuzer05/roundcube-easy-unsubscribe",
|
||||||
"repositories": [
|
|
||||||
{
|
|
||||||
"type": "composer",
|
|
||||||
"url": "https://plugins.roundcube.net"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"require": {
|
"require": {
|
||||||
"roundcube/plugin-installer": ">=0.1.6"
|
"roundcube/plugin-installer": ">=0.1.6"
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
.easy_unsubscribe_link img { height: 13px; margin-left: 10px; vertical-align: middle; opacity: 0.5; transition:all 0.3s ease; }
|
.easy_unsubscribe_link img {
|
||||||
.easy_unsubscribe_link:hover img { opacity:1; }
|
height: 20px;
|
||||||
|
margin-left: 10px;
|
||||||
|
vertical-align: middle;
|
||||||
|
opacity: 0.5;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
.easy_unsubscribe_link:hover img {
|
||||||
* Tooltip Styles
|
opacity: 1;
|
||||||
*/
|
}
|
||||||
|
|
||||||
.tooltip,[data-tooltip]{position:relative;cursor:pointer}.tooltip:after,.tooltip:before,[data-tooltip]:after,[data-tooltip]:before{position:absolute;visibility:hidden;-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";filter:alpha(Opacity=0);opacity:0;-webkit-transition:opacity .2s ease-in-out,visibility .2s ease-in-out,-webkit-transform .2s cubic-bezier(.71,1.7,.77,1.24);-moz-transition:opacity .2s ease-in-out,visibility .2s ease-in-out,-moz-transform .2s cubic-bezier(.71,1.7,.77,1.24);transition:opacity .2s ease-in-out,visibility .2s ease-in-out,transform .2s cubic-bezier(.71,1.7,.77,1.24);-webkit-transform:translate3d(0,0,0);-moz-transform:translate3d(0,0,0);transform:translate3d(0,0,0);pointer-events:none}.tooltip:focus:after,.tooltip:focus:before,.tooltip:hover:after,.tooltip:hover:before,[data-tooltip]:focus:after,[data-tooltip]:focus:before,[data-tooltip]:hover:after,[data-tooltip]:hover:before{visibility:visible;-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";filter:alpha(Opacity=100);opacity:1}.tooltip:before,[data-tooltip]:before{z-index:1001;border:6px solid transparent;background:0 0;content:""}.tooltip:after,[data-tooltip]:after{z-index:1000;padding:5px 10px;width:160px;background-color:#000;background-color:hsla(0,0%,20%,.9);color:#fff;content:attr(data-tooltip);font-size:11px;line-height:11px}.tooltip-top:after,.tooltip-top:before,.tooltip:after,.tooltip:before,[data-tooltip]:after,[data-tooltip]:before{bottom:100%;left:50%}.tooltip-top:before,.tooltip:before,[data-tooltip]:before{margin-left:-6px;margin-bottom:-12px;border-top-color:#000;border-top-color:hsla(0,0%,20%,.9)}.tooltip-right:after,.tooltip-right:before{bottom:50%;left:100%}.tooltip-right:before{margin-bottom:0;margin-left:-12px;border-top-color:transparent;border-right-color:#000;border-right-color:hsla(0,0%,20%,.9)}.tooltip-right:focus:after,.tooltip-right:focus:before,.tooltip-right:hover:after,.tooltip-right:hover:before{-webkit-transform:translateX(12px);-moz-transform:translateX(12px);transform:translateX(12px)}.tooltip-left:before,.tooltip-right:before{top:3px}.tooltip-left:after,.tooltip-right:after{margin-left:0;margin-bottom:-10px}
|
|
9
easy_unsubscribe.js
Normal file
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,129 @@
|
|||||||
<?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();
|
ini_set('display_errors', '1');
|
||||||
$layout = $rcmail->config->get('layout');
|
ini_set('display_startup_errors', '1');
|
||||||
|
error_reporting(E_ALL);
|
||||||
$this->add_hook('message_headers_output', array($this, 'message_headers'));
|
|
||||||
$this->add_hook('storage_init', array($this, 'storage_init'));
|
$rcmail = rcmail::get_instance();
|
||||||
|
$layout = $rcmail->config->get('layout');
|
||||||
$this->include_stylesheet('easy_unsubscribe.css');
|
|
||||||
|
$this->add_hook('message_headers_output', array($this, 'message_headers'));
|
||||||
$this->add_texts('localization/');
|
$this->add_hook('storage_init', array($this, 'storage_init'));
|
||||||
}
|
|
||||||
|
$this->include_stylesheet('easy_unsubscribe.css');
|
||||||
public function storage_init($p)
|
$this->include_script('easy_unsubscribe.js');
|
||||||
{
|
|
||||||
$p['fetch_headers'] = trim($p['fetch_headers'] . ' ' . strtoupper('List-Unsubscribe'));
|
$this->add_texts('localization/');
|
||||||
return $p;
|
|
||||||
}
|
$rcmail->output->add_label('easy_unsubscribe.confirm');
|
||||||
|
}
|
||||||
public function message_headers($p)
|
|
||||||
{
|
public function storage_init($p) {
|
||||||
if($this->message_headers_done===false)
|
$p['fetch_raw_body'] = true;
|
||||||
{
|
$p['fetch_headers'] = trim($p['fetch_headers'] . ' ' . strtoupper('List-Unsubscribe'));
|
||||||
$this->message_headers_done = true;
|
return $p;
|
||||||
|
|
||||||
$ListUnsubscribe = $p['headers']->others['list-unsubscribe'];
|
}
|
||||||
if ( preg_match_all('/<(.+)>/mU', $ListUnsubscribe, $items, PREG_PATTERN_ORDER) ) {
|
|
||||||
foreach ( $items[1] as $uri ) {
|
public function decodeMimeHeader($header) {
|
||||||
$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>';
|
$elements = imap_mime_header_decode($header);
|
||||||
}
|
|
||||||
}
|
return array_reduce($elements, function ($carry, $element) {
|
||||||
}
|
return $carry . $element->text;
|
||||||
|
}, '');
|
||||||
if(isset($p['output']['subject']))
|
}
|
||||||
{
|
|
||||||
$p['output']['subject']['value'] = $p['output']['subject']['value'] . $this->unsubscribe_img;
|
public function extractUnsubscribeUrls($content) {
|
||||||
$p['output']['subject']['html'] = 1;
|
// Array to store all patterns we want to match
|
||||||
}
|
$patterns = [
|
||||||
|
// Standard <a> tag pattern
|
||||||
return $p;
|
'/<a\s+(?:[^>]*?\s+)?href=(["\'])((?:https?:)?\/\/[^"\']*?(?:unsubscribe)[^"\']*)\1/i',
|
||||||
}
|
|
||||||
}
|
// Square bracket pattern [URL] common in email templates
|
||||||
|
'/\[\s*((?:https?:)?\/\/[^\]]*?(?:unsubscribe)[^\]]*)\s*\]/i',
|
||||||
|
|
||||||
|
// Bare URLs with unsubscribe/esclick
|
||||||
|
'/((?:https?:)?\/\/[^\s<>\[\]"\']*?(?:unsubscribe)[^\s<>\[\]"\']*)/i'
|
||||||
|
];
|
||||||
|
|
||||||
|
$allUrls = [];
|
||||||
|
foreach ($patterns as $pattern) {
|
||||||
|
$matches = [];
|
||||||
|
preg_match_all($pattern, $content, $matches);
|
||||||
|
|
||||||
|
// For the first pattern, we want group 2, for others group 1
|
||||||
|
$groupIndex = (strpos($pattern, 'href') !== false) ? 2 : 1;
|
||||||
|
if (!empty($matches[$groupIndex])) {
|
||||||
|
$allUrls = array_merge($allUrls, $matches[$groupIndex]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove duplicates and clean URLs
|
||||||
|
$allUrls = array_unique($allUrls);
|
||||||
|
$cleanUrls = array_map(function($url) {
|
||||||
|
return trim($url);
|
||||||
|
}, $allUrls);
|
||||||
|
|
||||||
|
return array_values(array_filter($cleanUrls));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function message_headers($p) {
|
||||||
|
if($this->message_headers_done === false) {
|
||||||
|
|
||||||
|
$this->message_headers_done = true;
|
||||||
|
|
||||||
|
$urls = [];
|
||||||
|
|
||||||
|
$rcmail = rcmail::get_instance();
|
||||||
|
$body = quoted_printable_decode($rcmail->storage->get_raw_body($p['uid']));
|
||||||
|
|
||||||
|
$urls = array_merge($urls, $this->extractUnsubscribeUrls($body));
|
||||||
|
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$urls = array_unique($urls);
|
||||||
|
|
||||||
|
$exclude_strings = ['?', 'esputnik', 'unsubscribe/'];
|
||||||
|
|
||||||
|
foreach ($urls as $uri) {
|
||||||
|
if (str_contains($uri, 'mailto')) 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 .= '<a class="easy_unsubscribe_link" title="'.$uri.'" data-href="'. htmlentities($uri) .'" target="_blank" onclick="easy_unsubscribe_click(this);"><img src="plugins/easy_unsubscribe/icon.png" alt="' . $this->gettext('unsubscribe') . '" /></a>';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($p['output']['subject'])) {
|
||||||
|
$p['output']['subject']['value'] = $p['output']['subject']['value'] . $this->unsubscribe_img;
|
||||||
|
$p['output']['subject']['html'] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $p;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
BIN
icon.png
BIN
icon.png
Binary file not shown.
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 2.0 KiB |
@ -2,6 +2,5 @@
|
|||||||
|
|
||||||
$labels = array();
|
$labels = array();
|
||||||
|
|
||||||
$labels['click_to_unsubscribe'] = "Click to unsubscribe";
|
|
||||||
$labels['confirm'] = "Are you sure you want to unsubscribe?";
|
$labels['confirm'] = "Are you sure you want to unsubscribe?";
|
||||||
$labels['unsubscribe'] = "Unsubscribe";
|
$labels['unsubscribe'] = "Unsubscribe";
|
||||||
|
6
localization/es_ES.inc
Normal file
6
localization/es_ES.inc
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$labels = array();
|
||||||
|
|
||||||
|
$labels['confirm'] = "¿Estás seguro de que deseas anular la suscripción?";
|
||||||
|
$labels['unsubscribe'] = "Anular suscripción";
|
6
localization/ru_RU.inc
Normal file
6
localization/ru_RU.inc
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$labels = array();
|
||||||
|
|
||||||
|
$labels['confirm'] = "Вы уверены, что хотите отказаться от подписки?";
|
||||||
|
$labels['unsubscribe'] = "Отписаться";
|
BIN
screenshots/icon-showcase.png
Normal file
BIN
screenshots/icon-showcase.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
Reference in New Issue
Block a user