' . "\n" . '\n" . "\n" . "$print_text\n"; } else { $result .= '$print_text\n"; } return ($result); } function ServerMDNSupport( $read ) { /* escaping $ doesn't work -> \x36 */ $ret = preg_match( '/(\x36MDNSent|\\\*)/i', $read ); return ( $ret ); } function SendMDN ( $mailbox, $passed_id, $sender, $message) { global $username, $attachment_dir, $SERVER_NAME, $version, $attachments; $header = $message->header; $hashed_attachment_dir = getHashedDir($username, $attachment_dir); $recipient_o = $header->dnt; $recipient = $recipient_o->getAddress(true); // part 1 (RFC2298) $senton = getLongDateString( $header->date ); $to_array = $header->to; $to = ''; foreach ($to_array as $line) { $to .= ' '.$line->getAddress(); } $subject = $header->subject; $now = getLongDateString( time() ); set_my_charset(); $body = _("Your message") . "\r\n\r\n" . "\t" . _("To:") . ' ' . $to . "\r\n" . "\t" . _("Subject:") . ' ' . $subject . "\r\n" . "\t" . _("Sent:") . ' ' . $senton . "\r\n" . "\r\n" . sprintf( _("Was displayed on %s"), $now ); // part2 (RFC2298) $original_recipient = $to; $original_message_id = $header->message_id; $part2 = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n"; if ($original_recipient != '') { $part2 .= "Original-Recipient : $original_recipient\r\n"; } $final_recipient = $sender; $part2 .= "Final-Recipient: rfc822; $final_recipient\r\n" . "Original-Message-ID : $original_message_id\r\n" . "Disposition: manual-action/MDN-sent-manually; displayed\r\n"; $localfilename = GenerateRandomString(32, 'FILE', 7); $full_localfilename = "$hashed_attachment_dir/$localfilename"; $fp = fopen( $full_localfilename, 'w'); fwrite ($fp, $part2); fclose($fp); $newAttachment = array(); $newAttachment['localfilename'] = $localfilename; $newAttachment['type'] = "message/disposition-notification"; $newAttachment['session']=-1; $attachments[] = $newAttachment; return (SendMessage($recipient, '', '', _("Read:") . ' ' . $subject, $body, 0, True, 3, -1) ); } function ToggleMDNflag ( $set ,$imapConnection, $mailbox, $passed_id, $uid_support) { $sg = $set?'+':'-'; $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)'; $read = sqimap_run_command ($imapConnection, $cmd, true, $response, $readmessage, $uid_support); } function ClearAttachments() { global $username, $attachments, $attachment_dir; $hashed_attachment_dir = getHashedDir($username, $attachment_dir); $rem_attachments = array(); foreach ($attachments as $info) { if ($info['session'] == -1) { $attached_file = "$hashed_attachment_dir/$info[localfilename]"; if (file_exists($attached_file)) { unlink($attached_file); } } else { $rem_attachments[] = $info; } } $attachments = $rem_attachments; } function formatRecipientString($recipients, $item ) { global $show_more_cc, $show_more, $show_more_bcc, $PHP_SELF; if ((is_array($recipients)) && (isset($recipients[0]))) { $string = ''; $ary = $recipients; $show = false; if ($item == 'to') { if ($show_more) { $show = true; $url = set_url_var($PHP_SELF, 'show_more',0); } else { $url = set_url_var($PHP_SELF, 'show_more',1); } } else if ($item == 'cc') { if ($show_more_cc) { $url = set_url_var($PHP_SELF, 'show_more_cc',0); $show = true; } else { $url = set_url_var($PHP_SELF, 'show_more_cc',1); } } else if ($item == 'bcc') { if ($show_more_bcc) { $url = set_url_var($PHP_SELF, 'show_more_bcc',0); $show = true; } else { $url = set_url_var($PHP_SELF, 'show_more_bcc',1); } } $cnt = count($ary); $i = 0; while ($i < $cnt) { $ary[$i] = htmlspecialchars($ary[$i]->getAddress()); if ($string) { $string .= '
'.$ary[$i]; } else { $string = $ary[$i]; if ($cnt>1) { $string .= ' ('._("less").')'; } else { $string .= '">'._("more").')'; break; } } } $i++; } } else { $string = ''; } return $string; } function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee) { global $msn_user_support, $default_use_mdn, $draft_folder, $sent_folder, $default_use_priority, $show_xmailer_default, $mdn_user_support, $PHP_SELF, $javascript_on; $header = $message->header; $env = array(); $env[_("Subject")] = htmlspecialchars($header->subject); $from_o = $header->from; if (is_object($from_o)) { $from_name = $from_o->getAddress(); } else { $from_name = _("Unknown sender"); } $env[_("From")] = htmlspecialchars($from_name); $env[_("Date")] = getLongDateString($header->date); $env[_("To")] = formatRecipientString($header->to, "to"); $env[_("Cc")] = formatRecipientString($header->cc, "cc"); $env[_("Bcc")] = formatRecipientString($header->bcc, "bcc"); if ($default_use_priority) { $env[_("Priority")] = getPriorityStr($header->priority); } if ($show_xmailer_default) { $env[_("Mailer")] = $header->xmailer; } if ($default_use_mdn) { if ($mdn_user_support) { if ($header->dnt) { if ($message->is_mdnsent) { $env[_("Read receipt")] = _("send"); } else { if ( !($mailbox == $draft_folder || $mailbox == $sent_folder || $message->is_deleted)) { $mdn_url = $PHP_SELF . '&sendreceipt=1'; if ($FirstTimeSee && $javascript_on) { $script = ''. "\n"; echo $script; } $env[_("Read receipt")] = _("requested") . ' ['. _("Send read receipt now") .']'; } else { $env[_("Read receipt")] = _("requested"); } } } } } $s = ''; foreach ($env as $key => $val) { if ($val) { $s .= ''; $s .= html_tag( 'td', ''.$key.':  ', 'right', $color[0], 'valign="top" width="20%"') . "\n"; $s .= html_tag( 'td', $val, 'left', $color[0], 'valign="top" width="80%"'); $s .= "\n"; } } $s .= '
'; echo $s; } function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response) { global $base_uri, $sent_folder, $draft_folder, $where, $what, $color, $sort, $startMessage, $compose_new_win, $PHP_SELF, $save_as_draft; $topbar_delimiter = ' | '; $urlMailbox = urlencode($mailbox); $s = '
'; $msgs_url = $base_uri . 'src/'; if (isset($where) && isset($what)) { $msgs_url .= 'search.php?where='.urlencode($where). '&what='.urlencode($what).'&mailbox='.$urlMailbox; $msgs_str = _("Search results"); } else { $msgs_url .= 'right_main.php?sort='.$sort.'&startMessage='. $startMessage.'&mailbox='.$urlMailbox; $msgs_str = _("Message List"); } $s .= ''.$msgs_str.''; $s .= $topbar_delimiter; $delete_url = $base_uri . 'src/delete_message.php?mailbox='.$urlMailbox. '&message='.$passed_id.'&'; if (!(isset($passed_ent_id) && $passed_ent_id)) { if ($where && $what) { $delete_url .= 'where=' . urlencode($where) . '&what=' . urlencode($what); } else { $delete_url .= 'sort='. $sort . '&startMessage='. $startMessage; } $s .= ''._("Delete").''; } $comp_uri = $base_uri . 'src/compose.php'. '?passed_id='.$passed_id. '&mailbox='.$urlMailbox. (isset($passed_ent_id)?'&passed_ent_id='.$passed_ent_id:''); if (($mailbox == $draft_folder) && ($save_as_draft)) { $comp_alt_uri = $comp_uri . '&action=draft'; $comp_alt_string = _("Resume Draft"); } else if ($mailbox == $sent_folder) { $comp_alt_uri = $comp_uri . '&action=edit_as_new'; $comp_alt_string = _("Edit Message as New"); } if (isset($comp_alt_uri)) { $s .= $topbar_delimiter; if ($compose_new_win == '1') { $s .= ''.$comp_alt_string.''; } else { $s .= ''.$comp_alt_string.''; } } $s .= ''; if (!(isset($where) && isset($what)) && !$passed_ent_id) { $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id); $next = findNextMessage($passed_id); if ($prev != -1) { $uri = $base_uri . 'src/read_body.php?passed_id='.$prev. '&mailbox='.$urlMailbox.'&sort='.$sort. '&startMessage='.$startMessage.'&show_more=0'; $s .= ''._("Previous").''; } else { $s .= _("Previous"); } $s .= $topbar_delimiter; if ($next != -1) { $uri = $base_uri . 'src/read_body.php?passed_id='.$next. '&mailbox='.$urlMailbox.'&sort='.$sort. '&startMessage='.$startMessage.'&show_more=0'; $s .= ''._("Next").''; } else { $s .= _("Next"); } } else if (isset($passed_ent_id) && $passed_ent_id) { /* code for navigating through attached message/rfc822 messages */ $url = set_url_var($PHP_SELF, 'passed_ent_id',0); $s .= ''._("View Message").''; $par_ent_id = $message->parent->entity_id; if ($par_ent_id) { $par_ent_id = substr($par_ent_id,0,-2); $s .= $topbar_delimiter; $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id); $s .= ''._("Up").''; } } $s .= ''; $comp_action_uri = $comp_uri . '&action=forward'; if ($compose_new_win == '1') { $s .= ''._("Forward").''; } else { $s .= ''._("Forward").''; } $s .= $topbar_delimiter; $comp_action_uri = decodeHeader($comp_uri . '&action=reply'); if ($compose_new_win == '1') { $s .= ''._("Reply").''; } else { $s .= ''._("Reply").''; } $s .= $topbar_delimiter; $comp_action_uri = $comp_uri . '&action=reply_all'; if ($compose_new_win == '1') { $s .= ''._("Reply All").''; } else { $s .= ''._("Reply All").''; } $s .= '
'; echo $s; } function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) { global $QUERY_STRING, $base_uri; $urlMailbox = urlencode($mailbox); $s = ''. "\n". ''; echo '
'; $url = $base_uri.'src/view_header.php?'.$QUERY_STRING; $s .= ''.("View Full Header").''; /* Output the printer friendly link if we are in subtle mode. */ $s .= ' | '. printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color); echo $s; do_hook("read_body_header_right"); echo '
'."\n"; } /* * Main of read_boby.php -------------------------------------------------- */ /* Urled vars ---------- $passed_id */ global $uid_support, $sqimap_capabilities; if (isset($mailbox)) { $mailbox = urldecode( $mailbox ); } $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true); if (!isset($messages)) { $messages = array(); session_register('messages'); } /** * $message contains all information about the message * including header and body */ $uidvalidity = $mbx_response['UIDVALIDITY']; if (!isset($messages[$uidvalidity])) { $messages[$uidvalidity] = array(); } if (!isset($messages[$uidvalidity][$passed_id]) || !$uid_support) { $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); $messages[$uidvalidity][$passed_id] = $message; } else { // $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); $message = $messages[$uidvalidity][$passed_id]; } $FirstTimeSee = !$message->is_seen; $message->is_seen = true; $messages[$uidvalidity][$passed_id] = $message; if (isset($passed_ent_id)) { $message = $message->getEntity($passed_ent_id); $message->id = $passed_id; $message->mailbox = $mailbox; } else { $passed_ent_id = 0; } $header = $message->header; //do_hook('html_top'); /* ============================================================================= * block for handling incoming url vars * * ============================================================================= */ if (isset($sendreceipt)) { if ( !$message->is_mdnsent ) { if (isset($identity) ) { $final_recipient = getPref($data_dir, $username, 'email_address' . '0', '' ); } else { $final_recipient = getPref($data_dir, $username, 'email_address', '' ); } $final_recipient = trim($final_recipient); if ($final_recipient == '' ) { $final_recipient = getPref($data_dir, $username, 'email_address', '' ); } $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]); if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message ) > 0 && $supportMDN ) { ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id, $uid_support); $message->is_mdnsent = true; $messages[$uidvalidity][$passed_id]=$message; } ClearAttachments(); } } /* ============================================================================= * end block for handling incoming url vars * * ============================================================================= */ $msgs[$passed_id]['FLAG_SEEN'] = true; $messagebody = ''; $ent_ar = $message->findDisplayEntity(array()); for ($i = 0; $i < count($ent_ar); $i++) { $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox); $messagebody .= '
'; } displayPageHeader($color, $mailbox); do_hook('read_body_top'); formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response); formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee); do_hook("read_body_header"); formatToolbar($mailbox,$passed_id,$passed_ent_id,$message, $color); echo ''; echo ''; echo ''; echo '
'.$messagebody.'
'.formatAttachments($message,$ent_ar,$mailbox, $passed_id).'
'; /* show attached images inline -- if pref'fed so */ if (($attachment_common_show_images) && is_array($attachment_common_show_images_list)) { foreach ($attachment_common_show_images_list as $img) { $imgurl = '../src/download.php' . '?' . 'passed_id=' . urlencode($img['passed_id']) . '&mailbox=' . urlencode($mailbox) . '&passed_ent_id=' . urlencode($img['ent_id']) . '&absolute_dl=true'; echo html_tag( 'table', "\n" . html_tag( 'tr', "\n" . html_tag( 'td', '' ."\n", 'left' ) ) , 'center', '', 'cellspacing=0 border="0" cellpadding="2"'); } } do_hook('read_body_bottom'); do_hook('html_bottom'); //$message->clean_up(); sqimap_logout($imapConnection); ?>