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