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