summaryrefslogtreecommitdiff
path: root/program
diff options
context:
space:
mode:
Diffstat (limited to 'program')
-rw-r--r--program/include/main.inc90
-rw-r--r--program/include/rcube_imap.inc46
-rw-r--r--program/include/rcube_shared.inc10
-rw-r--r--program/js/app.js6
-rw-r--r--program/steps/mail/func.inc8
-rw-r--r--program/steps/mail/sendmail.inc6
-rw-r--r--program/steps/settings/manage_folders.inc6
7 files changed, 84 insertions, 88 deletions
diff --git a/program/include/main.inc b/program/include/main.inc
index e40ab0948..ab11911b2 100644
--- a/program/include/main.inc
+++ b/program/include/main.inc
@@ -289,7 +289,7 @@ function rcube_language_prop($lang, $prop='lang')
// init output object for GUI and add common scripts
function load_gui()
{
- global $CONFIG, $OUTPUT, $COMM_PATH, $JS_OBJECT_NAME, $CHARSET, $sess_user_lang;
+ global $CONFIG, $OUTPUT, $COMM_PATH, $JS_OBJECT_NAME, $sess_user_lang;
// init output page
$OUTPUT = new rcube_html_page();
@@ -307,14 +307,9 @@ function load_gui()
// set user-selected charset
if (!empty($CONFIG['charset']))
- {
$OUTPUT->set_charset($CONFIG['charset']);
- $CHARSET = $CONFIG['charset'];
- }
else
- {
rcmail_set_locale($sess_user_lang);
- }
// add some basic label to client
rcube_add_label('loading');
@@ -324,10 +319,8 @@ function load_gui()
// set localization charset based on the given language
function rcmail_set_locale($lang)
{
- global $OUTPUT, $CHARSET;
-
- $CHARSET = rcube_language_prop($lang, 'charset');
- $OUTPUT->set_charset($CHARSET);
+ global $OUTPUT;
+ $OUTPUT->set_charset(rcube_language_prop($lang, 'charset'));
}
@@ -704,39 +697,46 @@ function rcmail_clear_session_temp($sess_id)
-// decode characters from any charset to UTF-8
-function decode_specialchars($input, $charset='')
+// convert a string from one charset to another
+// this function is not complete and not tested well
+function rcube_charset_convert($str, $from, $to=NULL)
{
- global $CHARSET;
- $charset = strtolower($charset);
+ $from = strtolower($from);
+ $to = $to==NULL ? strtolower($GLOBALS['CHARSET']) : strtolower($to);
- if ($charset=='utf-7')
- $output = UTF7DecodeString($input);
- else if ($charset=='utf-8' && $CHARSET!='UTF-8' && function_exists('utf8_decode'))
- $output = utf8_decode($input);
- else if ($charset=="koi8-r")
- $output = convert_cyr_string($input, 'k', 'w');
- else if ($charset=="iso8859-5")
- $output = convert_cyr_string($input, 'i', 'w');
- else if ($charset=="x-cp866")
- $output = convert_cyr_string($input, 'a', 'w');
- else if ($charset=="x-mac-cyrillic")
- $output = convert_cyr_string($input, 'm', 'w');
- else
- $output = $input;
-
+ if ($from==$to)
+ return $str;
+
+ // decode characters
+ if ($from=='utf-7')
+ $str = UTF7DecodeString($str);
+ else if ($from=='utf-8' && function_exists('utf8_decode'))
+ $str = utf8_decode($str);
+ else if ($from=="koi8-r")
+ $str = convert_cyr_string($str, 'k', 'i');
+ else if ($from=="windows-1251" || $from=="win-1251")
+ $str = convert_cyr_string($str, 'w', 'i');
+ else if ($from=="x-cp866")
+ $str = convert_cyr_string($str, 'a', 'i');
+ else if ($from=="x-mac-cyrillic")
+ $str = convert_cyr_string($str, 'm', 'i');
+
// encode string for output
- if ($CHARSET=='UTF-8' && $charset!='utf-8' && function_exists('utf8_encode'))
- $output = utf8_encode($output);
+ if ($to=='utf-8' && function_exists('utf8_encode'))
+ return utf8_encode($str);
+ else if ($to=='utf-7')
+ return UTF7EncodeString($str);
- return $output;
+ // return raw string
+ return $str;
}
+
// replace specials characters to a specific encoding type
function rep_specialchars_output($str, $enctype='', $mode='', $newlines=TRUE)
{
- global $OUTPUT_TYPE, $CHARSET;
+ global $OUTPUT_TYPE, $OUTPUT;
static $html_encode_arr, $js_rep_table, $rtf_rep_table, $xml_rep_table;
if (!$enctype)
@@ -794,7 +794,7 @@ function rep_specialchars_output($str, $enctype='', $mode='', $newlines=TRUE)
$rtf_rep_table[Chr($c)] = "\\'$hex";
$xml_rep_table[Chr($c)] = "&#$c;";
- if ($CHARSET=='ISO-8859-1')
+ if ($OUTPUT->get_charset()=='ISO-8859-1')
$js_rep_table[Chr($c)] = sprintf("\u%s%s", str_repeat('0', 4-strlen($hex)), $hex);
}
@@ -819,26 +819,6 @@ function rep_specialchars_output($str, $enctype='', $mode='', $newlines=TRUE)
}
-// convert a string from one charset to another
-// this function is not complete and not tested well
-function rcube_charset_convert($str, $from, $to)
- {
- $charset = strtolower($to);
-
- if (strtolower($from)==$charset)
- return $str;
-
- $str = decode_specialchars($str, $from);
-
- if ($charset=='utf-8' && function_exists('utf8_encode'))
- return utf8_encode($str);
- else if ($charset=='utf-7')
- return UTF7EncodeString($str);
-
- return $str;
- }
-
-
// ************** template parsing and gui functions **************
@@ -1022,7 +1002,7 @@ function rcube_xml_command($command, $str_attrib, $a_attrib=NULL)
else if (isset($GLOBALS['PAGE_TITLE']))
$title .= $GLOBALS['PAGE_TITLE'];
else if ($task=='mail' && ($mbox_name = $IMAP->get_mailbox_name()))
- $title .= $OUTPUT->encode_string(UTF7DecodeString($mbox_name));
+ $title .= rcube_charset_convert($mbox_name, 'UTF-7', 'UTF-8');
else
$title .= $task;
diff --git a/program/include/rcube_imap.inc b/program/include/rcube_imap.inc
index 7b71dc09c..eb021159d 100644
--- a/program/include/rcube_imap.inc
+++ b/program/include/rcube_imap.inc
@@ -70,7 +70,7 @@ class rcube_imap
*/
function __construct($db_conn)
{
- $this->db = $db_conn;
+ $this->db = $db_conn;
}
@@ -376,14 +376,28 @@ class rcube_imap
}
- // get message count for a specific mailbox; acceptes modes are: ALL, UNSEEN, RECENT
+ /**
+ * Get message count for a specific mailbox
+ *
+ * @param string Mailbox/folder name
+ * @param string Mode for count [ALL|UNSEEN|RECENT]
+ * @param boolean Force reading from server and update cache
+ * @return number Number of messages
+ * @access public
+ */
function messagecount($mbox='', $mode='ALL', $force=FALSE)
{
$mailbox = $mbox ? $this->_mod_mailbox($mbox) : $this->mailbox;
return $this->_messagecount($mailbox, $mode, $force);
}
- // private method for getting nr of mesages
+
+ /**
+ * Private method for getting nr of messages
+ *
+ * @access private
+ * @see rcube_imap::messagecount
+ */
function _messagecount($mailbox='', $mode='ALL', $force=FALSE)
{
$a_mailbox_cache = FALSE;
@@ -442,8 +456,17 @@ class rcube_imap
}
- // public method for listing headers
- // convert mailbox name with root dir first
+ /**
+ * Public method for listing headers
+ * convert mailbox name with root dir first
+ *
+ * @param string Mailbox/folder name
+ * @param number Current page to list
+ * @param string Header field to sort by
+ * @param string Sort order [ASC|DESC]
+ * @return array Indexed array with message header objects
+ * @access public
+ */
function list_headers($mbox='', $page=NULL, $sort_field=NULL, $sort_order=NULL)
{
$mailbox = $mbox ? $this->_mod_mailbox($mbox) : $this->mailbox;
@@ -451,7 +474,12 @@ class rcube_imap
}
- // private method for listing message header
+ /**
+ * Private method for listing message header
+ *
+ * @access private
+ * @see rcube_imap::list_headers
+ */
function _list_headers($mailbox='', $page=NULL, $sort_field=NULL, $sort_order=NULL, $recursive=FALSE)
{
if (!strlen($mailbox))
@@ -1548,10 +1576,10 @@ class rcube_imap
$rest = quoted_printable_decode($rest);
}
- return decode_specialchars($rest, $a[0]);
+ return rcube_charset_convert($rest, $a[0]);
}
else
- return $str; //we dont' know what to do with this
+ return $str; // we dont' know what to do with this
}
@@ -1599,7 +1627,7 @@ class rcube_imap
function charset_decode($body, $ctype_param)
{
if (is_array($ctype_param) && !empty($ctype_param['charset']))
- return decode_specialchars($body, $ctype_param['charset']);
+ return rcube_charset_convert($body, $ctype_param['charset']);
return $body;
}
diff --git a/program/include/rcube_shared.inc b/program/include/rcube_shared.inc
index b622203dd..a36458b00 100644
--- a/program/include/rcube_shared.inc
+++ b/program/include/rcube_shared.inc
@@ -88,13 +88,9 @@ class rcube_html_page
$this->charset = $charset;
}
-
- function encode_string($str)
+ function get_charset()
{
- if ($this->charset=='UTF-8' && function_exists('utf8_encode'))
- return utf8_encode($str);
- else
- return $str;
+ return $this->charset;
}
@@ -187,7 +183,7 @@ class rcube_html_page
// correct absolute pathes in images and other tags
$output = preg_replace('/(src|href|background)=(["\']?)(\/[a-z0-9_\-]+)/Ui', "\\1=\\2$base_path\\3", $output);
- print $output;
+ print rcube_charset_convert($output, 'UTF-8', $this->charset);
}
diff --git a/program/js/app.js b/program/js/app.js
index 4ed77fb3a..ad91e1fcb 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -232,8 +232,10 @@ function rcube_webmail()
this.display_message(this.pending_message[0], this.pending_message[1]);
// start interval for keep-alive/recent_check signal
- if (this.kepp_alive_interval)
- this.kepp_alive_int = setInterval(this.ref+'.'+(this.task=='mail'?'check_for_recent()':'send_keep_alive()'), this.kepp_alive_interval);
+ if (this.kepp_alive_interval && this.task=='mail' && this.gui_objects.messagelist)
+ this.kepp_alive_int = setInterval(this.ref+'.check_for_recent()', this.kepp_alive_interval);
+ else
+ this.kepp_alive_int = setInterval(this.ref+'.send_keep_alive()', this.kepp_alive_interval);
};
diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc
index 4c6e56a50..f05193d96 100644
--- a/program/steps/mail/func.inc
+++ b/program/steps/mail/func.inc
@@ -21,8 +21,6 @@
require_once('lib/html2text.inc');
require_once('lib/enriched.inc');
-require_once('lib/utf8.inc');
-require_once('lib/utf7.inc');
$EMAIL_ADDRESS_PATTERN = '/([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9]([a-z0-9\-][.]?)*[a-z0-9]\\.[a-z]{2,5})/i';
@@ -148,7 +146,7 @@ function rcmail_build_folder_tree(&$arrFolders, $folder, $delm='/', $path='')
if (!isset($arrFolders[$currentFolder]))
{
$arrFolders[$currentFolder] = array('id' => $path,
- 'name' => UTF7DecodeString($currentFolder),
+ 'name' => rcube_charset_convert($currentFolder, 'UTF-7'),
'folders' => array());
}
@@ -174,7 +172,7 @@ function rcmail_render_folder_tree_html(&$arrFolders, &$special, &$mbox, $maxlen
$foldername = rcube_label($folder_lc);
else
{
- $foldername = $OUTPUT->encode_string($folder['name']);
+ $foldername = $folder['name'];
// shorten the folder name to a given length
if ($maxlength && $maxlength>1)
@@ -242,7 +240,7 @@ function rcmail_render_folder_tree_select(&$arrFolders, &$special, &$mbox, $maxl
$foldername = rcube_label($folder_lc);
else
{
- $foldername = $OUTPUT->encode_string($folder['name']);
+ $foldername = $folder['name'];
// shorten the folder name to a given length
if ($maxlength && $maxlength>1)
diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc
index ee278189a..ab0c6ed07 100644
--- a/program/steps/mail/sendmail.inc
+++ b/program/steps/mail/sendmail.inc
@@ -80,9 +80,6 @@ if (empty($CHARSET))
$input_charset = $CHARSET;
$message_charset = isset($_POST['_charset']) ? $_POST['_charset'] : $input_charset;
-// unset global var
-$CHARSET = '';
-
$mailto_regexp = array('/[,;]\s*[\r\n]+/', '/[\r\n]+/', '/[,;]\s*$/m');
$mailto_replace = array(', ', ', ', '');
@@ -243,9 +240,6 @@ else
}
-// resore page charset
-$CHARSET = $input_charset;
-
// return to compose page if sending failed
if (!$sent)
{
diff --git a/program/steps/settings/manage_folders.inc b/program/steps/settings/manage_folders.inc
index 0702ce91d..c98de3951 100644
--- a/program/steps/settings/manage_folders.inc
+++ b/program/steps/settings/manage_folders.inc
@@ -19,8 +19,6 @@
*/
-require_once('lib/utf7.inc');
-
// init IAMP connection
rcmail_imap_init(TRUE);
@@ -53,7 +51,7 @@ else if ($_action=='create-folder')
if ($create && $_GET['_remote'])
{
- $commands = sprintf("this.add_folder_row('%s')", $OUTPUT->encode_string(rep_specialchars_output($create, 'js')));
+ $commands = sprintf("this.add_folder_row('%s')", rep_specialchars_output($create, 'js'));
rcube_remote_response($commands);
}
else if (!$create && $_GET['_remote'])
@@ -129,7 +127,7 @@ function rcube_subscription_form($attrib)
$out .= sprintf('<tr id="rcmrow%d" class="%s"><td>%s</td><td>%s</td><td><a href="#delete" onclick="%s.command(\'delete-folder\',\'%s\')" title="%s">%s</a></td>',
$i+1,
$zebra_class,
- $OUTPUT->encode_string(rep_specialchars_output(UTF7DecodeString($folder), 'html', 'all')),
+ rep_specialchars_output(rcube_charset_convert($folder, 'UTF-7', 'UTF-8'), 'html', 'all'),
$checkbox_subscribe->show(in_array($folder, $a_subscribed)?$folder:'', array('value' => $folder)),
$JS_OBJECT_NAME,
$folder_js,