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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
<?php
/**
* This plugin parses email headers looking for mailinglist specific
* information. If headers are found, it uses them to create an additional
* header in the header box to easily perform certain mailinglist commands
* like subscribing, unsubscribing, asking for help, and sending a new mail.
*
* @version 2.1
* @author Cor Bosman
*
*/
class listcommands extends rcube_plugin
{
public $task = 'mail';
function init()
{
$rcmail = rcmail::get_instance();
if (!$rcmail->action || in_array($rcmail->action, array('list', 'show', 'preview'))) {
$this->add_hook('storage_init', array($this, 'storage_init'));
$this->add_hook('message_headers_output', array($this, 'listcommands_output'));
}
}
function storage_init($p)
{
$rcmail = rcmail::get_instance();
$mailinglist_headers = array_keys($this->get_list_headers());
if (isset($p['fetch_headers'])) {
$p['fetch_headers'] .= trim($p['fetch_headers'] . ' ' . strtoupper(join(' ', $mailinglist_headers)));
} else {
$p['fetch_headers'] = trim(strtoupper(join(' ', $mailinglist_headers)));
}
return($p);
}
function listcommands_output($p)
{
$list_output = "";
$rcmail = rcmail::get_instance();
$this->add_texts('localization/', false);
$mailinglist_headers = $this->get_list_headers();
foreach ($mailinglist_headers as $header => $title) {
$key = strtolower($header);
if (isset($p['headers']->others[$key])) {
$value = $p['headers']->others[$key];
if ($value) {
if (is_string($value)) {
$list_output .= $this->create_link($key, $value, $title) . ' ';
} else {
$list_output .= $this->create_link($key, $value[0], $title) . ' ';
}
}
}
}
if ($list_output != "") {
$p['output']['Mailinglist'] = array(
'title' => $this->gettext('listcommands_mailinglist'),
'value' => $list_output,
'html' => true
);
}
return($p);
}
private function get_list_headers()
{
$mailinglist_headers = array(
'List-Help' => $this->gettext('listcommands_help'),
'List-Subscribe' => $this->gettext('listcommands_subscribe'),
'List-Unsubscribe' => $this->gettext('listcommands_unsubscribe'),
'X-Unsubscribe-Web' => $this->gettext('listcommands_unsubscribe'),
'List-Post' => $this->gettext('listcommands_post'),
'List-Owner' => $this->gettext('listcommands_admin'),
'List-Archive' => $this->gettext('listcommands_archive')
);
return($mailinglist_headers);
}
private function create_link($key, $value, $title)
{
$proto = "";
// some headers have multiple targets
$targets = explode(',', $value);
// only use 1 of the targets
$target = $this->strip_quotes($targets[0]);
// first strip angle brackets
$link = trim($target, "<>");
if(preg_match('/^(mailto|http|https)(:\/\/|:)(.*)$/', $link, $matches)) {
$proto = $matches[1];
$target = $matches[3];
}
// use RC for emailing instead of relying on the mailto header
if($proto == "mailto") {
$onclick = "return rcmail.command('compose','$target',this)";
} else {
$onclick = "";
}
$a = html::a(array('href' => $link ,
'target' => '_blank',
'onclick' => $onclick
), $title);
return($a);
}
private function strip_quotes($str)
{
return str_replace(array("'", '"'), '', $str);
}
}
?>
|