| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * view_header.php |
| 5 | * |
| 6 | * Copyright (c) 1999-2003 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 | |
| 14 | /* Path for SquirrelMail required files. */ |
| 15 | define('SM_PATH','../'); |
| 16 | |
| 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'); |
| 22 | |
| 23 | function parse_viewheader($imapConnection,$id, $passed_ent_id) { |
| 24 | global $uid_support; |
| 25 | |
| 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); |
| 30 | } else { |
| 31 | $query = "FETCH $id BODY[".$passed_ent_id.'.HEADER]'; |
| 32 | $read=sqimap_run_command ($imapConnection, $query, |
| 33 | true, $a, $b, $uid_support); |
| 34 | } |
| 35 | $cnum = 0; |
| 36 | for ($i=1; $i < count($read); $i++) { |
| 37 | $line = htmlspecialchars($read[$i]); |
| 38 | switch (true) { |
| 39 | case (eregi("^>", $line)): |
| 40 | $second[$i] = $line; |
| 41 | $first[$i] = ' '; |
| 42 | $cnum++; |
| 43 | break; |
| 44 | case (eregi("^[ |\t]", $line)): |
| 45 | $second[$i] = $line; |
| 46 | $first[$i] = ''; |
| 47 | break; |
| 48 | case (eregi("^([^:]+):(.+)", $line, $regs)): |
| 49 | $first[$i] = $regs[1] . ':'; |
| 50 | $second[$i] = $regs[2]; |
| 51 | $cnum++; |
| 52 | break; |
| 53 | default: |
| 54 | $second[$i] = trim($line); |
| 55 | $first[$i] = ''; |
| 56 | break; |
| 57 | } |
| 58 | } |
| 59 | for ($i=0; $i < count($second); $i = $j) { |
| 60 | $f = (isset($first[$i]) ? $first[$i] : ''); |
| 61 | $s = (isset($second[$i]) ? nl2br($second[$i]) : ''); |
| 62 | $j = $i + 1; |
| 63 | while (($first[$j] == '') && ($j < count($first))) { |
| 64 | $s .= ' ' . nl2br($second[$j]); |
| 65 | $j++; |
| 66 | } |
| 67 | if(strtolower($f) != 'message-id:') { |
| 68 | parseEmail($s); |
| 69 | } |
| 70 | if ($f) { |
| 71 | $header_output[] = array($f,$s); |
| 72 | } |
| 73 | } |
| 74 | sqimap_logout($imapConnection); |
| 75 | return $header_output; |
| 76 | } |
| 77 | |
| 78 | function view_header($header, $mailbox, $color) { |
| 79 | $ret_addr = SM_PATH . 'src/read_body.php?'.$_SERVER['QUERY_STRING']; |
| 80 | |
| 81 | displayPageHeader($color, $mailbox); |
| 82 | |
| 83 | echo '<BR>' . |
| 84 | '<TABLE WIDTH="100%" CELLPADDING="2" CELLSPACING="0" BORDER="0"'. |
| 85 | ' ALIGN="CENTER">' . "\n" . |
| 86 | " <TR><TD BGCOLOR=\"$color[9]\" WIDTH=\"100%\" ALIGN=\"CENTER\"><B>". |
| 87 | _("Viewing Full Header") . '</B> - '. |
| 88 | '<a href="'; |
| 89 | echo_template_var($ret_addr); |
| 90 | echo '">' ._("View message") . "</a></b></td></tr></table>\n"; |
| 91 | |
| 92 | echo_template_var($header, |
| 93 | array( |
| 94 | "<table width='99%' cellpadding='2' cellspacing='0' border='0'". |
| 95 | "align=center>\n".'<tr><td>', |
| 96 | '<nobr><tt><b>', |
| 97 | '</b>', |
| 98 | '</tt></nobr>', |
| 99 | '</td></tr></table>'."\n" |
| 100 | ) ); |
| 101 | echo '</body></html>'; |
| 102 | } |
| 103 | |
| 104 | /* get global vars */ |
| 105 | $passed_id = $_GET['passed_id']; |
| 106 | $username = $_SESSION['username']; |
| 107 | $key = $_COOKIE['key']; |
| 108 | $delimiter = $_SESSION['delimiter']; |
| 109 | $onetimepad = $_SESSION['onetimepad']; |
| 110 | |
| 111 | if (!isset($_GET['passed_ent_id'])) { |
| 112 | $passed_ent_id = ''; |
| 113 | } else { |
| 114 | $passed_ent_id = $_GET['passed_ent_id']; |
| 115 | } |
| 116 | |
| 117 | $mailbox = urldecode($_GET['mailbox']); |
| 118 | |
| 119 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, |
| 120 | $imapPort, 0); |
| 121 | $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true); |
| 122 | |
| 123 | $header = parse_viewheader($imapConnection,$passed_id, $passed_ent_id); |
| 124 | view_header($header, $mailbox, $color); |
| 125 | |
| 126 | ?> |