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