bbdea028 |
1 | <?php |
2 | |
3 | /** Message Source |
4 | * |
5 | * Plugin to view the RFC822 raw message output and the bodystructure of a message |
6 | * |
7 | * Copyright (c) 2002 Marc Groot Koerkamp, The Netherlands |
8 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
9 | * |
10 | * $Id$ |
11 | **/ |
12 | |
13 | |
14 | //require_once('./message_viewentity.php'); |
15 | chdir('..'); |
16 | require_once('../functions/imap.php'); |
17 | require_once('../functions/mime.php'); |
18 | require_once('../config/config.php'); |
19 | require_once('../src/validate.php'); |
20 | require_once('../src/load_prefs.php'); |
21 | |
22 | global $color, $uid_support; |
23 | |
24 | function CalcEntity($entString, $direction) { |
25 | $result = $entString; |
26 | if ($direction == -1) { |
27 | $pos = strrpos($entString,'.'); |
28 | $result = substr($entString,0,$pos); |
29 | } |
30 | |
31 | switch ($direction) { |
32 | case 0: |
33 | $pos = strrpos($entString,'.'); |
34 | if ($pos === false) { |
35 | $entString++; |
36 | $result= $entString; |
37 | } |
38 | else { |
39 | $level = substr($entString,0,$pos); |
40 | $sublevel = substr($entString,$pos+1); |
41 | $sublevel++; |
42 | $result = "$level".'.'."$sublevel"; |
43 | } |
44 | break; |
45 | case 1: |
46 | $result = "$entString".".0"; |
47 | break; |
48 | default: |
49 | break; |
50 | } |
51 | return ($result); |
52 | } |
53 | |
54 | function returnTime($start) { |
55 | $stop = gettimeofday(); |
56 | $timepassed = 1000000 * ($stop['sec'] - $start['sec']) + $stop['usec'] - $start['usec']; |
57 | return $timepassed; |
58 | } |
59 | |
60 | function GetMimeProperties($header) { |
61 | } |
62 | |
63 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
64 | $read = sqimap_mailbox_select($imapConnection, $mailbox); |
65 | $start = gettimeofday(); |
66 | $body = sqimap_run_command($imapConnection, "FETCH $passed_id RFC822",true, $response, $readmessage, $uid_support); |
67 | $message_body = ''; |
68 | $header = false; |
69 | $mimepart = false; |
70 | $bnd_end = false; |
71 | $messageheader = true; |
72 | $messageheaderstart=false; |
73 | $boundaries = array(); |
74 | $entities = array(); |
75 | session_unregister("entities"); |
76 | $pre = '<b>'; |
77 | $end = '</b>'; |
78 | $entStr = ''; |
79 | $bla =''; |
80 | $content = array (); |
81 | $content_indx = -1; |
82 | $contentset = false; |
83 | |
84 | $count=count($body); |
85 | $body[$count-1] = substr($body[$count-1], -1); |
86 | for ($i=1; $i < $count; $i++) { |
87 | $line = trim($body[$i]); |
88 | if ($line == '') { |
89 | $pre = ''; |
90 | $end = ''; |
91 | if ($bnd_end) { |
92 | $header = true; |
93 | $mimepart = false; |
94 | } else if ($messageheader) { |
95 | if ($header) { |
96 | $header=false; |
97 | $end = "\n \n".'</div>'."\n \n".'<div class="ent_body" ID="'.$entStr.'B">'."\n \n"; |
98 | } |
99 | $mimepart = -$header; |
100 | $bnd_end = false; |
101 | if ($messageheaderstart) { |
102 | $messageheaderstart=false; |
103 | } |
104 | } else if ($messageheaderstart) { |
105 | $messageheader= false; |
106 | } else { |
107 | if ($header) { |
108 | $pre = ''; |
109 | $end = "\n \n".'</div>'."\n \n".'<div class="ent_body" ID="'.$entStr.'B">'."\n \n"; |
110 | } |
111 | $header = false; |
112 | $mimepart=true; |
113 | } |
114 | $contentset = false; |
115 | $nameset = false; |
116 | } else { |
117 | if (!$header && $messageheader) { |
118 | $messageheaderstart=true; |
119 | if ($pre != '<b>') { |
120 | $pre = '<i><font color ='."$color[1]>"; |
121 | $end = '</i></font>'; |
122 | } |
123 | } |
124 | if (!$messageheader && !$header ) { |
125 | $mimepart=true; |
126 | } else { |
127 | $mimepart=false; |
128 | } |
129 | $pre = ''; |
130 | $end = ''; |
131 | } |
132 | if ( ( $header || $messageheader) && (preg_match("/^.*boundary=\"?(.+(?=\")|.+).*/i",$line,$reg)) ) { |
133 | $bnd = $reg[1]; |
134 | $bndreg = $bnd; |
135 | $bndreg = str_replace("\\","\\\\",$bndreg); |
136 | $bndreg = str_replace("?","\\?",$bndreg); |
137 | $bndreg = str_replace("+","\\+",$bndreg); |
138 | $bndreg = str_replace(".","\\.",$bndreg); |
139 | $bndreg = str_replace("/","\\/",$bndreg); |
140 | $bndreg = str_replace("-","\\-",$bndreg); |
141 | $bndreg = str_replace("(","\\(",$bndreg); |
142 | $bndreg = str_replace(")","\\)",$bndreg); |
143 | |
144 | $boundaries[] = array( 'bnd' => $bnd, 'bndreg' => $bndreg); |
145 | $messageheader = false; |
146 | $messageheaderstart=false; |
147 | $mimepart=false; |
148 | if ($entStr=='') { |
149 | $entStr='0'; |
150 | } else { |
151 | $entStr = CalcEntity("$entStr",1); |
152 | } |
153 | } |
154 | |
155 | if (($line != '' && $line{0} == '-' || $header) && isset($boundaries[0])) { |
156 | $cnt=count($boundaries)-1; |
157 | $bnd = $boundaries[$cnt]['bnd']; |
158 | $bndreg = $boundaries[$cnt]['bndreg']; |
159 | |
160 | $regstr = '/^--'."($bndreg)".".*".'/'; |
161 | if (preg_match($regstr,$line,$reg) ) { |
162 | $bndlen = strlen($reg[1]); |
163 | $bndend = false; |
164 | if (strlen($line) > ($bndlen + 3)) { |
165 | if ($line{$bndlen+2} == '-' && $line{$bndlen+3} == '-') |
166 | $bndend = true; |
167 | } |
168 | if ($bndend) { |
169 | $entStr = CalcEntity("$entStr",-1); |
170 | array_pop($boundaries); |
171 | $pre .= '<b><font color ='."$color[2]>"; |
172 | $end .= '</font></b>'; |
173 | $header = true; |
174 | $mimepart = false; |
175 | $bnd_end = true; |
176 | $encoding = ''; |
177 | } else { |
178 | $header = true; |
179 | $bnd_end = false; |
180 | $entStr = CalcEntity("$entStr",0); |
181 | $content_indx++; |
182 | $content[$content_indx]=array(); |
183 | $content[$content_indx]['ent'] = '<A HREF="#'."$entStr \">$entStr".'</a>'; |
184 | $pre .= "\n \n".'</div>'."\n \n".'<div class="entheader" ID="'.$entStr.'H"><a name="'."$entStr".'"><b><font color ='."$color[2]>"; |
185 | $end .= '</font></b>'."\n"; |
186 | $header = true; |
187 | $mimepart = false; |
188 | $encoding = ''; |
189 | } |
190 | } else { |
191 | if ($header) { |
192 | if (!$contentset && preg_match("/^.*(content-type:)\s*(\w+)\/(\w+).*/i",$line,$reg)) { |
193 | if (strtolower($reg[2]) == 'message' && strtolower($reg[3]) == 'rfc822') { |
194 | $messageheader = true; |
195 | } |
196 | $content[$content_indx]['type'] = "$reg[2]/$reg[3]"; |
197 | $contentset = true; |
198 | if ($reg[2] == 'image') { |
199 | $entities["$entStr"] = array(); |
200 | $entities["$entStr"]['entity'] = $entStr; |
201 | $entities["$entStr"]['contenttype']=$reg[2].'/'.$reg[3]; |
202 | } |
203 | } else if (!$nameset && preg_match("/^.*(name=\s*)\"(.*)\".*/i",$line,$reg)) { |
204 | $name = htmlspecialchars($reg[2]); |
205 | $content[$content_indx]['name'] = decodeHeader($name); |
206 | $nameset = true; |
207 | if (isset($entities["$entStr"])) { |
208 | $entities["$entStr"]['name'] = urlEncode($reg[2]); |
209 | } |
210 | } else if (preg_match("/^.*(content-transfer-encoding:)\s*(\w+-?(\w+)?).*/i",$line,$reg) ) { |
211 | $encoding = $reg[2]; |
212 | if (isset($entities["$entStr"])) { |
213 | $entities["$entStr"]['encoding']=$reg[2]; |
214 | } |
215 | $content[$content_indx]['encoding'] = $encoding; |
216 | $mimeentity = ''; |
217 | } |
218 | |
219 | $pre .= '<b><font color ='."$color[7]>"; |
220 | $end .= '</font></b>'; |
221 | //$mimepart=false; |
222 | } |
223 | } |
224 | } |
225 | /* |
226 | if ($mimepart) { |
227 | if (isset($entities["$entStr"])) { |
228 | if (isset($encoding) && $encoding == 'base64') { |
229 | if (!isset( $entities["$entStr"]['content'])) $entities[$entStr]['content'] = ''; |
230 | $entities["$entStr"]['content'] .= $line; |
231 | } |
232 | } |
233 | } |
234 | */ |
235 | $line = htmlspecialchars($line); |
236 | $message_body .= "$pre"."$line"."$end".'<BR>'."\r\n"; |
237 | } |
238 | //echo returnTime($start).'<BR>'; |
239 | $xtra = <<<ECHO |
240 | |
241 | <STYLE> |
242 | |
243 | <!-- |
244 | .ent_body { |
245 | display:inline; |
246 | } |
247 | |
248 | .header { |
249 | display:inline; |
250 | } |
251 | |
252 | .entheader { |
253 | display:inline; |
254 | margin-bottom:1em; |
255 | padding-bottom:1em; |
256 | border-style: solid none solid none; |
257 | border-width:0.1em; |
258 | width:99%; |
259 | } |
260 | //--> |
261 | |
262 | </STYLE> |
263 | |
264 | ECHO; |
265 | |
266 | displayHtmlHeader( _("Message Details"), $xtra, FALSE ); |
267 | /* body */ |
268 | echo '<body><code>'."\n"; |
269 | echo '<font face = "monospace">'."\n"; |
270 | echo '<BR>'."\n"; |
271 | //session_register("entities"); |
272 | //$keys = array_keys($entities); |
273 | //$start = gettimeofday(); |
274 | //foreach ($keys as $key) { |
275 | // if (isset($entities[$key])) { |
276 | // if ($entities[$key]['encoding'] == 'base64') { |
277 | // echo '<img src="message_viewentity.php?ent='.$entities[$key]['entity'].'&name='.$entities[$key]['name'].'"><br>'; |
278 | // } |
279 | // } |
280 | //} |
281 | //session_unregister("entities"); |
282 | |
283 | if (count($content) > 0) { |
284 | echo '<h2> Bodystructure </h2>'."\n\n"; |
285 | echo '<table border=1 width="98%"><thead>'. |
286 | '<tr bgcolor="'."$color[7]".'">'. |
287 | '<td><b><font color="'."$color[5]".'">Entity</font></b></td>'. |
288 | '<td><b><font color="'."$color[5]".'">Content-Type</font></b></td>'. |
289 | '<td><b><font color="'."$color[5]".'">Name</font></b></td>'. |
290 | '<td><b><font color="'."$color[5]".'">Encoding</font></b></td>'. |
291 | |
292 | '</tr>'. |
293 | '</thead><tbody>'; |
294 | for ($i = 0; $i < count($content);$i++) { |
295 | echo '<tr><td>'; |
296 | echo $content[$i]['ent'].'</td><td>'; |
297 | if (isset($content[$i]['type'])) { |
298 | echo $content[$i]['type']; |
299 | } else echo 'TEXT/PLAIN'; |
300 | echo '</td><td>'; |
301 | if (isset($content[$i]['name'])) { |
302 | echo $content[$i]['name']; |
303 | } else echo ' '; |
304 | echo '</td><td>'; |
305 | if (isset($content[$i]['encoding'])) { |
306 | echo $content[$i]['encoding']; |
307 | } else echo ' '; |
308 | echo '</td></tr>'."\n"; |
309 | } |
310 | echo '</tbody></table><br>'."\n"; |
311 | } |
312 | echo '<h2> RFC822 Message body </h2>'."\n\n"; |
313 | echo '<div><div class="header">'."\n\n"; |
314 | echo $message_body; |
315 | echo '</div></div></font></code></body></html>'; |
316 | ?> |