| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * view_header.php |
| 5 | * |
| 6 | * This is the code to view the message header. |
| 7 | * |
| 8 | * @copyright © 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 | * Include the SquirrelMail initialization file. |
| 16 | */ |
| 17 | require('../include/init.php'); |
| 18 | |
| 19 | /* SquirrelMail required files. */ |
| 20 | require_once(SM_PATH . 'functions/imap.php'); |
| 21 | require_once(SM_PATH . 'functions/url_parser.php'); |
| 22 | |
| 23 | function parse_viewheader($imapConnection,$id, $passed_ent_id) { |
| 24 | |
| 25 | $header_output = array(); |
| 26 | $second = array(); |
| 27 | $first = array(); |
| 28 | |
| 29 | if (!$passed_ent_id) { |
| 30 | $read=sqimap_run_command ($imapConnection, "FETCH $id BODY[HEADER]", |
| 31 | true, $a, $b, TRUE); |
| 32 | } else { |
| 33 | $query = "FETCH $id BODY[".$passed_ent_id.'.HEADER]'; |
| 34 | $read=sqimap_run_command ($imapConnection, $query, |
| 35 | true, $a, $b, TRUE); |
| 36 | } |
| 37 | $cnum = 0; |
| 38 | for ($i=1; $i < count($read); $i++) { |
| 39 | $line = htmlspecialchars($read[$i]); |
| 40 | switch (true) { |
| 41 | case (eregi("^>", $line)): |
| 42 | $second[$i] = $line; |
| 43 | $first[$i] = ' '; |
| 44 | $cnum++; |
| 45 | break; |
| 46 | case (eregi("^[ |\t]", $line)): |
| 47 | $second[$i] = $line; |
| 48 | $first[$i] = ''; |
| 49 | break; |
| 50 | case (eregi("^([^:]+):(.+)", $line, $regs)): |
| 51 | $first[$i] = $regs[1] . ':'; |
| 52 | $second[$i] = $regs[2]; |
| 53 | $cnum++; |
| 54 | break; |
| 55 | default: |
| 56 | $second[$i] = trim($line); |
| 57 | $first[$i] = ''; |
| 58 | break; |
| 59 | } |
| 60 | } |
| 61 | for ($i=0; $i < count($second); $i = $j) { |
| 62 | $f = (isset($first[$i]) ? $first[$i] : ''); |
| 63 | $s = (isset($second[$i]) ? nl2br($second[$i]) : ''); |
| 64 | $j = $i + 1; |
| 65 | while (($first[$j] == '') && ($j < count($first))) { |
| 66 | $s .= ' ' . nl2br($second[$j]); |
| 67 | $j++; |
| 68 | } |
| 69 | $lowf=strtolower($f); |
| 70 | /* do not mark these headers as emailaddresses */ |
| 71 | if($lowf != 'message-id:' && $lowf != 'in-reply-to:' && $lowf != 'references:') { |
| 72 | parseEmail($s); |
| 73 | } |
| 74 | if ($f) { |
| 75 | $header_output[] = array($f,$s); |
| 76 | } |
| 77 | } |
| 78 | sqimap_logout($imapConnection); |
| 79 | return $header_output; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Temporary test function to process template vars with formatting. |
| 84 | * I use it for viewing the message_header (view_header.php) with |
| 85 | * a sort of template. |
| 86 | * @param mixed $var |
| 87 | * @param mixed $format_ar |
| 88 | * @since 1.3.0 |
| 89 | * @todo if function is temporary, then why it is used. |
| 90 | * @deprecated |
| 91 | */ |
| 92 | function echo_template_var($var, $format_ar = array() ) { |
| 93 | $frm_last = count($format_ar) -1; |
| 94 | |
| 95 | if (isset($format_ar[0])) echo $format_ar[0]; |
| 96 | $i = 1; |
| 97 | |
| 98 | switch (true) { |
| 99 | case (is_string($var)): |
| 100 | echo $var; |
| 101 | break; |
| 102 | case (is_array($var)): |
| 103 | $frm_a = array_slice($format_ar,1,$frm_last-1); |
| 104 | foreach ($var as $a_el) { |
| 105 | if (is_array($a_el)) { |
| 106 | echo_template_var($a_el,$frm_a); |
| 107 | } else { |
| 108 | echo $a_el; |
| 109 | if (isset($format_ar[$i])) { |
| 110 | echo $format_ar[$i]; |
| 111 | } |
| 112 | $i++; |
| 113 | } |
| 114 | } |
| 115 | break; |
| 116 | default: |
| 117 | break; |
| 118 | } |
| 119 | if (isset($format_ar[$frm_last]) && $frm_last>$i ) { |
| 120 | echo $format_ar[$frm_last]; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | function view_header($header, $mailbox, $color) { |
| 125 | sqgetGlobalVar('QUERY_STRING', $queryStr, SQ_SERVER); |
| 126 | $ret_addr = SM_PATH . 'src/read_body.php?'.$queryStr; |
| 127 | |
| 128 | displayPageHeader($color, $mailbox); |
| 129 | |
| 130 | echo '<br />' . |
| 131 | '<table width="100%" cellpadding="2" cellspacing="0" border="0" '. |
| 132 | 'align="center">' . "\n" . |
| 133 | '<tr><td bgcolor="'.$color[9].'" width="100%" align="center"><b>'. |
| 134 | _("Viewing Full Header") . '</b> - '. |
| 135 | '<a href="'; |
| 136 | echo_template_var($ret_addr); |
| 137 | echo '">' ._("View message") . "</a></td></tr></table>\n"; |
| 138 | |
| 139 | echo_template_var($header, |
| 140 | array( |
| 141 | '<table width="99%" cellpadding="2" cellspacing="0" border="0" '. |
| 142 | "align=center>\n".'<tr><td>', |
| 143 | '<tt style="white-space: nowrap;"><b>', |
| 144 | '</b>', |
| 145 | '</tt>', |
| 146 | '</td></tr></table>'."\n" |
| 147 | ) |
| 148 | ); |
| 149 | echo '</body></html>'; |
| 150 | } |
| 151 | |
| 152 | /* get global vars */ |
| 153 | if ( sqgetGlobalVar('passed_id', $temp, SQ_GET) ) { |
| 154 | $passed_id = (int) $temp; |
| 155 | } |
| 156 | if ( sqgetGlobalVar('mailbox', $temp, SQ_GET) ) { |
| 157 | $mailbox = $temp; |
| 158 | } |
| 159 | if ( !sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET) ) { |
| 160 | $passed_ent_id = ''; |
| 161 | } |
| 162 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
| 163 | sqgetGlobalVar('username', $username, SQ_SESSION); |
| 164 | sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION); |
| 165 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); |
| 166 | |
| 167 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, |
| 168 | $imapPort, 0); |
| 169 | $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true); |
| 170 | |
| 171 | $header = parse_viewheader($imapConnection,$passed_id, $passed_ent_id); |
| 172 | view_header($header, $mailbox, $color); |
| 173 | |
| 174 | ?> |