示例#1
0
 /**
  * Handler for submitted form (ajax request)
  *
  * Check fields and save to default identity if valid.
  * Afterwards the session flag is removed and we're done.
  */
 function save_data()
 {
     $rcmail = rcmail::get_instance();
     $identity = $rcmail->user->get_identity();
     $ident_level = intval($rcmail->config->get('identities_level', 0));
     $save_data = array('name' => rcube_utils::get_input_value('_name', rcube_utils::INPUT_POST), 'email' => rcube_utils::get_input_value('_email', rcube_utils::INPUT_POST), 'organization' => rcube_utils::get_input_value('_organization', rcube_utils::INPUT_POST), 'signature' => rcube_utils::get_input_value('_signature', rcube_utils::INPUT_POST));
     // don't let the user alter the e-mail address if disabled by config
     if (in_array($ident_level, array(1, 3, 4))) {
         $save_data['email'] = $identity['email'];
     }
     if (empty($save_data['name']) || empty($save_data['email'])) {
         $rcmail->output->show_message('formincomplete', 'error');
     } else {
         if (!rcube_utils::check_email($save_data['email'] = rcube_utils::idn_to_ascii($save_data['email']))) {
             $rcmail->output->show_message('emailformaterror', 'error', array('email' => $save_data['email']));
         } else {
             // save data
             $rcmail->user->update_identity($identity['identity_id'], $save_data);
             $rcmail->session->remove('plugin.newuserdialog');
             // hide dialog
             $rcmail->output->command('new_user_dialog_close');
             $rcmail->output->show_message('successfullysaved', 'confirmation');
         }
     }
     $rcmail->output->send();
 }
 public function create_identity($p)
 {
     $rcmail = rcmail::get_instance();
     // prefs are set in create_user()
     if ($this->prefs) {
         if ($this->prefs['full_name']) {
             $p['record']['name'] = $this->prefs['full_name'];
         }
         if (($this->identities_level == 0 || $this->identities_level == 2) && $this->prefs['email_address']) {
             $p['record']['email'] = $this->prefs['email_address'];
         }
         if ($this->prefs['___signature___']) {
             $p['record']['signature'] = $this->prefs['___signature___'];
         }
         if ($this->prefs['reply_to']) {
             $p['record']['reply-to'] = $this->prefs['reply_to'];
         }
         if (($this->identities_level == 0 || $this->identities_level == 1) && isset($this->prefs['identities']) && $this->prefs['identities'] > 1) {
             for ($i = 1; $i < $this->prefs['identities']; $i++) {
                 unset($ident_data);
                 $ident_data = array('name' => '', 'email' => '');
                 // required data
                 if ($this->prefs['full_name' . $i]) {
                     $ident_data['name'] = $this->prefs['full_name' . $i];
                 }
                 if ($this->identities_level == 0 && $this->prefs['email_address' . $i]) {
                     $ident_data['email'] = $this->prefs['email_address' . $i];
                 } else {
                     $ident_data['email'] = $p['record']['email'];
                 }
                 if ($this->prefs['reply_to' . $i]) {
                     $ident_data['reply-to'] = $this->prefs['reply_to' . $i];
                 }
                 if ($this->prefs['___sig' . $i . '___']) {
                     $ident_data['signature'] = $this->prefs['___sig' . $i . '___'];
                 }
                 // insert identity
                 $rcmail->user->insert_identity($ident_data);
             }
         }
         // copy address book
         $contacts = $rcmail->get_address_book(null, true);
         if ($contacts && count($this->abook)) {
             foreach ($this->abook as $rec) {
                 // #1487096 handle multi-address and/or too long items
                 $rec['email'] = array_shift(explode(';', $rec['email']));
                 if (rcube_utils::check_email(rcube_utils::idn_to_ascii($rec['email']))) {
                     $rec['email'] = rcube_utils::idn_to_utf8($rec['email']);
                     $contacts->insert($rec, true);
                 }
             }
         }
         // mark identity as complete for following hooks
         $p['complete'] = true;
     }
     return $p;
 }
 /**
  * Callback function used to build mailto: links around e-mail strings
  *
  * This also adds an onclick-handler to open the Rouncube compose message screen on such links
  *
  * @param array Matches result from preg_replace_callback
  * @return int Index of saved string value
  * @see rcube_string_replacer::mailto_callback()
  */
 public function mailto_callback($matches)
 {
     $href = $matches[1];
     $suffix = $this->parse_url_brackets($href);
     $email = $href;
     if (strpos($email, '?')) {
         list($email, ) = explode('?', $email);
     }
     // skip invalid emails
     if (!rcube_utils::check_email($email, false)) {
         return $matches[1];
     }
     $i = $this->add(html::a(array('href' => 'mailto:' . $href, 'onclick' => "return " . rcmail_output::JS_OBJECT_NAME . ".command('compose','" . rcube::JQ($href) . "',this)"), rcube::Q($href)) . $suffix);
     return $i >= 0 ? $this->get_replacement($i) : '';
 }
