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