6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This is the code to view the message header.
14 /* Path for SquirrelMail required files. */
15 define('SM_PATH','../');
17 /* SquirrelMail required files. */
18 require_once(SM_PATH
. 'include/validate.php');
19 require_once(SM_PATH
. 'functions/imap.php');
20 require_once(SM_PATH
. 'functions/html.php');
21 require_once(SM_PATH
. 'functions/url_parser.php');
23 function parse_viewheader($imapConnection,$id, $passed_ent_id) {
26 $header_full = array();
27 if (!$passed_ent_id) {
28 $read=sqimap_run_command ($imapConnection, "FETCH $id BODY[HEADER]",
29 true, $a, $b, $uid_support);
31 $query = "FETCH $id BODY[".$passed_ent_id.'.HEADER]';
32 $read=sqimap_run_command ($imapConnection, $query,
33 true, $a, $b, $uid_support);
36 for ($i=1; $i < count($read); $i++
) {
37 $line = htmlspecialchars($read[$i]);
38 if (eregi("^>", $line)) {
40 $first[$i] = ' ';
42 } else if (eregi("^[ |\t]", $line)) {
45 } else if (eregi("^([^:]+):(.+)", $line, $regs)) {
46 $first[$i] = $regs[1] . ':';
47 $second[$i] = $regs[2];
50 $second[$i] = trim($line);
54 for ($i=0; $i < count($second); $i = $j) {
55 if (isset($first[$i])) {
58 if (isset($second[$i])) {
59 $s = nl2br($second[$i]);
62 while (($first[$j] == '') && ($j < count($first))) {
63 $s .= ' ' . nl2br($second[$j]);
68 $header_output[] = array($f,$s);
71 sqimap_logout($imapConnection);
72 return $header_output;
75 function view_header($header, $mailbox, $color) {
76 global $QUERY_STRING, $base_uri;
78 $ret_addr = $base_uri . 'src/read_body.php?'.$QUERY_STRING;
80 displayPageHeader($color, $mailbox);
83 '<TABLE WIDTH="100%" CELLPADDING="2" CELLSPACING="0" BORDER="0"'.
84 ' ALIGN="CENTER">' . "\n" .
85 " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=\"100%\" ALIGN=\"CENTER\"><B>".
86 _("Viewing Full Header") . '</B> - '.
88 echo_template_var($ret_addr);
89 echo '">' ._("View message") . "</a></b></td></tr></table>\n";
91 echo_template_var($header,
93 "<table width='99%' cellpadding='2' cellspacing='0' border='0'".
94 "align=center>\n".'<tr><td>',
98 '</td></tr></table>'."\n"
100 echo '</body></html>';
103 if (!isset($passed_ent_id)) {
106 $mailbox = decodeHeader($mailbox);
108 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
110 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
112 $header = parse_viewheader($imapConnection,$passed_id, $passed_ent_id);
113 view_header($header, $mailbox, $color);