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