Skip to content

Commit

Permalink
Make email recipients separator configurable + suppress dupes in auto…
Browse files Browse the repository at this point in the history
…-completion
  • Loading branch information
thomascube committed Nov 8, 2011
1 parent 9230525 commit 62c8618
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
@@ -1,6 +1,7 @@
CHANGELOG Roundcube Webmail
===========================

- Make email recipients separator configurable
- Fix so folders with \Noinferiors attribute aren't listed in parent selector
- Fix handling of curly brackets in URLs (#1488168)
- Fix handling of dates (birthday/anniversary) in contact data (#1488147)
Expand Down
5 changes: 4 additions & 1 deletion config/main.inc.php.dist
Expand Up @@ -5,7 +5,7 @@
| Main configuration file |
| |
| This file is part of the Roundcube Webmail client |
| Copyright (C) 2005-2010, The Roundcube Dev Team |
| Copyright (C) 2005-2011, The Roundcube Dev Team |
| Licensed under the GNU GPL |
| |
+-----------------------------------------------------------------------+
Expand Down Expand Up @@ -460,6 +460,9 @@ $rcmail_config['spellcheck_ignore_nums'] = false;
// Makes that words with symbols will be ignored (e.g. g@@gle)
$rcmail_config['spellcheck_ignore_syms'] = false;

// Use this char/string to separate recipients when composing a new message
$rcmail_config['recipients_separator'] = ',';

// don't let users set pagesize to more than this value if set
$rcmail_config['max_pagesize'] = 200;

Expand Down
10 changes: 6 additions & 4 deletions program/js/app.js
Expand Up @@ -20,7 +20,7 @@

function rcube_webmail()
{
this.env = {};
this.env = { recipients_separator:',', recipients_delimiter:', ' };
this.labels = {};
this.buttons = {};
this.buttons_sel = {};
Expand Down Expand Up @@ -2926,6 +2926,8 @@ function rcube_webmail()

this.init_address_input_events = function(obj, props)
{
this.env.recipients_delimiter = this.env.recipients_separator + ' ';

obj[bw.ie || bw.safari || bw.chrome ? 'keydown' : 'keypress'](function(e) { return ref.ksearch_keydown(e, this, props); })
.attr('autocomplete', 'off');
};
Expand Down Expand Up @@ -3590,13 +3592,13 @@ function rcube_webmail()

// insert all members of a group
if (typeof this.env.contacts[id] === 'object' && this.env.contacts[id].id) {
insert += this.env.contacts[id].name + ', ';
insert += this.env.contacts[id].name + this.env.recipients_delimiter;
this.group2expand = $.extend({}, this.env.contacts[id]);
this.group2expand.input = this.ksearch_input;
this.http_request('mail/group-expand', '_source='+urlencode(this.env.contacts[id].source)+'&_gid='+urlencode(this.env.contacts[id].id), false);
}
else if (typeof this.env.contacts[id] === 'string') {
insert = this.env.contacts[id] + ', ';
insert = this.env.contacts[id] + this.env.recipients_delimiter;
trigger = true;
}

Expand Down Expand Up @@ -3633,7 +3635,7 @@ function rcube_webmail()

// get string from current cursor pos to last comma
var cpos = this.get_caret_pos(this.ksearch_input),
p = inp_value.lastIndexOf(',', cpos-1),
p = inp_value.lastIndexOf(this.env.recipients_separator, cpos-1),
q = inp_value.substring(p+1, cpos),
min = this.env.autocomplete_min_length,
ac = this.ksearch_data;
Expand Down
7 changes: 4 additions & 3 deletions program/steps/mail/autocomplete.inc
Expand Up @@ -32,7 +32,8 @@ if ($RCMAIL->action == 'group-expand') {
$members[] = format_email_recipient($email, $sql_arr['name']);
}

$OUTPUT->command('replace_group_recipients', $gid, join(', ', $members));
$separator = trim($RCMAIL->config->get('recipients_separator', ',')) . ' ';
$OUTPUT->command('replace_group_recipients', $gid, join($separator, array_unique($members)));
}

$OUTPUT->send();
Expand Down Expand Up @@ -70,8 +71,8 @@ if (!empty($book_types) && strlen($search)) {
if ($email_cnt > 1 && stripos($contact, $search) === false) {
continue;
}
// when we've got more than one book, we need to skip duplicates
if ($books_num == 1 || !in_array($contact, $contacts)) {
// skip duplicates
if (!in_array($contact, $contacts)) {
$contacts[] = $contact;
if (count($contacts) >= $MAXNUM)
break 2;
Expand Down
12 changes: 7 additions & 5 deletions program/steps/mail/compose.inc
Expand Up @@ -5,7 +5,7 @@
| program/steps/mail/compose.inc |
| |
| This file is part of the Roundcube Webmail client |
| Copyright (C) 2005-2009, The Roundcube Dev Team |
| Copyright (C) 2005-2011, The Roundcube Dev Team |
| Licensed under the GNU GPL |
| |
| PURPOSE: |
Expand Down Expand Up @@ -122,8 +122,9 @@ if (!empty($CONFIG['drafts_mbox'])) {
}
// set current mailbox in client environment
$OUTPUT->set_env('mailbox', $IMAP->get_mailbox_name());
$OUTPUT->set_env('sig_above', $CONFIG['sig_above']);
$OUTPUT->set_env('top_posting', $CONFIG['top_posting']);
$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('recipients_separator', trim($RCMAIL->config->get('recipients_separator', ',')));

// get reference message and set compose mode
if ($msg_uid = $_SESSION['compose']['param']['draft_uid']) {
Expand Down Expand Up @@ -324,6 +325,7 @@ else if (count($MESSAGE->identities)) {
// Set other headers
$a_recipients = array();
$parts = array('to', 'cc', 'bcc', 'replyto', 'followupto');
$separator = trim($RCMAIL->config->get('recipients_separator', ',')) . ' ';

foreach ($parts as $header) {
$fvalue = '';
Expand Down Expand Up @@ -367,7 +369,7 @@ foreach ($parts as $header) {
if ($v = $MESSAGE->headers->to)
$fvalue .= $v;
if ($v = $MESSAGE->headers->cc)
$fvalue .= (!empty($fvalue) ? ', ' : '') . $v;
$fvalue .= (!empty($fvalue) ? $separator : '') . $v;
}
}
else if (in_array($compose_mode, array(RCUBE_COMPOSE_DRAFT, RCUBE_COMPOSE_EDIT))) {
Expand Down Expand Up @@ -410,7 +412,7 @@ foreach ($parts as $header) {
}
}

$fvalue = implode(', ', $fvalue);
$fvalue = implode($separator, $fvalue);
}

$MESSAGE->compose[$header] = $fvalue;
Expand Down
31 changes: 16 additions & 15 deletions program/steps/mail/sendmail.inc
Expand Up @@ -5,7 +5,7 @@
| program/steps/mail/sendmail.inc |
| |
| This file is part of the Roundcube Webmail client |
| Copyright (C) 2005-2010, The Roundcube Dev Team |
| Copyright (C) 2005-2011, The Roundcube Dev Team |
| Licensed under the GNU GPL |
| |
| PURPOSE: |
Expand Down Expand Up @@ -138,22 +138,30 @@ function rcmail_fix_emoticon_paths(&$mime_message)
return $body;
}

// parse email address input (and count addresses)
/**
* Parse and cleanup email address input (and count addresses)
*
* @param string Address input
* @param boolean Do count recipients (saved in global $RECIPIENT_COUNT)
* @param boolean Validate addresses (errors saved in global $EMAIL_FORMAT_ERROR)
* @return string Canonical recipients string separated by comma
*/
function rcmail_email_input_format($mailto, $count=false, $check=true)
{
global $EMAIL_FORMAT_ERROR, $RECIPIENT_COUNT;
global $RCMAIL, $EMAIL_FORMAT_ERROR, $RECIPIENT_COUNT;

// simplified email regexp, supporting quoted local part
$email_regexp = '(\S+|("[^"]+"))@\S+';

$regexp = array('/[,;]\s*[\r\n]+/', '/[\r\n]+/', '/[,;]\s*$/m', '/;/', '/(\S{1})(<'.$email_regexp.'>)/U');
$replace = array(', ', ', ', '', ',', '\\1 \\2');
$delim = trim($RCMAIL->config->get('recipients_separator', ','));
$regexp = array("/[,;$delim]\s*[\r\n]+/", '/[\r\n]+/', "/[,;$delim]\s*\$/m", '/;/', '/(\S{1})(<'.$email_regexp.'>)/U');
$replace = array($delim.' ', ', ', '', $delim, '\\1 \\2');

// replace new lines and strip ending ', ', make address input more valid
$mailto = trim(preg_replace($regexp, $replace, $mailto));

$result = array();
$items = rcube_explode_quoted_string(',', $mailto);
$items = rcube_explode_quoted_string($delim, $mailto);

foreach($items as $item) {
$item = trim($item);
Expand All @@ -168,16 +176,9 @@ function rcmail_email_input_format($mailto, $count=false, $check=true)
// address with name (handle name)
} else if (preg_match('/<*'.$email_regexp.'>*$/', $item, $matches)) {
$address = $matches[0];
$name = str_replace($address, '', $item);
$name = trim($name);
if ($name && ($name[0] != '"' || $name[strlen($name)-1] != '"')
&& preg_match('/[\(\)\<\>\\\.\[\]@,;:"]/', $name)) {
$name = '"'.addcslashes($name, '"').'"';
}
$name = trim(str_replace($address, '', $item), '" ');
$address = rcube_idn_to_ascii(trim($address, '<>'));
$address = '<' . $address . '>';

$result[] = $name.' '.$address;
$result[] = format_email_recipient($address, $name);
$item = $address;
} else if (trim($item)) {
continue;
Expand Down

0 comments on commit 62c8618

Please sign in to comment.