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