summaryrefslogtreecommitdiff
path: root/program/steps/mail/compose.inc
diff options
context:
space:
mode:
Diffstat (limited to 'program/steps/mail/compose.inc')
-rw-r--r--program/steps/mail/compose.inc83
1 files changed, 52 insertions, 31 deletions
diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc
index 71a1c0f21..29e12675e 100644
--- a/program/steps/mail/compose.inc
+++ b/program/steps/mail/compose.inc
@@ -139,7 +139,7 @@ if (!empty($CONFIG['drafts_mbox'])) {
// set current mailbox in client environment
$OUTPUT->set_env('mailbox', $RCMAIL->storage->get_folder());
$OUTPUT->set_env('sig_above', $RCMAIL->config->get('sig_above', false));
-$OUTPUT->set_env('top_posting', $RCMAIL->config->get('top_posting', false));
+$OUTPUT->set_env('top_posting', intval($RCMAIL->config->get('reply_mode')) > 0);
$OUTPUT->set_env('recipients_separator', trim($RCMAIL->config->get('recipients_separator', ',')));
// default font for HTML editor
@@ -252,7 +252,8 @@ $MESSAGE->identities = $RCMAIL->user->list_identities();
if (count($MESSAGE->identities))
{
foreach ($MESSAGE->identities as $idx => $ident) {
- $email = mb_strtolower(rcube_idn_to_utf8($ident['email']));
+ $ident['email'] = format_email($ident['email']);
+ $email = format_email(rcube_idn_to_utf8($ident['email']));
$MESSAGE->identities[$idx]['email_ascii'] = $ident['email'];
$MESSAGE->identities[$idx]['ident'] = format_email_recipient($ident['email'], $ident['name']);
@@ -277,7 +278,7 @@ else if (count($MESSAGE->identities)) {
$a_to = rcube_mime::decode_address_list($MESSAGE->headers->to, null, true, $MESSAGE->headers->charset);
foreach ($a_to as $addr) {
if (!empty($addr['mailto'])) {
- $a_recipients[] = strtolower($addr['mailto']);
+ $a_recipients[] = format_email($addr['mailto']);
$a_names[] = $addr['name'];
}
}
@@ -286,7 +287,7 @@ else if (count($MESSAGE->identities)) {
$a_cc = rcube_mime::decode_address_list($MESSAGE->headers->cc, null, true, $MESSAGE->headers->charset);
foreach ($a_cc as $addr) {
if (!empty($addr['mailto'])) {
- $a_recipients[] = strtolower($addr['mailto']);
+ $a_recipients[] = format_email($addr['mailto']);
$a_names[] = $addr['name'];
}
}
@@ -294,16 +295,12 @@ else if (count($MESSAGE->identities)) {
}
$from_idx = null;
- $default_identity = null;
+ $found_idx = null;
+ $default_identity = 0; // default identity is always first on the list
$return_path = $MESSAGE->headers->others['return-path'];
// Select identity
foreach ($MESSAGE->identities as $idx => $ident) {
- // save default identity ID
- if ($ident['standard']) {
- $default_identity = $idx;
- }
-
// use From header
if (in_array($compose_mode, array(RCUBE_COMPOSE_DRAFT, RCUBE_COMPOSE_EDIT))) {
if ($MESSAGE->headers->from == $ident['ident']) {
@@ -318,13 +315,22 @@ else if (count($MESSAGE->identities)) {
}
// use replied message recipients
else if (($found = array_search($ident['email_ascii'], $a_recipients)) !== false) {
- // match identity name, prefer default identity
- if ($from_idx === null || ($a_names[$found] && $ident['name'] && $a_names[$found] == $ident['name'])) {
+ if ($found_idx === null) {
+ $found_idx = $idx;
+ }
+ // match identity name
+ if ($a_names[$found] && $ident['name'] && $a_names[$found] == $ident['name']) {
$from_idx = $idx;
+ break;
}
}
}
+ // If matching by name+address doesn't found any amtches, get first found address (identity)
+ if ($from_idx === null) {
+ $from_idx = $found_idx;
+ }
+
// Fallback using Return-Path
if ($from_idx === null && $return_path) {
foreach ($MESSAGE->identities as $idx => $ident) {
@@ -335,12 +341,7 @@ else if (count($MESSAGE->identities)) {
}
}
- // Still no ID, use default/first identity
- if ($from_idx === null) {
- $from_idx = $default_identity !== null ? $default_identity : key(reset($MESSAGE->identities));
- }
-
- $ident = $MESSAGE->identities[$from_idx];
+ $ident = $MESSAGE->identities[$from_idx !== null ? $from_idx : $default_identity];
$from_id = $ident['identity_id'];
$MESSAGE->compose['from_email'] = $ident['email'];
@@ -433,7 +434,7 @@ foreach ($parts as $header) {
if (empty($addr_part['mailto']))
continue;
- $mailto = mb_strtolower(rcube_idn_to_utf8($addr_part['mailto']));
+ $mailto = format_email(rcube_idn_to_utf8($addr_part['mailto']));
if (!in_array($mailto, $a_recipients)
&& ($header == 'to' || empty($MESSAGE->compose['from_email']) || $mailto != $MESSAGE->compose['from_email'])
@@ -529,7 +530,7 @@ function rcmail_compose_headers($attrib)
function rcmail_compose_header_from($attrib)
{
- global $MESSAGE, $OUTPUT;
+ global $MESSAGE, $OUTPUT, $RCMAIL, $compose_mode;
// pass the following attributes to the form class
$field_attrib = array('name' => '_from');
@@ -540,6 +541,8 @@ function rcmail_compose_header_from($attrib)
if (count($MESSAGE->identities))
{
$a_signatures = array();
+ $separator = $RCMAIL->config->get('sig_above')
+ && ($compose_mode == RCUBE_COMPOSE_REPLY || $compose_mode == RCUBE_COMPOSE_FORWARD) ? '---' : '-- ';
$field_attrib['onchange'] = JS_OBJECT_NAME.".change_identity(this)";
$select_from = new html_select($field_attrib);
@@ -553,13 +556,27 @@ function rcmail_compose_header_from($attrib)
// add signature to array
if (!empty($sql_arr['signature']) && empty($COMPOSE['param']['nosig']))
{
- $a_signatures[$identity_id]['text'] = $sql_arr['signature'];
- $a_signatures[$identity_id]['is_html'] = ($sql_arr['html_signature'] == 1) ? true : false;
- if ($a_signatures[$identity_id]['is_html'])
- {
- $h2t = new html2text($a_signatures[$identity_id]['text'], false, false);
- $a_signatures[$identity_id]['plain_text'] = trim($h2t->get_text());
+ $text = $html = $sql_arr['signature'];
+
+ if ($sql_arr['html_signature']) {
+ $h2t = new html2text($sql_arr['signature'], false, false);
+ $text = trim($h2t->get_text());
}
+ else {
+ $html = htmlentities($html, ENT_NOQUOTES, RCMAIL_CHARSET);
+ }
+
+ if (!preg_match('/^--[ -]\r?\n/m', $text)) {
+ $text = $separator . "\n" . $text;
+ $html = $separator . "<br>" . $html;
+ }
+
+ if (!$sql_arr['html_signature']) {
+ $html = "<pre>" . $html . "</pre>";
+ }
+
+ $a_signatures[$identity_id]['text'] = $text;
+ $a_signatures[$identity_id]['html'] = $html;
}
}
@@ -593,9 +610,12 @@ function rcmail_compose_editor_mode()
$useHtml = $MESSAGE->has_html_part(false);
}
else if ($compose_mode == RCUBE_COMPOSE_REPLY) {
- $useHtml = ($html_editor == 1 || ($html_editor == 2 && $MESSAGE->has_html_part(false)));
+ $useHtml = ($html_editor == 1 || ($html_editor >= 2 && $MESSAGE->has_html_part(false)));
+ }
+ else if ($compose_mode == RCUBE_COMPOSE_FORWARD) {
+ $useHtml = ($html_editor == 1 || ($html_editor == 3 && $MESSAGE->has_html_part(false)));
}
- else { // RCUBE_COMPOSE_FORWARD or NEW
+ else {
$useHtml = ($html_editor == 1);
}
@@ -624,7 +644,7 @@ function rcmail_prepare_message_body()
rcmail_write_forward_attachment($MESSAGE);
}
// reply/edit/draft/forward
- else if ($compose_mode) {
+ else if ($compose_mode && ($compose_mode != RCUBE_COMPOSE_REPLY || $RCMAIL->config->get('reply_mode') != -1)) {
$isHtml = rcmail_compose_editor_mode();
if (!empty($MESSAGE->parts)) {
@@ -889,8 +909,9 @@ function rcmail_create_reply_body($body, $bodyIsHtml)
$prefix .= "\n";
$suffix = '';
- if ($RCMAIL->config->get('top_posting'))
+ if (intval($RCMAIL->config->get('reply_mode')) > 0) { // top-posting
$prefix = "\n\n\n" . $prefix;
+ }
}
else {
// save inline images to files
@@ -904,7 +925,7 @@ function rcmail_create_reply_body($body, $bodyIsHtml)
$prefix = '<p>' . Q($prefix) . "</p>\n";
$prefix .= '<blockquote>';
- if ($RCMAIL->config->get('top_posting')) {
+ if (intval($RCMAIL->config->get('reply_mode')) > 0) { // top-posting
$prefix = '<br>' . $prefix;
$suffix = '</blockquote>';
}