A few more unnecessary urldecodes when not needed. Now we can view headers
[squirrelmail.git] / functions / mime.php
... / ...
CommitLineData
1<?php
2
3/**
4 * mime.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 contains the functions necessary to detect and decode MIME
10 * messages.
11 *
12 * $Id$
13 */
14
15require_once(SM_PATH . 'functions/imap.php');
16require_once(SM_PATH . 'functions/attachment_common.php');
17
18/* --------------------------------------------------------------------------------- */
19/* MIME DECODING */
20/* --------------------------------------------------------------------------------- */
21
22/* This function gets the structure of a message and stores it in the "message" class.
23 * It will return this object for use with all relevant header information and
24 * fully parsed into the standard "message" object format.
25 */
26
27function mime_structure ($bodystructure, $flags=array()) {
28
29 /* Isolate the body structure and remove beginning and end parenthesis. */
30 $read = trim(substr ($bodystructure, strpos(strtolower($bodystructure), 'bodystructure') + 13));
31 $read = trim(substr ($read, 0, -1));
32 $i = 0;
33 $msg = Message::parseStructure($read,$i);
34 if (!is_object($msg)) {
35 include_once(SM_PATH . 'functions/display_messages.php');
36 global $color, $mailbox;
37 /* removed urldecode because $_GET is auto urldecoded ??? */
38 displayPageHeader( $color, $mailbox );
39 echo "<BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n\n" .
40 '<CENTER>';
41 $errormessage = _("SquirrelMail could not decode the bodystructure of the message");
42 $errormessage .= '<BR>'._("the provided bodystructure by your imap-server").':<BR><BR>';
43 $errormessage .= '<table><tr><td>' . htmlspecialchars($read) . '</td></tr></table>';
44 plain_error_message( $errormessage, $color );
45 echo '</body></html>';
46 exit;
47 }
48 if (count($flags)) {
49 foreach ($flags as $flag) {
50 $char = strtoupper($flag{1});
51 switch ($char) {
52 case 'S':
53 if (strtolower($flag) == '\\seen') {
54 $msg->is_seen = true;
55 }
56 break;
57 case 'A':
58 if (strtolower($flag) == '\\answered') {
59 $msg->is_answered = true;
60 }
61 break;
62 case 'D':
63 if (strtolower($flag) == '\\deleted') {
64 $msg->is_deleted = true;
65 }
66 break;
67 case 'F':
68 if (strtolower($flag) == '\\flagged') {
69 $msg->is_flagged = true;
70 }
71 break;
72 case 'M':
73 if (strtolower($flag) == '$mdnsent') {
74 $msg->is_mdnsent = true;
75 }
76 break;
77 default:
78 break;
79 }
80 }
81 }
82 // listEntities($msg);
83 return $msg;
84}
85
86
87
88/* This starts the parsing of a particular structure. It is called recursively,
89 * so it can be passed different structures. It returns an object of type
90 * $message.
91 * First, it checks to see if it is a multipart message. If it is, then it
92 * handles that as it sees is necessary. If it is just a regular entity,
93 * then it parses it and adds the necessary header information (by calling out
94 * to mime_get_elements()
95 */
96
97function mime_fetch_body($imap_stream, $id, $ent_id=1) {
98 global $uid_support;
99 /* Do a bit of error correction. If we couldn't find the entity id, just guess
100 * that it is the first one. That is usually the case anyway.
101 */
102 if (!$ent_id) {
103 $cmd = "FETCH $id BODY[]";
104 } else {
105 $cmd = "FETCH $id BODY[$ent_id]";
106 }
107
108 $data = sqimap_run_command ($imap_stream, $cmd, true, $response, $message, $uid_support);
109 do {
110 $topline = trim(array_shift($data));
111 } while($topline && ($topline[0] == '*') && !preg_match('/\* [0-9]+ FETCH.*/i', $topline)) ;
112
113 $wholemessage = implode('', $data);
114 if (ereg('\\{([^\\}]*)\\}', $topline, $regs)) {
115 $ret = substr($wholemessage, 0, $regs[1]);
116 /* There is some information in the content info header that could be important
117 * in order to parse html messages. Let's get them here.
118 */
119 if ($ret{0} == '<') {
120 $data = sqimap_run_command ($imap_stream, "FETCH $id BODY[$ent_id.MIME]", true, $response, $message, $uid_support);
121 }
122 } else if (ereg('"([^"]*)"', $topline, $regs)) {
123 $ret = $regs[1];
124 } else {
125 global $where, $what, $mailbox, $passed_id, $startMessage;
126 $par = 'mailbox=' . urlencode($mailbox) . '&amp;passed_id=' . $passed_id;
127 if (isset($where) && isset($what)) {
128 $par .= '&amp;where=' . urlencode($where) . '&amp;what=' . urlencode($what);
129 } else {
130 $par .= '&amp;startMessage=' . $startMessage . '&amp;show_more=0';
131 }
132 $par .= '&amp;response=' . urlencode($response) .
133 '&amp;message=' . urlencode($message) .
134 '&amp;topline=' . urlencode($topline);
135
136 echo '<tt><br>' .
137 '<table width="80%"><tr>' .
138 '<tr><td colspan=2>' .
139 _("Body retrieval error. The reason for this is most probably that the message is malformed.") .
140 '</td></tr>' .
141 '<tr><td><b>' . _("Command:") . "</td><td>$cmd</td></tr>" .
142 '<tr><td><b>' . _("Response:") . "</td><td>$response</td></tr>" .
143 '<tr><td><b>' . _("Message:") . "</td><td>$message</td></tr>" .
144 '<tr><td><b>' . _("FETCH line:") . "</td><td>$topline</td></tr>" .
145 "</table><BR></tt></font><hr>";
146
147 $data = sqimap_run_command ($imap_stream, "FETCH $passed_id BODY[]", true, $response, $message, $uid_support);
148 array_shift($data);
149 $wholemessage = implode('', $data);
150
151 $ret = $wholemessage;
152 }
153 return $ret;
154}
155
156function mime_print_body_lines ($imap_stream, $id, $ent_id=1, $encoding) {
157 global $uid_support;
158
159 $sid = sqimap_session_id($uid_support);
160 /* Don't kill the connection if the browser is over a dialup
161 * and it would take over 30 seconds to download it.
162