-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy patheasy_unsubscribe.php
64 lines (37 loc) · 1.68 KB
/
easy_unsubscribe.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
class easy_unsubscribe extends rcube_plugin {
public $task = 'mail';
private $message_headers_done = false;
private $unsubscribe_img;
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');
$this->include_script('easy_unsubscribe.js');
$this->add_texts('localization/');
$rcmail->output->add_label('easy_unsubscribe.confirm');
}
public function storage_init($p) {
if(isset($p['fetch_headers'])) $p['fetch_headers'] = trim($p['fetch_headers'] . ' ' . strtoupper('List-Unsubscribe'));
return $p;
}
public function message_headers($p) {
if($this->message_headers_done===false) {
$this->message_headers_done = true;
if(!isset($p['headers']->others['list-unsubscribe'])) return $p;
$ListUnsubscribe = $p['headers']->others['list-unsubscribe'];
if (preg_match_all('/<(.+)>/mU', $ListUnsubscribe, $items, PREG_PATTERN_ORDER)) {
foreach ( $items[1] as $uri ) {
$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>';
}
}
}
if(isset($p['output']['subject'])) {
$p['output']['subject']['value'] = $p['output']['subject']['value'] . $this->unsubscribe_img;
$p['output']['subject']['html'] = 1;
}
return $p;
}
}