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