示例#4
0
 /**
  * Check the given data before saving.
  * If input isn't valid, the message to display can be fetched using get_error()
  *
  * @param array Assoziative array with data to save
  * @param boolean Attempt to fix/complete record automatically
  * @return boolean True if input is valid, False if not.
  */
 public function validate(&$save_data, $autofix = false)
 {
     $rcube = rcube::get_instance();
     $valid = true;
     // check validity of email addresses
     foreach ($this->get_col_values('email', $save_data, true) as $email) {
         if (strlen($email)) {
             if (!rcube_utils::check_email(rcube_utils::idn_to_ascii($email))) {
                 $error = $rcube->gettext(array('name' => 'emailformaterror', 'vars' => array('email' => $email)));
                 $this->set_error(self::ERROR_VALIDATE, $error);
                 $valid = false;
                 break;
             }
         }
     }
     // allow plugins to do contact validation and auto-fixing
     $plugin = $rcube->plugins->exec_hook('contact_validate', array('record' => $save_data, 'autofix' => $autofix, 'valid' => $valid));
     if ($valid && !$plugin['valid']) {
         $this->set_error(self::ERROR_VALIDATE, $plugin['error']);
     }
     if (is_array($plugin['record'])) {
         $save_data = $plugin['record'];
     }
     return $plugin['valid'];
 }
 function save()
 {
     // Init plugin and handle managesieve connection
     $error = $this->start();
     // get request size limits (#1488648)
     $max_post = max(array(ini_get('max_input_vars'), ini_get('suhosin.request.max_vars'), ini_get('suhosin.post.max_vars')));
     $max_depth = max(array(ini_get('suhosin.request.max_array_depth'), ini_get('suhosin.post.max_array_depth')));
     // check request size limit
     if ($max_post && count($_POST, COUNT_RECURSIVE) >= $max_post) {
         rcube::raise_error(array('code' => 500, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Request size limit exceeded (one of max_input_vars/suhosin.request.max_vars/suhosin.post.max_vars)"), true, false);
         $this->rc->output->show_message('managesieve.filtersaveerror', 'error');
     } else {
         if ($max_depth && count($_POST['_header']) > $max_depth) {
             rcube::raise_error(array('code' => 500, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Request size limit exceeded (one of suhosin.request.max_array_depth/suhosin.post.max_array_depth)"), true, false);
             $this->rc->output->show_message('managesieve.filtersaveerror', 'error');
         } else {
             if (!empty($_POST['_newset'])) {
                 $name = rcube_utils::get_input_value('_name', rcube_utils::INPUT_POST, true);
                 $copy = rcube_utils::get_input_value('_copy', rcube_utils::INPUT_POST, true);
                 $from = rcube_utils::get_input_value('_from', rcube_utils::INPUT_POST);
                 $exceptions = $this->rc->config->get('managesieve_filename_exceptions');
                 $kolab = $this->rc->config->get('managesieve_kolab_master');
                 $name_uc = mb_strtolower($name);
                 $list = $this->list_scripts();
                 if (!$name) {
                     $this->errors['name'] = $this->plugin->gettext('cannotbeempty');
                 } else {
                     if (mb_strlen($name) > 128) {
                         $this->errors['name'] = $this->plugin->gettext('nametoolong');
                     } else {
                         if (!empty($exceptions) && in_array($name, (array) $exceptions)) {
                             $this->errors['name'] = $this->plugin->gettext('namereserved');
                         } else {
                             if (!empty($kolab) && in_array($name_uc, array('MASTER', 'USER', 'MANAGEMENT'))) {
                                 $this->errors['name'] = $this->plugin->gettext('namereserved');
                             } else {
                                 if (in_array($name, $list)) {
                                     $this->errors['name'] = $this->plugin->gettext('setexist');
                                 } else {
                                     if ($from == 'file') {
                                         // from file
                                         if (is_uploaded_file($_FILES['_file']['tmp_name'])) {
                                             $file = file_get_contents($_FILES['_file']['tmp_name']);
                                             $file = preg_replace('/\\r/', '', $file);
                                             // for security don't save script directly
                                             // check syntax before, like this...
                                             $this->sieve->load_script($file);
                                             if (!$this->save_script($name)) {
                                                 $this->errors['file'] = $this->plugin->gettext('setcreateerror');
                                             }
                                         } else {
                                             // upload failed
                                             $err = $_FILES['_file']['error'];
                                             if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) {
                                                 $msg = $this->rc->gettext(array('name' => 'filesizeerror', 'vars' => array('size' => $this->rc->show_bytes(parse_bytes(ini_get('upload_max_filesize'))))));
                                             } else {
                                                 $this->errors['file'] = $this->plugin->gettext('fileuploaderror');
                                             }
                                         }
                                     } else {
                                         if (!$this->sieve->copy($name, $from == 'set' ? $copy : '')) {
                                             $error = 'managesieve.setcreateerror';
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if (!$error && empty($this->errors)) {
                     // Find position of the new script on the list
                     $list[] = $name;
                     asort($list, SORT_LOCALE_STRING);
                     $list = array_values($list);
                     $index = array_search($name, $list);
                     $this->rc->output->show_message('managesieve.setcreated', 'confirmation');
                     $this->rc->output->command('parent.managesieve_updatelist', 'setadd', array('name' => $name, 'index' => $index));
                 } else {
                     if ($msg) {
                         $this->rc->output->command('display_message', $msg, 'error');
                     } else {
                         if ($error) {
                             $this->rc->output->show_message($error, 'error');
                         }
                     }
                 }
             } else {
                 if (isset($_POST['_name'])) {
                     $name = trim(rcube_utils::get_input_value('_name', rcube_utils::INPUT_POST, true));
                     $fid = trim(rcube_utils::get_input_value('_fid', rcube_utils::INPUT_POST));
                     $join = trim(rcube_utils::get_input_value('_join', rcube_utils::INPUT_POST));
                     // and arrays
                     $headers = rcube_utils::get_input_value('_header', rcube_utils::INPUT_POST);
                     $cust_headers = rcube_utils::get_input_value('_custom_header', rcube_utils::INPUT_POST);
                     $ops = rcube_utils::get_input_value('_rule_op', rcube_utils::INPUT_POST);
                     $sizeops = rcube_utils::get_input_value('_rule_size_op', rcube_utils::INPUT_POST);
                     $sizeitems = rcube_utils::get_input_value('_rule_size_item', rcube_utils::INPUT_POST);
                     $sizetargets = rcube_utils::get_input_value('_rule_size_target', rcube_utils::INPUT_POST);
                     $targets = rcube_utils::get_input_value('_rule_target', rcube_utils::INPUT_POST, true);
                     $mods = rcube_utils::get_input_value('_rule_mod', rcube_utils::INPUT_POST);
                     $mod_types = rcube_utils::get_input_value('_rule_mod_type', rcube_utils::INPUT_POST);
                     $body_trans = rcube_utils::get_input_value('_rule_trans', rcube_utils::INPUT_POST);
                     $body_types = rcube_utils::get_input_value('_rule_trans_type', rcube_utils::INPUT_POST, true);
                     $comparators = rcube_utils::get_input_value('_rule_comp', rcube_utils::INPUT_POST);
                     $indexes = rcube_utils::get_input_value('_rule_index', rcube_utils::INPUT_POST);
                     $lastindexes = rcube_utils::get_input_value('_rule_index_last', rcube_utils::INPUT_POST);
                     $dateheaders = rcube_utils::get_input_value('_rule_date_header', rcube_utils::INPUT_POST);
                     $dateparts = rcube_utils::get_input_value('_rule_date_part', rcube_utils::INPUT_POST);
                     $act_types = rcube_utils::get_input_value('_action_type', rcube_utils::INPUT_POST, true);
                     $mailboxes = rcube_utils::get_input_value('_action_mailbox', rcube_utils::INPUT_POST, true);
                     $act_targets = rcube_utils::get_input_value('_action_target', rcube_utils::INPUT_POST, true);
                     $domain_targets = rcube_utils::get_input_value('_action_target_domain', rcube_utils::INPUT_POST);
                     $area_targets = rcube_utils::get_input_value('_action_target_area', rcube_utils::INPUT_POST, true);
                     $reasons = rcube_utils::get_input_value('_action_reason', rcube_utils::INPUT_POST, true);
                     $addresses = rcube_utils::get_input_value('_action_addresses', rcube_utils::INPUT_POST, true);
                     $intervals = rcube_utils::get_input_value('_action_interval', rcube_utils::INPUT_POST);
                     $interval_types = rcube_utils::get_input_value('_action_interval_type', rcube_utils::INPUT_POST);
                     $subject = rcube_utils::get_input_value('_action_subject', rcube_utils::INPUT_POST, true);
                     $flags = rcube_utils::get_input_value('_action_flags', rcube_utils::INPUT_POST);
                     $varnames = rcube_utils::get_input_value('_action_varname', rcube_utils::INPUT_POST);
                     $varvalues = rcube_utils::get_input_value('_action_varvalue', rcube_utils::INPUT_POST);
                     $varmods = rcube_utils::get_input_value('_action_varmods', rcube_utils::INPUT_POST);
                     $notifymethods = rcube_utils::get_input_value('_action_notifymethod', rcube_utils::INPUT_POST);
                     $notifytargets = rcube_utils::get_input_value('_action_notifytarget', rcube_utils::INPUT_POST, true);
                     $notifyoptions = rcube_utils::get_input_value('_action_notifyoption', rcube_utils::INPUT_POST, true);
                     $notifymessages = rcube_utils::get_input_value('_action_notifymessage', rcube_utils::INPUT_POST, true);
                     $notifyfrom = rcube_utils::get_input_value('_action_notifyfrom', rcube_utils::INPUT_POST);
                     $notifyimp = rcube_utils::get_input_value('_action_notifyimportance', rcube_utils::INPUT_POST);
                     // we need a "hack" for radiobuttons
                     foreach ($sizeitems as $item) {
                         $items[] = $item;
                     }
                     $this->form['disabled'] = $_POST['_disabled'] ? true : false;
                     $this->form['join'] = $join == 'allof' ? true : false;
                     $this->form['name'] = $name;
                     $this->form['tests'] = array();
                     $this->form['actions'] = array();
                     if ($name == '') {
                         $this->errors['name'] = $this->plugin->gettext('cannotbeempty');
                     } else {
                         foreach ($this->script as $idx => $rule) {
                             if ($rule['name'] == $name && $idx != $fid) {
                                 $this->errors['name'] = $this->plugin->gettext('ruleexist');
                                 break;
                             }
                         }
                     }
                     $i = 0;
                     // rules
                     if ($join == 'any') {
                         $this->form['tests'][0]['test'] = 'true';
                     } else {
                         foreach ($headers as $idx => $header) {
                             // targets are indexed differently (assume form order)
                             $target = $this->strip_value(array_shift($targets), true);
                             $header = $this->strip_value($header);
                             $operator = $this->strip_value($ops[$idx]);
                             $comparator = $this->strip_value($comparators[$idx]);
                             if ($header == 'size') {
                                 $sizeop = $this->strip_value($sizeops[$idx]);
                                 $sizeitem = $this->strip_value($items[$idx]);
                                 $sizetarget = $this->strip_value($sizetargets[$idx]);
                                 $this->form['tests'][$i]['test'] = 'size';
                                 $this->form['tests'][$i]['type'] = $sizeop;
                                 $this->form['tests'][$i]['arg'] = $sizetarget;
                                 if ($sizetarget == '') {
                                     $this->errors['tests'][$i]['sizetarget'] = $this->plugin->gettext('cannotbeempty');
                                 } else {
                                     if (!preg_match('/^[0-9]+(K|M|G)?$/i', $sizetarget . $sizeitem, $m)) {
                                         $this->errors['tests'][$i]['sizetarget'] = $this->plugin->gettext('forbiddenchars');
                                         $this->form['tests'][$i]['item'] = $sizeitem;
                                     } else {
                                         $this->form['tests'][$i]['arg'] .= $m[1];
                                     }
                                 }
                             } else {
                                 if ($header == 'currentdate') {
                                     $datepart = $this->strip_value($dateparts[$idx]);
                                     if (preg_match('/^not/', $operator)) {
                                         $this->form['tests'][$i]['not'] = true;
                                     }
                                     $type = preg_replace('/^not/', '', $operator);
                                     if ($type == 'exists') {
                                         $this->errors['tests'][$i]['op'] = true;
                                     }
                                     $this->form['tests'][$i]['test'] = 'currentdate';
                                     $this->form['tests'][$i]['type'] = $type;
                                     $this->form['tests'][$i]['part'] = $datepart;
                                     $this->form['tests'][$i]['arg'] = $target;
                                     if ($type != 'exists') {
                                         if (!count($target)) {
                                             $this->errors['tests'][$i]['target'] = $this->plugin->gettext('cannotbeempty');
                                         } else {
                                             if (strpos($type, 'count-') === 0) {
                                                 foreach ($target as $arg) {
                                                     if (preg_match('/[^0-9]/', $arg)) {
                                                         $this->errors['tests'][$i]['target'] = $this->plugin->gettext('forbiddenchars');
                                                     }
                                                 }
                                             } else {
                                                 if (strpos($type, 'value-') === 0) {
                                                     // Some date/time formats do not support i;ascii-numeric comparator
                                                     if ($comparator == 'i;ascii-numeric' && in_array($datepart, array('date', 'time', 'iso8601', 'std11'))) {
                                                         $comparator = '';
                                                     }
                                                 }
                                             }
                                         }
                                         if (!preg_match('/^(regex|matches|count-)/', $type) && count($target)) {
                                             foreach ($target as $arg) {
                                                 if (!$this->validate_date_part($datepart, $arg)) {
                                                     $this->errors['tests'][$i]['target'] = $this->plugin->gettext('invaliddateformat');
                                                     break;
                                                 }
                                             }
                                         }
                                     }
                                 } else {
                                     if ($header == 'date') {
                                         $datepart = $this->strip_value($dateparts[$idx]);
                                         $dateheader = $this->strip_value($dateheaders[$idx]);
                                         $index = $this->strip_value($indexes[$idx]);
                                         $indexlast = $this->strip_value($lastindexes[$idx]);
                                         if (preg_match('/^not/', $operator)) {
                                             $this->form['tests'][$i]['not'] = true;
                                         }
                                         $type = preg_replace('/^not/', '', $operator);
                                         if ($type == 'exists') {
                                             $this->errors['tests'][$i]['op'] = true;
                                         }
                                         if (!empty($index) && $mod != 'envelope') {
                                             $this->form['tests'][$i]['index'] = intval($index);
                                             $this->form['tests'][$i]['last'] = !empty($indexlast);
                                         }
                                         if (empty($dateheader)) {
                                             $dateheader = 'Date';
                                         } else {
                                             if (!preg_match('/^[\\x21-\\x39\\x41-\\x7E]+$/i', $dateheader)) {
                                                 $this->errors['tests'][$i]['dateheader'] = $this->plugin->gettext('forbiddenchars');
                                             }
                                         }
                                         $this->form['tests'][$i]['test'] = 'date';
                                         $this->form['tests'][$i]['type'] = $type;
                                         $this->form['tests'][$i]['part'] = $datepart;
                                         $this->form['tests'][$i]['arg'] = $target;
                                         $this->form['tests'][$i]['header'] = $dateheader;
                                         if ($type != 'exists') {
                                             if (!count($target)) {
                                                 $this->errors['tests'][$i]['target'] = $this->plugin->gettext('cannotbeempty');
                                             } else {
                                                 if (strpos($type, 'count-') === 0) {
                                                     foreach ($target as $arg) {
                                                         if (preg_match('/[^0-9]/', $arg)) {
                                                             $this->errors['tests'][$i]['target'] = $this->plugin->gettext('forbiddenchars');
                                                         }
                                                     }
                                                 } else {
                                                     if (strpos($type, 'value-') === 0) {
                                                         // Some date/time formats do not support i;ascii-numeric comparator
                                                         if ($comparator == 'i;ascii-numeric' && in_array($datepart, array('date', 'time', 'iso8601', 'std11'))) {
                                                             $comparator = '';
                                                         }
                                                     }
                                                 }
                                             }
                                             if (count($target) && !preg_match('/^(regex|matches|count-)/', $type)) {
                                                 foreach ($target as $arg) {
                                                     if (!$this->validate_date_part($datepart, $arg)) {
                                                         $this->errors['tests'][$i]['target'] = $this->plugin->gettext('invaliddateformat');
                                                         break;
                                                     }
                                                 }
                                             }
                                         }
                                     } else {
                                         if ($header == 'body') {
                                             $trans = $this->strip_value($body_trans[$idx]);
                                             $trans_type = $this->strip_value($body_types[$idx], true);
                                             if (preg_match('/^not/', $operator)) {
                                                 $this->form['tests'][$i]['not'] = true;
                                             }
                                             $type = preg_replace('/^not/', '', $operator);
                                             if ($type == 'exists') {
                                                 $this->errors['tests'][$i]['op'] = true;
                                             }
                                             $this->form['tests'][$i]['test'] = 'body';
                                             $this->form['tests'][$i]['type'] = $type;
                                             $this->form['tests'][$i]['arg'] = $target;
                                             if (empty($target) && $type != 'exists') {
                                                 $this->errors['tests'][$i]['target'] = $this->plugin->gettext('cannotbeempty');
                                             } else {
                                                 if (preg_match('/^(value|count)-/', $type)) {
                                                     foreach ($target as $target_value) {
                                                         if (preg_match('/[^0-9]/', $target_value)) {
                                                             $this->errors['tests'][$i]['target'] = $this->plugin->gettext('forbiddenchars');
                                                         }
                                                     }
                                                 }
                                             }
                                             $this->form['tests'][$i]['part'] = $trans;
                                             if ($trans == 'content') {
                                                 $this->form['tests'][$i]['content'] = $trans_type;
                                             }
                                         } else {
                                             $cust_header = $headers = $this->strip_value(array_shift($cust_headers));
                                             $mod = $this->strip_value($mods[$idx]);
                                             $mod_type = $this->strip_value($mod_types[$idx]);
                                             $index = $this->strip_value($indexes[$idx]);
                                             $indexlast = $this->strip_value($lastindexes[$idx]);
                                             if (preg_match('/^not/', $operator)) {
                                                 $this->form['tests'][$i]['not'] = true;
                                             }
                                             $type = preg_replace('/^not/', '', $operator);
                                             if (!empty($index) && $mod != 'envelope') {
                                                 $this->form['tests'][$i]['index'] = intval($index);
                                                 $this->form['tests'][$i]['last'] = !empty($indexlast);
                                             }
                                             if ($header == '...') {
                                                 if (!count($headers)) {
                                                     $this->errors['tests'][$i]['header'] = $this->plugin->gettext('cannotbeempty');
                                                 } else {
                                                     foreach ($headers as $hr) {
                                                         // RFC2822: printable ASCII except colon
                                                         if (!preg_match('/^[\\x21-\\x39\\x41-\\x7E]+$/i', $hr)) {
                                                             $this->errors['tests'][$i]['header'] = $this->plugin->gettext('forbiddenchars');
                                                         }
                                                     }
                                                 }
                                                 if (empty($this->errors['tests'][$i]['header'])) {
                                                     $cust_header = is_array($headers) && count($headers) == 1 ? $headers[0] : $headers;
                                                 }
                                             }
                                             $header = $header == '...' ? $cust_header : $header;
                                             if (is_array($header)) {
                                                 foreach ($header as $h_index => $val) {
                                                     if (isset($this->headers[$val])) {
                                                         $header[$h_index] = $this->headers[$val];
                                                     }
                                                 }
                                             }
                                             if ($type == 'exists') {
                                                 $this->form['tests'][$i]['test'] = 'exists';
                                                 $this->form['tests'][$i]['arg'] = $header;
                                             } else {
                                                 $test = 'header';
                                                 if ($mod == 'address' || $mod == 'envelope') {
                                                     $found = false;
                                                     if (empty($this->errors['tests'][$i]['header'])) {
                                                         foreach ((array) $header as $hdr) {
                                                             if (!in_array(strtolower(trim($hdr)), $this->addr_headers)) {
                                                                 $found = true;
                                                             }
                                                         }
                                                     }
                                                     if (!$found) {
                                                         $test = $mod;
                                                     }
                                                 }
                                                 $this->form['tests'][$i]['type'] = $type;
                                                 $this->form['tests'][$i]['test'] = $test;
                                                 $this->form['tests'][$i]['arg1'] = $header;
                                                 $this->form['tests'][$i]['arg2'] = $target;
                                                 if (empty($target)) {
                                                     $this->errors['tests'][$i]['target'] = $this->plugin->gettext('cannotbeempty');
                                                 } else {
                                                     if (preg_match('/^(value|count)-/', $type)) {
                                                         foreach ($target as $target_value) {
                                                             if (preg_match('/[^0-9]/', $target_value)) {
                                                                 $this->errors['tests'][$i]['target'] = $this->plugin->gettext('forbiddenchars');
                                                             }
                                                         }
                                                     }
                                                 }
                                                 if ($mod) {
                                                     $this->form['tests'][$i]['part'] = $mod_type;
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                             if ($header != 'size' && $comparator) {
                                 $this->form['tests'][$i]['comparator'] = $comparator;
                             }
                             $i++;
                         }
                     }
                     $i = 0;
                     // actions
                     foreach ($act_types as $idx => $type) {
                         $type = $this->strip_value($type);
                         switch ($type) {
                             case 'fileinto':
                             case 'fileinto_copy':
                                 $mailbox = $this->strip_value($mailboxes[$idx], false, false);
                                 $this->form['actions'][$i]['target'] = $this->mod_mailbox($mailbox, 'in');
                                 if ($type == 'fileinto_copy') {
                                     $type = 'fileinto';
                                     $this->form['actions'][$i]['copy'] = true;
                                 }
                                 break;
                             case 'reject':
                             case 'ereject':
                                 $target = $this->strip_value($area_targets[$idx]);
                                 $this->form['actions'][$i]['target'] = str_replace("\r\n", "\n", $target);
                                 //                 if ($target == '')
                                 //                      $this->errors['actions'][$i]['targetarea'] = $this->plugin->gettext('cannotbeempty');
                                 break;
                             case 'redirect':
                             case 'redirect_copy':
                                 $target = $this->strip_value($act_targets[$idx]);
                                 $domain = $this->strip_value($domain_targets[$idx]);
                                 // force one of the configured domains
                                 $domains = (array) $this->rc->config->get('managesieve_domains');
                                 if (!empty($domains) && !empty($target)) {
                                     if (!$domain || !in_array($domain, $domains)) {
                                         $domain = $domains[0];
                                     }
                                     $target .= '@' . $domain;
                                 }
                                 $this->form['actions'][$i]['target'] = $target;
                                 if ($target == '') {
                                     $this->errors['actions'][$i]['target'] = $this->plugin->gettext('cannotbeempty');
                                 } else {
                                     if (!rcube_utils::check_email($target)) {
                                         $this->errors['actions'][$i]['target'] = $this->plugin->gettext(!empty($domains) ? 'forbiddenchars' : 'noemailwarning');
                                     }
                                 }
                                 if ($type == 'redirect_copy') {
                                     $type = 'redirect';
                                     $this->form['actions'][$i]['copy'] = true;
                                 }
                                 break;
                             case 'addflag':
                             case 'setflag':
                             case 'removeflag':
                                 $_target = array();
                                 if (empty($flags[$idx])) {
                                     $this->errors['actions'][$i]['target'] = $this->plugin->gettext('noflagset');
                                 } else {
                                     foreach ($flags[$idx] as $flag) {
                                         $_target[] = $this->strip_value($flag);
                                     }
                                 }
                                 $this->form['actions'][$i]['target'] = $_target;
                                 break;
                             case 'vacation':
                                 $reason = $this->strip_value($reasons[$idx]);
                                 $interval_type = $interval_types[$idx] == 'seconds' ? 'seconds' : 'days';
                                 $this->form['actions'][$i]['reason'] = str_replace("\r\n", "\n", $reason);
                                 $this->form['actions'][$i]['subject'] = $subject[$idx];
                                 $this->form['actions'][$i]['addresses'] = array_shift($addresses);
                                 $this->form['actions'][$i][$interval_type] = $intervals[$idx];
                                 // @TODO: vacation :mime, :from, :handle
                                 foreach ((array) $this->form['actions'][$i]['addresses'] as $aidx => $address) {
                                     $this->form['actions'][$i]['addresses'][$aidx] = $address = trim($address);
                                     if (empty($address)) {
                                         unset($this->form['actions'][$i]['addresses'][$aidx]);
                                     } else {
                                         if (!rcube_utils::check_email($address)) {
                                             $this->errors['actions'][$i]['addresses'] = $this->plugin->gettext('noemailwarning');
                                             break;
                                         }
                                     }
                                 }
                                 if ($this->form['actions'][$i]['reason'] == '') {
                                     $this->errors['actions'][$i]['reason'] = $this->plugin->gettext('cannotbeempty');
                                 }
                                 if ($this->form['actions'][$i][$interval_type] && !preg_match('/^[0-9]+$/', $this->form['actions'][$i][$interval_type])) {
                                     $this->errors['actions'][$i]['interval'] = $this->plugin->gettext('forbiddenchars');
                                 }
                                 break;
                             case 'set':
                                 $this->form['actions'][$i]['name'] = $varnames[$idx];
                                 $this->form['actions'][$i]['value'] = $varvalues[$idx];
                                 foreach ((array) $varmods[$idx] as $v_m) {
                                     $this->form['actions'][$i][$v_m] = true;
                                 }
                                 if (empty($varnames[$idx])) {
                                     $this->errors['actions'][$i]['name'] = $this->plugin->gettext('cannotbeempty');
                                 } else {
                                     if (!preg_match('/^[0-9a-z_]+$/i', $varnames[$idx])) {
                                         $this->errors['actions'][$i]['name'] = $this->plugin->gettext('forbiddenchars');
                                     }
                                 }
                                 if (!isset($varvalues[$idx]) || $varvalues[$idx] === '') {
                                     $this->errors['actions'][$i]['value'] = $this->plugin->gettext('cannotbeempty');
                                 }
                                 break;
                             case 'notify':
                                 if (empty($notifymethods[$idx])) {
                                     $this->errors['actions'][$i]['method'] = $this->plugin->gettext('cannotbeempty');
                                 }
                                 if (empty($notifytargets[$idx])) {
                                     $this->errors['actions'][$i]['target'] = $this->plugin->gettext('cannotbeempty');
                                 }
                                 if (!empty($notifyfrom[$idx]) && !rcube_utils::check_email($notifyfrom[$idx])) {
                                     $this->errors['actions'][$i]['from'] = $this->plugin->gettext('noemailwarning');
                                 }
                                 // skip empty options
                                 foreach ((array) $notifyoptions[$idx] as $opt_idx => $opt) {
                                     if (!strlen(trim($opt))) {
                                         unset($notifyoptions[$idx][$opt_idx]);
                                     }
                                 }
                                 $this->form['actions'][$i]['method'] = $notifymethods[$idx] . ':' . $notifytargets[$idx];
                                 $this->form['actions'][$i]['options'] = $notifyoptions[$idx];
                                 $this->form['actions'][$i]['message'] = $notifymessages[$idx];
                                 $this->form['actions'][$i]['from'] = $notifyfrom[$idx];
                                 $this->form['actions'][$i]['importance'] = $notifyimp[$idx];
                                 break;
                         }
                         $this->form['actions'][$i]['type'] = $type;
                         $i++;
                     }
                     if (!$this->errors && !$error) {
                         // save the script
                         if (!isset($this->script[$fid])) {
                             $fid = $this->sieve->script->add_rule($this->form);
                             $new = true;
                         } else {
                             $fid = $this->sieve->script->update_rule($fid, $this->form);
                         }
                         if ($fid !== false) {
                             $save = $this->save_script();
                         }
                         if ($save && $fid !== false) {
                             $this->rc->output->show_message('managesieve.filtersaved', 'confirmation');
                             if ($this->rc->task != 'mail') {
                                 $this->rc->output->command('parent.managesieve_updatelist', isset($new) ? 'add' : 'update', array('name' => $this->form['name'], 'id' => $fid, 'disabled' => $this->form['disabled']));
                             } else {
                                 $this->rc->output->command('managesieve_dialog_close');
                                 $this->rc->output->send('iframe');
                             }
                         } else {
                             $this->rc->output->show_message('managesieve.filtersaveerror', 'error');
                             //                  $this->rc->output->send();
                         }
                     }
                 }
             }
         }
     }
     $this->send();
 }
示例#6
0
 /**
  * @dataProvider data_invalid_email
  */
 function test_invalid_email($email, $title)
 {
     $this->assertFalse(rcube_utils::check_email($email, false), $title);
 }
 /**
  * API: set vacation rule
  *
  * @param array $vacation Vacation rule information (see self::get_vacation())
  *
  * @return bool True on success, False on failure
  */
 public function set_vacation($data)
 {
     $this->exts = $this->sieve->get_extensions();
     $this->error = false;
     $this->init_script();
     $this->vacation_rule();
     // check supported extensions
     $date_extension = in_array('date', $this->exts);
     $regex_extension = in_array('regex', $this->exts);
     $seconds_extension = in_array('vacation-seconds', $this->exts);
     $vacation['type'] = 'vacation';
     $vacation['reason'] = $this->strip_value(str_replace("\r\n", "\n", $data['message']));
     $vacation['addresses'] = $data['addresses'];
     $vacation['subject'] = trim($data['subject']);
     $vacation['from'] = trim($data['from']);
     $vacation_tests = (array) $this->vacation['tests'];
     foreach ((array) $vacation['addresses'] as $aidx => $address) {
         $vacation['addresses'][$aidx] = $address = trim($address);
         if (empty($address)) {
             unset($vacation['addresses'][$aidx]);
         } else {
             if (!rcube_utils::check_email($address)) {
                 $this->error = "Invalid address in vacation addresses: {$address}";
                 return false;
             }
         }
     }
     if (!empty($vacation['from']) && !rcube_utils::check_email($vacation['from'])) {
         $this->error = "Invalid address in 'from': " . $vacation['from'];
         return false;
     }
     if ($vacation['reason'] == '') {
         $this->error = "No vacation message specified";
         return false;
     }
     if ($data['interval']) {
         if (!preg_match('/^([0-9]+)\\s*([sd])$/', $data['interval'], $m)) {
             $this->error = "Invalid vacation interval value: " . $data['interval'];
             return false;
         } else {
             if ($m[1]) {
                 $vacation[strtolower($m[2]) == 's' ? 'seconds' : 'days'] = $m[1];
             }
         }
     }
     // find and remove existing date/regex/true rules
     foreach ((array) $vacation_tests as $idx => $t) {
         if ($t['test'] == 'currentdate' || $t['test'] == 'true' || $t['test'] == 'header' && $t['type'] == 'regex' && $t['arg1'] == 'received') {
             unset($vacation_tests[$idx]);
         }
     }
     if ($date_extension) {
         foreach (array('start', 'end') as $var) {
             if ($dt = $data[$var]) {
                 $vacation_tests[] = array('test' => 'currentdate', 'part' => 'iso8601', 'type' => 'value-' . ($var == 'start' ? 'ge' : 'le'), 'zone' => $dt->format('O'), 'arg' => str_replace('+00:00', 'Z', strtoupper($dt->format('c'))));
             }
         }
     } else {
         if ($regex_extension) {
             // Add date range rules if range specified
             if ($data['start'] && $data['end']) {
                 if ($tests = self::build_regexp_tests($data['start'], $data['end'], $error)) {
                     $vacation_tests = array_merge($vacation_tests, $tests);
                 }
                 if ($error) {
                     $this->error = "Invalid dates specified or unsupported period length";
                     return false;
                 }
             }
         }
     }
     if ($data['action'] == 'redirect' || $data['action'] == 'copy') {
         if (empty($data['target']) || !rcube_utils::check_email($data['target'])) {
             $this->error = "Invalid address in action taget: " . $data['target'];
             return false;
         }
     } else {
         if ($data['action'] && $data['action'] != 'keep' && $data['action'] != 'discard') {
             $this->error = "Unsupported vacation action: " . $data['action'];
             return false;
         }
     }
     if (empty($vacation_tests)) {
         $vacation_tests = $this->rc->config->get('managesieve_vacation_test', array(array('test' => 'true')));
     }
     $rule = $this->vacation;
     $rule['type'] = 'if';
     $rule['name'] = $rule['name'] ?: 'Out-of-Office';
     $rule['disabled'] = isset($data['enabled']) && !$data['enabled'];
     $rule['tests'] = $vacation_tests;
     $rule['join'] = $date_extension ? count($vacation_tests) > 1 : false;
     $rule['actions'] = array($vacation);
     if ($data['action'] && $data['action'] != 'keep') {
         $rule['actions'][] = array('type' => $data['action'] == 'discard' ? 'discard' : 'redirect', 'copy' => $data['action'] == 'copy', 'target' => $data['action'] != 'discard' ? $data['target'] : '');
     }
     return $this->save_vacation_script($rule);
 }
示例#8
0
function check_email($email, $dns_check = true)
{
    return rcube_utils::check_email($email, $dns_check);
}
 /**
  * Check the given data before saving.
  * If input isn't valid, the message to display can be fetched using get_error()
  *
  * @param array Assoziative array with data to save
  * @param boolean Attempt to fix/complete record automatically
  * @return boolean True if input is valid, False if not.
  */
 public function validate(&$save_data, $autofix = false)
 {
     $rcmail = rcmail::get_instance();
     // check validity of email addresses
     foreach ($this->get_col_values('email', $save_data, true) as $email) {
         if (strlen($email)) {
             if (!rcube_utils::check_email(rcube_utils::idn_to_ascii($email))) {
                 $error = $rcmail->gettext(array('name' => 'emailformaterror', 'vars' => array('email' => $email)));
                 $this->set_error(self::ERROR_VALIDATE, $error);
                 return false;
             }
         }
     }
     return true;
 }
 public function create_identity($p)
 {
     $rcmail = rcmail::get_instance();
     // prefs are set in create_user()
     if ($this->prefs) {
         if ($this->prefs['full_name']) {
             $p['record']['name'] = $this->prefs['full_name'];
         }
         if (($this->identities_level == 0 || $this->identities_level == 2) && $this->prefs['email_address']) {
             $p['record']['email'] = $this->prefs['email_address'];
         }
         if ($this->prefs['___signature___']) {
             $p['record']['signature'] = $this->prefs['___signature___'];
         }
         if ($this->prefs['reply_to']) {
             $p['record']['reply-to'] = $this->prefs['reply_to'];
         }
         if (($this->identities_level == 0 || $this->identities_level == 1) && isset($this->prefs['identities']) && $this->prefs['identities'] > 1) {
             for ($i = 1; $i < $this->prefs['identities']; $i++) {
                 unset($ident_data);
                 $ident_data = array('name' => '', 'email' => '');
                 // required data
                 if ($this->prefs['full_name' . $i]) {
                     $ident_data['name'] = $this->prefs['full_name' . $i];
                 }
                 if ($this->identities_level == 0 && $this->prefs['email_address' . $i]) {
                     $ident_data['email'] = $this->prefs['email_address' . $i];
                 } else {
                     $ident_data['email'] = $p['record']['email'];
                 }
                 if ($this->prefs['reply_to' . $i]) {
                     $ident_data['reply-to'] = $this->prefs['reply_to' . $i];
                 }
                 if ($this->prefs['___sig' . $i . '___']) {
                     $ident_data['signature'] = $this->prefs['___sig' . $i . '___'];
                 }
                 // insert identity
                 $rcmail->user->insert_identity($ident_data);
             }
         }
         // copy address book
         $contacts = $rcmail->get_address_book(null, true);
         $addresses = array();
         $groups = array();
         if ($contacts && !empty($this->abook)) {
             foreach ($this->abook as $rec) {
                 // #1487096: handle multi-address and/or too long items
                 // #1487858: convert multi-address contacts into groups
                 $emails = preg_split('/[;,]/', $rec['email'], -1, PREG_SPLIT_NO_EMPTY);
                 $group_id = null;
                 // create group for addresses
                 if (count($emails) > 1) {
                     if (!($group_id = $groups[$rec['name']])) {
                         if ($group = $contacts->create_group($rec['name'])) {
                             $group_id = $group['id'];
                             $groups[$rec['name']] = $group_id;
                         }
                     }
                 }
                 // create contacts
                 foreach ($emails as $email) {
                     if (!($contact_id = $addresses[$email]) && rcube_utils::check_email(rcube_utils::idn_to_ascii($email))) {
                         $rec['email'] = rcube_utils::idn_to_utf8($email);
                         if ($contact_id = $contacts->insert($rec, true)) {
                             $addresses[$email] = $contact_id;
                         }
                     }
                     if ($group_id && $contact_id) {
                         $contacts->add_to_group($group_id, array($contact_id));
                     }
                 }
             }
         }
         // mark identity as complete for following hooks
         $p['complete'] = true;
     }
     return $p;
 }
 private function vacation_post()
 {
     if (empty($_POST)) {
         return;
     }
     $status = rcube_utils::get_input_value('vacation_status', rcube_utils::INPUT_POST);
     $subject = rcube_utils::get_input_value('vacation_subject', rcube_utils::INPUT_POST, true);
     $reason = rcube_utils::get_input_value('vacation_reason', rcube_utils::INPUT_POST, true);
     $addresses = rcube_utils::get_input_value('vacation_addresses', rcube_utils::INPUT_POST, true);
     $interval = rcube_utils::get_input_value('vacation_interval', rcube_utils::INPUT_POST);
     $interval_type = rcube_utils::get_input_value('vacation_interval_type', rcube_utils::INPUT_POST);
     $date_from = rcube_utils::get_input_value('vacation_datefrom', rcube_utils::INPUT_POST);
     $date_to = rcube_utils::get_input_value('vacation_dateto', rcube_utils::INPUT_POST);
     $after = rcube_utils::get_input_value('vacation_after', rcube_utils::INPUT_POST);
     $interval_type = $interval_type == 'seconds' ? 'seconds' : 'days';
     $vacation_action['type'] = 'vacation';
     $vacation_action['reason'] = $this->strip_value(str_replace("\r\n", "\n", $reason));
     $vacation_action['subject'] = $subject;
     $vacation_action['addresses'] = $addresses;
     $vacation_action[$interval_type] = $interval;
     $vacation_tests = (array) $this->vacation['tests'];
     foreach ((array) $vacation_action['addresses'] as $aidx => $address) {
         $vacation_action['addresses'][$aidx] = $address = trim($address);
         if (empty($address)) {
             unset($vacation_action['addresses'][$aidx]);
         } else {
             if (!rcube_utils::check_email($address)) {
                 $error = 'noemailwarning';
                 break;
             }
         }
     }
     if ($vacation_action['reason'] == '') {
         $error = 'managesieve.emptyvacationbody';
     }
     if ($vacation_action[$interval_type] && !preg_match('/^[0-9]+$/', $vacation_action[$interval_type])) {
         $error = 'managesieve.forbiddenchars';
     }
     foreach (array('date_from', 'date_to') as $var) {
         $date = ${$var};
         if ($date && ($dt = rcube_utils::anytodatetime($date))) {
             $type = 'value-' . ($var == 'date_from' ? 'ge' : 'le');
             $test = array('test' => 'currentdate', 'part' => 'date', 'type' => $type, 'arg' => $dt->format('Y-m-d'));
             // find existing date rule
             foreach ((array) $vacation_tests as $idx => $t) {
                 if ($t['test'] == 'currentdate' && $t['part'] == 'date' && $t['type'] == $type) {
                     $vacation_tests[$idx] = $test;
                     continue 2;
                 }
             }
             $vacation_tests[] = $test;
         }
     }
     if (empty($vacation_tests)) {
         $vacation_tests = $this->rc->config->get('managesieve_vacation_test', array(array('test' => 'true')));
     }
     // @TODO: handle situation when there's no active script
     if (!$error) {
         $rule = $this->vacation;
         $rule['type'] = 'if';
         $rule['name'] = $rule['name'] ? $rule['name'] : $this->plugin->gettext('vacation');
         $rule['disabled'] = $status == 'off';
         $rule['actions'][0] = $vacation_action;
         $rule['tests'] = $vacation_tests;
         $rule['join'] = count($vacation_tests) > 1;
         // reset original vacation rule
         if (isset($this->vacation['idx'])) {
             $this->script[$this->vacation['idx']] = null;
         }
         // re-order rules if needed
         if (isset($after) && $after !== '') {
             // add at target position
             if ($after >= count($this->script) - 1) {
                 $this->script[] = $rule;
             } else {
                 $script = array();
                 foreach ($this->script as $idx => $r) {
                     if ($r) {
                         $script[] = $r;
                     }
                     if ($idx == $after) {
                         $script[] = $rule;
                     }
                 }
                 $this->script = $script;
             }
         } else {
             array_unshift($this->script, $rule);
         }
         $this->sieve->script->content = array_values(array_filter($this->script));
         if ($this->save_script()) {
             $this->rc->output->show_message('managesieve.vacationsaved', 'confirmation');
             $this->rc->output->send();
         }
     }
     $this->rc->output->show_message($error ? $error : 'managesieve.saveerror', 'error');
     $this->rc->output->send();
 }
示例#12
0
function check_email($email, $dns_check = true)
{
    _deprecation_warning(__FUNCTION__);
    return rcube_utils::check_email($email, $dns_check);
}