summaryrefslogtreecommitdiff
path: root/program/include
diff options
context:
space:
mode:
Diffstat (limited to 'program/include')
-rw-r--r--program/include/main.inc8
-rw-r--r--program/include/rcmail.php17
-rw-r--r--program/include/rcube_imap.php2
-rw-r--r--program/include/rcube_shared.inc48
-rw-r--r--program/include/rcube_user.php91
5 files changed, 109 insertions, 57 deletions
diff --git a/program/include/main.inc b/program/include/main.inc
index 9adcd4cfc..b22be1aca 100644
--- a/program/include/main.inc
+++ b/program/include/main.inc
@@ -192,7 +192,7 @@ function rcube_charset_convert($str, $from, $to=NULL)
if ($to == 'UNICODE-1-1-UTF-7')
$to = 'UTF-7';
- if ($from==$to || $str=='' || empty($from))
+ if ($from == $to || empty($str) || empty($from))
return $str;
$aliases = array(
@@ -246,6 +246,8 @@ function rcube_charset_convert($str, $from, $to=NULL)
if ($from == 'UTF-7') {
if ($_str = utf7_to_utf8($str))
$str = $_str;
+ else
+ $error = true;
}
else if (($from == 'ISO-8859-1') && function_exists('utf8_encode')) {
$str = utf8_encode($str);
@@ -254,7 +256,7 @@ function rcube_charset_convert($str, $from, $to=NULL)
$conv->loadCharset($from);
$str = $conv->strToUtf8($str);
}
- else if ($from != 'UTF-8') {}
+ else if ($from != 'UTF-8')
$error = true;
// encode string for output
@@ -278,7 +280,7 @@ function rcube_charset_convert($str, $from, $to=NULL)
'code' => 500,
'type' => 'php',
'file' => __FILE__,
- 'message' => "Could not convert string charset. Make sure iconv is installed or lib/utf8.class is available"
+ 'message' => "Could not convert string from $from to $to. Make sure iconv is installed or lib/utf8.class is available"
), true, false);
$convert_warning = true;
diff --git a/program/include/rcmail.php b/program/include/rcmail.php
index f109c16fd..9aad25b27 100644
--- a/program/include/rcmail.php
+++ b/program/include/rcmail.php
@@ -436,11 +436,13 @@ class rcmail
if ($a_host['host']) {
$host = $a_host['host'];
$imap_ssl = (isset($a_host['scheme']) && in_array($a_host['scheme'], array('ssl','imaps','tls'))) ? $a_host['scheme'] : null;
- $imap_port = isset($a_host['port']) ? $a_host['port'] : ($imap_ssl ? 993 : $config['default_port']);
+ if(!empty($a_host['port']))
+ $imap_port = $a_host['port'];
+ else if ($imap_ssl && $imap_ssl != 'tls')
+ $imap_port = 993;
}
- else
- $imap_port = $config['default_port'];
-
+
+ $imap_port = $imap_port ? $imap_port : $config['default_port'];
/* Modify username with domain if required
Inspired by Marco <P0L0_notspam_binware.org>
@@ -453,9 +455,10 @@ class rcmail
$username .= '@'.$config['username_domain'];
}
- // try to resolve email address from virtuser table
- if (!empty($config['virtuser_file']) && strpos($username, '@'))
- $username = rcube_user::email2user($username);
+ // try to resolve email address from virtuser table
+ if (strpos($username, '@'))
+ if ($virtuser = rcube_user::email2user($username))
+ $username = $virtuser;
// lowercase username if it's an e-mail address (#1484473)
if (strpos($username, '@'))
diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php
index 637e25b92..da7c5bf88 100644
--- a/program/include/rcube_imap.php
+++ b/program/include/rcube_imap.php
@@ -97,7 +97,7 @@ class rcube_imap
global $ICL_SSL, $ICL_PORT, $IMAP_USE_INTERNAL_DATE;
// check for Open-SSL support in PHP build
- if ($use_ssl && in_array('openssl', get_loaded_extensions()))
+ if ($use_ssl && extension_loaded('openssl'))
$ICL_SSL = $use_ssl == 'imaps' ? 'ssl' : $use_ssl;
else if ($use_ssl)
{
diff --git a/program/include/rcube_shared.inc b/program/include/rcube_shared.inc
index f1cbb19c3..a05815800 100644
--- a/program/include/rcube_shared.inc
+++ b/program/include/rcube_shared.inc
@@ -405,6 +405,54 @@ function rc_strrpos($haystack, $needle, $offset=0)
return strrpos($haystack, $needle, $offset);
}
+/**
+ * Wrapper function for wordwrap
+ */
+function rc_wordwrap($string, $width=75, $break="\n", $cut=false)
+{
+ if (!function_exists('mb_substr') || !function_exists('mb_strlen'))
+ return wordwrap($string, $width, $break, $cut);
+
+ $para = explode($break, $string);
+ $string = '';
+ while (count($para)) {
+ $list = explode(' ', array_shift($para));
+ $len = 0;
+ while (count($list)) {
+ $line = array_shift($list);
+ $l = mb_strlen($line);
+ $newlen = $len + $l + ($len ? 1 : 0);
+
+ if ($newlen <= $width) {
+ $string .= ($len ? ' ' : '').$line;
+ $len += ($len ? 1 : 0) + $l;
+ } else {
+ if ($l > $width) {
+ if ($cut) {
+ $start = 0;
+ while ($l) {
+ $str = mb_substr($line, $start, $width);
+ $strlen = mb_strlen($str);
+ $string .= ($len ? $break : '').$str;
+ $start += $strlen;
+ $l -= $strlen;
+ $len = $strlen;
+ }
+ } else {
+ $string .= ($len ? $break : '').$line;
+ if (count($list)) $string .= $break;
+ $len = 0;
+ }
+ } else {
+ $string .= $break.$line;
+ $len = $l;
+ }
+ }
+ }
+ if (count($para)) $string .= $break;
+ }
+ return $string;
+}
/**
* Read a specific HTTP request header
diff --git a/program/include/rcube_user.php b/program/include/rcube_user.php
index b8833b3c7..17debeb7a 100644
--- a/program/include/rcube_user.php
+++ b/program/include/rcube_user.php
@@ -350,10 +350,12 @@ class rcube_user
$rcmail = rcmail::get_instance();
$dbh = $rcmail->get_dbh();
- // try to resolve user in virtusertable
- if ($rcmail->config->get('virtuser_file') && !strpos($user, '@'))
- $user_email = rcube_user::user2email($user);
-
+ // try to resolve user in virtuser table and file
+ if (!strpos($user, '@')) {
+ if ($email_list = self::user2email($user, false))
+ $user_email = $email_list[0];
+ }
+
$dbh->query(
"INSERT INTO ".get_table_name('users')."
(created, last_login, username, mail_host, alias, language)
@@ -372,35 +374,21 @@ class rcube_user
$user_name = $user != $user_email ? $user : '';
- // try to resolve the e-mail address from the virtuser table
- if (($virtuser_query = $rcmail->config->get('virtuser_query'))
- && ($sql_result = $dbh->query(preg_replace('/%u/', $dbh->escapeSimple($user), $virtuser_query)))
- && ($dbh->num_rows() > 0))
- {
- $standard = 1;
- while ($sql_arr = $dbh->fetch_array($sql_result))
- {
- $dbh->query(
+ if (empty($email_list))
+ $email_list[] = strip_newlines($user_email);
+
+ // also create new identity records
+ $standard = 1;
+ foreach ($email_list as $email) {
+ $dbh->query(
"INSERT INTO ".get_table_name('identities')."
(user_id, del, standard, name, email)
VALUES (?, 0, ?, ?, ?)",
$user_id,
$standard,
strip_newlines($user_name),
- preg_replace('/^@/', $user . '@', $sql_arr[0]));
- $standard = 0;
- }
- }
- else
- {
- // also create new identity records
- $dbh->query(
- "INSERT INTO ".get_table_name('identities')."
- (user_id, del, standard, name, email)
- VALUES (?, 0, 1, ?, ?)",
- $user_id,
- strip_newlines($user_name),
- strip_newlines($user_email));
+ preg_replace('/^@/', $user . '@', $email));
+ $standard = 0;
}
}
else
@@ -418,14 +406,13 @@ class rcube_user
/**
- * Resolve username using a virtuser table
+ * Resolve username using a virtuser file
*
* @param string E-mail address to resolve
* @return string Resolved IMAP username
*/
static function email2user($email)
{
- $user = $email;
$r = self::findinvirtual('^' . quotemeta($email) . '[[:space:]]');
for ($i=0; $i<count($r); $i++)
@@ -433,44 +420,57 @@ class rcube_user
$data = trim($r[$i]);
$arr = preg_split('/\s+/', $data);
if (count($arr) > 0)
- {
- $user = trim($arr[count($arr)-1]);
- break;
- }
+ return trim($arr[count($arr)-1]);
}
- return $user;
+ return NULL;
}
/**
- * Resolve e-mail address from virtuser table
+ * Resolve e-mail address from virtuser file/table
*
* @param string User name
- * @return string Resolved e-mail address
+ * @param boolean If true returns first found entry
+ * @return mixed Resolved e-mail address string or array of strings
*/
- static function user2email($user)
+ static function user2email($user, $first=true)
{
- $email = '';
- $r = self::findinvirtual('[[:space:]]' . quotemeta($user) . '[[:space:]]*$');
+ $result = array();
+ $rcmail = rcmail::get_instance();
+ $dbh = $rcmail->get_dbh();
+ // SQL lookup
+ if ($virtuser_query = $rcmail->config->get('virtuser_query')) {
+ $sql_result = $dbh->query(preg_replace('/%u/', $dbh->escapeSimple($user), $virtuser_query));
+ while ($sql_arr = $dbh->fetch_array($sql_result))
+ if (strpos($sql_arr[0], '@')) {
+ $result[] = $sql_arr[0];
+ if ($first)
+ return $result[0];
+ }
+ }
+ // File lookup
+ $r = self::findinvirtual('[[:space:]]' . quotemeta($user) . '[[:space:]]*$');
for ($i=0; $i<count($r); $i++)
{
$data = $r[$i];
$arr = preg_split('/\s+/', $data);
- if (count($arr) > 0)
+ if (count($arr) > 0 && strpos($arr[0], '@'))
{
- $email = trim(str_replace('\\@', '@', $arr[0]));
- break;
+ $result[] = trim(str_replace('\\@', '@', $arr[0]));
+
+ if ($first)
+ return $result[0];
}
}
-
- return $email;
+
+ return empty($result) ? NULL : $result;
}
/**
- * Find matches of the given pattern in virtuser table
+ * Find matches of the given pattern in virtuser file
*
* @param string Regular expression to search for
* @return array Matching entries
@@ -500,7 +500,6 @@ class rcube_user
return $result;
}
-
}