b6d897c2f9c451f605ffccb1d2d9a8ad1827b39f
4 * Message Details plugin - bottom frame with message structure and rfc822 body
6 * Plugin to view the RFC822 raw message output and the bodystructure of a message
8 * @author Marc Groot Koerkamp
9 * @copyright © 2002 Marc Groot Koerkamp, The Netherlands
10 * @copyright © 2002-2006 The SquirrelMail Project Team
11 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
14 * @subpackage message_details
18 * Include the SquirrelMail initialization file.
20 require('../../include/init.php');
21 require(SM_PATH
. 'functions/imap_general.php');
22 require(SM_PATH
. 'functions/imap_messages.php');
23 require(SM_PATH
. 'functions/mime.php');
25 sqgetGlobalVar('get_message_details', $md_action, SQ_GET
);
28 * Controls display of 8bit symbols in message source
29 * @global boolean $msgd_8bit_in_hex;
31 global $msgd_8bit_in_hex;
32 $msgd_8bit_in_hex=false;
34 if (!empty($md_action)) {
35 sqgetGlobalVar('passed_id', $passed_id, SQ_GET
);
36 sqgetGlobalVar('mailbox', $mailbox, SQ_GET
);
38 * add third function argument, if you want to see
39 * message source without formating
41 echo get_message_details($mailbox, $passed_id);
45 // ---------- function definitions ----------
48 * Converts 8bit string to hex
50 * Replaces 8bit symbols with their hex strings,
51 * encloses them in curly brackets and uses different color.
52 * @param string $string text
56 function msgd_convert_to_hex($string) {
58 return preg_replace("/([\200-\377])/e","'<font color=\"$color[2]\">{'.dechex(ord('\\1')).'}</font>'",$string);
62 * Calculates id of MIME entity
63 * @param string $entString
64 * @param integer $direction
68 function CalcEntity($entString, $direction) {
70 if ($direction == -1) {
71 $pos = strrpos($entString,'.');
72 $result = substr($entString,0,$pos);
77 $pos = strrpos($entString,'.');
83 $level = substr($entString,0,$pos);
84 $sublevel = substr($entString,$pos+
1);
86 $result = "$level".'.'."$sublevel";
90 $result = "$entString".".0";
100 * Returns actual message details
101 * @param string $mailbox
102 * @param string $passed_id
103 * @param boolean $stripHTML If TRUE, only plain text is returned,
104 * default is FALSE, wherein output contains
105 * pretty-HTMLification of message body
106 * @return string The formatted message details
109 function get_message_details($mailbox, $passed_id, $stripHTML=FALSE) {
110 global $imapServerAddress, $imapPort, $color,$msgd_8bit_in_hex;
114 sqgetGlobalVar('username', $username, SQ_SESSION
);
116 $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0);
117 $read = sqimap_mailbox_select($imapConnection, $mailbox);
118 $body = sqimap_run_command($imapConnection, "FETCH $passed_id RFC822",true, $response, $readmessage, TRUE);
123 $messageheader = true;
124 $messageheaderstart=false;
125 $boundaries = array();
127 session_unregister("entities");
137 $body[$count-1] = substr($body[$count-1], -1);
138 for ($i=1; $i < $count; $i++
) {
139 $line = rtrim($body[$i]);
146 } else if ($messageheader) {
149 $end = '</div><div class="ent_body" id="'.$entStr.'B">';
151 $mimepart = -$header;
153 if ($messageheaderstart) {
154 $messageheaderstart=false;
156 } else if ($messageheaderstart) {
157 $messageheader= false;
161 $end = '</div><div class="ent_body" id="'.$entStr.'B">';
169 if (!$header && $messageheader) {
170 $messageheaderstart=true;
172 $pre = '<i><font color ="'.$color[1].'">';
173 $end = '</i></font>';
176 if (!$messageheader && !$header ) {
184 if ( ( $header ||
$messageheader) && (preg_match("/^.*boundary=\"?(.+(?=\")|.+).*/i",$line,$reg)) ) {
187 $bndreg = str_replace("\\","\\\\",$bndreg);
188 $bndreg = str_replace("?","\\?",$bndreg);
189 $bndreg = str_replace("+","\\+",$bndreg);
190 $bndreg = str_replace(".","\\.",$bndreg);
191 $bndreg = str_replace("/","\\/",$bndreg);
192 $bndreg = str_replace("-","\\-",$bndreg);
193 $bndreg = str_replace("(","\\(",$bndreg);
194 $bndreg = str_replace(")","\\)",$bndreg);
196 $boundaries[] = array( 'bnd' => $bnd, 'bndreg' => $bndreg);
197 $messageheader = false;
198 $messageheaderstart=false;
203 $entStr = CalcEntity("$entStr",1);
207 if (($line != '' && $line{0} == '-' ||
$header) && isset($boundaries[0])) {
208 $cnt=count($boundaries)-1;
209 $bnd = $boundaries[$cnt]['bnd'];
210 $bndreg = $boundaries[$cnt]['bndreg'];
212 $regstr = '/^--'."($bndreg)".".*".'/';
213 if (preg_match($regstr,$line,$reg) ) {
214 $bndlen = strlen($reg[1]);
216 if (strlen($line) > ($bndlen +
3)) {
217 if ($line{$bndlen+
2} == '-' && $line{$bndlen+
3} == '-')
221 $entStr = CalcEntity("$entStr",-1);
222 array_pop($boundaries);
223 $pre .= '<b><font color ="'.$color[2].'">';
224 $end .= '</font></b>';
232 $entStr = CalcEntity("$entStr",0);
234 $content[$content_indx]=array();
235 $content[$content_indx]['ent'] = '<a href="#'."$entStr \">$entStr".'</a>';
236 $pre .= '</div><div class="entheader" id="'.
237 $entStr.'H"><a name="'."$entStr".'"><b><font color="'.$color[2].'">';
238 $end .= '</font></b>';
245 if (!$contentset && preg_match("/^.*(content-type:)\s*(\w+)\/(\w+).*/i",$line,$reg)) {
246 if (strtolower($reg[2]) == 'message' && strtolower($reg[3]) == 'rfc822') {
247 $messageheader = true;
249 $content[$content_indx]['type'] = "$reg[2]/$reg[3]";
251 if ($reg[2] == 'image') {
252 $entities["$entStr"] = array();
253 $entities["$entStr"]['entity'] = $entStr;
254 $entities["$entStr"]['contenttype']=$reg[2].'/'.$reg[3];
256 } else if (!$nameset && preg_match("/^.*(name=\s*)\"(.*)\".*/i",$line,$reg)) {
257 $name = htmlspecialchars($reg[2]);
258 $content[$content_indx]['name'] = decodeHeader($name);
260 if (isset($entities["$entStr"])) {
261 $entities["$entStr"]['name'] = urlEncode($reg[2]);
263 } else if (preg_match("/^.*(content-transfer-encoding:)\s*(\w+-?(\w+)?).*/i",$line,$reg) ) {
265 if (isset($entities["$entStr"])) {
266 $entities["$entStr"]['encoding']=$reg[2];
268 $content[$content_indx]['encoding'] = $encoding;
272 $pre .= '<b><font color='.$color[7].'">';
273 $end .= '</font></b>';
280 $message_body .= $line . "\r\n";
282 $line = htmlspecialchars($line);
283 if ($msgd_8bit_in_hex) $line = msgd_convert_to_hex($line);
284 $message_body .= "$pre"."$line"."$end"."\r\n";
288 //$returnValue .= returnTime($start).'<br />';
291 <style type="text/css">
314 displayHtmlHeader( _("Message Details"), $xtra, FALSE );
315 $returnValue .= ob_get_contents();
321 $returnValue .= "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n";
322 $returnValue .= '<font face="monospace">'."\n";
323 $returnValue .= '<br />'."\n";
326 if (count($content) > 0 && !$stripHTML) {
327 $returnValue .= '<h2>'._("Bodystructure")."</h2>\n\n";
328 $returnValue .= '<table border="1" width="98%"><thead>'.
329 '<tr bgcolor="'.$color[7].'">'.
330 '<td><b><font color="'.$color[5].'">'._("Entity").'</font></b></td>'.
331 '<td><b><font color="'.$color[5].'">'._("Content-Type").'</font></b></td>'.
332 '<td><b><font color="'.$color[5].'">'._("Name").'</font></b></td>'.
333 '<td><b><font color="'.$color[5].'">'._("Encoding").'</font></b></td>'.
336 for ($i = 0; $i < count($content);$i++
) {
337 $returnValue .= '<tr><td>';
338 $returnValue .= $content[$i]['ent'].'</td><td>';
339 if (isset($content[$i]['type'])) {
340 $returnValue .= $content[$i]['type'];
341 } else $returnValue .= 'TEXT/PLAIN';
342 $returnValue .= '</td><td>';
343 if (isset($content[$i]['name'])) {
344 $returnValue .= $content[$i]['name'];
345 } else $returnValue .= ' ';
346 $returnValue .= '</td><td>';
347 if (isset($content[$i]['encoding'])) {
348 $returnValue .= $content[$i]['encoding'];
349 } else $returnValue .= ' ';
350 $returnValue .= '</td></tr>'."\n";
352 $returnValue .= '</tbody></table><br />'."\n";
356 $returnValue .= '<h2>'._("RFC822 Message body")."</h2>\n\n";
357 $returnValue .= '<pre><div><div class="header">';
359 $returnValue .= '<pre>';
362 $returnValue .= $message_body;
365 $returnValue .= '</div></div></pre></font></body></html>';
367 $returnValue .= '</pre>';