| | |
| | | |
| | | // if configured, the Received headers goes to top, for good measure |
| | | if ($RCMAIL->config->get('http_received_header')) { |
| | | $nldlm = "\r\n\t"; |
| | | $encrypt = $RCMAIL->config->get('http_received_header_encrypt'); |
| | | |
| | | // FROM/VIA |
| | | $nldlm = "\r\n\t"; |
| | | $http_header = 'from '; |
| | | |
| | | // FROM/VIA |
| | | if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
| | | $hosts = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'], 2); |
| | | $hostname = gethostbyaddr($hosts[0]); |
| | | |
| | | if ($encrypt) { |
| | | $http_header .= rcmail_encrypt_header($hostname); |
| | | if ($host != $hostname) |
| | | $http_header .= ' ('. rcmail_encrypt_header($host) . ')'; |
| | | } |
| | | else { |
| | | $http_header .= (($host != $hostname) ? $hostname : '[' . $host . ']'); |
| | | if ($host != $hostname) |
| | | $http_header .= ' (['. $host .'])'; |
| | | } |
| | | $http_header .= $nldlm . ' via '; |
| | | $hosts = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'], 2); |
| | | $http_header .= rcmail_received_host($hosts[0]) . $nldlm . ' via '; |
| | | } |
| | | |
| | | $host = $_SERVER['REMOTE_ADDR']; |
| | | $hostname = gethostbyaddr($host); |
| | | |
| | | if ($encrypt) { |
| | | $http_header .= rcmail_encrypt_header($hostname); |
| | | if ($host != $hostname) |
| | | $http_header .= ' ('. rcmail_encrypt_header($host) . ')'; |
| | | } |
| | | else { |
| | | $http_header .= (($host != $hostname) ? $hostname : '[' . $host . ']'); |
| | | if ($host != $hostname) |
| | | $http_header .= ' (['. $host .'])'; |
| | | } |
| | | $http_header .= rcmail_received_host($_SERVER['REMOTE_ADDR']); |
| | | |
| | | // BY |
| | | $http_header .= $nldlm . 'by ' . $_SERVER['HTTP_HOST']; |
| | | |
| | | // WITH |
| | | $http_header .= $nldlm . 'with HTTP (' . $_SERVER['SERVER_PROTOCOL'] . |
| | | ' '.$_SERVER['REQUEST_METHOD'] . '); ' . date('r'); |
| | | $http_header = wordwrap($http_header, 69, $nldlm); |
| | | $http_header .= $nldlm . 'with HTTP (' . $_SERVER['SERVER_PROTOCOL'] |
| | | . ' ' . $_SERVER['REQUEST_METHOD'] . '); ' . date('r'); |
| | | |
| | | $headers['Received'] = $http_header; |
| | | $headers['Received'] = wordwrap($http_header, 69, $nldlm); |
| | | } |
| | | |
| | | $headers['Date'] = $RCMAIL->user_date(); |
| | |
| | | |
| | | $MAIL_MIME->setHTMLBody($plugin['body']); |
| | | |
| | | // replace emoticons |
| | | $plugin['body'] = $RCMAIL->replace_emoticons($plugin['body']); |
| | | |
| | | // add a plain text version of the e-mail as an alternative part. |
| | | $h2t = new rcube_html2text($plugin['body'], false, true, 0, $message_charset); |
| | | $plainTextPart = rcube_mime::wordwrap($h2t->get_text(), $LINE_LENGTH, "\r\n", false, $message_charset); |
| | | $plainTextPart = $RCMAIL->html2text($plugin['body'], array('width' => 0, 'charset' => $message_charset)); |
| | | $plainTextPart = rcube_mime::wordwrap($plainTextPart, $LINE_LENGTH, "\r\n", false, $message_charset); |
| | | $plainTextPart = wordwrap($plainTextPart, 998, "\r\n", true); |
| | | |
| | | // make sure all line endings are CRLF (#1486712) |
| | |
| | | $MAIL_MIME->setParam('html_charset', $message_charset); |
| | | $MAIL_MIME->setParam('text_charset', $text_charset); |
| | | |
| | | // encoding subject header with mb_encode provides better results with asian characters |
| | | if (function_exists('mb_encode_mimeheader')) { |
| | | mb_internal_encoding($message_charset); |
| | | $headers['Subject'] = mb_encode_mimeheader($headers['Subject'], |
| | | $message_charset, 'Q', "\r\n", 8); |
| | | mb_internal_encoding(RCUBE_CHARSET); |
| | | } |
| | | |
| | | // pass headers to message object |
| | | $MAIL_MIME->headers($headers); |
| | | |
| | |
| | | else { |
| | | $temp_dir = $RCMAIL->config->get('temp_dir'); |
| | | $mailbody_file = tempnam($temp_dir, 'rcmMsg'); |
| | | $msg = $MAIL_MIME->saveMessageBody($mailbody_file); |
| | | |
| | | if (!PEAR::isError($msg = $MAIL_MIME->saveMessageBody($mailbody_file))) { |
| | | if (!is_a($msg, 'PEAR_Error')) { |
| | | $msg = $mailbody_file; |
| | | } |
| | | } |
| | |
| | | $headers = ''; |
| | | } |
| | | |
| | | if (PEAR::isError($msg)) { |
| | | if (is_a($msg, 'PEAR_Error')) { |
| | | rcube::raise_error(array('code' => 650, 'type' => 'php', |
| | | 'file' => __FILE__, 'line' => __LINE__, |
| | | 'message' => "Could not create message: ".$msg->getMessage()), |
| | |
| | | $OUTPUT->send('iframe'); |
| | | } |
| | | } |
| | | |
| | | // delete previous saved draft |
| | | if ($saved && ($old_id = rcube_utils::get_input_value('_draft_saveid', rcube_utils::INPUT_POST))) { |
| | | $deleted = $RCMAIL->storage->delete_message($old_id, $drafts_mbox); |
| | | |
| | | // raise error if deletion of old draft failed |
| | | if (!$deleted) { |
| | | rcube::raise_error(array('code' => 800, 'type' => 'imap', |
| | | 'file' => __FILE__, 'line' => __LINE__, |
| | | 'message' => "Could not delete message from $drafts_mbox"), true, false); |
| | | } |
| | | } |
| | | } |
| | | // remove temp file |
| | | else if ($mailbody_file) { |
| | | unlink($mailbody_file); |
| | | } |
| | | |
| | | // delete previous saved draft |
| | | $old_id = rcube_utils::get_input_value('_draft_saveid', rcube_utils::INPUT_POST); |
| | | if ($old_id && ($sent || $saved)) { |
| | | $deleted = $RCMAIL->storage->delete_message($old_id, $drafts_mbox); |
| | | |
| | | // raise error if deletion of old draft failed |
| | | if (!$deleted) { |
| | | rcube::raise_error(array('code' => 800, 'type' => 'imap', |
| | | 'file' => __FILE__, 'line' => __LINE__, |
| | | 'message' => "Could not delete message from $drafts_mbox"), true, false); |
| | | } |
| | | } |
| | | |
| | | if ($savedraft) { |
| | | // remember new draft-uid ($saved could be an UID or true/false here) |
| | |
| | | |
| | | /****** message sending functions ********/ |
| | | |
| | | // encrypt parts of the header |
| | | function rcmail_encrypt_header($what) |
| | | function rcmail_received_host($host) |
| | | { |
| | | $hostname = gethostbyaddr($host); |
| | | |
| | | $result = rcmail_encrypt_host($hostname); |
| | | |
| | | if ($host != $hostname) { |
| | | $result .= ' (' . rcmail_encrypt_host($host) . ')'; |
| | | } |
| | | |
| | | return $result; |
| | | } |
| | | |
| | | // encrypt host IP or hostname for Received header |
| | | function rcmail_encrypt_host($host) |
| | | { |
| | | global $RCMAIL; |
| | | |
| | | if (!$RCMAIL->config->get('http_received_header_encrypt')) { |
| | | return $what; |
| | | if ($RCMAIL->config->get('http_received_header_encrypt')) { |
| | | return $RCMAIL->encrypt($host); |
| | | } |
| | | |
| | | return $RCMAIL->encrypt($what); |
| | | if (!preg_match('/[^0-9:.]/', $host)) { |
| | | return "[$host]"; |
| | | } |
| | | |
| | | return $host; |
| | | } |
| | | |
| | | // get identity record |
| | |
| | | if (!in_array($image_name, $included_images)) { |
| | | // add the image to the MIME message |
| | | $res = $mime_message->addHTMLImage($img_file, 'image/gif', '', true, $image_name); |
| | | if (PEAR::isError($res)) { |
| | | if (is_a($res, 'PEAR_Error')) { |
| | | $RCMAIL->output->show_message("emoticonerror", 'error'); |
| | | continue; |
| | | } |
| | |
| | | |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * clear message composing settings |
| | | */ |
| | | function rcmail_compose_cleanup($id) |
| | | { |
| | | if (!isset($_SESSION['compose_data_'.$id])) { |
| | | return; |
| | | } |
| | | |
| | | $rcmail = rcmail::get_instance(); |
| | | $rcmail->plugins->exec_hook('attachments_cleanup', array('group' => $id)); |
| | | $rcmail->session->remove('compose_data_'.$id); |
| | | |
| | | $_SESSION['last_compose_session'] = $id; |
| | | } |