correct Move & next when moving the first message in a mailbox
[squirrelmail.git] / src / read_body.php
1 <?php
2 /**
3 * read_body.php
4 *
5 * Copyright (c) 1999-2004 The SquirrelMail Project Team
6 * Licensed under the GNU GPL. For full terms see the file COPYING.
7 *
8 * This file is used for reading the msgs array and displaying
9 * the resulting emails in the right frame.
10 *
11 * $Id$
12 * @package squirrelmail
13 */
14
15 /** Path for SquirrelMail required files. */
16 define('SM_PATH','../');
17
18 /* SquirrelMail required files. */
19 require_once(SM_PATH . 'include/validate.php');
20 require_once(SM_PATH . 'functions/global.php');
21 require_once(SM_PATH . 'functions/imap.php');
22 require_once(SM_PATH . 'functions/mime.php');
23 require_once(SM_PATH . 'functions/date.php');
24 require_once(SM_PATH . 'functions/url_parser.php');
25 require_once(SM_PATH . 'functions/html.php');
26 require_once(SM_PATH . 'functions/global.php');
27 require_once(SM_PATH . 'functions/identity.php');
28 require_once(SM_PATH . 'functions/mailbox_display.php');
29
30 /**
31 * Given an IMAP message id number, this will look it up in the cached
32 * and sorted msgs array and return the index of the next message
33 *
34 * @param int $passed_id The current message UID
35 * @return the index of the next valid message from the array
36 */
37 function findNextMessage($passed_id) {
38 global $msort, $msgs, $sort,
39 $thread_sort_messages, $allow_server_sort,
40 $server_sort_array;
41 if (!is_array($server_sort_array)) {
42 $thread_sort_messages = 0;
43 $allow_server_sort = FALSE;
44 }
45 $result = -1;
46 if ($thread_sort_messages || $allow_server_sort) {
47 $count = count($server_sort_array) - 1;
48 foreach($server_sort_array as $key=>$value) {
49 if ($passed_id == $value) {
50 if ($key == $count) {
51 break;
52 }
53 $result = $server_sort_array[$key + 1];
54 break;
55 }
56 }
57 } else {
58 if (is_array($msort)) {
59 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
60 if ($passed_id == $msgs[$key]['ID']) {
61 next($msort);
62 $key = key($msort);
63 if (isset($key)){
64 $result = $msgs[$key]['ID'];
65 break;
66 }
67 }
68 }
69 }
70 }
71 return $result;
72 }
73
74 /**
75 * Given an IMAP message id number, this will look it up in the cached
76 * and sorted msgs array and return the index of the previous message
77 *
78 * @param int $passed_id The current message UID
79 * @return the index of the next valid message from the array
80 */
81 function findPreviousMessage($numMessages, $passed_id) {
82 global $msort, $sort, $msgs,
83 $thread_sort_messages,
84 $allow_server_sort, $server_sort_array;
85 $result = -1;
86 if (!is_array($server_sort_array)) {
87 $thread_sort_messages = 0;
88 $allow_server_sort = FALSE;
89 }
90 if ($thread_sort_messages || $allow_server_sort ) {
91 foreach($server_sort_array as $key=>$value) {
92 if ($passed_id == $value) {
93 if ($key != 0) {
94 $result = $server_sort_array[$key - 1];
95 }
96 break;
97 }
98 }
99 } else {
100 if (is_array($msort)) {
101 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
102 if ($passed_id == $msgs[$key]['ID']) {
103 prev($msort);
104 $key = key($msort);
105 if (isset($key)) {
106 $result = $msgs[$key]['ID'];
107 break;
108 }
109 }
110 }
111 }
112 }
113 return $result;
114 }
115
116 /**
117 * Displays a link to a page where the message is displayed more
118 * "printer friendly".
119 * @param string $mailbox Name of current mailbox
120 * @param int $passed_id
121 */
122 function printer_friendly_link($mailbox, $passed_id, $passed_ent_id) {
123 global $javascript_on, $color;
124
125 $params = '?passed_ent_id=' . $passed_ent_id .
126 '&mailbox=' . urlencode($mailbox) .
127 '&passed_id=' . $passed_id;
128
129 $print_text = _("View Printable Version");
130
131 $result = '';
132 /* Output the link. */
133 if ($javascript_on) {
134 $result = '<script language="javascript" type="text/javascript">' . "\n" .
135 '<!--' . "\n" .
136 " function printFormat() {\n" .
137 ' window.open("../src/printer_friendly_main.php' .
138 $params . '","Print","width=800,height=600");' . "\n".
139 " }\n" .
140 "// -->\n" .
141 "</script>\n" .
142 "<a href=\"javascript:printFormat();\">$print_text</a>\n";
143 } else {
144 $result = '<a target="_blank" href="../src/printer_friendly_bottom.php' .
145 "$params\">$print_text</a>\n";
146 }
147 return $result;
148 }
149
150 function ServerMDNSupport($read) {
151 /* escaping $ doesn't work -> \x36 */
152 $ret = preg_match('/(\x36MDNSent|\\\\\*)/i', $read);
153 return $ret;
154 }
155
156 function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) {
157 global $username, $attachment_dir,
158 $version, $attachments, $squirrelmail_language, $default_charset,
159 $languages, $useSendmail, $domain, $sent_folder,
160 $popuser, $data_dir, $username;
161
162 sqgetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER);
163
164 $header = $message->rfc822_header;
165 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
166
167 $rfc822_header = new Rfc822Header();
168 $content_type = new ContentType('multipart/report');
169 $content_type->properties['report-type']='disposition-notification';
170
171 set_my_charset();
172 if ($default_charset) {
173 $content_type->properties['charset']=$default_charset;
174 }
175 $rfc822_header->content_type = $content_type;
176 $rfc822_header->to[] = $header->dnt;
177 $rfc822_header->subject = _("Read:") . ' ' . encodeHeader($header->subject);
178
179 // Patch #793504 Return Receipt Failing with <@> from Tim Craig (burny_md)
180 // This merely comes from compose.php and only happens when there is no
181 // email_addr specified in user's identity (which is the startup config)
182 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
183 $popuser = $usernamedata[1];
184 $domain = $usernamedata[2];
185 unset($usernamedata);
186 } else {
187 $popuser = $username;
188 }
189
190 $reply_to = '';
191 $ident = get_identities();
192 if(!isset($identity)) $identity = 0;
193 $full_name = $ident[$identity]['full_name'];
194 $from_mail = $ident[$identity]['email_address'];
195 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
196 $reply_to = $ident[$identity]['reply_to'];
197
198 if (!$from_mail) {
199 $from_mail = "$popuser@$domain";
200 $from_addr = $from_mail;
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 }
206
207 // part 1 (RFC2298)
208 $senton = getLongDateString( $header->date );
209 $to_array = $header->to;
210 $to = '';
211 foreach ($to_array as $line) {
212 $to .= ' '.$line->getAddress();
213 }
214 $now = getLongDateString( time() );
215 set_my_charset();
216 $body = _("Your message") . "\r\n\r\n" .
217 "\t" . _("To:") . ' ' . decodeHeader($to,false,false) . "\r\n" .
218 "\t" . _("Subject:") . ' ' . decodeHeader($header->subject,false,false) . "\r\n" .
219 "\t" . _("Sent:") . ' ' . $senton . "\r\n" .
220 "\r\n" .
221 sprintf( _("Was displayed on %s"), $now );
222
223 $special_encoding = '';
224 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
225 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
226 $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body);
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 }
235 }
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;
243 } else {
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
251 // part2 (RFC2298)
252 $original_recipient = $to;
253 $original_message_id = $header->message_id;
254
255 $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
256 if ($original_recipient != '') {
257 $report .= "Original-Recipient : $original_recipient\r\n";
258 }
259 $final_recipient = $sender;
260 $report .= "Final-Recipient: rfc822; $final_recipient\r\n" .
261 "Original-Message-ID : $original_message_id\r\n" .
262 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
263
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
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);
283 } else {
284 require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php');
285 $deliver = new Deliver_SMTP();
286 global $smtpServerAddress, $smtpPort, $smtp_auth_mech, $pop_before_smtp;
287 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false;
288 get_smtp_user($user, $pass);
289 $stream = $deliver->initStream($composeMessage,$domain,0,
290 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
291 }
292 $success = false;
293 if ($stream) {
294 $length = $deliver->mail($composeMessage, $stream);
295 $success = $deliver->finalizeStream($stream);
296 }
297 if (!$success) {
298 $msg = $deliver->dlv_msg . '<br>' .
299 _("Server replied: ") . $deliver->dlv_ret_nr . ' '.
300 $deliver->dlv_server_msg;
301 require_once(SM_PATH . 'functions/display_messages.php');
302 plain_error_message($msg, $color);
303 } else {
304 unset ($deliver);
305 if (sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
306 sqimap_append ($imapConnection, $sent_folder, $length);
307 require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
308 $imap_deliver = new Deliver_IMAP();
309 $imap_deliver->mail($composeMessage, $imapConnection);
310 sqimap_append_done ($imapConnection);
311 unset ($imap_deliver);
312 }
313 }
314 return $success;
315 }
316
317 function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id) {
318 $sg = $set?'+':'-';
319 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
320 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
321 $readmessage, TRUE);
322 }
323
324 function ClearAttachments() {
325 global $username, $attachments, $attachment_dir;
326
327 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
328
329 $rem_attachments = array();
330 if (isset($attachments)) {
331 foreach ($attachments as $info) {
332 if ($info['session'] == -1) {
333 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
334 if (file_exists($attached_file)) {
335 unlink($attached_file);
336 }
337 } else {
338 $rem_attachments[] = $info;
339 }
340 }
341 }
342 $attachments = $rem_attachments;
343 }
344
345 function formatRecipientString($recipients, $item ) {
346 global $show_more_cc, $show_more, $show_more_bcc,
347 $PHP_SELF;
348
349 $string = '';
350 if ((is_array($recipients)) && (isset($recipients[0]))) {
351 $show = false;
352
353 if ($item == 'to') {
354 if ($show_more) {
355 $show = true;
356 $url = set_url_var($PHP_SELF, 'show_more',0);
357 } else {
358 $url = set_url_var($PHP_SELF, 'show_more',1);
359 }
360 } else if ($item == 'cc') {
361 if ($show_more_cc) {
362 $show = true;
363 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
364 } else {
365 $url = set_url_var($PHP_SELF, 'show_more_cc',1);
366 }
367 } else if ($item == 'bcc') {
368 if ($show_more_bcc) {
369 $show = true;
370 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
371 } else {
372 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
373 }
374 }
375
376 $cnt = count($recipients);
377 foreach($recipients as $r) {
378 $add = decodeHeader($r->getAddress(true));
379 if ($string) {
380 $string .= '<BR>' . $add;
381 } else {
382 $string = $add;
383 if ($cnt > 1) {
384 $string .= '&nbsp;(<A HREF="'.$url;
385 if ($show) {
386 $string .= '">'._("less").'</A>)';
387 } else {
388 $string .= '">'._("more").'</A>)';
389 break;
390 }
391 }
392 }
393 }
394 }
395 return $string;
396 }
397
398 function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message,
399 $color, $FirstTimeSee) {
400 global $msn_user_support, $default_use_mdn, $default_use_priority,
401 $show_xmailer_default, $mdn_user_support, $PHP_SELF, $javascript_on,
402 $squirrelmail_language;
403
404 $header = $message->rfc822_header;
405 $env = array();
406 $env[_("Subject")] = str_replace("&nbsp;"," ",decodeHeader($header->subject));
407
408 $from_name = $header->getAddr_s('from');
409 if (!$from_name)
410 $from_name = $header->getAddr_s('sender');
411 if (!$from_name)
412 $env[_("From")] = _("Unknown sender");
413 else
414 $env[_("From")] = decodeHeader($from_name);
415 $env[_("Date")] = getLongDateString($header->date);
416 $env[_("To")] = formatRecipientString($header->to, "to");
417 $env[_("Cc")] = formatRecipientString($header->cc, "cc");
418 $env[_("Bcc")] = formatRecipientString($header->bcc, "bcc");
419 if ($default_use_priority) {
420 $env[_("Priority")] = htmlspecialchars(getPriorityStr($header->priority));
421 }
422 if ($show_xmailer_default) {
423 $env[_("Mailer")] = decodeHeader($header->xmailer);
424 }
425 if ($default_use_mdn) {
426 if ($mdn_user_support) {
427 if ($header->dnt) {
428 if ($message->is_mdnsent) {
429 $env[_("Read receipt")] = _("sent");
430 } else {
431 $env[_("Read receipt")] = _("requested");
432 if (!(handleAsSent($mailbox) ||
433 $message->is_deleted ||
434 $passed_ent_id)) {
435 $mdn_url = $PHP_SELF . '&sendreceipt=1';
436 if ($FirstTimeSee && $javascript_on) {
437 $script = '<script language="JavaScript" type="text/javascript">' . "\n";
438 $script .= '<!--'. "\n";
439 $script .= 'if(window.confirm("' .
440 _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
441 '")) { '."\n" .
442 ' sendMDN()'.
443 '}' . "\n";
444 $script .= '// -->'. "\n";
445 $script .= '</script>'. "\n";
446 echo $script;
447 }
448 $env[_("Read receipt")] .= '&nbsp;<a href="' . $mdn_url . '">[' .
449 _("Send read receipt now") . ']</a>';
450 }
451 }
452 }
453 }
454 }
455
456 $s = '<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="2" BORDER="0"';
457 $s .= ' ALIGN="center" BGCOLOR="'.$color[0].'">';
458 foreach ($env as $key => $val) {
459 if ($val) {
460 $s .= '<TR>';
461 $s .= html_tag('TD', '<B>' . $key . ':&nbsp;&nbsp;</B>', 'RIGHT', '', 'VALIGN="TOP" WIDTH="20%"') . "\n";
462 $s .= html_tag('TD', $val, 'left', '', 'VALIGN="TOP" WIDTH="80%"') . "\n";
463 $s .= '</TR>';
464 }
465 }
466 echo '<TABLE BGCOLOR="'.$color[9].'" WIDTH="100%" CELLPADDING="1"'.
467 ' CELLSPACING="0" BORDER="0" ALIGN="center">'."\n";
468 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
469 $color[4].'"></TD></TR><TR><TD align=center>'."\n";
470 echo $s;
471 do_hook('read_body_header');
472 formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color);
473 echo '</TABLE>';
474 echo '</TD></TR><TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.$color[4].'"></TD></TR>'."\n";
475 echo '</TABLE>';
476 }
477
478 /**
479 * Format message toolbar
480 *
481 * @param string $mailbox Name of current mailbox
482 * @param int $passed_id UID of current message
483 * @param int $passed_ent_id Id of entity within message
484 * @param object $message Current message object
485 * @param object $mbx_response
486 */
487 function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response, $nav_on_top = TRUE) {
488 global $base_uri, $draft_folder, $where, $what, $color, $sort,
489 $startMessage, $PHP_SELF, $save_as_draft,
490 $enable_forward_as_attachment, $imapConnection, $lastTargetMailbox,
491 $data_dir, $username, $delete_prev_next_display,
492 $compose_new_win, $javascript_on;
493
494 $topbar_delimiter = '&nbsp;|&nbsp;';
495 $double_delimiter = '&nbsp;&nbsp;&nbsp;&nbsp;';
496 $urlMailbox = urlencode($mailbox);
497
498 $msgs_url = $base_uri . 'src/';
499
500 // BEGIN NAV ROW - PREV/NEXT, DEL PREV/NEXT, LINKS TO INDEX, etc.
501 $nav_row = '<tr><td align="left" colspan="2" style="border: 1px solid '.$color[9].';"><small>';
502
503 // Create Prev & Next links
504 // Handle nested entities first (i.e. Mime Attach parts)
505 if (isset($passed_ent_id) && $passed_ent_id) {
506 // code for navigating through attached message/rfc822 messages
507 $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
508 $entities = array();
509 $entity_count = array();
510 $c = 0;
511
512 foreach($message->parent->entities as $ent) {
513 if ($ent->type0 == 'message' && $ent->type1 == 'rfc822') {
514 $c++;
515 $entity_count[$c] = $ent->entity_id;
516 $entities[$ent->entity_id] = $c;
517 }
518 }
519
520 $prev_link = _("Previous");
521 if($entities[$passed_ent_id] > 1) {
522 $prev_ent_id = $entity_count[$entities[$passed_ent_id] - 1];
523 $prev_link = '<a href="'
524 . set_url_var($PHP_SELF, 'passed_ent_id', $prev_ent_id)
525 . '">' . $prev_link . '</a>';
526 }
527
528 $next_link = _("Next");
529 if($entities[$passed_ent_id] < $c) {
530 $next_ent_id = $entity_count[$entities[$passed_ent_id] + 1];
531 $next_link = '<a href="'
532 . set_url_var($PHP_SELF, 'passed_ent_id', $next_ent_id)
533 . '">' . $next_link . '</a>';
534 }
535
536 $par_ent_id = $message->parent->entity_id;
537 $up_link = '';
538 if ($par_ent_id) {
539 $par_ent_id = substr($par_ent_id,0,-2);
540 if ( $par_ent_id != 0 ) {
541 $up_link = $topbar_delimiter;
542 $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
543 $up_link .= '<a href="'.$url.'">'._("Up").'</a>';
544 }
545 }
546
547 $nav_row .= $prev_link . $up_link . $topbar_delimiter . $next_link;
548 $nav_row .= $double_delimiter . '[<a href="'.$url.'">'._("View Message").'</a>]';
549
550 // Prev/Next links for regular messages
551 } else if ( !(isset($where) && isset($what)) ) {
552 $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id);
553 $next = findNextMessage($passed_id);
554
555 $prev_link = _("Previous");
556 if ($prev >= 0) {
557 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
558 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
559 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
560 $prev_link = '<a href="'.$uri.'">'.$prev_link.'</a>';
561 }
562
563 $next_link = _("Next");
564 if ($next >= 0) {
565 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
566 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
567 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
568 $next_link = '<a href="'.$uri.'">'.$next_link.'</a>';
569 }
570
571 // Only bother with Delete & Prev and Delete & Next IF
572 // top display is enabled.
573 if ( $delete_prev_next_display == 1 ) {
574 $del_prev_link = _("Delete & Prev");
575 if ($prev >= 0) {
576 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
577 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
578 '&amp;startMessage='.$startMessage.'&amp;show_more=0'.
579 '&amp;delete_id='.$passed_id;
580 $del_prev_link = '<a href="'.$uri.'">'.$del_prev_link.'</a>';
581 }
582
583 $del_next_link = _("Delete & Next");
584 if ($next >= 0) {
585 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
586 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
587 '&amp;startMessage='.$startMessage.'&amp;show_more=0'.
588 '&amp;delete_id='.$passed_id;
589 $del_next_link = '<a href="'.$uri.'">'.$del_next_link.'</a>';
590 }
591 }
592
593 $nav_row .= '['.$prev_link.$topbar_delimiter.$next_link.']';
594 if ( isset($del_prev_link) && isset($del_next_link) )
595 $nav_row .= $double_delimiter.'['.$del_prev_link.$topbar_delimiter.$del_next_link.']';
596 }
597
598 // Start with Search Results or Message List link.
599 if (isset($where) && isset($what)) {
600 $msgs_url .= 'search.php?where=' . urlencode($where) .
601 '&amp;what=' . urlencode($what) . '&amp;mailbox=' . $urlMailbox;
602 $msgs_str = _("Search Results");
603 } else {
604 $msgs_url .= 'right_main.php?sort=' . $sort . '&amp;startMessage=' .
605 $startMessage . '&amp;mailbox=' . $urlMailbox;
606 $msgs_str = _("Message List");
607 }
608 $nav_row .= $double_delimiter .
609 '[<a href="' . $msgs_url . '">' . $msgs_str . '</a>]';
610
611 $nav_row .= '</small></td></tr>';
612
613
614 // BEGIN MENU ROW - DELETE/REPLY/FORWARD/MOVE/etc.
615 $menu_row = '<tr bgcolor="'.$color[9].'"><td><small>';
616 $comp_uri = $base_uri.'src/compose.php' .
617 '?passed_id=' . $passed_id .
618 '&amp;mailbox=' . $urlMailbox .
619 '&amp;startMessage=' . $startMessage .
620 (isset($passed_ent_id) ? '&amp;passed_ent_id='.$passed_ent_id : '');
621
622 // Start form for reply/reply all/forward..
623 $target = '';
624 $on_click='';
625 $method='method="post" ';
626 if ($compose_new_win == '1') {
627 if ( $javascript_on ) {
628 $on_click=' onclick="comp_in_new_form(\''.$comp_uri.'\', this, this.form)"';
629 $comp_uri = 'javascript:void(0)';
630 $method='method="get" ';
631 } else {
632 $target = 'target="_blank"';
633 }
634 }
635
636 $menu_row .= "\n".'<form name="composeForm" action="'.$comp_uri.'" '.$method.$target.'><small>'."\n";
637
638 // If Draft folder - create Resume link
639 if (($mailbox == $draft_folder) && ($save_as_draft)) {
640 $new_button = 'smaction_draft';
641 $comp_alt_string = _("Resume Draft");
642 } else if (handleAsSent($mailbox)) {
643 // If in Sent folder, edit as new
644 $new_button = 'smaction_edit_new';
645 $comp_alt_string = _("Edit Message as New");
646 }
647 // Show Alt URI for Draft/Sent
648 if (isset($comp_alt_string))
649 $menu_row .= getButton('SUBMIT', $new_button, $comp_alt_string, $on_click) . "\n";
650
651 $menu_row .= getButton('SUBMIT', 'smaction_reply', _("Reply"), $on_click) . "\n";
652 $menu_row .= getButton('SUBMIT', 'smaction_reply_all', _("Reply All"), $on_click) ."\n";
653 $menu_row .= getButton('SUBMIT', 'smaction_forward', _("Forward"), $on_click);
654 if ($enable_forward_as_attachment)
655 $menu_row .= '<input type="checkbox" name="smaction_attache">' . _("Attachment") ."\n";
656
657 $menu_row .= '</form>'.'&nbsp;&nbsp;'."\n";
658
659 // Form for deletion
660 $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox;
661 $menu_row .= '<form action="'.$delete_url.'" method="post" style="display: inline"><small>';
662
663 if (!(isset($passed_ent_id) && $passed_ent_id)) {
664 $menu_row .= '<input type="hidden" name="message" value="'.$passed_id.'" />';
665
666 if ($where && $what) {
667 $menu_row .= '<input type="hidden" name="where" value="'.$where.'" />';
668 $menu_row .= '<input type="hidden" name="what" value="'.$what.'" />';
669 } else {
670 $menu_row .= '<input type="hidden" name="sort" value="'.$sort.'" />';
671 $menu_row .= '<input type="hidden" name="startMessage" value="'.$startMessage.'" />';
672 }
673 $menu_row .= getButton('SUBMIT', 'delete', _("Delete"));
674 $menu_row .= '<input type="checkbox" name="bypass_trash">' . _("Bypass Trash");
675 }
676 else
677 $menu_row .= getButton('SUBMIT', 'delete', _("Delete"), '', FALSE) . "\n"; // delete button is disabled
678
679 $menu_row .= '</form>' . "\n";
680
681
682 // Add top move link
683 $menu_row .= '</small></td><td align="right">';
684 if ( !(isset($passed_ent_id) && $passed_ent_id) ) {
685
686 $current_box = 'mailbox='.$mailbox.'&sort='.$sort.'&startMessage='.$startMessage;
687
688 // Set subsequent location based on whether or not there is a 'next' message.
689 if ( isset($next) && $next >= 0 ) {
690 $location = $base_uri . 'src/read_body.php?passed_id='.$next.'&';
691 } else {
692 $location = $base_uri . 'src/right_main.php?';
693 }
694
695 $menu_row .= '<form action="'.$base_uri.'src/move_messages.php?'.$current_box.'" method="post">'.
696 '<small><input type="hidden" name="show_more" value="0" />'.
697 '<input type="hidden" name="dmn" value="1" />'.
698 '<input type="hidden" name="location" value="'.$location.$current_box.'" />'.
699 '<input type="hidden" name="msg[0]" value="'.$passed_id.'" />'._("Move to:") .
700 '<select name="targetMailbox" style="padding: 0px; margin: 0px">';
701
702 if (isset($lastTargetMailbox) && !empty($lastTargetMailbox)) {
703 $menu_row .= sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)));
704 } else {
705 $menu_row .= sqimap_mailbox_option_list($imapConnection);
706 }
707 $menu_row .= '</select> ';
708
709 $menu_row .= getButton('SUBMIT', 'moveButton',_("Move")) . "\n" . '</form>';
710 }
711 $menu_row .= '</td></tr>';
712
713 // echo rows, with hooks
714 $ret = do_hook_function('read_body_menu_top', array($nav_row, $menu_row));
715 if (is_array($ret)) {
716 if (isset($ret[0]) && !empty($ret[0])) {
717 $nav_row = $ret[0];
718 }
719 if (isset($ret[1]) && !empty($ret[1])) {
720 $menu_row = $ret[1];
721 }
722 }
723 echo '<table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
724 echo $nav_on_top ? $nav_row . $menu_row : $menu_row . $nav_row;
725 echo '</table>'."\n";
726 do_hook('read_body_menu_bottom');
727 }
728
729 function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
730 global $base_uri;
731
732 $urlMailbox = urlencode($mailbox);
733 sqgetGlobalVar('QUERY_STRING', $query_string, SQ_SERVER);
734 $url = $base_uri.'src/view_header.php?'.$query_string;
735
736 $s = "<TR>\n" .
737 html_tag( 'td', '', 'right', '', 'VALIGN="MIDDLE" WIDTH="20%"' ) . '<B>' . _("Options") . ":&nbsp;&nbsp;</B></TD>\n" .
738 html_tag( 'td', '', 'left', '', 'VALIGN="MIDDLE" WIDTH="80%"' ) . '<SMALL>' .
739 '<a href="'.$url.'">'._("View Full Header").'</a>';
740
741 /* Output the printer friendly link if we are in subtle mode. */
742 $s .= '&nbsp;|&nbsp;' .
743 printer_friendly_link($mailbox, $passed_id, $passed_ent_id);
744 echo $s;
745 do_hook("read_body_header_right");
746 $s = "</SMALL></TD>\n" .
747 "</TR>\n";
748 echo $s;
749
750 }
751
752 /***************************/
753 /* Main of read_body.php */
754 /***************************/
755
756 /* get the globals we may need */
757
758 sqgetGlobalVar('key', $key, SQ_COOKIE);
759 sqgetGlobalVar('username', $username, SQ_SESSION);
760 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
761 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
762 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
763
764 sqgetGlobalVar('msgs', $msgs, SQ_SESSION);
765 sqgetGlobalVar('msort', $msort, SQ_SESSION);
766 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION);
767 sqgetGlobalVar('server_sort_array', $server_sort_array, SQ_SESSION);
768 if (!sqgetGlobalVar('messages', $messages, SQ_SESSION) ) {
769 $messages = array();
770 }
771
772 /** GET VARS */
773 sqgetGlobalVar('sendreceipt', $sendreceipt, SQ_GET);
774 sqgetGlobalVar('where', $where, SQ_GET);
775 sqgetGlobalVar('what', $what, SQ_GET);
776 if ( sqgetGlobalVar('show_more', $temp, SQ_GET) ) {
777 $show_more = (int) $temp;
778 }
779 if ( sqgetGlobalVar('show_more_cc', $temp, SQ_GET) ) {
780 $show_more_cc = (int) $temp;
781 }
782 if ( sqgetGlobalVar('show_more_bcc', $temp, SQ_GET) ) {
783 $show_more_bcc = (int) $temp;
784 }
785 if ( sqgetGlobalVar('view_hdr', $temp, SQ_GET) ) {
786 $view_hdr = (int) $temp;
787 }
788
789 /** GET/POST VARS */
790 sqgetGlobalVar('passed_ent_id', $passed_ent_id);
791 sqgetGlobalVar('mailbox', $mailbox);
792
793 if ( sqgetGlobalVar('passed_id', $temp) ) {
794 $passed_id = (int) $temp;
795 }
796 if ( sqgetGlobalVar('sort', $temp) ) {
797 $sort = (int) $temp;
798 }
799 if ( sqgetGlobalVar('startMessage', $temp) ) {
800 $startMessage = (int) $temp;
801 }
802
803 /* end of get globals */
804 global $sqimap_capabilities, $lastTargetMailbox;
805
806 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
807 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
808
809 /**
810 * Process Delete from delete-move-next
811 * but only if delete_id was set
812 */
813 if ( sqgetGlobalVar('delete_id', $delete_id, SQ_GET) ) {
814 sqimap_messages_delete($imapConnection, $delete_id, $delete_id, $mailbox);
815
816 sqimap_mailbox_expunge_dmn($delete_id);
817 }
818
819 /**
820 * $message contains all information about the message
821 * including header and body
822 */
823
824 $uidvalidity = $mbx_response['UIDVALIDITY'];
825
826 if (!isset($messages[$uidvalidity])) {
827 $messages[$uidvalidity] = array();
828 }
829 if (!isset($messages[$uidvalidity][$passed_id])) {
830 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
831 $FirstTimeSee = !$message->is_seen;
832 $message->is_seen = true;
833 $messages[$uidvalidity][$passed_id] = $message;
834 } else {
835 // $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
836 $message = $messages[$uidvalidity][$passed_id];
837 $FirstTimeSee = !$message->is_seen;
838 }
839
840 if (isset($passed_ent_id) && $passed_ent_id) {
841 $message = $message->getEntity($passed_ent_id);
842 if ($message->type0 != 'message' && $message->type1 != 'rfc822') {
843 $message = $message->parent;
844 }
845 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, TRUE);
846 $rfc822_header = new Rfc822Header();
847 $rfc822_header->parseHeader($read);
848 $message->rfc822_header = $rfc822_header;
849 } else {
850 $passed_ent_id = 0;
851 }
852 $header = $message->header;
853
854 do_hook('html_top');
855
856 /****************************************/
857 /* Block for handling incoming url vars */
858 /****************************************/
859
860 if (isset($sendreceipt)) {
861 if ( !$message->is_mdnsent ) {
862 $final_recipient = '';
863 if ((isset($identity)) && ($identity != 0)) //Main identity
864 $final_recipient = trim(getPref($data_dir, $username, 'email_address' . $identity, '' ));
865 if ($final_recipient == '' )
866 $final_recipient = trim(getPref($data_dir, $username, 'email_address', '' ));
867 $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]);
868 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
869 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id);
870 $message->is_mdnsent = true;
871 $messages[$uidvalidity][$passed_id]=$message;
872 }
873 ClearAttachments();
874 }
875 }
876 /***********************************************/
877 /* End of block for handling incoming url vars */
878 /***********************************************/
879
880 $msgs[$passed_id]['FLAG_SEEN'] = true;
881
882 $messagebody = '';
883 do_hook('read_body_top');
884 if ($show_html_default == 1) {
885 $ent_ar = $message->findDisplayEntity(array());
886 } else {
887 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
888 }
889 $cnt = count($ent_ar);
890 for ($i = 0; $i < $cnt; $i++) {
891 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
892 if ($i != $cnt-1) {
893 $messagebody .= '<hr noshade size=1>';
894 }
895 }
896
897 displayPageHeader($color, $mailbox);
898 formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
899 formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
900 echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
901 echo ' <tr><td>';
902 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
903 echo ' <tr><td>';
904 echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
905 echo ' <tr bgcolor="'.$color[4].'"><td>';
906 // echo ' <table cellpadding="1" cellspacing="5" align="left" border="0">';
907 echo html_tag( 'table' ,'' , 'left', '', 'cellpadding="1" cellspacing="5" border="0"' );
908 echo ' <tr>' . html_tag( 'td', '<br>'. $messagebody."\n", 'left')
909 . '</tr>';
910 echo ' </table>';
911 echo ' </td></tr>';
912 echo ' </table></td></tr>';
913 echo ' </table>';
914 echo ' </td></tr>';
915
916 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
917 $color[4].'"></TD></TR>'."\n";
918
919 $attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
920 if ($attachmentsdisplay) {
921 echo ' </table>';
922 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
923 echo ' <tr><td>';
924 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
925 echo ' <tr>' . html_tag( 'td', '', 'left', $color[9] );
926 echo ' <b>' . _("Attachments") . ':</b>';
927 echo ' </td></tr>';
928 echo ' <tr><td>';
929 echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>';
930 echo $attachmentsdisplay;
931 echo ' </td></tr></table>';
932 echo ' </td></tr></table>';
933 echo ' </td></tr>';
934 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
935 $color[4].'"></TD></TR>';
936 }
937 echo '</table>';
938
939 /* show attached images inline -- if pref'fed so */
940 if (($attachment_common_show_images) &&
941 is_array($attachment_common_show_images_list)) {
942 foreach ($attachment_common_show_images_list as $img) {
943 $imgurl = SM_PATH . 'src/download.php' .
944 '?' .
945 'passed_id=' . urlencode($img['passed_id']) .
946 '&amp;mailbox=' . urlencode($mailbox) .
947 '&amp;ent_id=' . urlencode($img['ent_id']) .
948 '&amp;absolute_dl=true';
949
950 echo html_tag( 'table', "\n" .
951 html_tag( 'tr', "\n" .
952 html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left'
953 )
954 ) ,
955 'center', '', 'cellspacing=0 border="0" cellpadding="2"');
956 }
957 }
958
959 formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response, FALSE);
960
961 do_hook('read_body_bottom');
962 do_hook('html_bottom');
963 sqimap_logout($imapConnection);
964 /* sessions are written at the end of the script. it's better to register
965 them at the end so we avoid double session_register calls */
966 sqsession_register($messages,'messages');
967
968 ?>
969 </body>
970 </html>