diff options
Diffstat (limited to 'program/include')
-rw-r--r-- | program/include/html.php | 4 | ||||
-rw-r--r-- | program/include/rcmail.php | 16 | ||||
-rw-r--r-- | program/include/rcube.php | 30 | ||||
-rw-r--r-- | program/include/rcube_charset.php | 57 | ||||
-rw-r--r-- | program/include/rcube_config.php | 2 | ||||
-rw-r--r-- | program/include/rcube_csv2vcard.php | 363 | ||||
-rw-r--r-- | program/include/rcube_image.php | 23 | ||||
-rw-r--r-- | program/include/rcube_imap.php | 2 | ||||
-rw-r--r-- | program/include/rcube_imap_generic.php | 3 | ||||
-rw-r--r-- | program/include/rcube_ldap.php | 30 | ||||
-rw-r--r-- | program/include/rcube_message.php | 9 | ||||
-rw-r--r-- | program/include/rcube_output_html.php | 10 | ||||
-rw-r--r-- | program/include/rcube_plugin_api.php | 2 | ||||
-rw-r--r-- | program/include/rcube_session.php | 20 | ||||
-rw-r--r-- | program/include/rcube_user.php | 25 | ||||
-rw-r--r-- | program/include/rcube_utils.php | 2 | ||||
-rw-r--r-- | program/include/rcube_vcard.php | 59 |
17 files changed, 515 insertions, 142 deletions
diff --git a/program/include/html.php b/program/include/html.php index 880873ddc..0f93e969d 100644 --- a/program/include/html.php +++ b/program/include/html.php @@ -252,9 +252,9 @@ class html * @return string HTML code * @see html::tag() */ - public static function br() + public static function br($attrib = array()) { - return self::tag('br'); + return self::tag('br', $attrib); } /** diff --git a/program/include/rcmail.php b/program/include/rcmail.php index 3728e5d19..99a68e81d 100644 --- a/program/include/rcmail.php +++ b/program/include/rcmail.php @@ -94,9 +94,6 @@ class rcmail extends rcube // create user object $this->set_user(new rcube_user($_SESSION['user_id'])); - // configure session (after user config merge!) - $this->session_configure(); - // set task and action properties $this->set_task(rcube_utils::get_input_value('_task', rcube_utils::INPUT_GPC)); $this->action = asciiwords(rcube_utils::get_input_value('_action', rcube_utils::INPUT_GPC)); @@ -320,10 +317,9 @@ class rcmail extends rcube if (!($this->output instanceof rcube_output_html)) $this->output = new rcube_output_html($this->task, $framed); - // set keep-alive/check-recent interval - if ($this->session && ($keep_alive = $this->session->get_keep_alive())) { - $this->output->set_env('keep_alive', $keep_alive); - } + // set refresh interval + $this->output->set_env('refresh_interval', $this->config->get('refresh_interval', 0)); + $this->output->set_env('session_lifetime', $this->config->get('session_lifetime', 0) * 60); if ($framed) { $this->comm_path .= '&_framed=1'; @@ -336,7 +332,7 @@ class rcmail extends rcube $this->output->set_charset(RCMAIL_CHARSET); // add some basic labels to client - $this->output->add_label('loading', 'servererror', 'requesttimedout'); + $this->output->add_label('loading', 'servererror', 'requesttimedout', 'refreshing'); return $this->output; } @@ -522,7 +518,6 @@ class rcmail extends rcube // Configure environment $this->set_user($user); $this->set_storage_prop(); - $this->session_configure(); // fix some old settings according to namespace prefix $this->fix_namespace_settings($user); @@ -775,6 +770,7 @@ class rcmail extends rcube } } + /** * Registers action aliases for current task * @@ -789,6 +785,7 @@ class rcmail extends rcube } } + /** * Returns current action filename * @@ -803,6 +800,7 @@ class rcmail extends rcube return strtr($this->action, '-', '_') . '.inc'; } + /** * Fixes some user preferences according to namespace handling change. * Old Roundcube versions were using folder names with removed namespace prefix. diff --git a/program/include/rcube.php b/program/include/rcube.php index 0e40b3c6b..9c1a6d84a 100644 --- a/program/include/rcube.php +++ b/program/include/rcube.php @@ -434,6 +434,9 @@ class rcube $this->session->register_gc_handler(array($this, 'temp_gc')); $this->session->register_gc_handler(array($this, 'cache_gc')); + $this->session->set_secret($this->config->get('des_key') . dirname($_SERVER['SCRIPT_NAME'])); + $this->session->set_ip_check($this->config->get('ip_check')); + // start PHP session (if not in CLI mode) if ($_SERVER['REMOTE_ADDR']) { session_start(); @@ -442,33 +445,6 @@ class rcube /** - * Configure session object internals - */ - public function session_configure() - { - if (!$this->session) { - return; - } - - $lifetime = $this->config->get('session_lifetime', 0) * 60; - $keep_alive = $this->config->get('keep_alive'); - - // set keep-alive/check-recent interval - if ($keep_alive) { - // be sure that it's less than session lifetime - if ($lifetime) { - $keep_alive = min($keep_alive, $lifetime - 30); - } - $keep_alive = max(60, $keep_alive); - $this->session->set_keep_alive($keep_alive); - } - - $this->session->set_secret($this->config->get('des_key') . dirname($_SERVER['SCRIPT_NAME'])); - $this->session->set_ip_check($this->config->get('ip_check')); - } - - - /** * Garbage collector function for temp files. * Remove temp files older than two days */ diff --git a/program/include/rcube_charset.php b/program/include/rcube_charset.php index ff4c2bbce..4d24ed135 100644 --- a/program/include/rcube_charset.php +++ b/program/include/rcube_charset.php @@ -655,22 +655,49 @@ class rcube_charset */ public static function detect($string, $failover='') { - if (!function_exists('mb_detect_encoding')) { - return $failover; - } - - // FIXME: the order is important, because sometimes - // iso string is detected as euc-jp and etc. - $enc = array( - 'UTF-8', 'SJIS', 'BIG5', 'GB2312', - 'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3', 'ISO-8859-4', - 'ISO-8859-5', 'ISO-8859-6', 'ISO-8859-7', 'ISO-8859-8', 'ISO-8859-9', - 'ISO-8859-10', 'ISO-8859-13', 'ISO-8859-14', 'ISO-8859-15', 'ISO-8859-16', - 'WINDOWS-1252', 'WINDOWS-1251', 'EUC-JP', 'EUC-TW', 'KOI8-R', - 'ISO-2022-KR', 'ISO-2022-JP' - ); + if (substr($string, 0, 4) == "\0\0\xFE\xFF") return 'UTF-32BE'; // Big Endian + if (substr($string, 0, 4) == "\xFF\xFE\0\0") return 'UTF-32LE'; // Little Endian + if (substr($string, 0, 2) == "\xFE\xFF") return 'UTF-16BE'; // Big Endian + if (substr($string, 0, 2) == "\xFF\xFE") return 'UTF-16LE'; // Little Endian + if (substr($string, 0, 3) == "\xEF\xBB\xBF") return 'UTF-8'; + + // heuristics + if ($string[0] == "\0" && $string[1] == "\0" && $string[2] == "\0" && $string[3] != "\0") return 'UTF-32BE'; + if ($string[0] != "\0" && $string[1] == "\0" && $string[2] == "\0" && $string[3] == "\0") return 'UTF-32LE'; + if ($string[0] == "\0" && $string[1] != "\0" && $string[2] == "\0" && $string[3] != "\0") return 'UTF-16BE'; + if ($string[0] != "\0" && $string[1] == "\0" && $string[2] != "\0" && $string[3] == "\0") return 'UTF-16LE'; + + if (function_exists('mb_detect_encoding')) { + // FIXME: the order is important, because sometimes + // iso string is detected as euc-jp and etc. + $enc = array( + 'UTF-8', 'SJIS', 'GB2312', + 'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3', 'ISO-8859-4', + 'ISO-8859-5', 'ISO-8859-6', 'ISO-8859-7', 'ISO-8859-8', 'ISO-8859-9', + 'ISO-8859-10', 'ISO-8859-13', 'ISO-8859-14', 'ISO-8859-15', 'ISO-8859-16', + 'WINDOWS-1252', 'WINDOWS-1251', 'EUC-JP', 'EUC-TW', 'KOI8-R', 'BIG5', + 'ISO-2022-KR', 'ISO-2022-JP', + ); - $result = mb_detect_encoding($string, join(',', $enc)); + $result = mb_detect_encoding($string, join(',', $enc)); + } + else { + // No match, check for UTF-8 + // from http://w3.org/International/questions/qa-forms-utf-8.html + if (preg_match('/\A( + [\x09\x0A\x0D\x20-\x7E] + | [\xC2-\xDF][\x80-\xBF] + | \xE0[\xA0-\xBF][\x80-\xBF] + | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} + | \xED[\x80-\x9F][\x80-\xBF] + | \xF0[\x90-\xBF][\x80-\xBF]{2} + | [\xF1-\xF3][\x80-\xBF]{3} + | \xF4[\x80-\x8F][\x80-\xBF]{2} + )*\z/xs', substr($string, 0, 2048)) + ) { + return 'UTF-8'; + } + } return $result ? $result : $failover; } diff --git a/program/include/rcube_config.php b/program/include/rcube_config.php index 1f165ba4a..bbc3e9c6e 100644 --- a/program/include/rcube_config.php +++ b/program/include/rcube_config.php @@ -43,6 +43,8 @@ class rcube_config 'mail_pagesize' => 'pagesize', 'addressbook_pagesize' => 'pagesize', 'reply_mode' => 'top_posting', + 'refresh_interval' => 'keep_alive', + 'min_refresh_interval' => 'min_keep_alive', ); diff --git a/program/include/rcube_csv2vcard.php b/program/include/rcube_csv2vcard.php new file mode 100644 index 000000000..bde8198ba --- /dev/null +++ b/program/include/rcube_csv2vcard.php @@ -0,0 +1,363 @@ +<?php + +/* + +-----------------------------------------------------------------------+ + | program/include/rcube_csv2vcard.php | + | | + | This file is part of the Roundcube Webmail client | + | Copyright (C) 2008-2012, The Roundcube Dev Team | + | | + | Licensed under the GNU General Public License version 3 or | + | any later version with exceptions for skins & plugins. | + | See the README file for a full license statement. | + | | + | PURPOSE: | + | CSV to vCard data conversion | + +-----------------------------------------------------------------------+ + | Author: Aleksander Machniak <alec@alec.pl> | + +-----------------------------------------------------------------------+ +*/ + +/** + * CSV to vCard data converter + * + * @package Roundcube Framework + * @author Aleksander Machniak <alec@alec.pl> + */ +class rcube_csv2vcard +{ + /** + * CSV to vCard fields mapping + * + * @var array + */ + protected $csv2vcard_map = array( + // MS Outlook 2010 + 'anniversary' => 'anniversary', + 'assistants_name' => 'assistant', + 'assistants_phone' => 'phone:assistant', + 'birthday' => 'birthday', + 'business_city' => 'locality:work', + 'business_countryregion' => 'country:work', + 'business_fax' => 'phone:work,fax', + 'business_phone' => 'phone:work', + 'business_phone_2' => 'phone:work2', + 'business_postal_code' => 'zipcode:work', + 'business_state' => 'region:work', + 'business_street' => 'street:work', + //'business_street_2' => '', + //'business_street_3' => '', + 'car_phone' => 'phone:car', + 'categories' => 'categories', + //'children' => '', + 'company' => 'organization', + //'company_main_phone' => '', + 'department' => 'department', + //'email_2_address' => '', //@TODO + //'email_2_type' => '', + //'email_3_address' => '', //@TODO + //'email_3_type' => '', + 'email_address' => 'email:main', + //'email_type' => '', + 'first_name' => 'firstname', + 'gender' => 'gender', + 'home_city' => 'locality:home', + 'home_countryregion' => 'country:home', + 'home_fax' => 'phone:home,fax', + 'home_phone' => 'phone:home', + 'home_phone_2' => 'phone:home2', + 'home_postal_code' => 'zipcode:home', + 'home_state' => 'region:home', + 'home_street' => 'street:home', + //'home_street_2' => '', + //'home_street_3' => '', + //'initials' => '', + //'isdn' => '', + 'job_title' => 'jobtitle', + //'keywords' => '', + //'language' => '', + 'last_name' => 'surname', + //'location' => '', + 'managers_name' => 'manager', + 'middle_name' => 'middlename', + //'mileage' => '', + 'mobile_phone' => 'phone:cell', + 'notes' => 'notes', + //'office_location' => '', + 'other_city' => 'locality:other', + 'other_countryregion' => 'country:other', + 'other_fax' => 'phone:other,fax', + 'other_phone' => 'phone:other', + 'other_postal_code' => 'zipcode:other', + 'other_state' => 'region:other', + 'other_street' => 'street:other', + //'other_street_2' => '', + //'other_street_3' => '', + 'pager' => 'phone:pager', + 'primary_phone' => 'phone:pref', + //'profession' => '', + //'radio_phone' => '', + 'spouse' => 'spouse', + 'suffix' => 'suffix', + 'title' => 'title', + 'web_page' => 'website:homepage', + + // Thunderbird + 'birth_day' => 'birthday-d', + 'birth_month' => 'birthday-m', + 'birth_year' => 'birthday-y', + 'display_name' => 'displayname', + 'fax_number' => 'phone:fax', + 'home_address' => 'street:home', + //'home_address_2' => '', + 'home_country' => 'country:home', + 'home_zipcode' => 'zipcode:home', + 'mobile_number' => 'phone:cell', + 'nickname' => 'nickname', + 'organization' => 'organization', + 'pager_number' => 'phone:pager', + 'primary_email' => 'email:pref', + 'secondary_email' => 'email:other', + 'web_page_1' => 'website:homepage', + 'web_page_2' => 'website:other', + 'work_phone' => 'phone:work', + 'work_address' => 'street:work', + //'work_address_2' => '', + 'work_country' => 'country:work', + 'work_zipcode' => 'zipcode:work', + ); + + /** + * CSV label to text mapping for English + * + * @var array + */ + protected $label_map = array( + // MS Outlook 2010 + 'anniversary' => "Anniversary", + 'assistants_name' => "Assistant's Name", + 'assistants_phone' => "Assistant's Phone", + 'birthday' => "Birthday", + 'business_city' => "Business City", + 'business_countryregion' => "Business Country/Region", + 'business_fax' => "Business Fax", + 'business_phone' => "Business Phone", + 'business_phone_2' => "Business Phone 2", + 'business_postal_code' => "Business Postal Code", + 'business_state' => "Business State", + 'business_street' => "Business Street", + //'business_street_2' => "Business Street 2", + //'business_street_3' => "Business Street 3", + 'car_phone' => "Car Phone", + 'categories' => "Categories", + //'children' => "Children", + 'company' => "Company", + //'company_main_phone' => "Company Main Phone", + 'department' => "Department", + //'directory_server' => "Directory Server", + //'email_2_address' => "E-mail 2 Address", + //'email_2_type' => "E-mail 2 Type", + //'email_3_address' => "E-mail 3 Address", + //'email_3_type' => "E-mail 3 Type", + 'email_address' => "E-mail Address", + //'email_type' => "E-mail Type", + 'first_name' => "First Name", + 'gender' => "Gender", + 'home_city' => "Home City", + 'home_countryregion' => "Home Country/Region", + 'home_fax' => "Home Fax", + 'home_phone' => "Home Phone", + 'home_phone_2' => "Home Phone 2", + 'home_postal_code' => "Home Postal Code", + 'home_state' => "Home State", + 'home_street' => "Home Street", + //'home_street_2' => "Home Street 2", + //'home_street_3' => "Home Street 3", + //'initials' => "Initials", + //'isdn' => "ISDN", + 'job_title' => "Job Title", + //'keywords' => "Keywords", + //'language' => "Language", + 'last_name' => "Last Name", + //'location' => "Location", + 'managers_name' => "Manager's Name", + 'middle_name' => "Middle Name", + //'mileage' => "Mileage", + 'mobile_phone' => "Mobile Phone", + 'notes' => "Notes", + //'office_location' => "Office Location", + 'other_city' => "Other City", + 'other_countryregion' => "Other Country/Region", + 'other_fax' => "Other Fax", + 'other_phone' => "Other Phone", + 'other_postal_code' => "Other Postal Code", + 'other_state' => "Other State", + 'other_street' => "Other Street", + //'other_street_2' => "Other Street 2", + //'other_street_3' => "Other Street 3", + 'pager' => "Pager", + 'primary_phone' => "Primary Phone", + //'profession' => "Profession", + //'radio_phone' => "Radio Phone", + 'spouse' => "Spouse", + 'suffix' => "Suffix", + 'title' => "Title", + 'web_page' => "Web Page", + + // Thunderbird + 'birth_day' => "Birth Day", + 'birth_month' => "Birth Month", + 'birth_year' => "Birth Year", + 'display_name' => "Display Name", + 'fax_number' => "Fax Number", + 'home_address' => "Home Address", + //'home_address_2' => "Home Address 2", + 'home_country' => "Home Country", + 'home_zipcode' => "Home ZipCode", + 'mobile_number' => "Mobile Number", + 'nickname' => "Nickname", + 'organization' => "Organization", + 'pager_number' => "Pager Namber", + 'primary_email' => "Primary Email", + 'secondary_email' => "Secondary Email", + 'web_page_1' => "Web Page 1", + 'web_page_2' => "Web Page 2", + 'work_phone' => "Work Phone", + 'work_address' => "Work Address", + //'work_address_2' => "Work Address 2", + 'work_country' => "Work Country", + 'work_zipcode' => "Work ZipCode", + ); + + protected $vcards = array(); + protected $map = array(); + + + /** + * Class constructor + * + * @param string $lang File language + */ + public function __construct($lang = 'en_US') + { + // Localize fields map + if ($lang && $lang != 'en_US') { + if (file_exists(INSTALL_PATH . "program/localization/$lang/csv2vcard.inc")) { + include INSTALL_PATH . "program/localization/$lang/csv2vcard.inc"; + } + + if (!empty($map)) { + $this->label_map = array_merge($this->label_map, $map); + } + } + + $this->label_map = array_flip($this->label_map); + } + + /** + * + */ + public function import($csv) + { + // convert to UTF-8 + $head = substr($csv, 0, 4096); + $fallback = rcube::get_instance()->config->get('default_charset', 'ISO-8859-1'); // fallback to Latin-1? + $charset = rcube_charset::detect($head, RCMAIL_CHARSET); + $csv = rcube_charset::convert($csv, $charset); + $head = ''; + + $this->map = array(); + + // Parse file + foreach (preg_split("/[\r\n]+/", $csv) as $i => $line) { + $line = trim($line); + if (empty($line)) { + continue; + } + + $elements = rcube_utils::explode_quoted_string(',', $line); + + if (empty($elements)) { + continue; + } + + // Parse header + if (empty($this->map)) { + $this->parse_header($elements); + if (empty($this->map)) { + break; + } + } + // Parse data row + else { + $this->csv_to_vcard($elements); + } + } + } + + /** + * @return array rcube_vcard List of vcards + */ + public function export() + { + return $this->vcards; + } + + /** + * Parse CSV header line, detect fields mapping + */ + protected function parse_header($elements) + { + for ($i = 0, $size = count($elements); $i<$size; $i++) { + $label = $this->label_map[$elements[$i]]; + if ($label && !empty($this->csv2vcard_map[$label])) { + $this->map[$i] = $this->csv2vcard_map[$label]; + } + } + } + + /** + * Convert CSV data row to vCard + */ + protected function csv_to_vcard($data) + { + $contact = array(); + foreach ($this->map as $idx => $name) { + $value = $data[$idx]; + if ($value !== null && $value !== '') { + $contact[$name] = $value; + } + } + + if (empty($contact)) { + return; + } + + // Handle special values + if (!empty($contact['birthday-d']) && !empty($contact['birthday-m']) && !empty($contact['birthday-y'])) { + $contact['birthday'] = $contact['birthday-y'] .'-' .$contact['birthday-m'] . '-' . $contact['birthday-d']; + } + + foreach (array('birthday', 'anniversary') as $key) { + if (!empty($contact[$key]) && $contact[$key] == '0/0/00') { // @TODO: localization? + unset($contact[$key]); + } + } + + if (!empty($contact['gender']) && ($gender = strtolower($contact['gender']))) { + if (!in_array($gender, array('male', 'female'))) { + unset($contact['gender']); + } + } + + // Create vcard object + $vcard = new rcube_vcard(); + foreach ($contact as $name => $value) { + $name = explode(':', $name); + $vcard->set($name[0], $value, $name[1]); + } + + // add to the list + $this->vcards[] = $vcard; + } +} diff --git a/program/include/rcube_image.php b/program/include/rcube_image.php index 80e8bd4f3..c0d4e878d 100644 --- a/program/include/rcube_image.php +++ b/program/include/rcube_image.php @@ -78,10 +78,11 @@ class rcube_image * * @param int $size Max width/height size * @param string $filename Output filename + * @param boolean $browser_compat Convert to image type displayable by any browser * - * @return bool True on success, False on failure + * @return mixed Output type on success, False on failure */ - public function resize($size, $filename = null) + public function resize($size, $filename = null, $browser_compat = false) { $result = false; $rcube = rcube::get_instance(); @@ -104,15 +105,22 @@ class rcube_image } $type = strtr($type, array("jpeg" => "jpg", "tiff" => "tif", "ps" => "eps", "ept" => "eps")); + $p['intype'] = $type; + + // convert to an image format every browser can display + if ($browser_compat && !in_array($type, array('jpg','gif','png'))) { + $type = 'jpg'; + } + $p += array('type' => $type, 'types' => "bmp,eps,gif,jp2,jpg,png,svg,tif", 'quality' => 75); - $p['-opts'] = array('-resize' => $size.'>'); + $p['-opts'] = array('-resize' => $p['size'].'>'); if (in_array($type, explode(',', $p['types']))) { // Valid type? - $result = rcube::exec($convert . ' 2>&1 -flatten -auto-orient -colorspace RGB -quality {quality} {-opts} {in} {type}:{out}', $p); + $result = rcube::exec($convert . ' 2>&1 -flatten -auto-orient -colorspace RGB -quality {quality} {-opts} {intype}:{in} {type}:{out}', $p); } if ($result === '') { - return true; + return $type; } } @@ -148,16 +156,19 @@ class rcube_image if ($props['gd_type'] == IMAGETYPE_JPEG) { $result = imagejpeg($image, $filename, 75); + $type = 'jpg'; } elseif($props['gd_type'] == IMAGETYPE_GIF) { $result = imagegif($image, $filename); + $type = 'gid'; } elseif($props['gd_type'] == IMAGETYPE_PNG) { $result = imagepng($image, $filename, 6, PNG_ALL_FILTERS); + $type = 'png'; } if ($result) { - return true; + return $type; } } diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php index a89fd164d..f2645f60f 100644 --- a/program/include/rcube_imap.php +++ b/program/include/rcube_imap.php @@ -2074,7 +2074,7 @@ class rcube_imap extends rcube_storage if ($o_part && $o_part->size) { $body = $this->conn->handlePartBody($this->folder, $uid, true, - $part ? $part : 'TEXT', $o_part->encoding, $print, $fp); + $part ? $part : 'TEXT', $o_part->encoding, $print, $fp, $o_part->ctype_primary == 'text'); } if ($fp || $print) { diff --git a/program/include/rcube_imap_generic.php b/program/include/rcube_imap_generic.php index 651de9d97..bc7ecfc37 100644 --- a/program/include/rcube_imap_generic.php +++ b/program/include/rcube_imap_generic.php @@ -2379,7 +2379,7 @@ class rcube_imap_generic return $this->handlePartBody($mailbox, $id, $is_uid, $part); } - function handlePartBody($mailbox, $id, $is_uid=false, $part='', $encoding=NULL, $print=NULL, $file=NULL, $formatted=true) + function handlePartBody($mailbox, $id, $is_uid=false, $part='', $encoding=NULL, $print=NULL, $file=NULL, $formatted=false) { if (!$this->select($mailbox)) { return false; @@ -2417,6 +2417,7 @@ class rcube_imap_generic } if ($binary) { + // WARNING: Use $formatting argument with care, this may break binary data stream $mode = -1; } diff --git a/program/include/rcube_ldap.php b/program/include/rcube_ldap.php index 61a073fa3..7cef25556 100644 --- a/program/include/rcube_ldap.php +++ b/program/include/rcube_ldap.php @@ -160,7 +160,8 @@ class rcube_ldap extends rcube_addressbook } // make sure LDAP_rdn field is required - if (!empty($this->prop['LDAP_rdn']) && !in_array($this->prop['LDAP_rdn'], $this->prop['required_fields'])) { + if (!empty($this->prop['LDAP_rdn']) && !in_array($this->prop['LDAP_rdn'], $this->prop['required_fields']) + && !in_array($this->prop['LDAP_rdn'], array_keys((array)$this->prop['autovalues']))) { $this->prop['required_fields'][] = $this->prop['LDAP_rdn']; } @@ -1086,6 +1087,9 @@ class rcube_ldap extends rcube_addressbook $newentry = $this->_map_data($save_cols); $newentry['objectClass'] = $this->prop['LDAP_Object_Classes']; + // add automatically generated attributes + $this->add_autovalues($newentry); + // Verify that the required fields are set. $missing = null; foreach ($this->prop['required_fields'] as $fld) { @@ -1389,6 +1393,30 @@ class rcube_ldap extends rcube_addressbook } } + /** + * Generate missing attributes as configured + * + * @param array LDAP record attributes + */ + protected function add_autovalues(&$attrs) + { + $attrvals = array(); + foreach ($attrs as $k => $v) { + $attrvals['{'.$k.'}'] = is_array($v) ? $v[0] : $v; + } + + foreach ((array)$this->prop['autovalues'] as $lf => $templ) { + if (empty($attrs[$lf])) { + // replace {attr} placeholders with concrete attribute values + $templ = preg_replace('/\{\w+\}/', '', strtr($templ, $attrvals)); + + if (strpos($templ, '(') !== false) + $attrs[$lf] = eval("return ($templ);"); + else + $attrs[$lf] = $templ; + } + } + } /** * Execute the LDAP search based on the stored credentials diff --git a/program/include/rcube_message.php b/program/include/rcube_message.php index 47aa4493e..74bf4574f 100644 --- a/program/include/rcube_message.php +++ b/program/include/rcube_message.php @@ -198,14 +198,15 @@ class rcube_message * Determine if the message contains a HTML part * * @param bool $recursive Enables checking in all levels of the structure + * @param bool $enriched Enables checking for text/enriched parts too * * @return bool True if a HTML is available, False if not */ - function has_html_part($recursive = true) + function has_html_part($recursive = true, $enriched = false) { // check all message parts foreach ($this->parts as $part) { - if ($part->mimetype == 'text/html') { + if ($part->mimetype == 'text/html' || ($enriched && $part->mimetype == 'text/enriched')) { // Level check, we'll skip e.g. HTML attachments if (!$recursive) { $level = explode('.', $part->mime_id); @@ -270,10 +271,6 @@ class rcube_message else if ($part->mimetype == 'text/html') { $out = $this->get_part_content($mime_id); - // remove special chars encoding - $trans = array_flip(get_html_translation_table(HTML_ENTITIES)); - $out = strtr($out, $trans); - // create instance of html2text class $txt = new html2text($out); return $txt->get_text(); diff --git a/program/include/rcube_output_html.php b/program/include/rcube_output_html.php index d80d28a9b..ac07d58e9 100644 --- a/program/include/rcube_output_html.php +++ b/program/include/rcube_output_html.php @@ -457,7 +457,7 @@ class rcube_output_html extends rcube_output if (is_readable($path)) { $this->config->set('skin_path', $skin_path); - $this->base_path = $skin_path; + $this->base_path = preg_replace('!plugins/\w+/!', '', $skin_path); // set base_path to core skin directory (not plugin's skin) break; } else { @@ -494,8 +494,6 @@ class rcube_output_html extends rcube_output $output = $hook['content']; unset($hook['content']); - $output = $this->parse_with_globals($this->fix_paths($output)); - // make sure all <form> tags have a valid request token $output = preg_replace_callback('/<form\s+([^>]+)>/Ui', array($this, 'alter_form_tag'), $output); $this->footer = preg_replace_callback('/<form\s+([^>]+)>/Ui', array($this, 'alter_form_tag'), $this->footer); @@ -856,7 +854,7 @@ class rcube_output_html extends rcube_output case 'include': $old_base_path = $this->base_path; if ($path = $this->get_skin_file($attrib['file'], $skin_path, $attrib['skinpath'])) { - $this->base_path = $skin_path; + $this->base_path = preg_replace('!plugins/\w+/!', '', $skin_path); // set base_path to core skin directory (not plugin's skin) $path = realpath($path); } @@ -1089,7 +1087,7 @@ class rcube_output_html extends rcube_output // make valid href to specific buttons if (in_array($attrib['command'], rcmail::$main_tasks)) { $attrib['href'] = $this->app->url(array('task' => $attrib['command'])); - $attrib['onclick'] = sprintf("%s.command('switch-task','%s',null,event); return false", rcmail::JS_OBJECT_NAME, $attrib['command']); + $attrib['onclick'] = sprintf("return %s.command('switch-task','%s',this,event)", rcmail::JS_OBJECT_NAME, $attrib['command']); } else if ($attrib['task'] && in_array($attrib['task'], rcmail::$main_tasks)) { $attrib['href'] = $this->app->url(array('action' => $attrib['command'], 'task' => $attrib['task'])); @@ -1357,6 +1355,8 @@ class rcube_output_html extends rcube_output $output = substr_replace($output, $css, $pos, 0); } + $output = $this->parse_with_globals($this->fix_paths($output)); + // trigger hook with final HTML content to be sent $hook = $this->app->plugins->exec_hook("send_page", array('content' => $output)); if (!$hook['abort']) { diff --git a/program/include/rcube_plugin_api.php b/program/include/rcube_plugin_api.php index 107c81026..c473b0b17 100644 --- a/program/include/rcube_plugin_api.php +++ b/program/include/rcube_plugin_api.php @@ -327,7 +327,7 @@ class rcube_plugin_api if (isset($this->actions[$action])) { call_user_func($this->actions[$action]); } - else { + else if (rcube::get_instance()->action != 'refresh') { rcube::raise_error(array('code' => 524, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "No handler found for action $action"), true, true); diff --git a/program/include/rcube_session.php b/program/include/rcube_session.php index 6192466cd..c71efa2aa 100644 --- a/program/include/rcube_session.php +++ b/program/include/rcube_session.php @@ -43,7 +43,6 @@ class rcube_session private $secret = ''; private $ip_check = false; private $logging = false; - private $keep_alive = 0; private $memcache; /** @@ -525,24 +524,6 @@ class rcube_session $this->now = $now - ($now % ($this->lifetime / 2)); } - /** - * Setter for keep_alive interval - */ - public function set_keep_alive($keep_alive) - { - $this->keep_alive = $keep_alive; - - if ($this->lifetime < $keep_alive) - $this->set_lifetime($keep_alive + 30); - } - - /** - * Getter for keep_alive interval - */ - public function get_keep_alive() - { - return $this->keep_alive; - } /** * Getter for remote IP saved with this session @@ -552,6 +533,7 @@ class rcube_session return $this->ip; } + /** * Setter for cookie encryption secret */ diff --git a/program/include/rcube_user.php b/program/include/rcube_user.php index b92187ad4..72b03cd15 100644 --- a/program/include/rcube_user.php +++ b/program/include/rcube_user.php @@ -47,6 +47,13 @@ class rcube_user */ private $rc; + /** + * Internal identities cache + * + * @var array + */ + private $identities = array(); + const SEARCH_ADDRESSBOOK = 1; const SEARCH_MAIL = 2; @@ -213,8 +220,14 @@ class rcube_user */ function get_identity($id = null) { - $result = $this->list_identities($id ? sprintf('AND identity_id = %d', $id) : ''); - return $result[0]; + $id = (int)$id; + // cache identities for better performance + if (!array_key_exists($id, $this->identities)) { + $result = $this->list_identities($id ? 'AND identity_id = ' . $id : ''); + $this->identities[$id] = $result[0]; + } + + return $this->identities[$id]; } @@ -273,6 +286,8 @@ class rcube_user call_user_func_array(array($this->db, 'query'), array_merge(array($sql), $query_params)); + $this->identities = array(); + return $this->db->affected_rows(); } @@ -305,6 +320,8 @@ class rcube_user call_user_func_array(array($this->db, 'query'), array_merge(array($sql), $insert_values)); + $this->identities = array(); + return $this->db->insert_id('identities'); } @@ -339,6 +356,8 @@ class rcube_user $this->ID, $iid); + $this->identities = array(); + return $this->db->affected_rows(); } @@ -359,6 +378,8 @@ class rcube_user " AND del <> 1", $this->ID, $iid); + + unset($this->identities[0]); } } diff --git a/program/include/rcube_utils.php b/program/include/rcube_utils.php index 2a4d4c482..5cfd8e70e 100644 --- a/program/include/rcube_utils.php +++ b/program/include/rcube_utils.php @@ -761,7 +761,7 @@ class rcube_utils } } - $result[] = substr($string, $p); + $result[] = (string) substr($string, $p); return $result; } diff --git a/program/include/rcube_vcard.php b/program/include/rcube_vcard.php index 00903c257..51a7fe71a 100644 --- a/program/include/rcube_vcard.php +++ b/program/include/rcube_vcard.php @@ -62,7 +62,6 @@ class rcube_vcard public $middlename; public $nickname; public $organization; - public $notes; public $email = array(); public static $eol = "\r\n"; @@ -265,26 +264,25 @@ class rcube_vcard */ public function set($field, $value, $type = 'HOME') { - $field = strtolower($field); + $field = strtolower($field); $type_uc = strtoupper($type); - $typemap = array_flip($this->typemap); switch ($field) { case 'name': case 'displayname': - $this->raw['FN'][0][0] = $value; + $this->raw['FN'][0][0] = $this->displayname = $value; break; case 'surname': - $this->raw['N'][0][0] = $value; + $this->raw['N'][0][0] = $this->surname = $value; break; case 'firstname': - $this->raw['N'][0][1] = $value; + $this->raw['N'][0][1] = $this->firstname = $value; break; case 'middlename': - $this->raw['N'][0][2] = $value; + $this->raw['N'][0][2] = $this->middlename = $value; break; case 'prefix': @@ -296,11 +294,11 @@ class rcube_vcard break; case 'nickname': - $this->raw['NICKNAME'][0][0] = $value; + $this->raw['NICKNAME'][0][0] = $this->nickname = $value; break; case 'organization': - $this->raw['ORG'][0][0] = $value; + $this->raw['ORG'][0][0] = $this->organization = $value; break; case 'photo': @@ -348,8 +346,10 @@ class rcube_vcard if (($tag = self::$fieldmap[$field]) && (is_array($value) || strlen($value))) { $index = count($this->raw[$tag]); $this->raw[$tag][$index] = (array)$value; - if ($type) + if ($type) { + $typemap = array_flip($this->typemap); $this->raw[$tag][$index]['type'] = explode(',', ($typemap[$type_uc] ? $typemap[$type_uc] : $type)); + } } break; } @@ -784,42 +784,9 @@ class rcube_vcard */ private static function detect_encoding($string) { - if (substr($string, 0, 4) == "\0\0\xFE\xFF") return 'UTF-32BE'; // Big Endian - if (substr($string, 0, 4) == "\xFF\xFE\0\0") return 'UTF-32LE'; // Little Endian - if (substr($string, 0, 2) == "\xFE\xFF") return 'UTF-16BE'; // Big Endian - if (substr($string, 0, 2) == "\xFF\xFE") return 'UTF-16LE'; // Little Endian - if (substr($string, 0, 3) == "\xEF\xBB\xBF") return 'UTF-8'; - - // heuristics - if ($string[0] == "\0" && $string[1] == "\0" && $string[2] == "\0" && $string[3] != "\0") return 'UTF-32BE'; - if ($string[0] != "\0" && $string[1] == "\0" && $string[2] == "\0" && $string[3] == "\0") return 'UTF-32LE'; - if ($string[0] == "\0" && $string[1] != "\0" && $string[2] == "\0" && $string[3] != "\0") return 'UTF-16BE'; - if ($string[0] != "\0" && $string[1] == "\0" && $string[2] != "\0" && $string[3] == "\0") return 'UTF-16LE'; - - // use mb_detect_encoding() - $encodings = array('UTF-8', 'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3', - 'ISO-8859-4', 'ISO-8859-5', 'ISO-8859-6', 'ISO-8859-7', 'ISO-8859-8', 'ISO-8859-9', - 'ISO-8859-10', 'ISO-8859-13', 'ISO-8859-14', 'ISO-8859-15', 'ISO-8859-16', - 'WINDOWS-1252', 'WINDOWS-1251', 'BIG5', 'GB2312'); - - if (function_exists('mb_detect_encoding') && ($enc = mb_detect_encoding($string, $encodings))) - return $enc; - - // No match, check for UTF-8 - // from http://w3.org/International/questions/qa-forms-utf-8.html - if (preg_match('/\A( - [\x09\x0A\x0D\x20-\x7E] - | [\xC2-\xDF][\x80-\xBF] - | \xE0[\xA0-\xBF][\x80-\xBF] - | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} - | \xED[\x80-\x9F][\x80-\xBF] - | \xF0[\x90-\xBF][\x80-\xBF]{2} - | [\xF1-\xF3][\x80-\xBF]{3} - | \xF4[\x80-\x8F][\x80-\xBF]{2} - )*\z/xs', substr($string, 0, 2048))) - return 'UTF-8'; - - return rcube::get_instance()->config->get('default_charset', 'ISO-8859-1'); # fallback to Latin-1 + $fallback = rcube::get_instance()->config->get('default_charset', 'ISO-8859-1'); // fallback to Latin-1 + + return rcube_charset::detect($string, $fallback); } } |