/** * Function returns number of characters in string. * * Returned number might be different from number of bytes in string, * if $charset is multibyte charset. Detection depends on mbstring * functions. If mbstring does not support tested multibyte charset, * vanilla string length function is used. * @param string $str string * @param string $charset charset * @since 1.5.1 and 1.4.6 * @return integer number of characters in string */ function sq_strlen($str, $charset = null) { // default option if (is_null($charset)) { return strlen($str); } // lowercase charset name $charset = strtolower($charset); // use automatic charset detection, if function call asks for it if ($charset == 'auto') { global $default_charset; set_my_charset(); $charset = $default_charset; } // Use mbstring only with listed charsets $aList_of_mb_charsets = array('utf-8', 'big5', 'gb2312', 'gb18030', 'euc-jp', 'euc-cn', 'euc-tw', 'euc-kr'); // calculate string length according to charset if (in_array($charset, $aList_of_mb_charsets) && in_array($charset, sq_mb_list_encodings())) { $real_length = mb_strlen($str, $charset); } else { // own strlen detection code is removed because missing strpos, // strtoupper and substr implementations break string wrapping. $real_length = strlen($str); } return $real_length; }
function newMail($mailbox = '', $passed_id = '', $passed_ent_id = '', $action = '', $session = '') { global $editor_size, $default_use_priority, $body, $idents, $use_signature, $composesession, $data_dir, $username, $username, $key, $imapServerAddress, $imapPort, $compose_messages, $composeMessage, $body_quote; global $languages, $squirrelmail_language, $default_charset; /* * Set $default_charset to correspond with the user's selection * of language interface. $default_charset global is not correct, * if message is composed in new window. */ set_my_charset(); $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = ''; $mailprio = 3; if ($passed_id) { $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); sqimap_mailbox_select($imapConnection, $mailbox); $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); $body = ''; if ($passed_ent_id) { /* redefine the messsage in case of message/rfc822 */ $message = $message->getEntity($passed_ent_id); /* message is an entity which contains the envelope and type0=message * and type1=rfc822. The actual entities are childs from * $message->entities[0]. That's where the encoding and is located */ $entities = $message->entities[0]->findDisplayEntity(array(), $alt_order = array('text/plain')); if (!count($entities)) { $entities = $message->entities[0]->findDisplayEntity(array(), $alt_order = array('text/plain', 'html/plain')); } $orig_header = $message->rfc822_header; /* here is the envelope located */ /* redefine the message for picking up the attachments */ $message = $message->entities[0]; } else { $entities = $message->findDisplayEntity(array(), $alt_order = array('text/plain')); if (!count($entities)) { $entities = $message->findDisplayEntity(array(), $alt_order = array('text/plain', 'html/plain')); } $orig_header = $message->rfc822_header; } $encoding = $message->header->encoding; $type0 = $message->type0; $type1 = $message->type1; foreach ($entities as $ent) { $msg = $message->getEntity($ent); $type0 = $msg->type0; $type1 = $msg->type1; $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent); $body_part_entity = $message->getEntity($ent); $bodypart = decodeBody($unencoded_bodypart, $body_part_entity->header->encoding); if ($type1 == 'html') { $bodypart = str_replace("\n", ' ', $bodypart); $bodypart = preg_replace(array('/<\\/?p>/i', '/<div><\\/div>/i', '/<br\\s*(\\/)*>/i', '/<\\/?div>/i'), "\n", $bodypart); $bodypart = str_replace(array(' ', '>', '<'), array(' ', '>', '<'), $bodypart); $bodypart = strip_tags($bodypart); } if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode')) { if (mb_detect_encoding($bodypart) != 'ASCII') { $bodypart = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $bodypart); } } if (isset($body_part_entity->header->parameters['charset'])) { $actual = $body_part_entity->header->parameters['charset']; } else { $actual = 'us-ascii'; } if ($actual && is_conversion_safe($actual) && $actual != $default_charset) { $bodypart = charset_convert($actual, $bodypart, $default_charset, false); } $body .= $bodypart; } if ($default_use_priority) { $mailprio = substr($orig_header->priority, 0, 1); if (!$mailprio) { $mailprio = 3; } } else { $mailprio = ''; } //ClearAttachments($session); $identity = ''; $from_o = $orig_header->from; if (is_array($from_o)) { if (isset($from_o[0])) { $from_o = $from_o[0]; } } if (is_object($from_o)) { $orig_from = $from_o->getAddress(); } else { $orig_from = ''; } $identities = array(); if (count($idents) > 1) { foreach ($idents as $nr => $data) { $enc_from_name = '"' . $data['full_name'] . '" <' . $data['email_address'] . '>'; if ($enc_from_name == $orig_from) { $identity = $nr; break; } $identities[] = $enc_from_name; } $identity_match = $orig_header->findAddress($identities); if ($identity_match) { $identity = $identity_match; } } switch ($action) { case 'draft': $use_signature = FALSE; $composeMessage->rfc822_header = $orig_header; $send_to = decodeHeader($orig_header->getAddr_s('to'), false, false, true); $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'), false, false, true); $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'), false, false, true); $send_from = $orig_header->getAddr_s('from'); $send_from_parts = new AddressStructure(); $send_from_parts = $orig_header->parseAddress($send_from); $send_from_add = $send_from_parts->mailbox . '@' . $send_from_parts->host; $identities = get_identities(); if (count($identities) > 0) { foreach ($identities as $iddata) { if ($send_from_add == $iddata['email_address']) { $identity = $iddata['index']; break; } } } $subject = decodeHeader($orig_header->subject, false, false, true); /* remember the references and in-reply-to headers in case of an reply */ $composeMessage->rfc822_header->more_headers['References'] = $orig_header->references; $composeMessage->rfc822_header->more_headers['In-Reply-To'] = $orig_header->in_reply_to; // rewrap the body to clean up quotations and line lengths sqBodyWrap($body, $editor_size); $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); break; case 'edit_as_new': $send_to = decodeHeader($orig_header->getAddr_s('to'), false, false, true); $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'), false, false, true); $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'), false, false, true); $subject = decodeHeader($orig_header->subject, false, false, true); $mailprio = $orig_header->priority; $orig_from = ''; $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); // rewrap the body to clean up quotations and line lengths sqBodyWrap($body, $editor_size); break; case 'forward': $send_to = ''; $subject = getforwardSubject(decodeHeader($orig_header->subject, false, false, true)); $body = getforwardHeader($orig_header) . $body; // the logic for calling sqUnWordWrap here would be to allow the browser to wrap the lines // forwarded message text should be as undisturbed as possible, so commenting out this call // sqUnWordWrap($body); $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); //add a blank line after the forward headers $body = "\n" . $body; break; case 'forward_as_attachment': $subject = getforwardSubject(decodeHeader($orig_header->subject, false, false, true)); $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection); $body = ''; break; case 'reply_all': if (isset($orig_header->mail_followup_to) && $orig_header->mail_followup_to) { $send_to = $orig_header->getAddr_s('mail_followup_to'); } else { $send_to_cc = replyAllString($orig_header); $send_to_cc = decodeHeader($send_to_cc, false, false, true); } case 'reply': // skip this if send_to was already set right above here if (!$send_to) { $send_to = $orig_header->reply_to; if (is_array($send_to) && count($send_to)) { $send_to = $orig_header->getAddr_s('reply_to'); } else { if (is_object($send_to)) { /* unneccesarry, just for failsafe purpose */ $send_to = $orig_header->getAddr_s('reply_to'); } else { $send_to = $orig_header->getAddr_s('from'); } } } $send_to = decodeHeader($send_to, false, false, true); $subject = decodeHeader($orig_header->subject, false, false, true); $subject = str_replace('"', "'", $subject); $subject = trim($subject); if (substr(strtolower($subject), 0, 3) != 're:') { $subject = 'Re: ' . $subject; } /* this corrects some wrapping/quoting problems on replies */ $rewrap_body = explode("\n", $body); $from = is_array($orig_header->from) ? $orig_header->from[0] : $orig_header->from; $body = ''; $strip_sigs = getPref($data_dir, $username, 'strip_sigs'); foreach ($rewrap_body as $line) { if ($strip_sigs && substr($line, 0, 3) == '-- ') { break; } if (preg_match("/^(>+)/", $line, $matches)) { $gt = $matches[1]; $body .= $body_quote . str_replace("\n", "\n{$body_quote}{$gt} ", rtrim($line)) . "\n"; } else { $body .= $body_quote . (!empty($body_quote) ? ' ' : '') . str_replace("\n", "\n{$body_quote}" . (!empty($body_quote) ? ' ' : ''), rtrim($line)) . "\n"; } } //rewrap the body to clean up quotations and line lengths $body = sqBodyWrap($body, $editor_size); $body = getReplyCitation($from, $orig_header->date) . $body; $composeMessage->reply_rfc822_header = $orig_header; break; default: break; } $compose_messages[$session] = $composeMessage; sqsession_register($compose_messages, 'compose_messages'); session_write_close(); sqimap_logout($imapConnection); } $ret = array('send_to' => $send_to, 'send_to_cc' => $send_to_cc, 'send_to_bcc' => $send_to_bcc, 'subject' => $subject, 'mailprio' => $mailprio, 'body' => $body, 'identity' => $identity); return $ret; }
function SendMDN($mailbox, $passed_id, $sender, $message, $imapConnection) { global $username, $attachment_dir, $color, $default_move_to_sent, $version, $attachments, $squirrelmail_language, $default_charset, $languages, $useSendmail, $domain, $sent_folder, $popuser, $data_dir; sqgetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER); $header = $message->rfc822_header; $hashed_attachment_dir = getHashedDir($username, $attachment_dir); $rfc822_header = new Rfc822Header(); $content_type = new ContentType('multipart/report'); $content_type->properties['report-type'] = 'disposition-notification'; set_my_charset(); if ($default_charset) { $content_type->properties['charset'] = $default_charset; } $rfc822_header->content_type = $content_type; $rfc822_header->to[] = $header->dnt; $rfc822_header->subject = _("Read:") . ' ' . decodeHeader($header->subject, true, false); // FIXME: use identity.php from SM 1.5. Change this also in compose.php $reply_to = ''; if (isset($identity) && $identity != 'default') { $from_mail = getPref($data_dir, $username, 'email_address' . $identity); $full_name = getPref($data_dir, $username, 'full_name' . $identity); $from_addr = '"' . $full_name . '" <' . $from_mail . '>'; $reply_to = getPref($data_dir, $username, 'reply_to' . $identity); } else { $from_mail = getPref($data_dir, $username, 'email_address'); $full_name = getPref($data_dir, $username, 'full_name'); $from_addr = '"' . $full_name . '" <' . $from_mail . '>'; $reply_to = getPref($data_dir, $username, 'reply_to'); } // Patch #793504 Return Receipt Failing with <@> from Tim Craig (burny_md) // This merely comes from compose.php and only happens when there is no // email_addr specified in user's identity (which is the startup config) if (ereg("^([^@%/]+)[@%/](.+)\$", $username, $usernamedata)) { $popuser = $usernamedata[1]; $domain = $usernamedata[2]; unset($usernamedata); } else { $popuser = $username; } if (!$from_mail) { $from_mail = "{$popuser}@{$domain}"; $from_addr = $from_mail; } $rfc822_header->from = $rfc822_header->parseAddress($from_addr, true); if ($reply_to) { $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to, true); } // part 1 (RFC2298) $senton = getLongDateString($header->date, $header->date_unparsed); $to_array = $header->to; $to = ''; foreach ($to_array as $line) { $to .= ' ' . $line->getAddress(); } $now = getLongDateString(time()); set_my_charset(); $body = _("Your message") . "\r\n\r\n" . "\t" . _("To") . ': ' . decodeHeader($to, false, false, true) . "\r\n" . "\t" . _("Subject") . ': ' . decodeHeader($header->subject, false, false, true) . "\r\n" . "\t" . _("Sent") . ': ' . $senton . "\r\n" . "\r\n" . sprintf(_("Was displayed on %s"), $now); $special_encoding = ''; if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body); if (strtolower($default_charset) == 'iso-2022-jp') { if (mb_detect_encoding($body) == 'ASCII') { $special_encoding = '8bit'; } else { $body = mb_convert_encoding($body, 'JIS'); $special_encoding = '7bit'; } } } elseif (sq_is8bit($body)) { // detect 8bit symbols added by translations $special_encoding = '8bit'; } $part1 = new Message(); $part1->setBody($body); $mime_header = new MessageHeader(); $mime_header->type0 = 'text'; $mime_header->type1 = 'plain'; if ($special_encoding) { $mime_header->encoding = $special_encoding; } else { $mime_header->encoding = '7bit'; } if ($default_charset) { $mime_header->parameters['charset'] = $default_charset; } $part1->mime_header = $mime_header; // part2 (RFC2298) $original_recipient = $to; $original_message_id = $header->message_id; $report = "Reporting-UA : {$SERVER_NAME} ; SquirrelMail (version {$version}) \r\n"; if ($original_recipient != '') { $report .= "Original-Recipient : {$original_recipient}\r\n"; } $final_recipient = $sender; $report .= "Final-Recipient: rfc822; {$final_recipient}\r\n" . "Original-Message-ID : {$original_message_id}\r\n" . "Disposition: manual-action/MDN-sent-manually; displayed\r\n"; $part2 = new Message(); $part2->setBody($report); $mime_header = new MessageHeader(); $mime_header->type0 = 'message'; $mime_header->type1 = 'disposition-notification'; $mime_header->encoding = '7bit'; $part2->mime_header = $mime_header; $composeMessage = new Message(); $composeMessage->rfc822_header = $rfc822_header; $composeMessage->addEntity($part1); $composeMessage->addEntity($part2); if ($useSendmail) { require_once SM_PATH . 'class/deliver/Deliver_SendMail.class.php'; global $sendmail_path, $sendmail_args; // Check for outdated configuration if (!isset($sendmail_args)) { if ($sendmail_path == '/var/qmail/bin/qmail-inject') { $sendmail_args = ''; } else { $sendmail_args = '-i -t'; } } $deliver = new Deliver_SendMail(array('sendmail_args' => $sendmail_args)); $stream = $deliver->initStream($composeMessage, $sendmail_path); } else { require_once SM_PATH . 'class/deliver/Deliver_SMTP.class.php'; $deliver = new Deliver_SMTP(); global $smtpServerAddress, $smtpPort, $pop_before_smtp, $pop_before_smtp_host; $authPop = isset($pop_before_smtp) && $pop_before_smtp ? true : false; $user = ''; $pass = ''; if (empty($pop_before_smtp_host)) { $pop_before_smtp_host = $smtpServerAddress; } get_smtp_user($user, $pass); $stream = $deliver->initStream($composeMessage, $domain, 0, $smtpServerAddress, $smtpPort, $user, $pass, $authPop, $pop_before_smtp_host); } $success = false; if ($stream) { $deliver->mail($composeMessage, $stream); $success = $deliver->finalizeStream($stream); } if (!$success) { $msg = _("Message not sent.") . ' ' . _("Server replied:") . "\n<blockquote>\n" . $deliver->dlv_msg . '<br />' . $deliver->dlv_ret_nr . ' ' . $deliver->dlv_server_msg . "</blockquote>\n\n"; require_once SM_PATH . 'functions/display_messages.php'; plain_error_message($msg, $color); } else { unset($deliver); // copy message to sent folder $move_to_sent = getPref($data_dir, $username, 'move_to_sent'); if (isset($default_move_to_sent) && $default_move_to_sent != 0) { $svr_allow_sent = true; } else { $svr_allow_sent = false; } if (isset($sent_folder) && ($sent_folder != '' || $sent_folder != 'none') && sqimap_mailbox_exists($imapConnection, $sent_folder)) { $fld_sent = true; } else { $fld_sent = false; } if (isset($move_to_sent) && $move_to_sent != 0 || !isset($move_to_sent)) { $lcl_allow_sent = true; } else { $lcl_allow_sent = false; } if ($fld_sent && $svr_allow_sent && !$lcl_allow_sent || $fld_sent && $lcl_allow_sent) { require_once SM_PATH . 'class/deliver/Deliver_IMAP.class.php'; $imap_deliver = new Deliver_IMAP(); $imap_deliver->mail($composeMessage, $imapConnection, 0, 0, $imapConnection, $sent_folder); unset($imap_deliver); } } return $success; }
header('Pragma: '); header('Cache-Control: cache'); /* globals */ sqgetGlobalVar('key', $key, SQ_COOKIE); sqgetGlobalVar('username', $username, SQ_SESSION); sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION); sqgetGlobalVar('mailbox_cache', $mailbox_cache, SQ_SESSION); sqgetGlobalVar('messages', $messages, SQ_SESSION); sqgetGlobalVar('mailbox', $mailbox, SQ_GET); sqgetGlobalVar('ent_id', $ent_id, SQ_GET); sqgetGlobalVar('absolute_dl', $absolute_dl, SQ_GET); if (sqgetGlobalVar('passed_id', $temp, SQ_GET)) { $passed_id = (int) $temp; } global $default_charset; set_my_charset(); /* end globals */ $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); $aMailbox = sqm_api_mailbox_select($imapConnection, $mailbox, array(), array()); if (isset($aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT']) && is_object($aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'])) { $message = $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT']; } else { $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'] = $message; } //$mbx_response = sqimap_mailbox_select($imapConnection, $mailbox); //$message = &$messages[$mbx_response['UIDVALIDITY']]["$passed_id"]; //if (!is_object($message)) { // $message = sqimap_get_message($imapConnection,$passed_id, $mailbox); //} $subject = $message->rfc822_header->subject;
/** * Converts string from given charset to charset, that can be displayed by user translation. * * Function by default returns html encoded strings, if translation uses different encoding. * If Japanese translation is used - function returns string converted to euc-jp * If $charset is not supported - function returns unconverted string. * * sanitizing of html tags is also done by this function. * * @param string $charset * @param string $string Text to be decoded * @param boolean $force_decode converts string to html without $charset!=$default_charset check. * Argument is available since 1.5.1 and 1.4.5. * @param boolean $save_html disables htmlspecialchars() in order to preserve * html formating. Use with care. Available since 1.5.1 and 1.4.6 * @return string decoded string */ function charset_decode($charset, $string, $force_decode = false, $save_html = false) { global $languages, $squirrelmail_language, $default_charset; if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { $string = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $string); } /* All HTML special characters are 7 bit and can be replaced first */ if (!$save_html) { $string = htmlspecialchars($string); } $charset = strtolower($charset); set_my_charset(); // Don't do conversion if charset is the same. if (!$force_decode && $charset == strtolower($default_charset)) { return $string; } /* controls cpu and memory intensive decoding cycles */ global $aggressive_decoding; $aggressive_decoding = false; $decode = fixcharset($charset); $decodefile = SM_PATH . 'functions/decode/' . $decode . '.php'; if ($decode != 'index' && file_exists($decodefile)) { include_once $decodefile; $ret = call_user_func('charset_decode_' . $decode, $string, $save_html); } else { $ret = $string; } return $ret; }
/** * Converts string from given charset to charset, that can be displayed by user translation. * * Function by default returns html encoded strings, if translation uses different encoding. * If Japanese translation is used - function returns string converted to euc-jp * If iconv or recode functions are enabled and translation uses utf-8 - function returns utf-8 encoded string. * If $charset is not supported - function returns unconverted string. * * sanitizing of html tags is also done by this function. * * @param string $charset * @param string $string Text to be decoded * @return string decoded string */ function charset_decode($charset, $string) { global $languages, $squirrelmail_language, $default_charset; global $use_php_recode, $use_php_iconv, $aggressive_decoding; if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode')) { $string = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $string); } $charset = strtolower($charset); set_my_charset(); // Variables that allow to use functions without function_exist() calls if (!isset($use_php_recode) || $use_php_recode == "") { $use_php_recode = false; } if (!isset($use_php_iconv) || $use_php_iconv == "") { $use_php_iconv = false; } // Don't do conversion if charset is the same. if ($charset == strtolower($default_charset)) { return htmlspecialchars($string); } // catch iso-8859-8-i thing if ($charset == "iso-8859-8-i") { $charset = "iso-8859-8"; } /* * Recode converts html special characters automatically if you use * 'charset..html' decoding. There is no documented way to put -d option * into php recode function call. */ if ($use_php_recode) { if ($default_charset == "utf-8") { // other charsets can be converted to utf-8 without loss. // and output string is smaller $string = recode_string($charset . "..utf-8", $string); return htmlspecialchars($string); } else { $string = recode_string($charset . "..html", $string); // recode does not convert single quote, htmlspecialchars does. $string = str_replace("'", ''', $string); return $string; } } // iconv functions does not have html target and can be used only with utf-8 if ($use_php_iconv && $default_charset == 'utf-8') { $string = iconv($charset, $default_charset, $string); return htmlspecialchars($string); } // If we don't use recode and iconv, we'll do it old way. /* All HTML special characters are 7 bit and can be replaced first */ $string = htmlspecialchars($string); /* controls cpu and memory intensive decoding cycles */ if (!isset($aggressive_decoding) || $aggressive_decoding == "") { $aggressive_decoding = false; } $decode = fixcharset($charset); $decodefile = SM_PATH . 'functions/decode/' . $decode . '.php'; if (file_exists($decodefile)) { include_once $decodefile; $ret = call_user_func('charset_decode_' . $decode, $string); } else { $ret = $string; } return $ret; }
function imap_utf7_decode_local($s) { global $languages, $squirrelmail_language; if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { return $languages[$squirrelmail_language]['XTRA_CODE']('utf7-imap_decode', $s); } if ($s == '') { //If empty, don't bother return ''; } global $default_charset; set_my_charset(); //must be called before using $default_charset if (strtolower($default_charset) != 'iso-8859-1' && $default_charset != '') { $utf7_s = sqimap_mb_convert_encoding($s, $default_charset, 'UTF7-IMAP', $default_charset); if ($utf7_s != '') { return $utf7_s; } } // Later code works only for ISO-8859-1 $b64_s = ''; $iso_8859_1_s = ''; for ($i = 0, $len = strlen($s); $i < $len; $i++) { $c = $s[$i]; if (strlen($b64_s) > 0) { if ($c == '-') { if ($b64_s == '&') { $iso_8859_1_s = $iso_8859_1_s . '&'; } else { $iso_8859_1_s = $iso_8859_1_s . decodeBASE64(substr($b64_s, 1)); } $b64_s = ''; } else { $b64_s = $b64_s . $c; } } else { if ($c == '&') { $b64_s = '&'; } else { $iso_8859_1_s = $iso_8859_1_s . $c; } } } return $iso_8859_1_s; }
function newMail($mailbox = '', $passed_id = '', $passed_ent_id = '', $action = '', $session = '') { global $editor_size, $default_use_priority, $body, $idents, $use_signature, $data_dir, $username, $key, $imapServerAddress, $imapPort, $imap_stream_options, $composeMessage, $body_quote, $request_mdn, $request_dr, $mdn_user_support, $languages, $squirrelmail_language, $default_charset, $do_not_reply_to_self; /* * Set $default_charset to correspond with the user's selection * of language interface. $default_charset global is not correct, * if message is composed in new window. */ set_my_charset(); $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = ''; $mailprio = 3; if ($passed_id) { $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0, $imap_stream_options); sqimap_mailbox_select($imapConnection, $mailbox); $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); $body = ''; if ($passed_ent_id) { /* redefine the messsage in case of message/rfc822 */ $message = $message->getEntity($passed_ent_id); /* message is an entity which contains the envelope and type0=message * and type1=rfc822. The actual entities are childs from * $message->entities[0]. That's where the encoding and is located */ $entities = $message->entities[0]->findDisplayEntity(array(), $alt_order = array('text/plain')); if (!count($entities)) { $entities = $message->entities[0]->findDisplayEntity(array(), $alt_order = array('text/plain', 'text/html')); } $orig_header = $message->rfc822_header; /* here is the envelope located */ /* redefine the message for picking up the attachments */ $message = $message->entities[0]; } else { $entities = $message->findDisplayEntity(array(), $alt_order = array('text/plain')); if (!count($entities)) { $entities = $message->findDisplayEntity(array(), $alt_order = array('text/plain', 'text/html')); } $orig_header = $message->rfc822_header; } $type0 = $message->type0; $type1 = $message->type1; foreach ($entities as $ent) { $msg = $message->getEntity($ent); $type0 = $msg->type0; $type1 = $msg->type1; $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent); $body_part_entity = $message->getEntity($ent); $bodypart = decodeBody($unencoded_bodypart, $body_part_entity->header->encoding); if ($type1 == 'html') { $bodypart = str_replace("\n", ' ', $bodypart); $bodypart = preg_replace(array('/<\\/?p>/i', '/<div><\\/div>/i', '/<br\\s*(\\/)*>/i', '/<\\/?div>/i'), "\n", $bodypart); $bodypart = str_replace(array(' ', '>', '<'), array(' ', '>', '<'), $bodypart); $bodypart = strip_tags($bodypart); } if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode')) { if (mb_detect_encoding($bodypart) != 'ASCII') { $bodypart = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $bodypart); } } // charset encoding in compose form stuff if (isset($body_part_entity->header->parameters['charset'])) { $actual = $body_part_entity->header->parameters['charset']; } else { $actual = 'us-ascii'; } if ($actual && is_conversion_safe($actual) && $actual != $default_charset) { $bodypart = charset_convert($actual, $bodypart, $default_charset, false); } // end of charset encoding in compose $body .= $bodypart; } if ($default_use_priority) { $mailprio = substr($orig_header->priority, 0, 1); if (!$mailprio) { $mailprio = 3; } } else { $mailprio = ''; } $from_o = $orig_header->from; if (is_array($from_o)) { if (isset($from_o[0])) { $from_o = $from_o[0]; } } if (is_object($from_o)) { $orig_from = $from_o->getAddress(); } else { $orig_from = ''; } $identities = array(); if (count($idents) > 1) { foreach ($idents as $nr => $data) { $enc_from_name = '"' . $data['full_name'] . '" <' . $data['email_address'] . '>'; $identities[] = $enc_from_name; } $identity_match = $orig_header->findAddress($identities); if ($identity_match !== FALSE) { $identity = $identity_match; } } switch ($action) { case 'draft': $use_signature = FALSE; $composeMessage->rfc822_header = $orig_header; $send_to = decodeHeader($orig_header->getAddr_s('to'), false, false, true); $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'), false, false, true); $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'), false, false, true); $send_from = $orig_header->getAddr_s('from'); $send_from_parts = new AddressStructure(); $send_from_parts = $orig_header->parseAddress($send_from); $send_from_add = $send_from_parts->mailbox . '@' . $send_from_parts->host; $identity = find_identity(array($send_from_add)); $subject = decodeHeader($orig_header->subject, false, false, true); // Remember the receipt settings $request_mdn = $mdn_user_support && !empty($orig_header->dnt) ? '1' : '0'; $request_dr = $mdn_user_support && !empty($orig_header->drnt) ? '1' : '0'; /* remember the references and in-reply-to headers in case of an reply */ //FIXME: it would be better to fiddle with headers inside of the message object or possibly when delivering the message to its destination (drafts folder?); is this possible? $composeMessage->rfc822_header->more_headers['References'] = $orig_header->references; $composeMessage->rfc822_header->more_headers['In-Reply-To'] = $orig_header->in_reply_to; // rewrap the body to clean up quotations and line lengths sqBodyWrap($body, $editor_size); $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); break; case 'edit_as_new': $send_to = decodeHeader($orig_header->getAddr_s('to'), false, false, true); $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'), false, false, true); $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'), false, false, true); $subject = decodeHeader($orig_header->subject, false, false, true); $mailprio = $orig_header->priority; $orig_from = ''; $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); // rewrap the body to clean up quotations and line lengths sqBodyWrap($body, $editor_size); break; case 'forward': $send_to = ''; $subject = getforwardSubject(decodeHeader($orig_header->subject, false, false, true)); $body = getforwardHeader($orig_header) . $body; // the logic for calling sqUnWordWrap here would be to allow the browser to wrap the lines // forwarded message text should be as undisturbed as possible, so commenting out this call // sqUnWordWrap($body); $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); //add a blank line after the forward headers $body = "\n" . $body; break; case 'forward_as_attachment': $subject = getforwardSubject(decodeHeader($orig_header->subject, false, false, true)); $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection); $subject = decodeHeader($orig_header->subject, false, false, true); $subject = str_replace('"', "'", $subject); $subject = trim($subject); if (substr(strtolower($subject), 0, 4) != 'fwd:') { $subject = 'Fwd: ' . $subject; } $body = ''; break; case 'reply_all': if (isset($orig_header->mail_followup_to) && $orig_header->mail_followup_to) { $send_to = $orig_header->getAddr_s('mail_followup_to'); } else { $send_to_cc = replyAllString($orig_header); $send_to_cc = decodeHeader($send_to_cc, false, false, true); $send_to_cc = str_replace('""', '"', $send_to_cc); } case 'reply': // skip this if send_to was already set right above here if (!$send_to) { $send_to = $orig_header->reply_to; if (is_array($send_to) && count($send_to)) { $send_to = $orig_header->getAddr_s('reply_to', ',', FALSE, TRUE); } else { if (is_object($send_to)) { /* unneccesarry, just for failsafe purpose */ $send_to = $orig_header->getAddr_s('reply_to', ',', FALSE, TRUE); } else { $send_to = $orig_header->getAddr_s('from', ',', FALSE, TRUE); } } } $send_to = decodeHeader($send_to, false, false, true); $send_to = str_replace('""', '"', $send_to); // If user doesn't want replies to her own messages // going back to herself (instead send again to the // original recipient of the message being replied to), // then iterate through identities, checking if the TO // field is one of them (if the reply is to ourselves) // // Note we don't bother if the original message doesn't // have anything in the TO field itself (because that's // what we use if we change the recipient to be that of // the previous message) // if ($do_not_reply_to_self && !empty($orig_header->to)) { $orig_to = ''; foreach ($idents as $id) { if (!empty($id['email_address']) && strpos($send_to, $id['email_address']) !== FALSE) { // if this is a reply-all, the original recipient // is already in the CC field, so we can just blank // the recipient (TO field) (as long as the CC field // isn't empty that is)... but then move the CC into // the TO, so TO isn't empty // if ($action == 'reply_all' && !empty($send_to_cc)) { $orig_to = $send_to_cc; $send_to_cc = ''; break; } $orig_to = $orig_header->to; if (is_array($orig_to) && count($orig_to)) { $orig_to = $orig_header->getAddr_s('to', ',', FALSE, TRUE); } else { if (is_object($orig_to)) { /* unneccesarry, just for failsafe purpose */ $orig_to = $orig_header->getAddr_s('to', ',', FALSE, TRUE); } else { $orig_to = ''; } } $orig_to = decodeHeader($orig_to, false, false, true); $orig_to = str_replace('""', '"', $orig_to); break; } } // if the reply was addressed back to ourselves, // we will send it to the TO of the previous message // if (!empty($orig_to)) { $send_to = $orig_to; // in this case, we also want to reset the FROM // identity as well (it should match the original // *FROM* header instead of TO or CC) // if (count($idents) > 1) { $identity = ''; foreach ($idents as $i => $id) { if (!empty($id['email_address']) && strpos($orig_from, $id['email_address']) !== FALSE) { $identity = $i; break; } } } } } $subject = decodeHeader($orig_header->subject, false, false, true); $subject = str_replace('"', "'", $subject); $subject = trim($subject); if (substr(strtolower($subject), 0, 3) != 're:') { $subject = 'Re: ' . $subject; } /* this corrects some wrapping/quoting problems on replies */ $rewrap_body = explode("\n", $body); $from = is_array($orig_header->from) && !empty($orig_header->from) ? $orig_header->from[0] : $orig_header->from; $body = ''; $strip_sigs = getPref($data_dir, $username, 'strip_sigs'); foreach ($rewrap_body as $line) { if ($strip_sigs && rtrim($line, "\r\n") == '-- ') { break; } if (preg_match("/^(>+)/", $line, $matches)) { $gt = $matches[1]; $body .= $body_quote . str_replace("\n", "\n{$body_quote}{$gt} ", rtrim($line)) . "\n"; } else { $body .= $body_quote . (!empty($body_quote) ? ' ' : '') . str_replace("\n", "\n{$body_quote}" . (!empty($body_quote) ? ' ' : ''), rtrim($line)) . "\n"; } } //rewrap the body to clean up quotations and line lengths $body = sqBodyWrap($body, $editor_size); $body = getReplyCitation($from, $orig_header->date) . $body; $composeMessage->reply_rfc822_header = $orig_header; break; default: break; } //FIXME: we used to register $compose_messages in the session here, but not any more - so do we still need the session_write_close() and sqimap_logout() here? We probably need the IMAP logout, but what about the session closure? session_write_close(); sqimap_logout($imapConnection); } $ret = array('send_to' => $send_to, 'send_to_cc' => $send_to_cc, 'send_to_bcc' => $send_to_bcc, 'subject' => $subject, 'mailprio' => $mailprio, 'body' => $body, 'identity' => $identity); return $ret; }
function newMail($mailbox = '', $passed_id = '', $passed_ent_id = '', $action = '', $session = '') { global $editor_size, $default_use_priority, $body, $idents, $use_signature, $composesession, $data_dir, $username, $username, $key, $imapServerAddress, $imapPort, $compose_messages, $composeMessage, $body_quote; global $languages, $squirrelmail_language, $default_charset; /* * Set $default_charset to correspond with the user's selection * of language interface. $default_charset global is not correct, * if message is composed in new window. */ set_my_charset(); $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = ''; $mailprio = 3; if ($passed_id) { $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); sqimap_mailbox_select($imapConnection, $mailbox); $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); $body = ''; if ($passed_ent_id) { /* redefine the messsage in case of message/rfc822 */ $message = $message->getEntity($passed_ent_id); /* message is an entity which contains the envelope and type0=message * and type1=rfc822. The actual entities are childs from * $message->entities[0]. That's where the encoding and is located */ $entities = $message->entities[0]->findDisplayEntity(array(), $alt_order = array('text/plain')); if (!count($entities)) { $entities = $message->entities[0]->findDisplayEntity(array(), $alt_order = array('text/plain', 'html/plain')); } $orig_header = $message->rfc822_header; /* here is the envelope located */ /* redefine the message for picking up the attachments */ $message = $message->entities[0]; } else { $entities = $message->findDisplayEntity(array(), $alt_order = array('text/plain')); if (!count($entities)) { $entities = $message->findDisplayEntity(array(), $alt_order = array('text/plain', 'html/plain')); } $orig_header = $message->rfc822_header; } $encoding = $message->header->encoding; $type0 = $message->type0; $type1 = $message->type1; foreach ($entities as $ent) { $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent); $body_part_entity = $message->getEntity($ent); $bodypart = decodeBody($unencoded_bodypart, $body_part_entity->header->encoding); if ($type1 == 'html') { $bodypart = str_replace("\n", ' ', $bodypart); $bodypart = preg_replace(array('/<p>/i', '/<br\\s*(\\/)*>/i'), "\n", $bodypart); $bodypart = str_replace(array(' ', '>', '<'), array(' ', '>', '<'), $bodypart); $bodypart = strip_tags($bodypart); } if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { if (mb_detect_encoding($bodypart) != 'ASCII') { $bodypart = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $bodypart); } } // charset encoding in compose form stuff if (isset($body_part_entity->header->parameters['charset'])) { $actual = $body_part_entity->header->parameters['charset']; } else { $actual = 'us-ascii'; } if ($actual && is_conversion_safe($actual) && $actual != $default_charset) { $bodypart = charset_convert($actual, $bodypart, $default_charset, false); } // end of charset encoding in compose $body .= $bodypart; } if ($default_use_priority) { $mailprio = substr($orig_header->priority, 0, 1); if (!$mailprio) { $mailprio = 3; } } else { $mailprio = ''; } $identity = ''; $from_o = $orig_header->from; if (is_array($from_o)) { if (isset($from_o[0])) { $from_o = $from_o[0]; } } if (is_object($from_o)) { $orig_from = $from_o->getAddress(); } else { $orig_from = ''; } $identities = array(); if (count($idents) > 1) { foreach ($idents as $nr => $data) { $enc_from_name = '"' . $data['full_name'] . '" <' . $data['email_address'] . '>'; if ($enc_from_name == $orig_from) { $identity = $nr; break; } $identities[] = $enc_from_name; } $identity_match = $orig_header->findAddress($identities); if ($identity_match) { $identity = $identity_match; } } switch ($action) { case 'draft': $use_signature = FALSE; $composeMessage->rfc822_header = $orig_header; $send_to = decodeHeader($orig_header->getAddr_s('to'), false, false, true); $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'), false, false, true); $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'), false, false, true); // FIXME: ident support? $subject = decodeHeader($orig_header->subject, false, false, true); /* remember the references and in-reply-to headers in case of an reply */ $composeMessage->rfc822_header->more_headers['References'] = $orig_header->references; $composeMessage->rfc822_header->more_headers['In-Reply-To'] = $orig_header->in_reply_to; $body_ary = explode("\n", $body); $cnt = count($body_ary); $body = ''; for ($i = 0; $i < $cnt; $i++) { if (!ereg("^[>\\s]*\$", $body_ary[$i]) || !$body_ary[$i]) { sqWordWrap($body_ary[$i], $editor_size, $default_charset); $body .= $body_ary[$i] . "\n"; } unset($body_ary[$i]); } sqUnWordWrap($body); $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); break; case 'edit_as_new': $send_to = decodeHeader($orig_header->getAddr_s('to'), false, false, true); $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'), false, false, true); $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'), false, false, true); $subject = decodeHeader($orig_header->subject, false, false, true); $mailprio = $orig_header->priority; $orig_from = ''; $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); sqUnWordWrap($body); break; case 'forward': $send_to = ''; $subject = decodeHeader($orig_header->subject, false, false, true); if (substr(strtolower($subject), 0, 4) != 'fwd:' && substr(strtolower($subject), 0, 5) != '[fwd:' && substr(strtolower($subject), 0, 6) != '[ fwd:') { $subject = '[Fwd: ' . $subject . ']'; } $body = getforwardHeader($orig_header) . $body; $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); $body = "\n" . $body; break; case 'forward_as_attachment': $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection); $body = ''; break; case 'reply_all': if (isset($orig_header->mail_followup_to) && $orig_header->mail_followup_to) { $send_to = $orig_header->getAddr_s('mail_followup_to'); } else { $send_to_cc = replyAllString($orig_header); $send_to_cc = decodeHeader($send_to_cc, false, false, true); } case 'reply': if (!$send_to) { $send_to = $orig_header->reply_to; if (is_array($send_to) && count($send_to)) { $send_to = $orig_header->getAddr_s('reply_to'); } else { if (is_object($send_to)) { /* unneccesarry, just for failsafe purpose */ $send_to = $orig_header->getAddr_s('reply_to'); } else { $send_to = $orig_header->getAddr_s('from'); } } } $send_to = decodeHeader($send_to, false, false, true); $subject = decodeHeader($orig_header->subject, false, false, true); $subject = trim($subject); if (substr(strtolower($subject), 0, 3) != 're:') { $subject = 'Re: ' . $subject; } /* this corrects some wrapping/quoting problems on replies */ $rewrap_body = explode("\n", $body); $from = is_array($orig_header->from) && !empty($orig_header->from) ? $orig_header->from[0] : $orig_header->from; sqUnWordWrap($body); $body = ''; $cnt = count($rewrap_body); for ($i = 0; $i < $cnt; $i++) { sqWordWrap($rewrap_body[$i], $editor_size, $default_charset); if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) { $gt = $matches[1]; $body .= $body_quote . str_replace("\n", "\n" . $body_quote . "{$gt} ", rtrim($rewrap_body[$i])) . "\n"; } else { $body .= $body_quote . (!empty($body_quote) ? ' ' : '') . str_replace("\n", "\n" . $body_quote . (!empty($body_quote) ? ' ' : ''), rtrim($rewrap_body[$i])) . "\n"; } unset($rewrap_body[$i]); } $body = getReplyCitation($from, $orig_header->date) . $body; $composeMessage->reply_rfc822_header = $orig_header; break; default: break; } $compose_messages[$session] = $composeMessage; sqsession_register($compose_messages, 'compose_messages'); session_write_close(); sqimap_logout($imapConnection); } $ret = array('send_to' => $send_to, 'send_to_cc' => $send_to_cc, 'send_to_bcc' => $send_to_bcc, 'subject' => $subject, 'mailprio' => $mailprio, 'body' => $body, 'identity' => $identity); return $ret; }
/** * Wrapper that is used to switch between vanilla and multibyte strtoupper * functions. * @param string $string * @param string $charset * @return string * @since 1.5.1 * @link http://www.php.net/strtoupper * @link http://www.php.net/mb_strtoupper */ function sq_strtoupper($string, $charset = 'auto') { // use automatic charset detection, if function call asks for it static $charset_auto, $bUse_mb; if ($charset == 'auto') { if (!isset($charset_auto)) { global $default_charset, $squirrelmail_language; set_my_charset(); $charset = $default_charset; if ($squirrelmail_language == 'ja_JP') { $charset = 'euc-jp'; } $charset_auto = $charset; } else { $charset = $charset_auto; } } $charset = strtolower($charset); // in_array call is expensive => do it once and use a static var for // storing the results if (!isset($bUse_mb)) { if (function_exists('mb_strtoupper') && in_array($charset, sq_mb_list_encodings())) { $bUse_mb = true; } else { $bUse_mb = false; } } if ($bUse_mb) { return mb_strtoupper($string, $charset); } // TODO: add mbstring independent code // use vanilla string functions as last option return strtoupper($string); }
function SendMDN($mailbox, $passed_id, $message, $imapConnection) { global $squirrelmail_language, $default_charset, $default_move_to_sent, $languages, $useSendmail, $domain, $sent_folder, $username, $data_dir; sqgetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER); $header = $message->rfc822_header; $rfc822_header = new Rfc822Header(); $content_type = new ContentType('multipart/report'); $content_type->properties['report-type'] = 'disposition-notification'; set_my_charset(); if ($default_charset) { $content_type->properties['charset'] = $default_charset; } $rfc822_header->content_type = $content_type; $rfc822_header->to[] = $header->dnt; $rfc822_header->subject = _("Read:") . ' ' . decodeHeader($header->subject, true, false); $idents = get_identities(); $needles = array(); if ($header->to) { foreach ($header->to as $message_to) { $needles[] = $message_to->mailbox . '@' . $message_to->host; } } $identity = find_identity($needles); $from_addr = build_from_header($identity); $reply_to = isset($idents[$identity]['reply_to']) ? $idents[$identity]['reply_to'] : ''; // FIXME: this must actually be the envelope address of the orginal message, // but do we have that information? For now the first identity is our best guess. $final_recipient = $idents[0]['email_address']; $rfc822_header->from = $rfc822_header->parseAddress($from_addr, true); if ($reply_to) { $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to, true); } // part 1 (RFC2298) $senton = getLongDateString($header->date, $header->date_unparsed); $to_array = $header->to; $to = ''; foreach ($to_array as $line) { $to .= ' ' . $line->getAddress(); } $now = getLongDateString(time()); set_my_charset(); $body = _("Your message") . "\r\n\r\n" . "\t" . _("To") . ': ' . decodeHeader($to, false, false) . "\r\n" . "\t" . _("Subject") . ': ' . decodeHeader($header->subject, false, false) . "\r\n" . "\t" . _("Sent") . ': ' . $senton . "\r\n" . "\r\n" . sprintf(_("Was displayed on %s"), $now); $special_encoding = ''; if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_encode')) { $body = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_encode', $body); if (strtolower($default_charset) == 'iso-2022-jp') { if (mb_detect_encoding($body) == 'ASCII') { $special_encoding = '8bit'; } else { $body = mb_convert_encoding($body, 'JIS'); $special_encoding = '7bit'; } } } elseif (sq_is8bit($body)) { $special_encoding = '8bit'; } $part1 = new Message(); $part1->setBody($body); $mime_header = new MessageHeader(); $mime_header->type0 = 'text'; $mime_header->type1 = 'plain'; if ($special_encoding) { $mime_header->encoding = $special_encoding; } else { $mime_header->encoding = '7bit'; } if ($default_charset) { $mime_header->parameters['charset'] = $default_charset; } $part1->mime_header = $mime_header; // part2 (RFC2298) $original_recipient = $to; $original_message_id = $header->message_id; $report = "Reporting-UA : {$SERVER_NAME} ; SquirrelMail (version " . SM_VERSION . ") \r\n"; if ($original_recipient != '') { $report .= "Original-Recipient : {$original_recipient}\r\n"; } $report .= "Final-Recipient: rfc822; {$final_recipient}\r\n" . "Original-Message-ID : {$original_message_id}\r\n" . "Disposition: manual-action/MDN-sent-manually; displayed\r\n"; $part2 = new Message(); $part2->setBody($report); $mime_header = new MessageHeader(); $mime_header->type0 = 'message'; $mime_header->type1 = 'disposition-notification'; $mime_header->encoding = '7bit'; $part2->mime_header = $mime_header; $composeMessage = new Message(); $composeMessage->rfc822_header = $rfc822_header; $composeMessage->addEntity($part1); $composeMessage->addEntity($part2); if ($useSendmail) { require_once SM_PATH . 'class/deliver/Deliver_SendMail.class.php'; global $sendmail_path, $sendmail_args; // Check for outdated configuration if (!isset($sendmail_args)) { if ($sendmail_path == '/var/qmail/bin/qmail-inject') { $sendmail_args = ''; } else { $sendmail_args = '-i -t'; } } $deliver = new Deliver_SendMail(array('sendmail_args' => $sendmail_args)); $stream = $deliver->initStream($composeMessage, $sendmail_path); } else { require_once SM_PATH . 'class/deliver/Deliver_SMTP.class.php'; $deliver = new Deliver_SMTP(); global $smtpServerAddress, $smtpPort, $pop_before_smtp, $pop_before_smtp_host; $authPop = isset($pop_before_smtp) && $pop_before_smtp ? true : false; if (empty($pop_before_smtp_host)) { $pop_before_smtp_host = $smtpServerAddress; } get_smtp_user($user, $pass); $stream = $deliver->initStream($composeMessage, $domain, 0, $smtpServerAddress, $smtpPort, $user, $pass, $authPop, $pop_before_smtp_host); } $success = false; if ($stream) { $deliver->mail($composeMessage, $stream); $success = $deliver->finalizeStream($stream); } if (!$success) { $msg = _("Message not sent.") . "\n" . $deliver->dlv_msg; if (!empty($deliver->dlv_server_msg)) { $msg .= "\n" . _("Server replied:") . ' ' . $deliver->dlv_ret_nr . ' ' . nl2br(sm_encode_html_special_chars($deliver->dlv_server_msg)); } plain_error_message($msg); } else { unset($deliver); // move to sent folder // $move_to_sent = getPref($data_dir, $username, 'move_to_sent'); if (isset($default_move_to_sent) && $default_move_to_sent != 0) { $svr_allow_sent = true; } else { $svr_allow_sent = false; } if (isset($sent_folder) && ($sent_folder != '' || $sent_folder != 'none') && sqimap_mailbox_exists($imapConnection, $sent_folder)) { $fld_sent = true; } else { $fld_sent = false; } if (isset($move_to_sent) && $move_to_sent != 0 || !isset($move_to_sent)) { $lcl_allow_sent = true; } else { $lcl_allow_sent = false; } if ($fld_sent && $svr_allow_sent && !$lcl_allow_sent || $fld_sent && $lcl_allow_sent) { $save_reply_with_orig = getPref($data_dir, $username, 'save_reply_with_orig'); if ($save_reply_with_orig) { $sent_folder = $mailbox; } require_once SM_PATH . 'class/deliver/Deliver_IMAP.class.php'; $imap_deliver = new Deliver_IMAP(); $imap_deliver->mail($composeMessage, $imapConnection, 0, 0, $imapConnection, $sent_folder); unset($imap_deliver); } } return $success; }
function SendMDN($mailbox, $passed_id, $sender, $message, $imapConnection) { global $username, $attachment_dir, $version, $attachments, $squirrelmail_language, $default_charset, $languages, $useSendmail, $domain, $sent_folder, $popuser, $data_dir, $username; sqgetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER); $header = $message->rfc822_header; $hashed_attachment_dir = getHashedDir($username, $attachment_dir); $rfc822_header = new Rfc822Header(); $content_type = new ContentType('multipart/report'); $content_type->properties['report-type'] = 'disposition-notification'; set_my_charset(); if ($default_charset) { $content_type->properties['charset'] = $default_charset; } $rfc822_header->content_type = $content_type; $rfc822_header->to[] = $header->dnt; $rfc822_header->subject = _("Read:") . ' ' . encodeHeader($header->subject); // Patch #793504 Return Receipt Failing with <@> from Tim Craig (burny_md) // This merely comes from compose.php and only happens when there is no // email_addr specified in user's identity (which is the startup config) if (ereg("^([^@%/]+)[@%/](.+)\$", $username, $usernamedata)) { $popuser = $usernamedata[1]; $domain = $usernamedata[2]; unset($usernamedata); } else { $popuser = $username; } $reply_to = ''; $ident = get_identities(); if (!isset($identity)) { $identity = 0; } $full_name = $ident[$identity]['full_name']; $from_mail = $ident[$identity]['email_address']; $from_addr = '"' . $full_name . '" <' . $from_mail . '>'; $reply_to = $ident[$identity]['reply_to']; if (!$from_mail) { $from_mail = "{$popuser}@{$domain}"; $from_addr = $from_mail; } $rfc822_header->from = $rfc822_header->parseAddress($from_addr, true); if ($reply_to) { $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to, true); } // part 1 (RFC2298) $senton = getLongDateString($header->date); $to_array = $header->to; $to = ''; foreach ($to_array as $line) { $to .= ' ' . $line->getAddress(); } $now = getLongDateString(time()); set_my_charset(); $body = _("Your message") . "\r\n\r\n" . "\t" . _("To") . ': ' . decodeHeader($to, false, false) . "\r\n" . "\t" . _("Subject") . ': ' . decodeHeader($header->subject, false, false) . "\r\n" . "\t" . _("Sent") . ': ' . $senton . "\r\n" . "\r\n" . sprintf(_("Was displayed on %s"), $now); $special_encoding = ''; if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_encode')) { $body = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_encode', $body); if (strtolower($default_charset) == 'iso-2022-jp') { if (mb_detect_encoding($body) == 'ASCII') { $special_encoding = '8bit'; } else { $body = mb_convert_encoding($body, 'JIS'); $special_encoding = '7bit'; } } } elseif (sq_is8bit($body)) { $special_encoding = '8bit'; } $part1 = new Message(); $part1->setBody($body); $mime_header = new MessageHeader(); $mime_header->type0 = 'text'; $mime_header->type1 = 'plain'; if ($special_encoding) { $mime_header->encoding = $special_encoding; } else { $mime_header->encoding = 'us-ascii'; } if ($default_charset) { $mime_header->parameters['charset'] = $default_charset; } $part1->mime_header = $mime_header; // part2 (RFC2298) $original_recipient = $to; $original_message_id = $header->message_id; $report = "Reporting-UA : {$SERVER_NAME} ; SquirrelMail (version {$version}) \r\n"; if ($original_recipient != '') { $report .= "Original-Recipient : {$original_recipient}\r\n"; } $final_recipient = $sender; $report .= "Final-Recipient: rfc822; {$final_recipient}\r\n" . "Original-Message-ID : {$original_message_id}\r\n" . "Disposition: manual-action/MDN-sent-manually; displayed\r\n"; $part2 = new Message(); $part2->setBody($report); $mime_header = new MessageHeader(); $mime_header->type0 = 'message'; $mime_header->type1 = 'disposition-notification'; $mime_header->encoding = 'us-ascii'; $part2->mime_header = $mime_header; $composeMessage = new Message(); $composeMessage->rfc822_header = $rfc822_header; $composeMessage->addEntity($part1); $composeMessage->addEntity($part2); if ($useSendmail) { require_once SM_PATH . 'class/deliver/Deliver_SendMail.class.php'; global $sendmail_path; $deliver = new Deliver_SendMail(); $stream = $deliver->initStream($composeMessage, $sendmail_path); } else { require_once SM_PATH . 'class/deliver/Deliver_SMTP.class.php'; $deliver = new Deliver_SMTP(); global $smtpServerAddress, $smtpPort, $smtp_auth_mech, $pop_before_smtp; $authPop = isset($pop_before_smtp) && $pop_before_smtp ? true : false; get_smtp_user($user, $pass); $stream = $deliver->initStream($composeMessage, $domain, 0, $smtpServerAddress, $smtpPort, $user, $pass, $authPop); } $success = false; if ($stream) { $length = $deliver->mail($composeMessage, $stream); $success = $deliver->finalizeStream($stream); } if (!$success) { $msg = $deliver->dlv_msg . '<br />' . _("Server replied: ") . $deliver->dlv_ret_nr . ' ' . $deliver->dlv_server_msg; require_once SM_PATH . 'functions/display_messages.php'; plain_error_message($msg, $color); } else { unset($deliver); if (sqimap_mailbox_exists($imapConnection, $sent_folder)) { sqimap_append($imapConnection, $sent_folder, $length); require_once SM_PATH . 'class/deliver/Deliver_IMAP.class.php'; $imap_deliver = new Deliver_IMAP(); $imap_deliver->mail($composeMessage, $imapConnection); sqimap_append_done($imapConnection); unset($imap_deliver); } } return $success; }