Formatting and adding FIXME to addressbook.php
[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 $prev = findPreviousMessage($aMailbox['UIDSET'][$what], $passed_id);
526 $next = findNextMessage($aMailbox['UIDSET'][$what],$passed_id);
527
528 $prev_link = _("Previous");
529 if ($prev >= 0) {
530 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
531 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
532 "&amp;where=$where&amp;what=$what" .
533 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
534 $prev_link = '<a href="'.$uri.'">'.$prev_link.'</a>';
535 }
536
537 $next_link = _("Next");
538 if ($next >= 0) {
539 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
540 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
541 "&amp;where=$where&amp;what=$what" .
542 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
543 $next_link = '<a href="'.$uri.'">'.$next_link.'</a>';
544 }
545
546 // Only bother with Delete & Prev and Delete & Next IF
547 // top display is enabled.
548 if ( $delete_prev_next_display == 1 &&
549 in_array('\\deleted', $aMailbox['PERMANENTFLAGS'],true) ) {
550 $del_prev_link = _("Delete & Prev");
551 if ($prev >= 0) {
552 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
553 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
554 '&amp;startMessage='.$startMessage.'&amp;show_more=0'.
555 "&amp;where=$where&amp;what=$what" .
556 '&amp;delete_id='.$passed_id;
557 $del_prev_link = '<a href="'.$uri.'">'.$del_prev_link.'</a>';
558 }
559
560 $del_next_link = _("Delete & Next");
561 if ($next >= 0) {
562 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
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_next_link = '<a href="'.$uri.'">'.$del_next_link.'</a>';
568 }
569 }
570
571 $nav_row .= '['.$prev_link.$topbar_delimiter.$next_link.']';
572 if ( isset($del_prev_link) && isset($del_next_link) )
573 $nav_row .= $double_delimiter.'['.$del_prev_link.$topbar_delimiter.$del_next_link.']';
574 }
575
576 // Start with Search Results or Message List link.
577 $msgs_url .= "$where?where=read_body.php&amp;what=$what&amp;mailbox=" . $urlMailbox.
578 "&amp;startMessage=$startMessage";
579 if ($where == 'search.php') {
580 $msgs_str = _("Search Results");
581 } else {
582 $msgs_str = _("Message List");
583 }
584 $nav_row .= $double_delimiter .
585 '[<a href="' . $msgs_url . '">' . $msgs_str . '</a>]';
586
587 $nav_row .= '</small></td></tr>';
588
589
590 // BEGIN MENU ROW - DELETE/REPLY/FORWARD/MOVE/etc.
591 $menu_row = '<tr bgcolor="'.$color[0].'"><td><small>';
592 $comp_uri = $base_uri.'src/compose.php' .
593 '?passed_id=' . $passed_id .
594 '&amp;mailbox=' . $urlMailbox .
595 '&amp;startMessage=' . $startMessage .
596 (isset($passed_ent_id) ? '&amp;passed_ent_id='.$passed_ent_id : '');
597
598 // Start form for reply/reply all/forward..
599 $target = '';
600 $on_click='';
601 $method='method="post" ';
602 $onsubmit='';
603 if ($compose_new_win == '1') {
604 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
605 $compose_width = '640';
606 }
607 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
608 $compose_height = '550';
609 }
610 if ( $javascript_on ) {
611 $on_click=' onclick="comp_in_new_form(\''.$comp_uri.'\', this, this.form,'. $compose_width .',' . $compose_height .')"';
612 $comp_uri = 'javascript:void(0)';
613 $method='method="get" ';
614 $onsubmit = 'onsubmit="return false" ';
615 } else {
616 $target = 'target="_blank"';
617 }
618 }
619
620 $menu_row .= "\n".'<form name="composeForm" action="'.$comp_uri.'" '
621 . $method.$target.$onsubmit.' 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 .= addHidden('startMessage', $startMessage);
653 $menu_row .= getButton('submit', 'delete', _("Delete"));
654 $menu_row .= '<input type="checkbox" name="bypass_trash" />' . _("Bypass Trash");
655 } else {
656 $menu_row .= getButton('submit', 'delete', _("Delete"), '', FALSE) . "\n"; // delete button is disabled
657 }
658
659 $menu_row .= '</form>';
660 }
661
662 // Add top move link
663 $menu_row .= '</small></td><td align="right">';
664 if ( !(isset($passed_ent_id) && $passed_ent_id) &&
665 in_array('\\deleted', $aMailbox['PERMANENTFLAGS'],true) ) {
666
667 $menu_row .= '<form name="moveMessageForm" action="'.$base_uri.'src/'.$where.'?'.'" method="post" style="display: inline">'.
668 '<small>'.
669
670 addHidden('mailbox',$aMailbox['NAME']) .
671 addHidden('msg[0]', $passed_id) . _("Move to:") .
672 '<select name="targetMailbox" style="padding: 0px; margin: 0px">';
673
674 if (isset($lastTargetMailbox) && !empty($lastTargetMailbox)) {
675 $menu_row .= sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)));
676 } else {
677 $menu_row .= sqimap_mailbox_option_list($imapConnection);
678 }
679 $menu_row .= '</select> ';
680
681 $menu_row .= getButton('submit', 'moveButton',_("Move")) . "\n" . '</form>';
682 }
683 $menu_row .= '</td></tr>';
684
685 // echo rows, with hooks
686 $ret = do_hook_function('read_body_menu_top', array($nav_row, $menu_row));
687 if (is_array($ret)) {
688 if (isset($ret[0]) && !empty($ret[0])) {
689 $nav_row = $ret[0];
690 }
691 if (isset($ret[1]) && !empty($ret[1])) {
692 $menu_row = $ret[1];
693 }
694 }
695 echo '<table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
696 echo $nav_on_top ? $nav_row . $menu_row : $menu_row . $nav_row;
697 echo '</table>'."\n";
698 do_hook('read_body_menu_bottom');
699 }
700
701 function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
702 global $base_uri, $where, $what;
703
704 $urlMailbox = urlencode($mailbox);
705 $urlPassed_id = urlencode($passed_id);
706 $urlPassed_ent_id = urlencode($passed_ent_id);
707
708 $query_string = 'mailbox=' . $urlMailbox . '&amp;passed_id=' . $urlPassed_id . '&amp;passed_ent_id=' . $urlPassed_ent_id;
709
710 if (!empty($where)) {
711 $query_string .= '&amp;where=' . urlencode($where);
712 }
713
714 if (!empty($what)) {
715 $query_string .= '&amp;what=' . urlencode($what);
716 }
717
718 $url = $base_uri.'src/view_header.php?'.$query_string;
719
720 $s = "<tr>\n" .
721 html_tag( 'td', '', 'right', '', 'valign="middle" width="20%"' ) . '<b>' . _("Options") . ":&nbsp;&nbsp;</b></td>\n" .
722 html_tag( 'td', '', 'left', '', 'valign="middle" width="80%"' ) . '<small>' .
723 '<a href="'.$url.'">'._("View Full Header").'</a>';
724
725 /* Output the printer friendly link if we are in subtle mode. */
726 $s .= '&nbsp;|&nbsp;' .
727 printer_friendly_link($mailbox, $passed_id, $passed_ent_id);
728 echo $s;
729 do_hook("read_body_header_right");
730 $s = "</small></td>\n" .
731 "</tr>\n";
732 echo $s;
733
734 }
735
736 /**
737 * Creates button
738 *
739 * @deprecated see form functions available in 1.5.1 and 1.4.3.
740 * @param string $type
741 * @param string $name
742 * @param string $value
743 * @param string $js
744 * @param bool $enabled
745 */
746 function getButton($type, $name, $value, $js = '', $enabled = TRUE) {
747 $disabled = ( $enabled ? '' : 'disabled ' );
748 $js = ( $js ? $js.' ' : '' );
749 return '<input '.$disabled.$js.
750 'type="'.$type.
751 '" name="'.$name.
752 '" value="'.$value .
753 '" style="padding: 0px; margin: 0px" />';
754 }
755
756
757 /***************************/
758 /* Main of read_body.php */
759 /***************************/
760
761 /* get the globals we may need */
762
763 sqgetGlobalVar('key', $key, SQ_COOKIE);
764 sqgetGlobalVar('username', $username, SQ_SESSION);
765 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
766 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
767 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
768 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION);
769 if (!sqgetGlobalVar('messages', $messages, SQ_SESSION) ) {
770 $messages = array();
771 }
772
773 /** GET VARS */
774 sqgetGlobalVar('sendreceipt', $sendreceipt, SQ_GET);
775 if (!sqgetGlobalVar('where', $where, SQ_GET) ) {
776 $where = 'right_main.php';
777 }
778 /*
779 * Used as entry key to the list of uid's cached in the mailbox cache
780 * we use the cached uid's to get the next and prev message.
781 */
782 if (!sqgetGlobalVar('what', $what, SQ_GET) ){
783 $what = 0;
784 }
785 if ( sqgetGlobalVar('show_more', $temp, SQ_GET) ) {
786 $show_more = (int) $temp;
787 }
788 if ( sqgetGlobalVar('show_more_cc', $temp, SQ_GET) ) {
789 $show_more_cc = (int) $temp;
790 }
791 if ( sqgetGlobalVar('show_more_bcc', $temp, SQ_GET) ) {
792 $show_more_bcc = (int) $temp;
793 }
794 if ( sqgetGlobalVar('view_hdr', $temp, SQ_GET) ) {
795 $view_hdr = (int) $temp;
796 }
797
798 if ( sqgetGlobalVar('account', $temp, SQ_GET) ) {
799 $iAccount = (int) $temp;
800 } else {
801 $iAccount = 0;
802 }
803
804 /** GET/POST VARS */
805 sqgetGlobalVar('passed_ent_id', $passed_ent_id);
806 sqgetGlobalVar('mailbox', $mailbox);
807
808 if ( sqgetGlobalVar('passed_id', $temp) ) {
809 $passed_id = (int) $temp;
810 }
811 if ( sqgetGlobalVar('sort', $temp) ) {
812 $sort = (int) $temp;
813 }
814 if ( sqgetGlobalVar('startMessage', $temp) ) {
815 $startMessage = (int) $temp;
816 } else {
817 $startMessage = 1;
818 }
819 /**
820 * Retrieve mailbox cache
821 */
822 sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION);
823
824 /* end of get globals */
825 global $sqimap_capabilities, $lastTargetMailbox;
826
827 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
828 $aMailbox = sqm_api_mailbox_select($imapConnection, $iAccount, $mailbox,array('setindex' => $what, 'offset' => $startMessage),array());
829
830 /**
831 * Check if cache is still valid, $what contains the key
832 * which gives us acces to the array with uid's. At this moment
833 * 0 is used for a normal message list and search uses 1 as key. This can be
834 * changed / extended in the future.
835 * If on a select of a mailbox we detect that the cache should be invalidated due to
836 * the delete of messages or due to new messages we empty the list with uid's and
837 * that's what we detect below.
838 */
839 if (!is_array($aMailbox['UIDSET'][$what])) {
840 fetchMessageHeaders($imapConnection, $aMailbox);
841 }
842
843 $iSetIndex = $aMailbox['SETINDEX'];
844 $aMailbox['CURRENT_MSG'][$iSetIndex] = $passed_id;
845
846 /**
847 * Update the seen state
848 * and ignore in_array('\\seen',$aMailbox['PERMANENTFLAGS'],true)
849 */
850 if (isset($aMailbox['MSG_HEADERS'][$passed_id]['FLAGS'])) {
851 $aMailbox['MSG_HEADERS'][$passed_id]['FLAGS']['\\seen'] = true;
852 }
853
854 /**
855 * Process Delete from delete-move-next
856 * but only if delete_id was set
857 */
858 if ( sqgetGlobalVar('delete_id', $delete_id, SQ_GET) ) {
859 handleMessageListForm($imapConnection,$aMailbox,$sButton='setDeleted', array($delete_id));
860 }
861
862 /**
863 * $message contains all information about the message
864 * including header and body
865 */
866
867 if (isset($aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'])) {
868 $message = $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'];
869 $FirstTimeSee = !$message->is_seen;
870 } else {
871 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
872 $FirstTimeSee = !$message->is_seen;
873 $message->is_seen = true;
874 $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'] = $message;
875 }
876
877 if (isset($passed_ent_id) && $passed_ent_id) {
878 $message = $message->getEntity($passed_ent_id);
879 if ($message->type0 != 'message' && $message->type1 != 'rfc822') {
880 $message = $message->parent;
881 }
882 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, TRUE);
883 $rfc822_header = new Rfc822Header();
884 $rfc822_header->parseHeader($read);
885 $message->rfc822_header = $rfc822_header;
886 } else if ($message->type0 == 'message' && $message->type1 == 'rfc822' && isset($message->entities[0])) {
887 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[1.HEADER]", true, $response, $msg, TRUE);
888 $rfc822_header = new Rfc822Header();
889 $rfc822_header->parseHeader($read);
890 $message->rfc822_header = $rfc822_header;
891 } else {
892 $passed_ent_id = 0;
893 }
894 $header = $message->header;
895
896 $header = $message->header;
897
898
899 /****************************************/
900 /* Block for handling incoming url vars */
901 /****************************************/
902
903 if (isset($sendreceipt)) {
904 if ( !$message->is_mdnsent ) {
905 $final_recipient = '';
906 if ((isset($identity)) && ($identity != 0)) //Main identity
907 $final_recipient = trim(getPref($data_dir, $username, 'email_address' . $identity, '' ));
908 if ($final_recipient == '' )
909 $final_recipient = trim(getPref($data_dir, $username, 'email_address', '' ));
910 $supportMDN = ServerMDNSupport($aMailbox["PERMANENTFLAGS"]);
911 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
912 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id);
913 $message->is_mdnsent = true;
914 $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'] = $message;
915 }
916 ClearAttachments();
917 }
918 }
919 /***********************************************/
920 /* End of block for handling incoming url vars */
921 /***********************************************/
922
923
924
925 $messagebody = '';
926 do_hook('read_body_top');
927 if ($show_html_default == 1) {
928 $ent_ar = $message->findDisplayEntity(array());
929 } else {
930 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
931 }
932 $cnt = count($ent_ar);
933 for ($i = 0; $i < $cnt; $i++) {
934 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
935 if ($i != $cnt-1) {
936 $messagebody .= '<hr style="height: 1px;" />';
937 }
938 }
939
940 displayPageHeader($color, $mailbox,'','');
941 formatMenuBar($aMailbox, $passed_id, $passed_ent_id, $message,false);
942 formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
943 echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
944 echo ' <tr><td>';
945 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
946 echo ' <tr><td>';
947 echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
948 echo ' <tr bgcolor="'.$color[4].'"><td>';
949 // echo ' <table cellpadding="1" cellspacing="5" align="left" border="0">';
950 echo html_tag( 'table' ,'' , 'left', '', 'width="100%" cellpadding="1" cellspacing="5" border="0"' );
951 echo ' <tr>' . html_tag( 'td', '<br />'. $messagebody."\n", 'left')
952 . '</tr>';
953 echo ' </table>';
954 echo ' </td></tr>';
955 echo ' </table></td></tr>';
956 echo ' </table>';
957 echo ' </td></tr>';
958
959 echo '<tr><td height="5" colspan="2" bgcolor="'.
960 $color[4].'"></td></tr>'."\n";
961
962 $attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
963 if ($attachmentsdisplay) {
964 echo ' </table>';
965 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
966 echo ' <tr><td>';
967 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
968 echo ' <tr>' . html_tag( 'td', '', 'left', $color[9] );
969 echo ' <b>' . _("Attachments") . ':</b>';
970 echo ' </td></tr>';
971 echo ' <tr><td>';
972 echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>';
973 echo $attachmentsdisplay;
974 echo ' </td></tr></table>';
975 echo ' </td></tr></table>';
976 echo ' </td></tr>';
977 echo '<tr><td height="5" colspan="2" bgcolor="'.
978 $color[4].'"></td></tr>';
979 }
980 echo '</table>';
981
982 /* show attached images inline -- if pref'fed so */
983 if (($attachment_common_show_images) &&
984 is_array($attachment_common_show_images_list)) {
985 foreach ($attachment_common_show_images_list as $img) {
986 $imgurl = SM_PATH . 'src/download.php' .
987 '?' .
988 'passed_id=' . urlencode($img['passed_id']) .
989 '&amp;mailbox=' . urlencode($mailbox) .
990 '&amp;ent_id=' . urlencode($img['ent_id']) .
991 '&amp;absolute_dl=true';
992
993 echo html_tag( 'table', "\n" .
994 html_tag( 'tr', "\n" .
995 html_tag( 'td', '<img src="' . $imgurl . '" />' ."\n", 'left'
996 )
997 ) ,
998 'center', '', 'cellspacing="0" border="0" cellpadding="2"');
999 }
1000 }
1001
1002 formatMenuBar($aMailbox, $passed_id, $passed_ent_id, $message, false, FALSE);
1003
1004 do_hook('read_body_bottom');
1005 sqimap_logout($imapConnection);
1006
1007 /**
1008 * Write mailbox with updated seen flag information back to cache.
1009 */
1010 $mailbox_cache[$iAccount.'_'.$aMailbox['NAME']] = $aMailbox;
1011 sqsession_register($mailbox_cache,'mailbox_cache');
1012
1013 ?>
1014 </body></html>