Only show text/plain if show_html_default=0
[squirrelmail.git] / src / view_header.php
1 <?php
2
3 /**
4 * view_header.php
5 *
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This is the code to view the message header.
10 *
11 * $Id$
12 */
13 require_once('../src/validate.php');
14 require_once('../functions/imap.php');
15 require_once('../functions/html.php');
16 require_once('../functions/url_parser.php');
17
18 function parse_viewheader($imapConnection,$id, $passed_ent_id) {
19 global $uid_support;
20
21 $header_full = array();
22 if (!$passed_ent_id) {
23 $read=sqimap_run_command ($imapConnection, "FETCH $id BODY[HEADER]",
24 true, $a, $b, $uid_support);
25 } else {
26 $query = "FETCH $id BODY[".$passed_ent_id.'.HEADER]';
27 $read=sqimap_run_command ($imapConnection, $query,
28 true, $a, $b, $uid_support);
29 }
30 $cnum = 0;
31 for ($i=1; $i < count($read); $i++) {
32 $line = htmlspecialchars($read[$i]);
33 if (eregi("^&gt;", $line)) {
34 $second[$i] = $line;
35 $first[$i] = '&nbsp;';
36 $cnum++;
37 } else if (eregi("^[ |\t]", $line)) {
38 $second[$i] = $line;
39 $first[$i] = '';
40 } else if (eregi("^([^:]+):(.+)", $line, $regs)) {
41 $first[$i] = $regs[1] . ':';
42 $second[$i] = $regs[2];
43 $cnum++;
44 } else {
45 $second[$i] = trim($line);
46 $first[$i] = '';
47 }
48 }
49 for ($i=0; $i < count($second); $i = $j) {
50 if (isset($first[$i])) {
51 $f = $first[$i];
52 }
53 if (isset($second[$i])) {
54 $s = nl2br($second[$i]);
55 }
56 $j = $i + 1;
57 while (($first[$j] == '') && ($j < count($first))) {
58 $s .= '&nbsp;&nbsp;&nbsp;&nbsp;' . nl2br($second[$j]);
59 $j++;
60 }
61 parseEmail($s);
62 if (isset($f)) {
63 $header_output[] = array($f,$s);
64 }
65 }
66 sqimap_logout($imapConnection);
67 return $header_output;
68 }
69
70 function view_header($header, $mailbox, $color) {
71 global $QUERY_STRING, $base_uri;
72
73 $ret_addr = $base_uri . 'src/read_body.php?'.$QUERY_STRING;
74
75 displayPageHeader($color, $mailbox);
76
77 echo '<BR>' .
78 '<TABLE WIDTH="100%" CELLPADDING="2" CELLSPACING="0" BORDER="0"'.
79 ' ALIGN="CENTER">' . "\n" .
80 " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=\"100%\" ALIGN=\"CENTER\"><B>".
81 _("Viewing Full Header") . '</B> - '.
82 '<a href="';
83 echo_template_var($ret_addr);
84 echo '">' ._("View message") . "</a></b></td></tr></table>\n";
85
86 echo_template_var($header,
87 array(
88 "<table width='99%' cellpadding='2' cellspacing='0' border='0'".
89 "align=center>\n".'<tr><td>',
90 '<nobr><tt><b>',
91 '</b>',
92 '</tt></nobr>',
93 '</td></tr></table>'."\n"
94 ) );
95 echo '</body></html>';
96 }
97
98 if (!isset($passed_ent_id)) {
99 $passed_ent_id = '';
100 }
101 $mailbox = decodeHeader($mailbox);
102
103 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
104 $imapPort, 0);
105 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
106
107 $header = parse_viewheader($imapConnection,$passed_id, $passed_ent_id);
108 view_header($header, $mailbox, $color);
109
110 ?>