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 | |
86725763 |
15 | /* Path for SquirrelMail required files. */ |
16 | define('SM_PATH','../'); |
17 | |
18 | /* SquirrelMail required files. */ |
08185f2a |
19 | require_once(SM_PATH . 'include/validate.php'); |
86725763 |
20 | require_once(SM_PATH . 'functions/imap.php'); |
21 | require_once(SM_PATH . 'functions/mime.php'); |
22 | require_once(SM_PATH . 'functions/date.php'); |
23 | require_once(SM_PATH . 'functions/url_parser.php'); |
24 | require_once(SM_PATH . 'functions/html.php'); |
38c944cc |
25 | |
d9c1dccc |
26 | |
a07cd1a4 |
27 | /** |
1fca12b5 |
28 | * Given an IMAP message id number, this will look it up in the cached |
29 | * and sorted msgs array and return the index. Used for finding the next |
30 | * and previous messages. |
31 | * |
32 | * @return the index of the next valid message from the array |
33 | */ |
c615b1da |
34 | function findNextMessage($passed_id) { |
35 | global $msort, $msgs, $sort, |
cf710efe |
36 | $thread_sort_messages, $allow_server_sort, |
60a3e687 |
37 | $server_sort_array; |
2728fa19 |
38 | if (!is_array($server_sort_array)) { |
39 | $thread_sort_messages = 0; |
794d59c0 |
40 | $allow_server_sort = FALSE; |
2728fa19 |
41 | } |
a07cd1a4 |
42 | $result = -1; |
c615b1da |
43 | if ($thread_sort_messages || $allow_server_sort) { |
d9c1dccc |
44 | $count = count($server_sort_array) - 1; |
45 | foreach($server_sort_array as $key=>$value) { |
c615b1da |
46 | if ($passed_id == $value) { |
d9c1dccc |
47 | if ($key == $count) { |
60a3e687 |
48 | break; |
49 | } |
1fca12b5 |
50 | $result = $server_sort_array[$key + 1]; |
60a3e687 |
51 | break; |
789b4d79 |
52 | } |
60a3e687 |
53 | } |
d9c1dccc |
54 | } else { |
55 | if ($sort == 6) { |
56 | if ($passed_id != 1) { |
57 | $result = $passed_id - 1; |
58 | } |
59 | } else { |
60 | if (is_array($msort)) { |
61 | for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) { |
62 | if ($passed_id == $msgs[$key]['ID']) { |
63 | next($msort); |
64 | $key = key($msort); |
65 | if (isset($key)){ |
66 | $result = $msgs[$key]['ID']; |
67 | break; |
68 | } |
69 | } |
1fca12b5 |
70 | } |
10f0ce72 |
71 | } |
72 | } |
10f0ce72 |
73 | } |
d9c1dccc |
74 | return $result; |
a07cd1a4 |
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 ) { |
d9c1dccc |
88 | foreach($server_sort_array as $key=>$value) { |
c615b1da |
89 | if ($passed_id == $value) { |
60a3e687 |
90 | if ($key == 0) { |
60a3e687 |
91 | break; |
92 | } |
d9c1dccc |
93 | $result = $server_sort_array[$key - 1]; |
60a3e687 |
94 | break; |
789b4d79 |
95 | } |
60a3e687 |
96 | } |
d9c1dccc |
97 | } else { |
98 | if ($sort == 6) { |
99 | if ($passed_id != $numMessages) { |
100 | $result = $passed_id + 1; |
101 | } |
102 | } else { |
103 | if (is_array($msort)) { |
104 | for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) { |
105 | if ($passed_id == $msgs[$key]['ID']) { |
106 | prev($msort); |
107 | $key = key($msort); |
108 | if (isset($key)) { |
109 | //echo $msort[$key]; /* Why again were we echoing here? */ |
110 | $result = $msgs[$key]['ID']; |
111 | break; |
112 | } |
113 | } |
10f0ce72 |
114 | } |
115 | } |
10f0ce72 |
116 | } |
a07cd1a4 |
117 | } |
d9c1dccc |
118 | return $result; |
a07cd1a4 |
119 | } |
10f0ce72 |
120 | |
a07cd1a4 |
121 | /** |
1fca12b5 |
122 | * Displays a link to a page where the message is displayed more |
123 | * "printer friendly". |
124 | */ |
c615b1da |
125 | function printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color) { |
126 | global $javascript_on; |
a07cd1a4 |
127 | |
c615b1da |
128 | $params = '?passed_ent_id=' . $passed_ent_id . |
d9c1dccc |
129 | '&mailbox=' . urlencode($mailbox) . |
130 | '&passed_id=' . $passed_id; |
10f0ce72 |
131 | |
a07cd1a4 |
132 | $print_text = _("View Printable Version"); |
10f0ce72 |
133 | |
c615b1da |
134 | $result = ''; |
a07cd1a4 |
135 | /* Output the link. */ |
136 | if ($javascript_on) { |
3d570ba0 |
137 | $result .= '<script language="javascript" type="text/javascript">' . "\n" . |
d9c1dccc |
138 | '<!--' . "\n" . |
139 | " function printFormat() {\n" . |
140 | ' window.open("../src/printer_friendly_main.php' . |
141 | $params . '","Print","width=800,height=600");' . "\n". |
142 | " }\n" . |
143 | "// -->\n" . |
144 | "</script>\n" . |
145 | "<a href=\"javascript:printFormat();\">$print_text</a>\n"; |
a07cd1a4 |
146 | } else { |
b5058e9e |
147 | $result .= '<A target="_blank" HREF="../src/printer_friendly_bottom.php' . |
d9c1dccc |
148 | "$params\">$print_text</a>\n"; |
a07cd1a4 |
149 | } |
d9c1dccc |
150 | return $result; |
a07cd1a4 |
151 | } |
152 | |
d9c1dccc |
153 | function ServerMDNSupport($read) { |
f69feefe |
154 | /* escaping $ doesn't work -> \x36 */ |
d9c1dccc |
155 | $ret = preg_match('/(\x36MDNSent|\\\*)/i', $read); |
156 | return $ret; |
57257333 |
157 | } |
158 | |
fc224f68 |
159 | function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) { |
0b97a708 |
160 | global $username, $attachment_dir, $_SERVER, |
fc224f68 |
161 | $version, $attachments, $squirrelmail_language, $default_charset, |
d9c1dccc |
162 | $languages, $useSendmail, $domain, $sent_folder, |
163 | $popuser, $data_dir, $username; |
57257333 |
164 | |
0b97a708 |
165 | $SERVER_NAME = $_SERVER['SERVER_NAME']; |
166 | |
38bca81c |
167 | $header = $message->rfc822_header; |
57257333 |
168 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
169 | |
fc224f68 |
170 | $rfc822_header = new Rfc822Header(); |
d9c1dccc |
171 | $content_type = new ContentType('multipart/report'); |
fc224f68 |
172 | $content_type->properties['report-type']='disposition-notification'; |
d9c1dccc |
173 | |
fc224f68 |
174 | set_my_charset(); |
175 | if ($default_charset) { |
d9c1dccc |
176 | $content_type->properties['charset']=$default_charset; |
fc224f68 |
177 | } |
178 | $rfc822_header->content_type = $content_type; |
179 | $rfc822_header->to[] = $header->dnt; |
180 | $rfc822_header->subject = _("Read:") . ' ' . $header->subject; |
181 | |
182 | |
183 | $reply_to = ''; |
184 | if (isset($identity) && $identity != 'default') { |
185 | $from_mail = getPref($data_dir, $username, |
d9c1dccc |
186 | 'email_address' . $identity); |
fc224f68 |
187 | $full_name = getPref($data_dir, $username, |
d9c1dccc |
188 | 'full_name' . $identity); |
fc224f68 |
189 | $from_addr = '"'.$full_name.'" <'.$from_mail.'>'; |
d9c1dccc |
190 | $reply_to = getPref($data_dir, $username, |
191 | 'reply_to' . $identity); |
fc224f68 |
192 | } else { |
193 | $from_mail = getPref($data_dir, $username, 'email_address'); |
194 | $full_name = getPref($data_dir, $username, 'full_name'); |
195 | $from_addr = '"'.$full_name.'" <'.$from_mail.'>'; |
d9c1dccc |
196 | $reply_to = getPref($data_dir, $username,'reply_to'); |
fc224f68 |
197 | } |
198 | if (!$from_addr) { |
199 | $from_addr = "$popuser@$domain"; |
200 | $from_mail = $from_addr; |
201 | } |
202 | $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true); |
203 | if ($reply_to) { |
204 | $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true); |
205 | } |
d9c1dccc |
206 | |
57257333 |
207 | // part 1 (RFC2298) |
57257333 |
208 | $senton = getLongDateString( $header->date ); |
209 | $to_array = $header->to; |
210 | $to = ''; |
211 | foreach ($to_array as $line) { |
af568a82 |
212 | $to .= ' '.$line->getAddress(); |
57257333 |
213 | } |
57257333 |
214 | $now = getLongDateString( time() ); |
78db1583 |
215 | set_my_charset(); |
46bb8da8 |
216 | $body = _("Your message") . "\r\n\r\n" . |
217 | "\t" . _("To:") . ' ' . $to . "\r\n" . |
fc224f68 |
218 | "\t" . _("Subject:") . ' ' . $header->subject . "\r\n" . |
46bb8da8 |
219 | "\t" . _("Sent:") . ' ' . $senton . "\r\n" . |
220 | "\r\n" . |
221 | sprintf( _("Was displayed on %s"), $now ); |
f69feefe |
222 | |
fc224f68 |
223 | $special_encoding = ''; |
224 | if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && |
225 | function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { |
6fbd125b |
226 | $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body); |
d9c1dccc |
227 | if (strtolower($default_charset) == 'iso-2022-jp') { |
228 | if (mb_detect_encoding($body) == 'ASCII') { |
229 | $special_encoding = '8bit'; |
230 | } else { |
231 | $body = mb_convert_encoding($body, 'JIS'); |
232 | $special_encoding = '7bit'; |
233 | } |
234 | } |
6fbd125b |
235 | } |
fc224f68 |
236 | $part1 = new Message(); |
237 | $part1->setBody($body); |
238 | $mime_header = new MessageHeader; |
239 | $mime_header->type0 = 'text'; |
240 | $mime_header->type1 = 'plain'; |
241 | if ($special_encoding) { |
242 | $mime_header->encoding = $special_encoding; |
d9c1dccc |
243 | } else { |
fc224f68 |
244 | $mime_header->encoding = 'us-ascii'; |
245 | } |
246 | if ($default_charset) { |
247 | $mime_header->parameters['charset'] = $default_charset; |
248 | } |
249 | $part1->mime_header = $mime_header; |
250 | |
57257333 |
251 | // part2 (RFC2298) |
d9c1dccc |
252 | $original_recipient = $to; |
57257333 |
253 | $original_message_id = $header->message_id; |
254 | |
fc224f68 |
255 | $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n"; |
57257333 |
256 | if ($original_recipient != '') { |
fc224f68 |
257 | $report .= "Original-Recipient : $original_recipient\r\n"; |
57257333 |
258 | } |
259 | $final_recipient = $sender; |
fc224f68 |
260 | $report .= "Final-Recipient: rfc822; $final_recipient\r\n" . |
57257333 |
261 | "Original-Message-ID : $original_message_id\r\n" . |
262 | "Disposition: manual-action/MDN-sent-manually; displayed\r\n"; |
263 | |
fc224f68 |
264 | $part2 = new Message(); |
265 | $part2->setBody($report); |
266 | $mime_header = new MessageHeader; |
267 | $mime_header->type0 = 'message'; |
268 | $mime_header->type1 = 'disposition-notification'; |
269 | $mime_header->encoding = 'us-ascii'; |
270 | $part2->mime_header = $mime_header; |
271 | |
272 | $composeMessage = new Message(); |
273 | $composeMessage->rfc822_header = $rfc822_header; |
274 | $composeMessage->addEntity($part1); |
275 | $composeMessage->addEntity($part2); |
276 | |
277 | |
d9c1dccc |
278 | if ($useSendmail) { |
279 | require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php'); |
280 | global $sendmail_path; |
281 | $deliver = new Deliver_SendMail(); |
282 | $stream = $deliver->initStream($composeMessage,$sendmail_path); |
fc224f68 |
283 | } else { |
d9c1dccc |
284 | require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php'); |
285 | $deliver = new Deliver_SMTP(); |
286 | global $smtpServerAddress, $smtpPort, $use_authenticated_smtp, $pop_before_smtp; |
287 | if ($use_authenticated_smtp) { |
288 | global $key, $onetimepad; |
289 | $user = $username; |
290 | $pass = OneTimePadDecrypt($key, $onetimepad); |
291 | } else { |
292 | $user = ''; |
293 | $pass = ''; |
294 | } |
295 | $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false; |
296 | $stream = $deliver->initStream($composeMessage,$domain,0, |
297 | $smtpServerAddress, $smtpPort, $authPop); |
298 | } |
299 | $success = false; |
fc224f68 |
300 | if ($stream) { |
d9c1dccc |
301 | $length = $deliver->mail($composeMessage, $stream); |
302 | $success = $deliver->finalizeStream($stream); |
fc224f68 |
303 | } |
d9c1dccc |
304 | if (!$success) { |
fc224f68 |
305 | $msg = $deliver->dlv_msg . '<br>Server replied: '.$deliver->dlv_ret_nr; |
d9c1dccc |
306 | require_once(SM_PATH . 'functions/display_messages.php'); |
fc224f68 |
307 | plain_error_message($msg, $color); |
308 | } else { |
309 | unset ($deliver); |
d9c1dccc |
310 | if (sqimap_mailbox_exists ($imapConnection, $sent_folder)) { |
311 | sqimap_append ($imapConnection, $sent_folder, $length); |
312 | require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php'); |
313 | $imap_deliver = new Deliver_IMAP(); |
314 | $imap_deliver->mail($composeMessage, $imapConnection); |
315 | sqimap_append_done ($imapConnection); |
316 | unset ($imap_deliver); |
317 | } |
318 | } |
319 | return $success; |
57257333 |
320 | } |
321 | |
322 | |
d9c1dccc |
323 | function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id, $uid_support) { |
324 | $sg = $set?'+':'-'; |
325 | $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)'; |
0892e427 |
326 | $read = sqimap_run_command ($imapConnection, $cmd, true, $response, |
507d14ea |
327 | $readmessage, $uid_support); |
57257333 |
328 | } |
329 | |
330 | function ClearAttachments() { |
d9c1dccc |
331 | global $username, $attachments, $attachment_dir; |
332 | |
333 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
334 | |
335 | $rem_attachments = array(); |
336 | foreach ($attachments as $info) { |
337 | if ($info['session'] == -1) { |
338 | $attached_file = "$hashed_attachment_dir/$info[localfilename]"; |
339 | if (file_exists($attached_file)) { |
340 | unlink($attached_file); |
341 | } |
342 | } else { |
343 | $rem_attachments[] = $info; |
344 | } |
345 | } |
346 | $attachments = $rem_attachments; |
57257333 |
347 | } |
348 | |
4d0cd98b |
349 | function formatRecipientString($recipients, $item ) { |
d9c1dccc |
350 | global $show_more_cc, $show_more, $show_more_bcc, |
351 | $PHP_SELF; |
4d0cd98b |
352 | |
d9c1dccc |
353 | $string = ''; |
38c944cc |
354 | if ((is_array($recipients)) && (isset($recipients[0]))) { |
d9c1dccc |
355 | $show = false; |
38c944cc |
356 | |
357 | if ($item == 'to') { |
d9c1dccc |
358 | if ($show_more) { |
359 | $show = true; |
360 | $url = set_url_var($PHP_SELF, 'show_more',0); |
361 | } else { |
362 | $url = set_url_var($PHP_SELF, 'show_more',1); |
363 | } |
364 | } else if ($item == 'cc') { |
365 | if ($show_more_cc) { |
366 | $show = true; |
367 | $url = set_url_var($PHP_SELF, 'show_more_cc',0); |
368 | } else { |
369 | $url = set_url_var($PHP_SELF, 'show_more_cc',1); |
370 | } |
371 | } else if ($item == 'bcc') { |
372 | if ($show_more_bcc) { |
373 | $show = true; |
374 | $url = set_url_var($PHP_SELF, 'show_more_bcc',0); |
375 | } else { |
376 | $url = set_url_var($PHP_SELF, 'show_more_bcc',1); |
377 | } |
378 | } |
379 | |
380 | $cnt = count($recipients); |
381 | foreach($recipients as $r) { |
382 | $add = htmlspecialchars($r->getAddress()); |
383 | if ($string) { |
384 | $string .= '<BR>' . $add; |
385 | } else { |
386 | $string = $add; |
387 | if ($cnt > 1) { |
38c944cc |
388 | $string .= ' (<A HREF="'.$url; |
d9c1dccc |
389 | if ($show) { |
390 | $string .= '">'._("less").'</A>)'; |
391 | } else { |
392 | $string .= '">'._("more").'</A>)'; |
393 | break; |
394 | } |
395 | } |
396 | } |
1fca12b5 |
397 | } |
4d0cd98b |
398 | } |
c615b1da |
399 | return $string; |
400 | } |
401 | |
af568a82 |
402 | function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, |
403 | $color, $FirstTimeSee) { |
2ffa3f57 |
404 | global $msn_user_support, $default_use_mdn, $draft_folder, $sent_folder, |
405 | $default_use_priority, $show_xmailer_default, |
406 | $mdn_user_support, $PHP_SELF, $javascript_on; |
38bca81c |
407 | |
d9c1dccc |
408 | $header = $message->rfc822_header; |
409 | $env = array(); |
410 | $env[_("Subject")] = htmlspecialchars(decodeHeader($header->subject)); |
411 | $from_name = $header->getAddr_s('from'); |
412 | if (!$from_name) { |
413 | $from_name = $header->getAddr_s('sender'); |
414 | if (!$from_name) { |
415 | $from_name = _("Unknown sender"); |
416 | } |
417 | } |
418 | $env[_("From")] = htmlspecialchars(decodeHeader($from_name)); |
419 | $env[_("Date")] = getLongDateString($header->date); |
420 | $env[_("To")] = formatRecipientString($header->to, "to"); |
421 | $env[_("Cc")] = formatRecipientString($header->cc, "cc"); |
422 | $env[_("Bcc")] = formatRecipientString($header->bcc, "bcc"); |
423 | if ($default_use_priority) { |
424 | $env[_("Priority")] = getPriorityStr($header->priority); |
425 | } |
426 | if ($show_xmailer_default) { |
427 | $env[_("Mailer")] = decodeHeader($header->xmailer); |
428 | } |
429 | if ($default_use_mdn) { |
430 | if ($mdn_user_support) { |
431 | if ($header->dnt) { |
432 | if ($message->is_mdnsent) { |
433 | $env[_("Read receipt")] = _("send"); |
434 | } else { |
435 | $env[_("Read receipt")] = _("requested"); |
436 | if (!($mailbox == $draft_folder || |
437 | $mailbox == $sent_folder || |
438 | $message->is_deleted || |
439 | $passed_ent_id)) { |
440 | $mdn_url = $PHP_SELF . '&sendreceipt=1'; |
441 | if ($FirstTimeSee && $javascript_on) { |
442 | $script = '<script language="JavaScript" type="text/javascript">' . "\n"; |
443 | $script .= '<!--'. "\n"; |
444 | $script .= 'if(window.confirm("' . |
445 | _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") . |
446 | '")) { '."\n" . |
447 | ' sendMDN()'. |
448 | '}' . "\n"; |
449 | $script .= '// -->'. "\n"; |
450 | $script .= '</script>'. "\n"; |
451 | echo $script; |
452 | } |
453 | $env[_("Read receipt")] .= ' <a href="' . $mdn_url . '">[' . |
454 | _("Send read receipt now") . ']</a>'; |
455 | } |
456 | } |
457 | } |
458 | } |
459 | } |
c615b1da |
460 | |
d9c1dccc |
461 | $s = '<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="0" BORDER="0"'; |
462 | $s .= ' ALIGN="center" BGCOLOR="' . $color[0] . '">'; |
463 | foreach ($env as $key => $val) { |
464 | if ($val) { |
465 | $s .= '<TR>'; |
466 | $s .= html_tag('TD', '<B>' . $key . ': </B>', 'RIGHT', '', 'VALIGN="TOP" WIDTH="20%"') . "\n"; |
467 | $s .= html_tag('TD', $val, 'left', '', 'VALIGN="TOP" WIDTH="80%"') . "\n"; |
468 | $s .= '</TR>'; |
469 | } |
470 | } |
471 | echo $s; |
472 | do_hook("read_body_header"); |
473 | formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color); |
474 | echo '</TABLE>'; |
475 | } |
c615b1da |
476 | |
7172cad7 |
477 | function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response) { |
d9c1dccc |
478 | global $base_uri, $sent_folder, $draft_folder, $where, $what, $color, $sort, |
479 | $startMessage, $compose_new_win, $PHP_SELF, $save_as_draft, |
480 | $enable_forward_as_attachment; |
c615b1da |
481 | |
d9c1dccc |
482 | $topbar_delimiter = ' | '; |
483 | $urlMailbox = urlencode($mailbox); |
484 | $s = '<table width="100%" cellpadding="3" cellspacing="0" align="center"'. |
c615b1da |
485 | ' border="0" bgcolor="'.$color[9].'"><tr><td align="left" width="33%"><small>'; |
486 | |
d9c1dccc |
487 | $msgs_url = $base_uri . 'src/'; |
488 | if (isset($where) && isset($what)) { |
489 | $msgs_url .= 'search.php?where=' . urlencode($where) . |
490 | '&what=' . urlencode($what) . '&mailbox=' . $urlMailbox; |
491 | $msgs_str = _("Search results"); |
492 | } else { |
493 | $msgs_url .= 'right_main.php?sort=' . $sort . '&startMessage=' . |
494 | $startMessage . '&mailbox=' . $urlMailbox; |
495 | $msgs_str = _("Message List"); |
496 | } |
497 | $s .= '<a href="' . $msgs_url . '">' . $msgs_str . '</a>'; |
498 | $s .= $topbar_delimiter; |
499 | |
500 | $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox . |
501 | '&message=' . $passed_id . '&'; |
502 | if (!(isset($passed_ent_id) && $passed_ent_id)) { |
503 | if ($where && $what) { |
504 | $delete_url .= 'where=' . urlencode($where) . '&what=' . urlencode($what); |
505 | } else { |
506 | $delete_url .= 'sort=' . $sort . '&startMessage=' . $startMessage; |
507 | } |
508 | $s .= '<a href="' . $delete_url . '">' . _("Delete") . '</a>'; |
509 | } |
c615b1da |
510 | |
d9c1dccc |
511 | $comp_uri = $base_uri . 'src/compose.php' . |
512 | '?passed_id=' . $passed_id . |
513 | '&mailbox=' . $urlMailbox . |
514 | (isset($passed_ent_id)?'&passed_ent_id='.$passed_ent_id:''); |
2ffa3f57 |
515 | |
d9c1dccc |
516 | if ($compose_new_win == '1') { |
517 | $link_open = '<a href="javascript:void(0)" onclick="comp_in_new(\''; |
518 | $link_close = '\')">'; |
519 | } else { |
520 | $link_open = '<a href="'; |
521 | $link_close = '">'; |
522 | } |
523 | if (($mailbox == $draft_folder) && ($save_as_draft)) { |
524 | $comp_alt_uri = $comp_uri . '&action=draft'; |
525 | $comp_alt_string = _("Resume Draft"); |
526 | } else if ($mailbox == $sent_folder) { |
527 | $comp_alt_uri = $comp_uri . '&action=edit_as_new'; |
528 | $comp_alt_string = _("Edit Message as New"); |
529 | } |
530 | if (isset($comp_alt_uri)) { |
531 | $s .= $topbar_delimiter; |
532 | $s .= $link_open . $comp_alt_uri . $link_close . $comp_alt_string . '</a>'; |
533 | } |
2ffa3f57 |
534 | |
d9c1dccc |
535 | $s .= '</small></td><td align="center" width="33%"><small>'; |
536 | |
537 | if (!(isset($where) && isset($what)) && !$passed_ent_id) { |
538 | $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id); |
539 | $next = findNextMessage($passed_id); |
540 | if ($prev != -1) { |
541 | $uri = $base_uri . 'src/read_body.php?passed_id='.$prev. |
542 | '&mailbox='.$urlMailbox.'&sort='.$sort. |
543 | '&startMessage='.$startMessage.'&show_more=0'; |
544 | $s .= '<a href="'.$uri.'">'._("Previous").'</a>'; |
545 | } else { |
546 | $s .= _("Previous"); |
547 | } |
2ffa3f57 |
548 | $s .= $topbar_delimiter; |
d9c1dccc |
549 | if ($next != -1) { |
550 | $uri = $base_uri . 'src/read_body.php?passed_id='.$next. |
551 | '&mailbox='.$urlMailbox.'&sort='.$sort. |
552 | '&startMessage='.$startMessage.'&show_more=0'; |
553 | $s .= '<a href="'.$uri.'">'._("Next").'</a>'; |
554 | } else { |
555 | $s .= _("Next"); |
556 | } |
557 | } else if (isset($passed_ent_id) && $passed_ent_id) { |
558 | /* code for navigating through attached message/rfc822 messages */ |
559 | $url = set_url_var($PHP_SELF, 'passed_ent_id',0); |
560 | $s .= '<a href="'.$url.'">'._("View Message").'</a>'; |
561 | $par_ent_id = $message->parent->entity_id; |
562 | if ($par_ent_id) { |
563 | $par_ent_id = substr($par_ent_id,0,-2); |
564 | $s .= $topbar_delimiter; |
565 | $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id); |
566 | $s .= '<a href="'.$url.'">'._("Up").'</a>'; |
567 | } |
568 | } |
c615b1da |
569 | |
d9c1dccc |
570 | $s .= '</small></td>' . "\n" . '<td align="right" width="33%" nowrap><small>'; |
571 | $comp_action_uri = $comp_uri . '&action=forward'; |
572 | $s .= $link_open . $comp_action_uri . $link_close . _("Forward") . '</a>'; |
573 | $s .= $topbar_delimiter; |
c615b1da |
574 | |
d9c1dccc |
575 | if ($enable_forward_as_attachment) { |
576 | $comp_action_uri = $comp_uri . '&action=forward_as_attachment'; |
577 | $s .= $link_open . $comp_action_uri . $link_close . _("Forward as Attachment") . '</a>'; |
578 | $s .= $topbar_delimiter; |
579 | } |
a128c967 |
580 | |
d9c1dccc |
581 | $comp_action_uri = decodeHeader($comp_uri . '&action=reply'); |
582 | $s .= $link_open . $comp_action_uri . $link_close . _("Reply") . '</a>'; |
583 | $s .= $topbar_delimiter; |
584 | |
585 | $comp_action_uri = $comp_uri . '&action=reply_all'; |
586 | $s .= $link_open . $comp_action_uri . $link_close . _("Reply All") . '</a>'; |
587 | $s .= '</small></td></tr></table>'; |
588 | do_hook("read_body_menu_top"); |
589 | echo $s; |
590 | do_hook("read_body_menu_bottom"); |
c615b1da |
591 | } |
592 | |
593 | function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) { |
fe369c70 |
594 | global $base_uri; |
595 | |
d9c1dccc |
596 | $urlMailbox = urlencode($mailbox); |
fe369c70 |
597 | $url = $base_uri.'src/view_header.php?'.$_SERVER['QUERY_STRING']; |
d9c1dccc |
598 | |
599 | $s = "<TR>\n" . |
600 | '<TD VALIGN="MIDDLE" ALIGN="RIGHT" WIDTH="20%"><B>' . _("Options") . ": </B></TD>\n" . |
601 | '<TD VALIGN="MIDDLE" ALIGN="LEFT" WIDTH="80%"><SMALL>' . |
602 | '<a href="'.$url.'">'._("View Full Header").'</a>'; |
603 | |
604 | /* Output the printer friendly link if we are in subtle mode. */ |
605 | $s .= ' | ' . |
606 | printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color); |
607 | echo $s; |
608 | do_hook("read_body_header_right"); |
609 | $s = "</SMALL></TD>\n" . |
610 | "</TR>\n"; |
611 | echo $s; |
a128c967 |
612 | |
4d0cd98b |
613 | } |
614 | |
6206f6c4 |
615 | /***************************/ |
2ffa3f57 |
616 | /* Main of read_body.php */ |
6206f6c4 |
617 | /***************************/ |
57257333 |
618 | |
0b97a708 |
619 | /* get the globals we may need */ |
620 | |
621 | $username = $_SESSION['username']; |
622 | $key = $_COOKIE['key']; |
623 | $onetimepad = $_SESSION['onetimepad']; |
624 | $msgs = $_SESSION['msgs']; |
625 | $base_uri = $_SESSION['base_uri']; |
626 | $delimiter = $_SESSION['delimiter']; |
627 | |
628 | if (isset($_GET['passed_id'])) { |
629 | $passed_id = $_GET['passed_id']; |
630 | } |
631 | elseif (isset($_POST['passed_id'])) { |
632 | $passed_id = $_POST['passed_id']; |
633 | } |
634 | |
ce274df9 |
635 | if (isset($_GET['passed_ent_id'])) { |
636 | $passed_ent_id = $_GET['passed_ent_id']; |
637 | } |
638 | elseif (isset($_POST['passed_ent_id'])) { |
639 | $passed_ent_id = $_POST['passed_ent_id']; |
640 | } |
641 | |
0b97a708 |
642 | if (isset($_GET['sendreceipt'])) { |
643 | $sendreceipt = $_GET['sendreceipt']; |
644 | } |
645 | |
646 | if (isset($_GET['sort'])) { |
647 | $sort = $_GET['sort']; |
648 | } |
649 | elseif (isset($_POST['sort'])) { |
650 | $sort = $_POST['sort']; |
651 | } |
652 | if (isset($_GET['startMessage'])) { |
653 | $startMessage = $_GET['startMessage']; |
654 | } |
655 | elseif (isset($_POST['startMessage'])) { |
656 | $startMessage = $_POST['startMessage']; |
657 | } |
658 | if (isset($_GET['show_more'])) { |
659 | $show_more = $_GET['show_more']; |
660 | } |
661 | elseif (isset($_POST['show_more'])) { |
662 | $show_more = $_POST['show_more']; |
663 | } |
664 | if (isset($_GET['mailbox'])) { |
665 | $mailbox = $_GET['mailbox']; |
666 | } |
667 | elseif (isset($_POST['mailbox'])) { |
668 | $mailbox = $_POST['mailbox']; |
669 | } |
670 | if (isset($_GET['where'])) { |
671 | $where = $_GET['where']; |
672 | } |
673 | if (isset($_GET['what'])) { |
674 | $what = $_GET['what']; |
675 | } |
676 | if (isset($_GET['view_hdr'])) { |
677 | $view_hdr = $_GET['view_hdr']; |
678 | } |
679 | if (isset($_SESSION['server_sort_array'])) { |
680 | $server_sort_array = $_SESSION['server_sort_array']; |
681 | } |
682 | if (isset($_SESSION['msgs'])) { |
683 | $msgs = $_SESSION['msgs']; |
684 | } |
685 | if (isset($_SESSION['msort'])) { |
686 | $msort = $_SESSION['msort']; |
687 | } |
688 | if (isset($_POST['move_id'])) { |
689 | $move_id = $_POST['move_id']; |
690 | } |
691 | if (isset($_SESSION['lastTargetMailbox'])) { |
692 | $lastTargetMailbox = $_SESSION['lastTargetMailbox']; |
693 | } |
ce274df9 |
694 | if (isset($_SESSION['messages'])) { |
695 | $messages = $_SESSION['messages']; |
696 | } else { |
697 | $messages = array(); |
698 | } |
0b97a708 |
699 | |
a07cd1a4 |
700 | |
ce274df9 |
701 | |
702 | /* end of get globals */ |
38c944cc |
703 | global $uid_support, $sqimap_capabilities; |
704 | |
6a108031 |
705 | if (isset($mailbox)) { |
4366bea4 |
706 | $mailbox = urldecode( $mailbox ); |
707 | } |
38c944cc |
708 | |
6206f6c4 |
709 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
38c944cc |
710 | $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true); |
711 | |
38c944cc |
712 | |
713 | /** |
714 | * $message contains all information about the message |
715 | * including header and body |
716 | */ |
37d2a6ee |
717 | |
718 | $uidvalidity = $mbx_response['UIDVALIDITY']; |
719 | |
720 | if (!isset($messages[$uidvalidity])) { |
721 | $messages[$uidvalidity] = array(); |
722 | } |
5200c026 |
723 | if (!isset($messages[$uidvalidity][$passed_id]) || !$uid_support) { |
724 | $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
fc224f68 |
725 | $FirstTimeSee = !$message->is_seen; |
726 | $message->is_seen = true; |
5200c026 |
727 | $messages[$uidvalidity][$passed_id] = $message; |
38c944cc |
728 | } else { |
fc224f68 |
729 | // $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
730 | $message = $messages[$uidvalidity][$passed_id]; |
731 | $FirstTimeSee = !$message->is_seen; |
5200c026 |
732 | } |
af568a82 |
733 | |
dd628162 |
734 | if (isset($passed_ent_id) && $passed_ent_id) { |
5200c026 |
735 | $message = $message->getEntity($passed_ent_id); |
ff9d4297 |
736 | if ($message->type0 != 'message' && $message->type1 != 'rfc822') { |
737 | $message = $message->parent; |
738 | } |
141a16b2 |
739 | $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, $uid_support); |
19d470aa |
740 | $rfc822_header = new Rfc822Header(); |
141a16b2 |
741 | $rfc822_header->parseHeader($read); |
742 | $message->rfc822_header = $rfc822_header; |
c615b1da |
743 | } else { |
744 | $passed_ent_id = 0; |
38c944cc |
745 | } |
5200c026 |
746 | $header = $message->header; |
57257333 |
747 | |
6c31f818 |
748 | do_hook('html_top'); |
57257333 |
749 | |
6206f6c4 |
750 | /****************************************/ |
751 | /* Block for handling incoming url vars */ |
752 | /****************************************/ |
5200c026 |
753 | |
5200c026 |
754 | if (isset($sendreceipt)) { |
755 | if ( !$message->is_mdnsent ) { |
756 | if (isset($identity) ) { |
757 | $final_recipient = getPref($data_dir, $username, 'email_address' . '0', '' ); |
758 | } else { |
759 | $final_recipient = getPref($data_dir, $username, 'email_address', '' ); |
760 | } |
761 | |
762 | $final_recipient = trim($final_recipient); |
763 | if ($final_recipient == '' ) { |
764 | $final_recipient = getPref($data_dir, $username, 'email_address', '' ); |
765 | } |
af568a82 |
766 | $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]); |
fc224f68 |
767 | if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) { |
c615b1da |
768 | ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id, $uid_support); |
5200c026 |
769 | $message->is_mdnsent = true; |
6a108031 |
770 | $messages[$uidvalidity][$passed_id]=$message; |
5200c026 |
771 | } |
772 | ClearAttachments(); |
773 | } |
774 | } |
6206f6c4 |
775 | /***********************************************/ |
776 | /* End of block for handling incoming url vars */ |
777 | /***********************************************/ |
778 | |
38c944cc |
779 | $msgs[$passed_id]['FLAG_SEEN'] = true; |
38c944cc |
780 | |
5200c026 |
781 | $messagebody = ''; |
c4ad259b |
782 | do_hook('read_body_top'); |
783 | if ($show_html_default == 1) { |
784 | $ent_ar = $message->findDisplayEntity(array()); |
785 | } else { |
786 | $ent_ar = $message->findDisplayEntity(array(), array('text/plain')); |
787 | } |
a128c967 |
788 | $cnt = count($ent_ar); |
789 | for ($i = 0; $i < $cnt; $i++) { |
6a108031 |
790 | $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox); |
a128c967 |
791 | if ($i != $cnt-1) { |
792 | $messagebody .= '<hr noshade size=1>'; |
793 | } |
38c944cc |
794 | } |
6a108031 |
795 | |
c615b1da |
796 | displayPageHeader($color, $mailbox); |
7172cad7 |
797 | formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response); |
af568a82 |
798 | formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee); |
6206f6c4 |
799 | echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">'; |
800 | echo ' <tr><td>'; |
801 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">'; |
a128c967 |
802 | echo ' <tr><td>'; |
6206f6c4 |
803 | echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">'; |
804 | echo ' <tr bgcolor="'.$color[4].'"><td>'; |
805 | echo ' <table cellpadding="0" cellspacing="0" align="center" border="0">'; |
806 | echo ' <tr><td><br>' . $messagebody . '</td></td>'; |
807 | echo ' </table>'; |
808 | echo ' </td></tr>'; |
809 | echo ' </table></td></tr>'; |
2ffa3f57 |
810 | echo ' </table>'; |
811 | echo ' </td></tr>'; |
a128c967 |
812 | |
813 | $attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id); |
814 | if ($attachmentsdisplay) { |
2ffa3f57 |
815 | echo ' <tr><td>'; |
6206f6c4 |
816 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">'; |
2ffa3f57 |
817 | echo ' <tr><td>'; |
818 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">'; |
6206f6c4 |
819 | echo ' <tr><td ALIGN="left" bgcolor="'.$color[9].'">'; |
820 | echo ' <b>' . _("Attachments") . ':</b>'; |
821 | echo ' </td></tr>'; |
822 | echo ' <tr><td>'; |
823 | echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>'; |
824 | echo $attachmentsdisplay; |
825 | echo ' </td></tr></table>'; |
826 | echo ' </table></td></tr>'; |
2ffa3f57 |
827 | echo ' </table></td></tr>'; |
6206f6c4 |
828 | echo ' </table>'; |
829 | echo ' </td></tr>'; |
a128c967 |
830 | } |
c615b1da |
831 | echo '</table>'; |
a07cd1a4 |
832 | |
833 | /* show attached images inline -- if pref'fed so */ |
5be9f195 |
834 | if (($attachment_common_show_images) && |
a07cd1a4 |
835 | is_array($attachment_common_show_images_list)) { |
836 | foreach ($attachment_common_show_images_list as $img) { |
ce274df9 |
837 | $imgurl = SM_PATH . 'src/download.php' . |
57257333 |
838 | '?' . |
cd7b8833 |
839 | 'passed_id=' . urlencode($img['passed_id']) . |
3d570ba0 |
840 | '&mailbox=' . urlencode($mailbox) . |
ff9d4297 |
841 | '&ent_id=' . urlencode($img['ent_id']) . |
3d570ba0 |
842 | '&absolute_dl=true'; |
5be9f195 |
843 | |
b5058e9e |
844 | echo html_tag( 'table', "\n" . |
d9c1dccc |
845 | html_tag( 'tr', "\n" . |
846 | html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left' |
847 | ) |
848 | ) , |
b5058e9e |
849 | 'center', '', 'cellspacing=0 border="0" cellpadding="2"'); |
10f0ce72 |
850 | } |
a07cd1a4 |
851 | } |
852 | |
c615b1da |
853 | do_hook('read_body_bottom'); |
854 | do_hook('html_bottom'); |
a07cd1a4 |
855 | sqimap_logout($imapConnection); |
ce274df9 |
856 | /* sessions are written at the end of the script. it's better to register |
857 | them at the end so we avoid double session_register calls */ |
858 | sqsession_register($messages,'messages'); |
859 | |
a07cd1a4 |
860 | ?> |
c615b1da |
861 | </body> |
862 | </html> |