59177427 |
1 | <?php |
895905c0 |
2 | |
35586184 |
3 | /** |
4 | * read_body.php |
5 | * |
15e6162e |
6 | * Copyright (c) 1999-2002 The SquirrelMail Project Team |
35586184 |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
9 | * This file is used for reading the msgs array and displaying |
10 | * the resulting emails in the right frame. |
11 | * |
12 | * $Id$ |
a07cd1a4 |
13 | */ |
35586184 |
14 | |
15 | require_once('../src/validate.php'); |
16 | require_once('../functions/imap.php'); |
17 | require_once('../functions/mime.php'); |
18 | require_once('../functions/date.php'); |
19 | require_once('../functions/url_parser.php'); |
57257333 |
20 | require_once('../functions/smtp.php'); |
fab3baa6 |
21 | require_once('../functions/html.php'); |
38c944cc |
22 | require_once('../src/view_header.php'); |
23 | |
a07cd1a4 |
24 | /** |
1fca12b5 |
25 | * Given an IMAP message id number, this will look it up in the cached |
26 | * and sorted msgs array and return the index. Used for finding the next |
27 | * and previous messages. |
28 | * |
29 | * @return the index of the next valid message from the array |
30 | */ |
c615b1da |
31 | function findNextMessage($passed_id) { |
32 | global $msort, $msgs, $sort, |
cf710efe |
33 | $thread_sort_messages, $allow_server_sort, |
60a3e687 |
34 | $server_sort_array; |
2728fa19 |
35 | if (!is_array($server_sort_array)) { |
36 | $thread_sort_messages = 0; |
794d59c0 |
37 | $allow_server_sort = FALSE; |
2728fa19 |
38 | } |
a07cd1a4 |
39 | $result = -1; |
c615b1da |
40 | if ($thread_sort_messages || $allow_server_sort) { |
60a3e687 |
41 | reset($server_sort_array); |
42 | while(list($key, $value) = each ($server_sort_array)) { |
c615b1da |
43 | if ($passed_id == $value) { |
1fca12b5 |
44 | if ($key == (count($server_sort_array) - 1)) { |
60a3e687 |
45 | $result = -1; |
46 | break; |
47 | } |
1fca12b5 |
48 | $result = $server_sort_array[$key + 1]; |
60a3e687 |
49 | break; |
789b4d79 |
50 | } |
60a3e687 |
51 | } |
1fca12b5 |
52 | } |
c615b1da |
53 | elseif ($sort == 6 && !$allow_server_sort && |
54 | !$thread_sort_messages ) { |
55 | if ($passed_id != 1) { |
56 | $result = $passed_id - 1; |
a07cd1a4 |
57 | } |
1fca12b5 |
58 | } |
c615b1da |
59 | elseif (!$allow_server_sort && !$thread_sort_messages ) { |
75ef78d8 |
60 | if (!is_array($msort)) { |
61 | return -1; |
62 | } |
a07cd1a4 |
63 | for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) { |
c615b1da |
64 | if ($passed_id == $msgs[$key]['ID']) { |
a07cd1a4 |
65 | next($msort); |
66 | $key = key($msort); |
1fca12b5 |
67 | if (isset($key)){ |
a07cd1a4 |
68 | $result = $msgs[$key]['ID']; |
69 | break; |
1fca12b5 |
70 | } |
10f0ce72 |
71 | } |
72 | } |
10f0ce72 |
73 | } |
a07cd1a4 |
74 | return ($result); |
75 | } |
76 | |
a07cd1a4 |
77 | /** returns the index of the previous message from the array. */ |
c615b1da |
78 | function findPreviousMessage($numMessages, $passed_id) { |
79 | global $msort, $sort, $msgs, |
80 | $thread_sort_messages, |
60a3e687 |
81 | $allow_server_sort, $server_sort_array; |
a07cd1a4 |
82 | $result = -1; |
2728fa19 |
83 | if (!is_array($server_sort_array)) { |
84 | $thread_sort_messages = 0; |
794d59c0 |
85 | $allow_server_sort = FALSE; |
2728fa19 |
86 | } |
c615b1da |
87 | if ($thread_sort_messages || $allow_server_sort ) { |
60a3e687 |
88 | reset($server_sort_array); |
89 | while(list($key, $value) = each ($server_sort_array)) { |
c615b1da |
90 | if ($passed_id == $value) { |
60a3e687 |
91 | if ($key == 0) { |
92 | $result = -1; |
93 | break; |
94 | } |
95 | $result = $server_sort_array[$key -1]; |
96 | break; |
789b4d79 |
97 | } |
60a3e687 |
98 | } |
789b4d79 |
99 | } |
c615b1da |
100 | elseif ($sort == 6 && !$allow_server_sort && |
101 | !$thread_sort_messages) { |
102 | if ($passed_id != $numMessages) { |
103 | $result = $passed_id + 1; |
a07cd1a4 |
104 | } |
60a3e687 |
105 | } |
c615b1da |
106 | elseif (!$thread_sort_messages && !$allow_server_sort) { |
1fca12b5 |
107 | if (!is_array($msort)) { |
75ef78d8 |
108 | return -1; |
1fca12b5 |
109 | } |
a07cd1a4 |
110 | for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) { |
c615b1da |
111 | if ($passed_id == $msgs[$key]['ID']) { |
a07cd1a4 |
112 | prev($msort); |
113 | $key = key($msort); |
114 | if (isset($key)) { |
c615b1da |
115 | echo $msort[$key]; |
a07cd1a4 |
116 | $result = $msgs[$key]['ID']; |
117 | break; |
10f0ce72 |
118 | } |
119 | } |
10f0ce72 |
120 | } |
a07cd1a4 |
121 | } |
122 | return ($result); |
123 | } |
10f0ce72 |
124 | |
a07cd1a4 |
125 | /** |
1fca12b5 |
126 | * Displays a link to a page where the message is displayed more |
127 | * "printer friendly". |
128 | */ |
c615b1da |
129 | function printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color) { |
130 | global $javascript_on; |
a07cd1a4 |
131 | |
c615b1da |
132 | $params = '?passed_ent_id=' . $passed_ent_id . |
1fca12b5 |
133 | '&mailbox=' . urlencode($mailbox) . |
134 | '&passed_id=' . $passed_id; |
10f0ce72 |
135 | |
a07cd1a4 |
136 | $print_text = _("View Printable Version"); |
10f0ce72 |
137 | |
c615b1da |
138 | $result = ''; |
a07cd1a4 |
139 | /* Output the link. */ |
140 | if ($javascript_on) { |
3d570ba0 |
141 | $result .= '<script language="javascript" type="text/javascript">' . "\n" . |
a07cd1a4 |
142 | '<!--' . "\n" . |
143 | " function printFormat() {\n" . |
144 | ' window.open("../src/printer_friendly_main.php' . |
c615b1da |
145 | $params . '","Print","width=800,height=600");' . "\n". |
a07cd1a4 |
146 | " }\n" . |
147 | "// -->\n" . |
148 | "</script>\n" . |
b5058e9e |
149 | "<a href=\"javascript:printFormat();\">$print_text</a>\n"; |
a07cd1a4 |
150 | } else { |
b5058e9e |
151 | $result .= '<A target="_blank" HREF="../src/printer_friendly_bottom.php' . |
152 | "$params\">$print_text</a>\n"; |
a07cd1a4 |
153 | } |
a07cd1a4 |
154 | return ($result); |
155 | } |
156 | |
57257333 |
157 | function ServerMDNSupport( $read ) { |
f69feefe |
158 | /* escaping $ doesn't work -> \x36 */ |
159 | $ret = preg_match( '/(\x36MDNSent|\\\*)/i', $read ); |
57257333 |
160 | return ( $ret ); |
161 | } |
162 | |
c615b1da |
163 | function SendMDN ( $mailbox, $passed_id, $sender, $message) { |
164 | global $username, $attachment_dir, $SERVER_NAME, |
165 | $version, $attachments; |
57257333 |
166 | |
5200c026 |
167 | $header = $message->header; |
57257333 |
168 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
5200c026 |
169 | |
170 | $recipient_o = $header->dnt; |
171 | $recipient = $recipient_o->getAddress(true); |
57257333 |
172 | |
173 | // part 1 (RFC2298) |
174 | |
175 | $senton = getLongDateString( $header->date ); |
176 | $to_array = $header->to; |
177 | $to = ''; |
178 | foreach ($to_array as $line) { |
179 | $to .= " $line "; |
180 | } |
181 | |
182 | $subject = $header->subject; |
183 | $now = getLongDateString( time() ); |
46bb8da8 |
184 | |
78db1583 |
185 | set_my_charset(); |
186 | |
46bb8da8 |
187 | $body = _("Your message") . "\r\n\r\n" . |
188 | "\t" . _("To:") . ' ' . $to . "\r\n" . |
189 | "\t" . _("Subject:") . ' ' . $subject . "\r\n" . |
190 | "\t" . _("Sent:") . ' ' . $senton . "\r\n" . |
191 | "\r\n" . |
192 | sprintf( _("Was displayed on %s"), $now ); |
f69feefe |
193 | |
57257333 |
194 | // part2 (RFC2298) |
57257333 |
195 | $original_recipient = $to; |
196 | $original_message_id = $header->message_id; |
197 | |
198 | $part2 = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n"; |
199 | if ($original_recipient != '') { |
200 | $part2 .= "Original-Recipient : $original_recipient\r\n"; |
201 | } |
202 | $final_recipient = $sender; |
203 | $part2 .= "Final-Recipient: rfc822; $final_recipient\r\n" . |
204 | "Original-Message-ID : $original_message_id\r\n" . |
205 | "Disposition: manual-action/MDN-sent-manually; displayed\r\n"; |
206 | |
57257333 |
207 | $localfilename = GenerateRandomString(32, 'FILE', 7); |
208 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
209 | |
210 | $fp = fopen( $full_localfilename, 'w'); |
211 | fwrite ($fp, $part2); |
212 | fclose($fp); |
213 | |
214 | $newAttachment = array(); |
215 | $newAttachment['localfilename'] = $localfilename; |
216 | $newAttachment['type'] = "message/disposition-notification"; |
aa866a40 |
217 | $newAttachment['session']=-1; |
57257333 |
218 | $attachments[] = $newAttachment; |
5200c026 |
219 | |
5200c026 |
220 | return (SendMessage($recipient, '', '', _("Read:") . ' ' . $subject, |
c615b1da |
221 | $body, 0, True, 3, -1) ); |
57257333 |
222 | } |
223 | |
224 | |
c615b1da |
225 | function ToggleMDNflag ( $set ,$imapConnection, $mailbox, $passed_id, $uid_support) { |
0892e427 |
226 | $sg = $set?'+':'-'; |
227 | $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)'; |
0892e427 |
228 | $read = sqimap_run_command ($imapConnection, $cmd, true, $response, |
507d14ea |
229 | $readmessage, $uid_support); |
57257333 |
230 | } |
231 | |
232 | function ClearAttachments() { |
233 | global $username, $attachments, $attachment_dir; |
234 | |
235 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
236 | |
aa866a40 |
237 | $rem_attachments = array(); |
57257333 |
238 | foreach ($attachments as $info) { |
b2c19764 |
239 | if ($info['session'] == -1) { |
aa866a40 |
240 | $attached_file = "$hashed_attachment_dir/$info[localfilename]"; |
241 | if (file_exists($attached_file)) { |
242 | unlink($attached_file); |
243 | } |
244 | } else { |
245 | $rem_attachments[] = $info; |
246 | } |
247 | } |
68c3b52a |
248 | $attachments = $rem_attachments; |
57257333 |
249 | } |
250 | |
4d0cd98b |
251 | function formatRecipientString($recipients, $item ) { |
c615b1da |
252 | global $show_more_cc, $show_more, $show_more_bcc, |
38c944cc |
253 | $PHP_SELF; |
4d0cd98b |
254 | |
38c944cc |
255 | if ((is_array($recipients)) && (isset($recipients[0]))) { |
1fca12b5 |
256 | $string = ''; |
4d0cd98b |
257 | $ary = $recipients; |
38c944cc |
258 | $show = false; |
259 | |
260 | if ($item == 'to') { |
261 | if ($show_more) { |
262 | $show = true; |
263 | $url = set_url_var($PHP_SELF, 'show_more',0); |
264 | } else { |
265 | $url = set_url_var($PHP_SELF, 'show_more',1); |
266 | } |
267 | } else if ($item == 'cc') { |
268 | if ($show_more_cc) { |
269 | $url = set_url_var($PHP_SELF, 'show_more_cc',0); |
270 | $show = true; |
271 | } else { |
272 | $url = set_url_var($PHP_SELF, 'show_more_cc',1); |
273 | } |
274 | } else if ($item == 'bcc') { |
275 | if ($show_more_bcc) { |
276 | $url = set_url_var($PHP_SELF, 'show_more_bcc',0); |
277 | $show = true; |
278 | } else { |
279 | $url = set_url_var($PHP_SELF, 'show_more_bcc',1); |
280 | } |
281 | } |
4d0cd98b |
282 | |
38c944cc |
283 | $cnt = count($ary); |
c615b1da |
284 | $i = 0; |
38c944cc |
285 | while ($i < $cnt) { |
c615b1da |
286 | $ary[$i] = htmlspecialchars($ary[$i]->getAddress()); |
4d0cd98b |
287 | if ($string) { |
38c944cc |
288 | $string .= '<BR>'.$ary[$i]; |
4d0cd98b |
289 | } else { |
38c944cc |
290 | $string = $ary[$i]; |
291 | if ($cnt>1) { |
292 | $string .= ' (<A HREF="'.$url; |
293 | if ($show) { |
c615b1da |
294 | $string .= '">'._("less").'</A>)'; |
38c944cc |
295 | } else { |
c615b1da |
296 | $string .= '">'._("more").'</A>)'; |
38c944cc |
297 | break; |
298 | } |
299 | } |
4d0cd98b |
300 | } |
4d0cd98b |
301 | $i++; |
1fca12b5 |
302 | } |
4d0cd98b |
303 | } |
304 | else { |
1fca12b5 |
305 | $string = ''; |
4d0cd98b |
306 | } |
c615b1da |
307 | return $string; |
308 | } |
309 | |
310 | function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color) { |
311 | global $msn_user_support, $default_use_mdn, $draft_folder, $sent_folder, |
312 | $default_use_priority, $show_xmailer_default, |
313 | $mdn_user_support, $PHP_SELF, $javascript_on; |
314 | |
315 | $header = $message->header; |
316 | $env = array(); |
317 | $env[_("Subject")] = getLongDateString($header->date); |
318 | $from_o = $header->from; |
319 | if (is_object($from_o)) { |
320 | $from_name = $from_o->getAddress(); |
321 | } else { |
322 | $from_name = _("Unknown sender"); |
323 | } |
324 | $env[_("From")] = htmlspecialchars($from_name); |
325 | $env[_("Date")] = htmlspecialchars($header->subject); |
326 | $env[_("To")] = formatRecipientString($header->to, "to"); |
327 | $env[_("Cc")] = formatRecipientString($header->cc, "cc"); |
328 | $env[_("Bcc")] = formatRecipientString($header->bcc, "bcc"); |
329 | if ($default_use_priority) { |
330 | $env[_("Priority")] = getPriorityStr($header->priority); |
331 | } |
332 | if ($show_xmailer_default) { |
333 | $env[_("Mailer")] = $header->xmailer; |
334 | } |
335 | if ($default_use_mdn) { |
336 | if ($mdn_user_support) { |
337 | if ($header->dnt) { |
338 | if ($message->is_mdnsent) { |
339 | $env[_("Read receipt")] = _("send"); |
340 | } else { |
341 | if ( !($mailbox == $draft_folder || |
342 | $mailbox == $sent_folder || $message->is_deleted)) { |
343 | $mdn_url = $PHP_SELF . '&sendreceipt=1'; |
344 | $FirstTimeSee = false; |
345 | if ($FirstTimeSee && $javascript_on) { |
346 | $script = '<script language="JavaScript" type="text/javascript">' ."\n"; |
347 | $script .= '<!--'. "\n"; |
348 | $script .= 'if(window.confirm("' . |
349 | _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") . |
350 | '")) { '."\n" . |
351 | ' sendMDN()'. |
352 | '}' . "\n"; |
353 | $script .= '// -->'. "\n"; |
354 | $script .= '</script>'. "\n"; |
355 | echo $script; |
356 | } |
357 | $env[_("Read receipt")] = _("requested") . |
358 | ' <a href="'.$mdn_url.'">['. _("Send read receipt now") .']</a>'; |
359 | } else { |
360 | $env[_("Read receipt")] = _("requested"); |
361 | } |
362 | } |
363 | } |
364 | } |
365 | } |
366 | |
367 | $s = '<table width="100%" cellpadding="0" cellspacing="0" border="0" ' . |
368 | 'align="center">'; |
369 | foreach ($env as $key => $val) { |
370 | if ($val) { |
371 | $s .= '<tr>'; |
372 | $s .= html_tag( 'td', '<b>'.$key.': </b>', 'right', $color[0], 'valign="top" width="20%"') . "\n"; |
373 | $s .= html_tag( 'td', $val, 'left', $color[0], 'valign="top" width="80%"'); |
374 | $s .= "\n</tr>"; |
375 | } |
376 | } |
377 | $s .= '</table>'; |
378 | return $s; |
379 | } |
380 | |
381 | function formatMenubar($mailbox, $passed_id, $passed_ent_id, $msg, $mbx_response) { |
382 | global $base_uri, $sent_folder, $draft_folder, $where, $what, $color, $sort, |
383 | $startMessage, $data_dir, $username, $compose_new_win; |
384 | |
385 | $topbar_delimiter = ' | '; |
386 | $urlMailbox = encodeHeader($mailbox); |
387 | |
388 | $identity = ''; |
389 | $idents = getPref($data_dir, $username, 'identities'); |
390 | $from_name = $msg->header->from->getAddress(); |
391 | if (!empty($idents) && $idents > 1) { |
392 | for ($i = 1; $i < $idents; $i++) { |
393 | $enc_from_name = '"'. |
394 | encodeHeader(getPref($data_dir, |
395 | $username, |
396 | 'full_name' . $i)) . |
397 | '" <' . getPref($data_dir, $username, |
398 | 'email_address' . $i) . '>'; |
399 | if (htmlspecialchars($enc_from_name) == $from_name) { |
400 | $identity = $i; |
401 | break; |
402 | } |
403 | } |
404 | } |
405 | |
406 | $s = '<table width="100%" cellpadding="3" cellspacing="0" align="center"'. |
407 | ' border="0" bgcolor="'.$color[9].'"><tr><td align="left" width="33%"><small>'; |
408 | |
409 | $msgs_url = $base_uri . 'src/'; |
410 | if (isset($where) && isset($what)) { |
411 | if ($pos == '') { |
412 | $pos=0; |
413 | } |
414 | $msgs_url .= 'search.php?where='.urlencode($where).'&pos='.$pos. |
415 | '&what='.urlencode($what).'&mailbox='.$urlMailbox; |
416 | } else { |
417 | $msgs_url .= 'right_main.php?sort='.$sort.'&startMessage='. |
418 | $startMessage.'&mailbox='.$urlMailbox; |
419 | } |
420 | $s .= '<a href="'. $msgs_url.'">'._("Message List").'</a>'; |
421 | $s .= $topbar_delimiter; |
422 | |
423 | $delete_url = $base_uri . 'src/delete_message.php?mailbox='.$urlMailbox. |
424 | '&message='.$passed_id.'&'; |
425 | if (!(isset($passed_ent_id) && $passed_ent_id)) { |
426 | if ($where && $what) { |
427 | $delete_url .= 'where=' . urlencode($where) . '&what=' . urlencode($what); |
428 | } else { |
429 | $delete_url .= 'sort='. $sort . '&startMessage='. $startMessage; |
430 | } |
431 | $s .= '<a href="'. $delete_url.'">'._("Delete").'</a>'; |
432 | } |
433 | |
434 | $comp_uri = $base_uri . 'src/compose.php'. |
435 | '?passed_id='.$passed_id. |
436 | '&mailbox='.$urlMailbox. |
437 | (isset($passed_ent_id)?'&passed_ent_id='.$passed_ent_id:''). |
438 | '&identity='.$identity; |
439 | |
440 | |
441 | if (($mailbox == $draft_folder) && ($save_as_draft)) { |
442 | $comp_alt_uri = $comp_uri . '&action=draft'; |
443 | $comp_alt_string = _("Resume Draft"); |
444 | } else if ($mailbox == $sent_folder) { |
445 | $comp_alt_uri = $comp_uri . '&action=edit_as_new'; |
446 | $comp_alt_string = _("Edit Message as New"); |
447 | } |
448 | if (isset($comp_alt_uri)) { |
449 | $s .= $topbar_delimiter; |
450 | if ($compose_new_win == '1') { |
451 | $s .= '<a href="javascript:void(0)" '. |
452 | 'onclick="comp_in_new("'.$comp_alt_uri.'")">'.$comp_alt_string.'</a>'; |
453 | } else { |
454 | $s .= '<a href="'.$comp_alt_uri.'">'.$comp_alt_string.'</a>'; |
455 | } |
456 | } |
457 | |
458 | $s .= '</small></td><td align="center" width="33%"><small>'; |
459 | |
460 | if (!(isset($where) && isset($what)) && !$passed_ent_id) { |
461 | $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id); |
462 | $next = findNextMessage($passed_id); |
463 | if ($prev != -1) { |
464 | $uri = $base_uri . 'src/read_body.php?passed_id='.$prev. |
465 | '&mailbox='.$urlMailbox.'&sort='.$sort. |
466 | '&startMessage='.$startMessage.'&show_more=0'; |
467 | $s .= '<a href="'.$uri.'">'._("Previous").'</a>'; |
468 | } else { |
469 | $s .= _("Previous"); |
470 | } |
471 | $s .= $topbar_delimiter; |
472 | if ($next != -1) { |
473 | $uri = $base_uri . 'src/read_body.php?passed_id='.$next. |
474 | '&mailbox='.$urlMailbox.'&sort='.$sort. |
475 | '&startMessage='.$startMessage.'&show_more=0'; |
476 | $s .= '<a href="'.$uri.'">'._("Next").'</a>'; |
477 | } else { |
478 | $s .= _("Next"); |
479 | } |
480 | } else if (isset($passed_ent_id) && $passed_ent_id) { |
481 | } |
482 | |
483 | $s .= '</small></td><td align="right" width="33%"><small>'; |
484 | |
485 | $comp_action_uri = $comp_uri . '&action=forward'; |
486 | if ($compose_new_win == '1') { |
487 | $s .= '<a href="javascript:void(0)" '. |
488 | 'onclick="comp_in_new(\''.$comp_action_uri.'\')">'._("Forward").'</a>'; |
489 | } else { |
490 | $s .= '<a href="'.$comp_action_uri.'">'._("Forward").'</a>'; |
491 | } |
492 | $s .= $topbar_delimiter; |
493 | |
494 | $comp_action_uri = decodeHeader($comp_uri . '&action=reply'); |
495 | if ($compose_new_win == '1') { |
496 | $s .= '<a href="javascript:void(0)" '. |
497 | 'onclick="comp_in_new(\''.$comp_action_uri.'\')">'._("Reply").'</a>'; |
498 | } else { |
499 | $s .= '<a href="'.$comp_action_uri.'">'._("Reply").'</a>'; |
500 | } |
501 | $s .= $topbar_delimiter; |
502 | |
503 | $comp_action_uri = $comp_uri . '&action=reply_all'; |
504 | if ($compose_new_win == '1') { |
505 | $s .= '<a href="javascript:void(0)" '. |
506 | 'onclick="comp_in_new(\''.$comp_action_uri.'\')">'._("Reply All").'</a>'; |
507 | } else { |
508 | $s .= '<a href="'.$comp_action_uri.'">'._("Reply All").'</a>'; |
509 | } |
510 | $s .= '</small></td></tr></table>'; |
511 | return $s; |
512 | } |
513 | |
514 | function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) { |
515 | global $startMessage, $show_more, $base_uri, $where, $what; |
516 | |
517 | $urlMailbox = encodeHeader($mailbox); |
518 | $s = '<table width="100%" cellpadding="3" cellspacing="0" align="right"'. |
519 | ' border="0" bgcolor="'.$color[9].'">'. |
520 | '<tr align="right"><td valign="top" align="right"><small>'; |
521 | |
522 | $viewheader_url = $base_uri . 'src/read_body.php?mailbox=' . $urlMailbox . |
523 | '&passed_id='. $passed_id. '&'; |
524 | if ($where && $what) { |
525 | $viewheader_url .= 'where=' . urlencode($where) . '&what=' . urlencode($what) . |
526 | '&view_hdr=1'; |
527 | } else { |
528 | $viewheader_url .= 'startMessage=' .$startMessage. '&show_more='. |
529 | $show_more .'&view_hdr=1'; |
530 | } |
531 | $s .= '<a href="'.$viewheader_url.'">'.("View Full Header").'</a>'; |
532 | /* Output the printer friendly link if we are in subtle mode. */ |
533 | $s .= ' | '. |
534 | printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color); |
535 | |
536 | do_hook("read_body_header_right"); |
537 | |
538 | $s .= '</small></td></tr></table>'."\n"; |
539 | return $s; |
4d0cd98b |
540 | } |
541 | |
542 | |
57257333 |
543 | /* |
544 | * Main of read_boby.php -------------------------------------------------- |
545 | */ |
546 | |
547 | /* |
548 | Urled vars |
549 | ---------- |
550 | $passed_id |
551 | */ |
a07cd1a4 |
552 | |
38c944cc |
553 | global $uid_support, $sqimap_capabilities; |
554 | |
6a108031 |
555 | if (isset($mailbox)) { |
4366bea4 |
556 | $mailbox = urldecode( $mailbox ); |
557 | } |
38c944cc |
558 | |
1fca12b5 |
559 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, |
560 | $imapPort, 0); |
38c944cc |
561 | |
562 | $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true); |
563 | |
564 | if (!isset($messages)) { |
565 | $messages = array(); |
566 | session_register('messages'); |
38c944cc |
567 | } |
568 | |
569 | /** |
570 | * $message contains all information about the message |
571 | * including header and body |
572 | */ |
37d2a6ee |
573 | |
574 | $uidvalidity = $mbx_response['UIDVALIDITY']; |
575 | |
576 | if (!isset($messages[$uidvalidity])) { |
577 | $messages[$uidvalidity] = array(); |
578 | } |
5200c026 |
579 | if (!isset($messages[$uidvalidity][$passed_id]) || !$uid_support) { |
580 | $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
581 | $messages[$uidvalidity][$passed_id] = $message; |
38c944cc |
582 | } else { |
6a108031 |
583 | // $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
5200c026 |
584 | $message = $messages[$uidvalidity][$passed_id]; |
585 | } |
586 | if (isset($passed_ent_id)) { |
587 | $message = $message->getEntity($passed_ent_id); |
588 | $message->id = $passed_id; |
589 | $message->mailbox = $mailbox; |
c615b1da |
590 | } else { |
591 | $passed_ent_id = 0; |
38c944cc |
592 | } |
5200c026 |
593 | $header = $message->header; |
57257333 |
594 | |
5200c026 |
595 | //do_hook('html_top'); |
57257333 |
596 | |
597 | /* |
598 | * The following code sets necesarry stuff for the MDN thing |
599 | */ |
1fca12b5 |
600 | if($default_use_mdn && |
601 | ($mdn_user_support = getPref($data_dir, $username, 'mdn_user_support', |
602 | $default_use_mdn))) { |
38c944cc |
603 | $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]); |
604 | $FirstTimeSee = !$message->is_seen; |
57257333 |
605 | } |
606 | |
5200c026 |
607 | /* ============================================================================= |
608 | * block for handling incoming url vars |
609 | * |
610 | * ============================================================================= |
611 | */ |
612 | |
a07cd1a4 |
613 | |
57257333 |
614 | /* |
615 | * The following code shows the header of the message and then exit |
616 | */ |
a07cd1a4 |
617 | if (isset($view_hdr)) { |
38c944cc |
618 | $template_vars = array(); |
c615b1da |
619 | $template_vars['full_header'] = parse_viewheader($imapConnection,$passed_id, $passed_ent_id); |
38c944cc |
620 | $template_vars['return_address'] = set_url_var($PHP_SELF, 'view_hdr'); |
621 | view_header($template_vars, '', '</body></html>'); |
622 | exit; |
a07cd1a4 |
623 | } |
624 | |
5200c026 |
625 | if (isset($sendreceipt)) { |
626 | if ( !$message->is_mdnsent ) { |
627 | if (isset($identity) ) { |
628 | $final_recipient = getPref($data_dir, $username, 'email_address' . '0', '' ); |
629 | } else { |
630 | $final_recipient = getPref($data_dir, $username, 'email_address', '' ); |
631 | } |
632 | |
633 | $final_recipient = trim($final_recipient); |
634 | if ($final_recipient == '' ) { |
635 | $final_recipient = getPref($data_dir, $username, 'email_address', '' ); |
636 | } |
637 | |
c615b1da |
638 | if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message ) > 0 && $supportMDN ) { |
639 | ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id, $uid_support); |
5200c026 |
640 | $message->is_mdnsent = true; |
6a108031 |
641 | $messages[$uidvalidity][$passed_id]=$message; |
5200c026 |
642 | } |
643 | ClearAttachments(); |
644 | } |
645 | } |
5200c026 |
646 | /* ============================================================================= |
647 | * end block for handling incoming url vars |
648 | * |
649 | * ============================================================================= |
650 | */ |
38c944cc |
651 | $msgs[$passed_id]['FLAG_SEEN'] = true; |
38c944cc |
652 | |
5200c026 |
653 | $messagebody = ''; |
6a108031 |
654 | $ent_ar = $message->findDisplayEntity(array()); |
6a108031 |
655 | for ($i = 0; $i < count($ent_ar); $i++) { |
656 | $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox); |
38c944cc |
657 | } |
6a108031 |
658 | |
c615b1da |
659 | displayPageHeader($color, $mailbox); |
660 | do_hook('read_body_top'); |
661 | echo formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response); |
662 | echo formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color); |
663 | echo formatToolbar($mailbox,$passed_id,$passed_ent_id,$message, $color); |
664 | echo "BOE"; |
665 | echo '<table width="100%" cellpadding="3" cellspacing="3" align="center"'. |
666 | ' border="0" bgcolor="'.$color[4].'">'; |
667 | echo '<tr><td>'.$messagebody.'</td></tr>'; |
668 | echo '<tr><td>'.formatAttachments($message,$ent_ar,$mailbox, $passed_id).'</td></tr>'; |
669 | echo '</table>'; |
a07cd1a4 |
670 | |
671 | /* show attached images inline -- if pref'fed so */ |
5be9f195 |
672 | if (($attachment_common_show_images) && |
a07cd1a4 |
673 | is_array($attachment_common_show_images_list)) { |
674 | foreach ($attachment_common_show_images_list as $img) { |
5be9f195 |
675 | $imgurl = '../src/download.php' . |
57257333 |
676 | '?' . |
cd7b8833 |
677 | 'passed_id=' . urlencode($img['passed_id']) . |
3d570ba0 |
678 | '&mailbox=' . urlencode($mailbox) . |
679 | '&passed_ent_id=' . urlencode($img['ent_id']) . |
680 | '&absolute_dl=true'; |
5be9f195 |
681 | |
b5058e9e |
682 | echo html_tag( 'table', "\n" . |
683 | html_tag( 'tr', "\n" . |
684 | html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left' |
685 | ) |
686 | ) , |
687 | 'center', '', 'cellspacing=0 border="0" cellpadding="2"'); |
10f0ce72 |
688 | } |
a07cd1a4 |
689 | } |
690 | |
c615b1da |
691 | do_hook('read_body_bottom'); |
692 | do_hook('html_bottom'); |
a07cd1a4 |
693 | sqimap_logout($imapConnection); |
694 | ?> |
c615b1da |
695 | </body> |
696 | </html> |