a777439a |
1 | <?php |
2 | |
3 | /** |
4 | * view_header.php |
5 | * |
a777439a |
6 | * This is the code to view the message header. |
7 | * |
5e5daa47 |
8 | * @copyright 1999-2015 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 | |
65f8ca87 |
26 | function parse_viewheader($imapConnection,$id, $passed_ent_id) { |
a777439a |
27 | |
e44fc2eb |
28 | $header_output = array(); |
4a44f12c |
29 | $second = array(); |
79df8884 |
30 | $first = array(); |
e44fc2eb |
31 | |
dbdfdf6c |
32 | if (!$passed_ent_id) { |
91e0dccc |
33 | $read=sqimap_run_command ($imapConnection, "FETCH $id BODY[HEADER]", |
6201339c |
34 | true, $a, $b, TRUE); |
dbdfdf6c |
35 | } else { |
36 | $query = "FETCH $id BODY[".$passed_ent_id.'.HEADER]'; |
91e0dccc |
37 | $read=sqimap_run_command ($imapConnection, $query, |
6201339c |
38 | true, $a, $b, TRUE); |
91e0dccc |
39 | } |
a777439a |
40 | $cnum = 0; |
41 | for ($i=1; $i < count($read); $i++) { |
3047e291 |
42 | $line = sm_encode_html_special_chars($read[$i]); |
134e4174 |
43 | switch (true) { |
b7910e12 |
44 | case (preg_match('/^>/i', $line)): |
134e4174 |
45 | $second[$i] = $line; |
46 | $first[$i] = ' '; |
47 | $cnum++; |
48 | break; |
b7910e12 |
49 | // 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 |
50 | case (preg_match('/^[ |\t]/', $line)): |
134e4174 |
51 | $second[$i] = $line; |
52 | $first[$i] = ''; |
53 | break; |
b7910e12 |
54 | case (preg_match('/^([^:]+):(.+)/', $line, $regs)): |
134e4174 |
55 | $first[$i] = $regs[1] . ':'; |
56 | $second[$i] = $regs[2]; |
57 | $cnum++; |
58 | break; |
59 | default: |
60 | $second[$i] = trim($line); |
61 | $first[$i] = ''; |
62 | break; |
a777439a |
63 | } |
64 | } |
65 | for ($i=0; $i < count($second); $i = $j) { |
65f8ca87 |
66 | $f = (isset($first[$i]) ? $first[$i] : ''); |
91e0dccc |
67 | $s = (isset($second[$i]) ? nl2br($second[$i]) : ''); |
a777439a |
68 | $j = $i + 1; |
69 | while (($first[$j] == '') && ($j < count($first))) { |
70 | $s .= ' ' . nl2br($second[$j]); |
71 | $j++; |
72 | } |
dbdfdf6c |
73 | $lowf=strtolower($f); |
74 | /* do not mark these headers as emailaddresses */ |
75 | if($lowf != 'message-id:' && $lowf != 'in-reply-to:' && $lowf != 'references:') { |
76 | parseEmail($s); |
77 | } |
65f8ca87 |
78 | if ($f) { |
36cd4eaa |
79 | $header_output[] = array($f,$s); |
a777439a |
80 | } |
81 | } |
a777439a |
82 | sqimap_logout($imapConnection); |
98349cf6 |
83 | return $header_output; |
a777439a |
84 | } |
85 | |
fe369c70 |
86 | /* get global vars */ |
51bbe8fa |
87 | sqgetGlobalVar('passed_id', $passed_id, SQ_GET, NULL, SQ_TYPE_BIGINT); |
1e12d1ff |
88 | if ( sqgetGlobalVar('mailbox', $temp, SQ_GET) ) { |
fdc9d9b5 |
89 | $mailbox = $temp; |
1e12d1ff |
90 | } |
91 | if ( !sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET) ) { |
92 | $passed_ent_id = ''; |
91e0dccc |
93 | } |
1e12d1ff |
94 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); |
be61c5a6 |
95 | |
a9805897 |
96 | global $imap_stream_options; // in case not defined in config |
906f7e9f |
97 | $imapConnection = sqimap_login($username, false, $imapServerAddress, |
a9805897 |
98 | $imapPort, 0, $imap_stream_options); |
be61c5a6 |
99 | $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true); |
91e0dccc |
100 | $header = parse_viewheader($imapConnection,$passed_id, $passed_ent_id); |
be61c5a6 |
101 | |
d3558aef |
102 | $aTemplateHeaders = array(); |
103 | foreach ($header as $h) { |
104 | $aTemplateHeaders[] = array ( |
105 | 'Header' => $h[0], |
106 | 'Value' => $h[1] |
107 | ); |
108 | } |
109 | |
110 | sqgetGlobalVar('QUERY_STRING', $queryStr, SQ_SERVER); |
111 | $ret_addr = SM_PATH . 'src/read_body.php?'.$queryStr; |
112 | |
113 | displayPageHeader( $color, $mailbox ); |
114 | |
115 | $oTemplate->assign('view_message_href', $ret_addr); |
116 | $oTemplate->assign('headers', $aTemplateHeaders); |
117 | |
118 | $oTemplate->display('view_header.tpl'); |
119 | |
120 | $oTemplate->display('footer.tpl'); |