copyright update
[squirrelmail.git] / src / view_header.php
1 <?php
2
3 /**
4 * view_header.php
5 *
6 * This is the code to view the message header.
7 *
8 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id$
11 * @package squirrelmail
12 */
13
14 /**
15 * Path for SquirrelMail required files.
16 * @ignore
17 */
18 define('SM_PATH','../');
19
20 /* SquirrelMail required files. */
21 require_once(SM_PATH . 'include/validate.php');
22 require_once(SM_PATH . 'functions/global.php');
23 require_once(SM_PATH . 'functions/imap.php');
24 require_once(SM_PATH . 'functions/html.php');
25 require_once(SM_PATH . 'functions/url_parser.php');
26
27 function parse_viewheader($imapConnection,$id, $passed_ent_id) {
28
29 $header_output = array();
30 $second = array();
31 $first = array();
32
33 if (!$passed_ent_id) {
34 $read=sqimap_run_command ($imapConnection, "FETCH $id BODY[HEADER]",
35 true, $a, $b, TRUE);
36 } else {
37 $query = "FETCH $id BODY[".$passed_ent_id.'.HEADER]';
38 $read=sqimap_run_command ($imapConnection, $query,
39 true, $a, $b, TRUE);
40 }
41 $cnum = 0;
42 for ($i=1; $i < count($read); $i++) {
43 $line = htmlspecialchars($read[$i]);
44 switch (true) {
45 case (eregi("^&gt;", $line)):
46 $second[$i] = $line;
47 $first[$i] = '&nbsp;';
48 $cnum++;
49 break;
50 case (eregi("^[ |\t]", $line)):
51 $second[$i] = $line;
52 $first[$i] = '';
53 break;
54 case (eregi("^([^:]+):(.+)", $line, $regs)):
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;
63 }
64 }
65 for ($i=0; $i < count($second); $i = $j) {
66 $f = (isset($first[$i]) ? $first[$i] : '');
67 $s = (isset($second[$i]) ? nl2br($second[$i]) : '');
68 $j = $i + 1;
69 while (($first[$j] == '') && ($j < count($first))) {
70 $s .= '&nbsp;&nbsp;&nbsp;&nbsp;' . nl2br($second[$j]);
71 $j++;
72 }
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 }
78 if ($f) {
79 $header_output[] = array($f,$s);
80 }
81 }
82 sqimap_logout($imapConnection);
83 return $header_output;
84 }
85
86 function view_header($header, $mailbox, $color) {
87 sqgetGlobalVar('QUERY_STRING', $queryStr, SQ_SERVER);
88 $ret_addr = SM_PATH . 'src/read_body.php?'.$queryStr;
89
90 displayPageHeader($color, $mailbox);
91
92 echo '<br />' .
93 '<table width="100%" cellpadding="2" cellspacing="0" border="0" '.
94 'align="center">' . "\n" .
95 '<tr><td bgcolor="'.$color[9].'" width="100%" align="center"><b>'.
96 _("Viewing Full Header") . '</b> - '.
97 '<a href="';
98 echo_template_var($ret_addr);
99 echo '">' ._("View message") . "</a></td></tr></table>\n";
100
101 echo_template_var($header,
102 array(
103 '<table width="99%" cellpadding="2" cellspacing="0" border="0" '.
104 "align=center>\n".'<tr><td>',
105 '<tt style="white-space: nowrap;"><b>',
106 '</b>',
107 '</tt>',
108 '</td></tr></table>'."\n"
109 )
110 );
111 echo '</body></html>';
112 }
113
114 /* get global vars */
115 if ( sqgetGlobalVar('passed_id', $temp, SQ_GET) ) {
116 $passed_id = (int) $temp;
117 }
118 if ( sqgetGlobalVar('mailbox', $temp, SQ_GET) ) {
119 $mailbox = $temp;
120 }
121 if ( !sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET) ) {
122 $passed_ent_id = '';
123 }
124 sqgetGlobalVar('key', $key, SQ_COOKIE);
125 sqgetGlobalVar('username', $username, SQ_SESSION);
126 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
127 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
128
129 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
130 $imapPort, 0);
131 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
132
133 $header = parse_viewheader($imapConnection,$passed_id, $passed_ent_id);
134 view_header($header, $mailbox, $color);
135
136 ?>