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