]> git.donarmstrong.com Git - roundcube.git/blob - plugins/show_additional_headers/show_additional_headers.php
Imported Upstream version 0.5.2+dfsg
[roundcube.git] / plugins / show_additional_headers / show_additional_headers.php
1 <?php
2
3 /**
4  * Show additional message headers
5  *
6  * Proof-of-concept plugin which will fetch additional headers
7  * and display them in the message view.
8  *
9  * Enable the plugin in config/main.inc.php and add your desired headers:
10  *   $rcmail_config['show_additional_headers'] = array('User-Agent');
11  *
12  * @version 1.0
13  * @author Thomas Bruederli
14  * @website http://roundcube.net
15  */
16 class show_additional_headers extends rcube_plugin
17 {
18   public $task = 'mail';
19   
20   function init()
21   {
22     $rcmail = rcmail::get_instance();
23     if ($rcmail->action == 'show' || $rcmail->action == 'preview') {
24       $this->add_hook('imap_init', array($this, 'imap_init'));
25       $this->add_hook('message_headers_output', array($this, 'message_headers'));
26     } else if ($rcmail->action == '') {
27       // with enabled_caching we're fetching additional headers before show/preview
28       $this->add_hook('imap_init', array($this, 'imap_init'));
29     }
30   }
31   
32   function imap_init($p)
33   {
34     $rcmail = rcmail::get_instance();
35     if ($add_headers = (array)$rcmail->config->get('show_additional_headers', array()))
36       $p['fetch_headers'] = trim($p['fetch_headers'].' ' . strtoupper(join(' ', $add_headers)));
37
38     return $p;
39   }
40
41   function message_headers($p)
42   {
43     $rcmail = rcmail::get_instance();
44     foreach ((array)$rcmail->config->get('show_additional_headers', array()) as $header) {
45       $key = strtolower($header);
46       if ($value = $p['headers']->others[$key])
47         $p['output'][$key] = array('title' => $header, 'value' => Q($value));
48     }
49
50     return $p;
51   }
52 }