| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * view_header.php |
| 5 | * |
| 6 | * This is the code to view the message header. |
| 7 | * |
| 8 | * @copyright 1999-2020 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 | /** This is the view_header page */ |
| 15 | define('PAGE_NAME', 'view_header'); |
| 16 | |
| 17 | /** |
| 18 | * Include the SquirrelMail initialization file. |
| 19 | */ |
| 20 | require('../include/init.php'); |
| 21 | |
| 22 | /* SquirrelMail required files. */ |
| 23 | require_once(SM_PATH . 'functions/imap.php'); |
| 24 | require_once(SM_PATH . 'functions/url_parser.php'); |
| 25 | |
| 26 | /** |
| 27 | * Extract message headers |
| 28 | * |
| 29 | * @param resource $imapConnection |
| 30 | * @param string $id Message ID |
| 31 | * @param string $passed_ent_id Nested/attached/embedded message ID (if any) |
| 32 | * |
| 33 | * @return array List of all message headers, where each |
| 34 | * element is a sub-array that contains two |
| 35 | * elements: header name and header value |
| 36 | * (in that order) where the header value is |
| 37 | * HTML-formatted, ready for display in browser |
| 38 | * |
| 39 | */ |
| 40 | function parse_viewheader($imapConnection, $id, $passed_ent_id) { |
| 41 | |
| 42 | $header_output = array(); |
| 43 | $second = array(); |
| 44 | $first = array(); |
| 45 | |
| 46 | if (!$passed_ent_id) { |
| 47 | $read=sqimap_run_command ($imapConnection, "FETCH $id BODY[HEADER]", |
| 48 | true, $a, $b, TRUE); |
| 49 | } else { |
| 50 | $query = "FETCH $id BODY[".$passed_ent_id.'.HEADER]'; |
| 51 | $read=sqimap_run_command ($imapConnection, $query, |
| 52 | true, $a, $b, TRUE); |
| 53 | } |
| 54 | $cnum = 0; |
| 55 | for ($i=1; $i < count($read); $i++) { |
| 56 | $line = sm_encode_html_special_chars($read[$i]); |
| 57 | switch (true) { |
| 58 | case (preg_match('/^>/i', $line)): |
| 59 | $second[$i] = $line; |
| 60 | $first[$i] = ' '; |
| 61 | $cnum++; |
| 62 | break; |
| 63 | // FIXME: is the pipe character below a mistake? I think the original author might have thought it carried special meaning in the character class, which it does not... but then again, I am not currently trying to understand what this code actually does |
| 64 | case (preg_match('/^[ |\t]/', $line)): |
| 65 | $second[$i] = $line; |
| 66 | $first[$i] = ''; |
| 67 | break; |
| 68 | case (preg_match('/^([^:]+):(.+)/', $line, $regs)): |
| 69 | $first[$i] = $regs[1] . ':'; |
| 70 | $second[$i] = $regs[2]; |
| 71 | $cnum++; |
| 72 | break; |
| 73 | default: |
| 74 | $second[$i] = trim($line); |
| 75 | $first[$i] = ''; |
| 76 | break; |
| 77 | } |
| 78 | } |
| 79 | for ($i=0; $i < count($second); $i = $j) { |
| 80 | $f = (isset($first[$i]) ? $first[$i] : ''); |
| 81 | $s = (isset($second[$i]) ? nl2br($second[$i]) : ''); |
| 82 | $j = $i + 1; |
| 83 | while (($first[$j] == '') && ($j < count($first))) { |
| 84 | $s .= ' ' . nl2br($second[$j]); |
| 85 | $j++; |
| 86 | } |
| 87 | $lowf=strtolower($f); |
| 88 | /* do not mark these headers as emailaddresses */ |
| 89 | if($lowf != 'message-id:' && $lowf != 'in-reply-to:' && $lowf != 'references:') { |
| 90 | parseEmail($s); |
| 91 | } |
| 92 | if ($f) { |
| 93 | $header_output[] = array($f,$s); |
| 94 | } |
| 95 | } |
| 96 | sqimap_logout($imapConnection); |
| 97 | return $header_output; |
| 98 | } |
| 99 | |
| 100 | /* get global vars */ |
| 101 | sqgetGlobalVar('passed_id', $passed_id, SQ_GET, NULL, SQ_TYPE_BIGINT); |
| 102 | if ( sqgetGlobalVar('mailbox', $temp, SQ_GET) ) { |
| 103 | $mailbox = $temp; |
| 104 | } |
| 105 | if ( !sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET) ) { |
| 106 | $passed_ent_id = ''; |
| 107 | } |
| 108 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); |
| 109 | |
| 110 | global $imap_stream_options; // in case not defined in config |
| 111 | $imapConnection = sqimap_login($username, false, $imapServerAddress, |
| 112 | $imapPort, 0, $imap_stream_options); |
| 113 | $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true); |
| 114 | $header = parse_viewheader($imapConnection,$passed_id, $passed_ent_id); |
| 115 | |
| 116 | $aTemplateHeaders = array(); |
| 117 | foreach ($header as $h) { |
| 118 | $aTemplateHeaders[] = array ( |
| 119 | 'Header' => $h[0], |
| 120 | 'Value' => $h[1] |
| 121 | ); |
| 122 | } |
| 123 | |
| 124 | sqgetGlobalVar('QUERY_STRING', $queryStr, SQ_SERVER); |
| 125 | $ret_addr = SM_PATH . 'src/read_body.php?'.$queryStr; |
| 126 | |
| 127 | displayPageHeader( $color, $mailbox ); |
| 128 | |
| 129 | $oTemplate->assign('view_message_href', $ret_addr); |
| 130 | $oTemplate->assign('headers', $aTemplateHeaders); |
| 131 | |
| 132 | $oTemplate->display('view_header.tpl'); |
| 133 | |
| 134 | $oTemplate->display('footer.tpl'); |