function translateText(&$body, $wrap_at, $charset) { global $where, $what; /* from searching */ global $color; /* color theme */ require_once SM_PATH . 'functions/url_parser.php'; $body_ary = explode("\n", $body); for ($i = 0; $i < count($body_ary); $i++) { $line = $body_ary[$i]; if (strlen($line) - 2 >= $wrap_at) { sqWordWrap($line, $wrap_at, $charset); } $line = charset_decode($charset, $line); $line = str_replace("\t", ' ', $line); parseUrl($line); $quotes = 0; $pos = 0; $j = strlen($line); while ($pos < $j) { if ($line[$pos] == ' ') { $pos++; } else { if (strpos($line, '>', $pos) === $pos) { $pos += 4; $quotes++; } else { break; } } } if ($quotes % 2) { if (!isset($color[13])) { $color[13] = '#800000'; } $line = '<font color="' . $color[13] . '">' . $line . '</font>'; } elseif ($quotes) { if (!isset($color[14])) { $color[14] = '#FF0000'; } $line = '<font color="' . $color[14] . '">' . $line . '</font>'; } $body_ary[$i] = $line; } $body = '<pre>' . implode("\n", $body_ary) . '</pre>'; }
*/ $body = str_replace("\r\n", "\n", $body); $body = str_replace("\r", "\n", $body); /** * Rewrap $body so that no line is bigger than $editor_size */ $body = explode("\n", $body); $newBody = ''; foreach ($body as $line) { if ($line != '-- ') { $line = rtrim($line); } if (strlen($line) <= $editor_size + 1) { $newBody .= $line . "\n"; } else { sqWordWrap($line, $editor_size); $newBody .= $line . "\n"; } } $body = $newBody; $composeMessage = $compose_messages[$session]; $Result = deliverMessage($composeMessage); if (!$Result) { showInputForm($session); exit; } unset($compose_messages[$session]); if (isset($delete_draft)) { Header("Location: {$location}/delete_message.php?mailbox=" . urlencode($draft_folder) . "&message={$delete_draft}&startMessage=1&mail_sent=yes"); exit; }
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; }
*/ $body = str_replace("\r\n", "\n", $body); $body = str_replace("\r", "\n", $body); /** * Rewrap $body so that no line is bigger than $editor_size */ $body = explode("\n", $body); $newBody = ''; foreach ($body as $line) { if ($line != '-- ') { $line = rtrim($line); } if (sq_strlen($line, $default_charset) <= $editor_size + 1) { $newBody .= $line . "\n"; } else { sqWordWrap($line, $editor_size, $default_charset); $newBody .= $line . "\n"; } } $body = $newBody; $Result = deliverMessage($composeMessage); if ($Result) { $mail_sent = 'yes'; } else { $mail_sent = 'no'; } // NOTE: this hook changed in 1.5.2 from sending $Result and // $composeMessage as args #2 and #3 to being in an array // under arg #2 $temp = array(&$Result, &$composeMessage, &$mail_sent); do_hook('compose_send_after', $temp);
function translateText(&$body, $wrap_at, $charset) { global $where, $what; /* from searching */ global $color; /* color theme */ // require_once(SM_PATH . 'functions/url_parser.php'); $body_ary = explode("\n", $body); for ($i = 0; $i < count($body_ary); $i++) { $line = rtrim($body_ary[$i], "\r"); if (strlen($line) - 2 >= $wrap_at) { sqWordWrap($line, $wrap_at, $charset); } $line = charset_decode($charset, $line); $line = str_replace("\t", ' ', $line); parseUrl($line); $quotes = 0; $pos = 0; $j = strlen($line); while ($pos < $j) { if ($line[$pos] == ' ') { $pos++; } else { if (strpos($line, '>', $pos) === $pos) { $pos += 4; $quotes++; } else { break; } } } if ($quotes % 2) { $line = '<span class="quote1">' . $line . '</span>'; } elseif ($quotes) { $line = '<span class="quote2">' . $line . '</span>'; } $body_ary[$i] = $line; } $body = '<pre>' . implode("\n", $body_ary) . '</pre>'; }