ead59e36973adca2b630aaf84806c65e0560bce8
[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 include_once(SM_PATH . 'functions/arrays.php');
33 require_once(SM_PATH . 'functions/mailbox_display.php');
34
35 /**
36 * Given an IMAP message id number, this will look it up in the cached
37 * and sorted msgs array and return the index of the next message
38 *
39 * @param int $passed_id The current message UID
40 * @return the index of the next valid message from the array
41 */
42 function findNextMessage($uidset,$passed_id='backwards') {
43 if (!is_array($uidset)) {
44 return -1;
45 }
46 if ($passed_id=='backwards' || !is_array($uidset)) { // check for backwards compattibilty gpg plugin
47 $passed_id = $uidset;
48 }
49 $result = sqm_array_get_value_by_offset($uidset,$passed_id,1);
50 if ($result === false) {
51 return -1;
52 } else {
53 return $result;
54 }
55 }
56
57 /**
58 * Given an IMAP message id number, this will look it up in the cached
59 * and sorted msgs array and return the index of the previous message
60 *
61 * @param int $passed_id The current message UID
62 * @return the index of the next valid message from the array
63 */
64
65 function findPreviousMessage($uidset, $passed_id) {
66 if (!is_array($uidset)) {
67 return -1;
68 }
69 $result = sqm_array_get_value_by_offset($uidset,$passed_id,-1);
70 if ($result === false) {
71 return -1;
72 } else {
73 return $result;
74 }
75 }
76
77 /**
78 * Displays a link to a page where the message is displayed more
79 * "printer friendly".
80 * @param string $mailbox Name of current mailbox
81 * @param int $passed_id
82 */
83 function printer_friendly_link($mailbox, $passed_id, $passed_ent_id) {
84 global $javascript_on;
85
86 /* hackydiehack */
87 if( !sqgetGlobalVar('view_unsafe_images', $view_unsafe_images, SQ_GET) ) {
88 $view_unsafe_images = false;
89 } else {
90 $view_unsafe_images = true;
91 }
92 $params = '?passed_ent_id=' . urlencode($passed_ent_id) .
93 '&mailbox=' . urlencode($mailbox) .
94 '&passed_id=' . urlencode($passed_id).
95 '&view_unsafe_images='. (bool) $view_unsafe_images;
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 ClearAttachments() {
293 global $username, $attachments, $attachment_dir;
294
295 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
296
297 $rem_attachments = array();
298 if (isset($attachments)) {
299 foreach ($attachments as $info) {
300 if ($info['session'] == -1) {
301 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
302 if (file_exists($attached_file)) {
303 unlink($attached_file);
304 }
305 } else {
306 $rem_attachments[] = $info;
307 }
308 }
309 }
310 $attachments = $rem_attachments;
311 }
312
313 function formatRecipientString($recipients, $item ) {
314 global $show_more_cc, $show_more, $show_more_bcc,
315 $PHP_SELF;
316
317 $string = '';
318 if ((is_array($recipients)) && (isset($recipients[0]))) {
319 $show = false;
320
321 if ($item == 'to') {
322 if ($show_more) {
323 $show = true;
324 $url = set_url_var($PHP_SELF, 'show_more',0);
325 } else {
326 $url = set_url_var($PHP_SELF, 'show_more',1);
327 }
328 } else if ($item == 'cc') {
329 if ($show_more_cc) {
330 $show = true;
331 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
332 } else {
333 $url = set_url_var($PHP_SELF, 'show_more_cc',1);
334 }
335 } else if ($item == 'bcc') {
336 if ($show_more_bcc) {
337 $show = true;
338 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
339 } else {
340 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
341 }
342 }
343
344 $cnt = count($recipients);
345 foreach($recipients as $r) {
346 $add = decodeHeader($r->getAddress(true));
347 if ($string) {
348 $string .= '<br />' . $add;
349 } else {
350 $string = $add;
351 if ($cnt > 1) {
352 $string .= '&nbsp;(<a href="'.$url;
353 if ($show) {
354 $string .= '">'._("less").'</a>)';
355 } else {
356 $string .= '">'._("more").'</a>)';
357 break;
358 }
359 }
360 }
361 }
362 }
363 return $string;
364 }
365
366 function formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message,
367 $color, $FirstTimeSee) {
368 global $default_use_mdn, $default_use_priority,
369 $show_xmailer_default, $mdn_user_support, $PHP_SELF, $javascript_on,
370 $squirrelmail_language;
371
372 $mailbox = $aMailbox['NAME'];
373
374 $header = $message->rfc822_header;
375 $env = array();
376 $env[_("Subject")] = str_replace("&nbsp;"," ",decodeHeader($header->subject));
377
378 $from_name = $header->getAddr_s('from');
379 if (!$from_name)
380 $from_name = $header->getAddr_s('sender');
381 if (!$from_name)
382 $env[_("From")] = _("Unknown sender");
383 else
384 $env[_("From")] = decodeHeader($from_name);
385 $env[_("Date")] = getLongDateString($header->date);
386 $env[_("To")] = formatRecipientString($header->to, "to");
387 $env[_("Cc")] = formatRecipientString($header->cc, "cc");
388 $env[_("Bcc")] = formatRecipientString($header->bcc, "bcc");
389 if ($default_use_priority) {
390 $env[_("Priority")] = htmlspecialchars(getPriorityStr($header->priority));
391 }
392 if ($show_xmailer_default) {
393 $env[_("Mailer")] = decodeHeader($header->xmailer);
394 }
395 if ($default_use_mdn) {
396 if ($mdn_user_support) {
397 if ($header->dnt) {
398 if ($message->is_mdnsent) {
399 $env[_("Read receipt")] = _("sent");
400 } else {
401 $env[_("Read receipt")] = _("requested");
402 if (!(handleAsSent($mailbox) ||
403 $message->is_deleted ||
404 $passed_ent_id)) {
405 $mdn_url = $PHP_SELF . '&sendreceipt=1';
406 if ($FirstTimeSee && $javascript_on) {
407 $script = '<script language="JavaScript" type="text/javascript">' . "\n";
408 $script .= '<!--'. "\n";
409 $script .= 'if(window.confirm("' .
410 _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
411 '")) { '."\n" .
412 ' sendMDN()'.
413 '}' . "\n";
414 $script .= '// -->'. "\n";
415 $script .= '</script>'. "\n";
416 echo $script;
417 }
418 $env[_("Read receipt")] .= '&nbsp;<a href="' . $mdn_url . '">[' .
419 _("Send read receipt now") . ']</a>';
420 }
421 }
422 }
423 }
424 }
425
426 $s = '<table width="100%" cellpadding="0" cellspacing="2" border="0"';
427 $s .= ' align="center" bgcolor="'.$color[0].'">';
428 foreach ($env as $key => $val) {
429 if ($val) {
430 $s .= '<tr>';
431 $s .= html_tag('td', '<b>' . $key . ':&nbsp;&nbsp;</b>', 'right', '', 'valign="top" width="20%"') . "\n";
432 $s .= html_tag('td', $val, 'left', '', 'valign="top" width="80%"') . "\n";
433 $s .= '</tr>';
434 }
435 }
436 echo '<table bgcolor="'.$color[9].'" width="100%" cellpadding="1"'.
437 ' cellspacing="0" border="0" align="center">'."\n";
438 echo '<tr><td height="5" colspan="2" bgcolor="'.
439 $color[4].'"></td></tr><tr><td align="center">'."\n";
440 echo $s;
441 do_hook('read_body_header');
442 formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color);
443 echo '</table>';
444 echo '</td></tr><tr><td height="5" colspan="2" bgcolor="'.$color[4].'"></td></tr>'."\n";
445 echo '</table>';
446 }
447
448 /**
449 * Format message toolbar
450 *
451 * @param string $mailbox Name of current mailbox
452 * @param int $passed_id UID of current message
453 * @param int $passed_ent_id Id of entity within message
454 * @param object $message Current message object
455 * @param object $mbx_response
456 */
457 function formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message, $removedVar, $nav_on_top = TRUE) {
458 global $base_uri, $draft_folder, $where, $what, $color, $sort,
459 $startMessage, $PHP_SELF, $save_as_draft,
460 $enable_forward_as_attachment, $imapConnection, $lastTargetMailbox,
461 $username, $delete_prev_next_display,
462 $compose_new_win, $javascript_on, $compose_width, $compose_height;
463
464 //FIXME cleanup argument list, use $aMailbox where possible
465 $mailbox = $aMailbox['NAME'];
466
467 $topbar_delimiter = '&nbsp;|&nbsp;';
468 $double_delimiter = '&nbsp;&nbsp;&nbsp;&nbsp;';
469 $urlMailbox = urlencode($mailbox);
470
471 $msgs_url = $base_uri . 'src/';
472
473 // BEGIN NAV ROW - PREV/NEXT, DEL PREV/NEXT, LINKS TO INDEX, etc.
474 $nav_row = '<tr><td align="left" colspan="2" style="border: 1px solid '.$color[9].';"><small>';
475
476 // Create Prev & Next links
477 // Handle nested entities first (i.e. Mime Attach parts)
478 if (isset($passed_ent_id) && $passed_ent_id) {
479 // code for navigating through attached message/rfc822 messages
480 $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
481 $entities = array();
482 $entity_count = array();
483 $c = 0;
484
485 foreach($message->parent->entities as $ent) {
486 if ($ent->type0 == 'message' && $ent->type1 == 'rfc822') {
487 $c++;
488 $entity_count[$c] = $ent->entity_id;
489 $entities[$ent->entity_id] = $c;
490 }
491 }
492
493 $prev_link = _("Previous");
494 if(isset($entities[$passed_ent_id]) && $entities[$passed_ent_id] > 1) {
495 $prev_ent_id = $entity_count[$entities[$passed_ent_id] - 1];
496 $prev_link = '<a href="'
497 . set_url_var($PHP_SELF, 'passed_ent_id', $prev_ent_id)
498 . '">' . $prev_link . '</a>';
499 }
500
501 $next_link = _("Next");
502 if(isset($entities[$passed_ent_id]) && $entities[$passed_ent_id] < $c) {
503 $next_ent_id = $entity_count[$entities[$passed_ent_id] + 1];
504 $next_link = '<a href="'
505 . set_url_var($PHP_SELF, 'passed_ent_id', $next_ent_id)
506 . '">' . $next_link . '</a>';
507 }
508
509 $par_ent_id = $message->parent->entity_id;
510 $up_link = '';
511 if ($par_ent_id) {
512 $par_ent_id = substr($par_ent_id,0,-2);
513 if ( $par_ent_id != 0 ) {
514 $up_link = $topbar_delimiter;
515 $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
516 $up_link .= '<a href="'.$url.'">'._("Up").'</a>';
517 }
518 }
519
520 $nav_row .= $prev_link . $up_link . $topbar_delimiter . $next_link;
521 $nav_row .= $double_delimiter . '[<a href="'.$url.'">'._("View Message").'</a>]';
522
523 // Prev/Next links for regular messages
524 } else if ( true ) { //!(isset($where) && isset($what)) ) {
525 /**
526 * Check if cache is still valid
527 */
528 if (!is_array($aMailbox['UIDSET'][$what])) {
529 fetchMessageHeaders($imapConnection, $aMailbox);
530 }
531 $prev = findPreviousMessage($aMailbox['UIDSET'][$what], $passed_id);
532 $next = findNextMessage($aMailbox['UIDSET'][$what],$passed_id);
533
534 $prev_link = _("Previous");
535 if ($prev >= 0) {
536 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
537 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
538 "&amp;where=$where&amp;what=$what" .
539 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
540 $prev_link = '<a href="'.$uri.'">'.$prev_link.'</a>';
541 }
542
543 $next_link = _("Next");
544 if ($next >= 0) {
545 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
546 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
547 "&amp;where=$where&amp;what=$what" .
548 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
549 $next_link = '<a href="'.$uri.'">'.$next_link.'</a>';
550 }
551
552 // Only bother with Delete & Prev and Delete & Next IF
553 // top display is enabled.
554 if ( $delete_prev_next_display == 1 &&
555 in_array('\\deleted', $aMailbox['PERMANENTFLAGS'],true) ) {
556 $del_prev_link = _("Delete & Prev");
557 if ($prev >= 0) {
558 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
559 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
560 '&amp;startMessage='.$startMessage.'&amp;show_more=0'.
561 "&amp;where=$where&amp;what=$what" .
562 '&amp;delete_id='.$passed_id;
563 $del_prev_link = '<a href="'.$uri.'">'.$del_prev_link.'</a>';
564 }
565
566 $del_next_link = _("Delete & Next");
567 if ($next >= 0) {
568 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
569 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
570 '&amp;startMessage='.$startMessage.'&amp;show_more=0'.
571 "&amp;where=$where&amp;what=$what" .
572 '&amp;delete_id='.$passed_id;
573 $del_next_link = '<a href="'.$uri.'">'.$del_next_link.'</a>';
574 }
575 }
576
577 $nav_row .= '['.$prev_link.$topbar_delimiter.$next_link.']';
578 if ( isset($del_prev_link) && isset($del_next_link) )
579 $nav_row .= $double_delimiter.'['.$del_prev_link.$topbar_delimiter.$del_next_link.']';
580 }
581
582 // Start with Search Results or Message List link.
583 $msgs_url .= "$where?where=read_body.php&amp;what=$what&amp;mailbox=" . $urlMailbox.
584 "&amp;startMessage=$startMessage";
585 if ($where == 'search.php') {
586 $msgs_str = _("Search Results");
587 } else {
588 $msgs_str = _("Message List");
589 }
590 $nav_row .= $double_delimiter .
591 '[<a href="' . $msgs_url . '">' . $msgs_str . '</a>]';
592
593 $nav_row .= '</small></td></tr>';
594
595
596 // BEGIN MENU ROW - DELETE/REPLY/FORWARD/MOVE/etc.
597 $menu_row = '<tr bgcolor="'.$color[0].'"><td><small>';
598 $comp_uri = $base_uri.'src/compose.php' .
599 '?passed_id=' . $passed_id .
600 '&amp;mailbox=' . $urlMailbox .
601 '&amp;startMessage=' . $startMessage .
602 (isset($passed_ent_id) ? '&amp;passed_ent_id='.$passed_ent_id : '');
603
604 // Start form for reply/reply all/forward..
605 $target = '';
606 $on_click='';
607 $method='method="post" ';
608 $onsubmit='';
609 if ($compose_new_win == '1') {
610 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
611 $compose_width = '640';
612 }
613 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
614 $compose_height = '550';
615 }
616 if ( $javascript_on ) {
617 $on_click=' onclick="comp_in_new_form(\''.$comp_uri.'\', this, this.form,'. $compose_width .',' . $compose_height .')"';
618 $comp_uri = 'javascript:void(0)';
619 $method='method="get" ';
620 $onsubmit = 'onsubmit="return false" ';
621 } else {
622 $target = 'target="_blank"';
623 }
624 }
625
626 $menu_row .= "\n".'<form name="composeForm" action="'.$comp_uri.'" '
627 . $method.$target.$onsubmit.' style="display: inline">'."\n";
628
629 // If Draft folder - create Resume link
630 if (($mailbox == $draft_folder) && ($save_as_draft)) {
631 $new_button = 'smaction_draft';
632 $comp_alt_string = _("Resume Draft");
633 } else if (handleAsSent($mailbox)) {
634 // If in Sent folder, edit as new
635 $new_button = 'smaction_edit_new';
636 $comp_alt_string = _("Edit Message as New");
637 }
638 // Show Alt URI for Draft/Sent
639 if (isset($comp_alt_string))
640 $menu_row .= getButton('submit', $new_button, $comp_alt_string, $on_click) . "\n";
641
642 $menu_row .= getButton('submit', 'smaction_reply', _("Reply"), $on_click) . "\n";
643 $menu_row .= getButton('submit', 'smaction_reply_all', _("Reply All"), $on_click) ."\n";
644 $menu_row .= getButton('submit', 'smaction_forward', _("Forward"), $on_click);
645 if ($enable_forward_as_attachment)
646 $menu_row .= '<input type="checkbox" name="smaction_attache" />' . _("As Attachment") .'&nbsp;&nbsp;'."\n";
647
648 $menu_row .= '</form>&nbsp;';
649
650 if ( in_array('\\deleted', $aMailbox['PERMANENTFLAGS'],true) ) {
651 // Form for deletion. Form is handled by the originating display in $where. This is right_main.php or search.php
652 $delete_url = $base_uri . "src/$where";
653 $menu_row .= '<form name="deleteMessageForm" action="'.$delete_url.'" method="post" style="display: inline">';
654
655 if (!(isset($passed_ent_id) && $passed_ent_id)) {
656 $menu_row .= addHidden('mailbox', $aMailbox['NAME']);
657 $menu_row .= addHidden('msg[0]', $passed_id);
658 $menu_row .= addHidden('startMessage', $startMessage);
659 $menu_row .= getButton('submit', 'delete', _("Delete"));
660 $menu_row .= '<input type="checkbox" name="bypass_trash" />' . _("Bypass Trash");
661 } else {
662 $menu_row .= getButton('submit', 'delete', _("Delete"), '', FALSE) . "\n"; // delete button is disabled
663 }
664
665 $menu_row .= '</form>';
666 }
667
668 // Add top move link
669 $menu_row .= '</small></td><td align="right">';
670 if ( !(isset($passed_ent_id) && $passed_ent_id) &&
671 in_array('\\deleted', $aMailbox['PERMANENTFLAGS'],true) ) {
672
673 $menu_row .= '<form name="moveMessageForm" action="'.$base_uri.'src/'.$where.'?'.'" method="post" style="display: inline">'.
674 '<small>'.
675
676 addHidden('mailbox',$aMailbox['NAME']) .
677 addHidden('msg[0]', $passed_id) . _("Move to:") .
678 '<select name="targetMailbox" style="padding: 0px; margin: 0px">';
679
680 if (isset($lastTargetMailbox) && !empty($lastTargetMailbox)) {
681 $menu_row .= sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)));
682 } else {
683 $menu_row .= sqimap_mailbox_option_list($imapConnection);
684 }
685 $menu_row .= '</select> ';
686
687 $menu_row .= getButton('submit', 'moveButton',_("Move")) . "\n" . '</form>';
688 }
689 $menu_row .= '</td></tr>';
690
691 // echo rows, with hooks
692 $ret = do_hook_function('read_body_menu_top', array($nav_row, $menu_row));
693 if (is_array($ret)) {
694 if (isset($ret[0]) && !empty($ret[0])) {
695 $nav_row = $ret[0];
696 }
697 if (isset($ret[1]) && !empty($ret[1])) {
698 $menu_row = $ret[1];
699 }
700 }
701 echo '<table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
702 echo $nav_on_top ? $nav_row . $menu_row : $menu_row . $nav_row;
703 echo '</table>'."\n";
704 do_hook('read_body_menu_bottom');
705 }
706
707 function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
708 global $base_uri, $where, $what;
709
710 $urlMailbox = urlencode($mailbox);
711 $urlPassed_id = urlencode($passed_id);
712 $urlPassed_ent_id = urlencode($passed_ent_id);
713
714 $query_string = 'mailbox=' . $urlMailbox . '&amp;passed_id=' . $urlPassed_id . '&amp;passed_ent_id=' . $urlPassed_ent_id;
715
716 if (!empty($where)) {
717 $query_string .= '&amp;where=' . urlencode($where);
718 }
719
720 if (!empty($what)) {
721 $query_string .= '&amp;what=' . urlencode($what);
722 }
723
724 $url = $base_uri.'src/view_header.php?'.$query_string;
725
726 $s = "<tr>\n" .
727 html_tag( 'td', '', 'right', '', 'valign="middle" width="20%"' ) . '<b>' . _("Options") . ":&nbsp;&nbsp;</b></td>\n" .
728 html_tag( 'td', '', 'left', '', 'valign="middle" width="80%"' ) . '<small>' .
729 '<a href="'.$url.'">'._("View Full Header").'</a>';
730
731 /* Output the printer friendly link if we are in subtle mode. */
732 $s .= '&nbsp;|&nbsp;' .
733 printer_friendly_link($mailbox, $passed_id, $passed_ent_id);
734 echo $s;
735 do_hook("read_body_header_right");
736 $s = "</small></td>\n" .
737 "</tr>\n";
738 echo $s;
739
740 }
741
742 /**
743 * Creates button
744 *
745 * @deprecated see form functions available in 1.5.1 and 1.4.3.
746 * @param string $type
747 * @param string $name
748 * @param string $value
749 * @param string $js
750 * @param bool $enabled
751 */
752 function getButton($type, $name, $value, $js = '', $enabled = TRUE) {
753 $disabled = ( $enabled ? '' : 'disabled ' );
754 $js = ( $js ? $js.' ' : '' );
755 return '<input '.$disabled.$js.
756 'type="'.$type.
757 '" name="'.$name.
758 '" value="'.$value .
759 '" style="padding: 0px; margin: 0px" />';
760 }
761
762
763 /***************************/
764 /* Main of read_body.php */
765 /***************************/
766
767 /* get the globals we may need */
768
769 sqgetGlobalVar('key', $key, SQ_COOKIE);
770 sqgetGlobalVar('username', $username, SQ_SESSION);
771 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
772 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
773 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
774 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION);
775 if (!sqgetGlobalVar('messages', $messages, SQ_SESSION) ) {
776 $messages = array();
777 }
778
779 /** GET VARS */
780 sqgetGlobalVar('sendreceipt', $sendreceipt, SQ_GET);
781 if (!sqgetGlobalVar('where', $where, SQ_GET) ) {
782 $where = 'right_main.php';
783 }
784 if (!sqgetGlobalVar('what', $what, SQ_GET) ){
785 $what = 0;
786 }
787 if ( sqgetGlobalVar('show_more', $temp, SQ_GET) ) {
788 $show_more = (int) $temp;
789 }
790 if ( sqgetGlobalVar('show_more_cc', $temp, SQ_GET) ) {
791 $show_more_cc = (int) $temp;
792 }
793 if ( sqgetGlobalVar('show_more_bcc', $temp, SQ_GET) ) {
794 $show_more_bcc = (int) $temp;
795 }
796 if ( sqgetGlobalVar('view_hdr', $temp, SQ_GET) ) {
797 $view_hdr = (int) $temp;
798 }
799
800 if ( sqgetGlobalVar('account', $temp, SQ_GET) ) {
801 $iAccount = (int) $temp;
802 } else {
803 $iAccount = 0;
804 }
805
806 /** GET/POST VARS */
807 sqgetGlobalVar('passed_ent_id', $passed_ent_id);
808 sqgetGlobalVar('mailbox', $mailbox);
809
810 if ( sqgetGlobalVar('passed_id', $temp) ) {
811 $passed_id = (int) $temp;
812 }
813 if ( sqgetGlobalVar('sort', $temp) ) {
814 $sort = (int) $temp;
815 }
816 if ( sqgetGlobalVar('startMessage', $temp) ) {
817 $startMessage = (int) $temp;
818 } else {
819 $startMessage = 1;
820 }
821 /**
822 * Retrieve mailbox cache
823 */
824 sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION);
825
826 /* end of get globals */
827 global $sqimap_capabilities, $lastTargetMailbox;
828
829 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
830 $aMailbox = sqm_api_mailbox_select($imapConnection, $iAccount, $mailbox,array('setindex' => $what, 'offset' => $startMessage),array());
831
832 /**
833 * Check if cache is still valid
834 */
835 $iSetIndex = $aMailbox['SETINDEX'];
836 $aMailbox['CURRENT_MSG'][$iSetIndex] = $passed_id;
837 //$aMailbox['OFFSET'] = $startMessage -1;
838
839 sqgetGlobalVar('aFetchColumns',$aFetchColumns,SQ_SESSION);
840 if (!is_array($aMailbox['UIDSET'][$what])) {
841 fetchMessageHeaders($imapConnection, $aMailbox, $aFetchColumns);
842 }
843
844 /**
845 * Update the seen state
846 * and ignore in_array('\\seen',$aMailbox['PERMANENTFLAGS'],true)
847 */
848 if (isset($aMailbox['MSG_HEADERS'][$passed_id]['FLAGS'])) {
849 $aMailbox['MSG_HEADERS'][$passed_id]['FLAGS']['\\seen'] = true;
850 }
851
852 /**
853 * Process Delete from delete-move-next
854 * but only if delete_id was set
855 */
856 if ( sqgetGlobalVar('delete_id', $delete_id, SQ_GET) ) {
857 handleMessageListForm($imapConnection,$aMailbox,$sButton='setDeleted', array($delete_id));
858 }
859
860 /**
861 * $message contains all information about the message
862 * including header and body
863 */
864
865 if (isset($aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'])) {
866 $message = $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'];
867 $FirstTimeSee = !$message->is_seen;
868 } else {
869 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
870 $FirstTimeSee = !$message->is_seen;
871 $message->is_seen = true;
872 $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'] = $message;
873 }
874
875 if (isset($passed_ent_id) && $passed_ent_id) {
876 $message = $message->getEntity($passed_ent_id);
877 if ($message->type0 != 'message' && $message->type1 != 'rfc822') {
878 $message = $message->parent;
879 }
880 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, TRUE);
881 $rfc822_header = new Rfc822Header();
882 $rfc822_header->parseHeader($read);
883 $message->rfc822_header = $rfc822_header;
884 } else if ($message->type0 == 'message' && $message->type1 == 'rfc822' && isset($message->entities[0])) {
885 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[1.HEADER]", true, $response, $msg, TRUE);
886 $rfc822_header = new Rfc822Header();
887 $rfc822_header->parseHeader($read);
888 $message->rfc822_header = $rfc822_header;
889 } else {
890 $passed_ent_id = 0;
891 }
892 $header = $message->header;
893
894 $header = $message->header;
895
896
897 /****************************************/
898 /* Block for handling incoming url vars */
899 /****************************************/
900
901 if (isset($sendreceipt)) {
902 if ( !$message->is_mdnsent ) {
903 $final_recipient = '';
904 if ((isset($identity)) && ($identity != 0)) //Main identity
905 $final_recipient = trim(getPref($data_dir, $username, 'email_address' . $identity, '' ));
906 if ($final_recipient == '' )
907 $final_recipient = trim(getPref($data_dir, $username, 'email_address', '' ));
908 $supportMDN = ServerMDNSupport($aMailbox["PERMANENTFLAGS"]);
909 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
910 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id);
911 $message->is_mdnsent = true;
912 $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'] = $message;
913 }
914 ClearAttachments();
915 }
916 }
917 /***********************************************/
918 /* End of block for handling incoming url vars */
919 /***********************************************/
920
921
922
923 $messagebody = '';
924 do_hook('read_body_top');
925 if ($show_html_default == 1) {
926 $ent_ar = $message->findDisplayEntity(array());
927 } else {
928 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
929 }
930 $cnt = count($ent_ar);
931 for ($i = 0; $i < $cnt; $i++) {
932 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
933 if ($i != $cnt-1) {
934 $messagebody .= '<hr style="height: 1px;" />';
935 }
936 }
937
938 displayPageHeader($color, $mailbox);
939 formatMenuBar($aMailbox, $passed_id, $passed_ent_id, $message,false);
940 formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
941 echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
942 echo ' <tr><td>';
943 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
944 echo ' <tr><td>';
945 echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
946 echo ' <tr bgcolor="'.$color[4].'"><td>';
947 // echo ' <table cellpadding="1" cellspacing="5" align="left" border="0">';
948 echo html_tag( 'table' ,'' , 'left', '', 'width="100%" cellpadding="1" cellspacing="5" border="0"' );
949 echo ' <tr>' . html_tag( 'td', '<br />'. $messagebody."\n", 'left')
950 . '</tr>';
951 echo ' </table>';
952 echo ' </td></tr>';
953 echo ' </table></td></tr>';
954 echo ' </table>';
955 echo ' </td></tr>';
956
957 echo '<tr><td height="5" colspan="2" bgcolor="'.
958 $color[4].'"></td></tr>'."\n";
959
960 $attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
961 if ($attachmentsdisplay) {
962 echo ' </table>';
963 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
964 echo ' <tr><td>';
965 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
966 echo ' <tr>' . html_tag( 'td', '', 'left', $color[9] );
967 echo ' <b>' . _("Attachments") . ':</b>';
968 echo ' </td></tr>';
969 echo ' <tr><td>';
970 echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>';
971 echo $attachmentsdisplay;
972 echo ' </td></tr></table>';
973 echo ' </td></tr></table>';
974 echo ' </td></tr>';
975 echo '<tr><td height="5" colspan="2" bgcolor="'.
976 $color[4].'"></td></tr>';
977 }
978 echo '</table>';
979
980 /* show attached images inline -- if pref'fed so */
981 if (($attachment_common_show_images) &&
982 is_array($attachment_common_show_images_list)) {
983 foreach ($attachment_common_show_images_list as $img) {
984 $imgurl = SM_PATH . 'src/download.php' .
985 '?' .
986 'passed_id=' . urlencode($img['passed_id']) .
987 '&amp;mailbox=' . urlencode($mailbox) .
988 '&amp;ent_id=' . urlencode($img['ent_id']) .
989 '&amp;absolute_dl=true';
990
991 echo html_tag( 'table', "\n" .
992 html_tag( 'tr', "\n" .
993 html_tag( 'td', '<img src="' . $imgurl . '" />' ."\n", 'left'
994 )
995 ) ,
996 'center', '', 'cellspacing="0" border="0" cellpadding="2"');
997 }
998 }
999
1000 formatMenuBar($aMailbox, $passed_id, $passed_ent_id, $message, false, FALSE);
1001
1002 do_hook('read_body_bottom');
1003 sqimap_logout($imapConnection);
1004
1005 /**
1006 * Write mailbox with updated seen flag information back to cache.
1007 */
1008 $mailbox_cache[$iAccount.'_'.$aMailbox['NAME']] = $aMailbox;
1009 sqsession_register($mailbox_cache,'mailbox_cache');
1010 ?>
1011 </body></html>