a777439a |
1 | <?php |
2 | |
3 | /** |
4 | * view_header.php |
5 | * |
a777439a |
6 | * This is the code to view the message header. |
7 | * |
22387c8d |
8 | * @copyright 1999-2017 The SquirrelMail Project Team |
4b4abf93 |
9 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
30967a1e |
10 | * @version $Id$ |
8f6f9ba5 |
11 | * @package squirrelmail |
a777439a |
12 | */ |
86725763 |
13 | |
ebd2391c |
14 | /** This is the view_header page */ |
15 | define('PAGE_NAME', 'view_header'); |
16 | |
30967a1e |
17 | /** |
202bcbcc |
18 | * Include the SquirrelMail initialization file. |
30967a1e |
19 | */ |
202bcbcc |
20 | require('../include/init.php'); |
86725763 |
21 | |
22 | /* SquirrelMail required files. */ |
86725763 |
23 | require_once(SM_PATH . 'functions/imap.php'); |
86725763 |
24 | require_once(SM_PATH . 'functions/url_parser.php'); |
a777439a |
25 | |
f97a4124 |
26 | /** |
27 | * Extract message headers |
28 | * |
29 | * @param resource $imapConnection |
30 | * @param string $id Message ID |
31 | * @param string $passed_ent_id Nested/attached/embedded message ID (if any) |
32 | * |
33 | * @return array List of all message headers, where each |
34 | * element is a sub-array that contains two |
35 | * elements: header name and header value |
36 | * (in that order) where the header value is |
37 | * HTML-formatted, ready for display in browser |
38 | * |
39 | */ |
40 | function parse_viewheader($imapConnection, $id, $passed_ent_id) { |
a777439a |
41 | |
e44fc2eb |
42 | $header_output = array(); |
4a44f12c |
43 | $second = array(); |
79df8884 |
44 | $first = array(); |
e44fc2eb |
45 | |
dbdfdf6c |
46 | if (!$passed_ent_id) { |
91e0dccc |
47 | $read=sqimap_run_command ($imapConnection, "FETCH $id BODY[HEADER]", |
6201339c |
48 | true, $a, $b, TRUE); |
dbdfdf6c |
49 | } else { |
50 | $query = "FETCH $id BODY[".$passed_ent_id.'.HEADER]'; |
91e0dccc |
51 | $read=sqimap_run_command ($imapConnection, $query, |
6201339c |
52 | true, $a, $b, TRUE); |
91e0dccc |
53 | } |
a777439a |
54 | $cnum = 0; |
55 | for ($i=1; $i < count($read); $i++) { |
3047e291 |
56 | $line = sm_encode_html_special_chars($read[$i]); |
134e4174 |
57 | switch (true) { |
b7910e12 |
58 | case (preg_match('/^>/i', $line)): |
134e4174 |
59 | $second[$i] = $line; |
60 | $first[$i] = ' '; |
61 | $cnum++; |
62 | break; |
b7910e12 |
63 | // FIXME: is the pipe character below a mistake? I think the original author might have thought it carried special meaning in the character class, which it does not... but then again, I am not currently trying to understand what this code actually does |
64 | case (preg_match('/^[ |\t]/', $line)): |
134e4174 |
65 | $second[$i] = $line; |
66 | $first[$i] = ''; |
67 | break; |
b7910e12 |
68 | case (preg_match('/^([^:]+):(.+)/', $line, $regs)): |
134e4174 |
69 | $first[$i] = $regs[1] . ':'; |
70 | $second[$i] = $regs[2]; |
71 | $cnum++; |
72 | break; |
73 | default: |
74 | $second[$i] = trim($line); |
75 | $first[$i] = ''; |
76 | break; |
a777439a |
77 | } |
78 | } |
79 | for ($i=0; $i < count($second); $i = $j) { |
65f8ca87 |
80 | $f = (isset($first[$i]) ? $first[$i] : ''); |
91e0dccc |
81 | $s = (isset($second[$i]) ? nl2br($second[$i]) : ''); |
a777439a |
82 | $j = $i + 1; |
83 | while (($first[$j] == '') && ($j < count($first))) { |
84 | $s .= ' ' . nl2br($second[$j]); |
85 | $j++; |
86 | } |
dbdfdf6c |
87 | $lowf=strtolower($f); |
88 | /* do not mark these headers as emailaddresses */ |
89 | if($lowf != 'message-id:' && $lowf != 'in-reply-to:' && $lowf != 'references:') { |
90 | parseEmail($s); |
91 | } |
65f8ca87 |
92 | if ($f) { |
36cd4eaa |
93 | $header_output[] = array($f,$s); |
a777439a |
94 | } |
95 | } |
a777439a |
96 | sqimap_logout($imapConnection); |
98349cf6 |
97 | return $header_output; |
a777439a |
98 | } |
99 | |
fe369c70 |
100 | /* get global vars */ |
51bbe8fa |
101 | sqgetGlobalVar('passed_id', $passed_id, SQ_GET, NULL, SQ_TYPE_BIGINT); |
1e12d1ff |
102 | if ( sqgetGlobalVar('mailbox', $temp, SQ_GET) ) { |
fdc9d9b5 |
103 | $mailbox = $temp; |
1e12d1ff |
104 | } |
105 | if ( !sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET) ) { |
106 | $passed_ent_id = ''; |
91e0dccc |
107 | } |
1e12d1ff |
108 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); |
be61c5a6 |
109 | |
a9805897 |
110 | global $imap_stream_options; // in case not defined in config |
906f7e9f |
111 | $imapConnection = sqimap_login($username, false, $imapServerAddress, |
a9805897 |
112 | $imapPort, 0, $imap_stream_options); |
be61c5a6 |
113 | $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true); |
91e0dccc |
114 | $header = parse_viewheader($imapConnection,$passed_id, $passed_ent_id); |
be61c5a6 |
115 | |
d3558aef |
116 | $aTemplateHeaders = array(); |
117 | foreach ($header as $h) { |
118 | $aTemplateHeaders[] = array ( |
119 | 'Header' => $h[0], |
120 | 'Value' => $h[1] |
121 | ); |
122 | } |
123 | |
124 | sqgetGlobalVar('QUERY_STRING', $queryStr, SQ_SERVER); |
125 | $ret_addr = SM_PATH . 'src/read_body.php?'.$queryStr; |
126 | |
127 | displayPageHeader( $color, $mailbox ); |
128 | |
129 | $oTemplate->assign('view_message_href', $ret_addr); |
130 | $oTemplate->assign('headers', $aTemplateHeaders); |
131 | |
132 | $oTemplate->display('view_header.tpl'); |
133 | |
134 | $oTemplate->display('footer.tpl'); |