function check_size($args) { $limit = parse_bytes(rcmail::get_instance()->config->get('max_message_size', '10MB')); $total = $args['size']; if ($_SESSION['compose'] && $_SESSION['compose']['attachments']) { foreach ($_SESSION['compose']['attachments'] as $attachment) { $total += $attachment['size']; } } if ($total > $limit) { $this->add_texts('localization/'); $args['error'] = sprintf($this->gettext('overallsizeerror'), show_bytes(parse_bytes($limit))); $args['abort'] = true; } return $args; }
/** * */ function import_events() { // Upload progress update if (!empty($_GET['_progress'])) { rcube_upload_progress(); } @set_time_limit(0); // process uploaded file if there is no error $err = $_FILES['_data']['error']; if (!$err && $_FILES['_data']['tmp_name']) { $calendar = rcube_utils::get_input_value('calendar', rcube_utils::INPUT_GPC); $rangestart = $_REQUEST['_range'] ? date_create("now -" . intval($_REQUEST['_range']) . " months") : 0; // extract zip file if ($_FILES['_data']['type'] == 'application/zip') { $count = 0; if (class_exists('ZipArchive', false)) { $zip = new ZipArchive(); if ($zip->open($_FILES['_data']['tmp_name'])) { $randname = uniqid('zip-' . session_id(), true); $tmpdir = slashify($this->rc->config->get('temp_dir', sys_get_temp_dir())) . $randname; mkdir($tmpdir, 0700); // extract each ical file from the archive and import it for ($i = 0; $i < $zip->numFiles; $i++) { $filename = $zip->getNameIndex($i); if (preg_match('/\\.ics$/i', $filename)) { $tmpfile = $tmpdir . '/' . basename($filename); if (copy('zip://' . $_FILES['_data']['tmp_name'] . '#' . $filename, $tmpfile)) { $count += $this->import_from_file($tmpfile, $calendar, $rangestart, $errors); unlink($tmpfile); } } } rmdir($tmpdir); $zip->close(); } else { $errors = 1; $msg = 'Failed to open zip file.'; } } else { $errors = 1; $msg = 'Zip files are not supported for import.'; } } else { // attempt to import teh uploaded file directly $count = $this->import_from_file($_FILES['_data']['tmp_name'], $calendar, $rangestart, $errors); } if ($count) { $this->rc->output->command('display_message', $this->gettext(array('name' => 'importsuccess', 'vars' => array('nr' => $count))), 'confirmation'); $this->rc->output->command('plugin.import_success', array('source' => $calendar, 'refetch' => true)); } else { if (!$errors) { $this->rc->output->command('display_message', $this->gettext('importnone'), 'notice'); $this->rc->output->command('plugin.import_success', array('source' => $calendar)); } else { $this->rc->output->command('plugin.import_error', array('message' => $this->gettext('importerror') . ($msg ? ': ' . $msg : ''))); } } } else { if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) { $msg = rcube_label(array('name' => 'filesizeerror', 'vars' => array('size' => show_bytes(parse_bytes(ini_get('upload_max_filesize')))))); } else { $msg = rcube_label('fileuploaderror'); } $this->rc->output->command('plugin.import_error', array('message' => $msg)); } $this->rc->output->send('iframe'); }
function managesieve_save() { // load localization $this->add_texts('localization/', array('filters', 'managefilters')); // include main js script if ($this->api->output->type == 'html') { $this->include_script('managesieve.js'); } // Init plugin and handle managesieve connection $error = $this->managesieve_start(); // filters set add action if (!empty($_POST['_newset'])) { $name = get_input_value('_name', RCUBE_INPUT_POST, true); $copy = get_input_value('_copy', RCUBE_INPUT_POST, true); $from = get_input_value('_from', RCUBE_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->gettext('cannotbeempty'); } else { if (mb_strlen($name) > 128) { $this->errors['name'] = $this->gettext('nametoolong'); } else { if (!empty($exceptions) && in_array($name, (array) $exceptions)) { $this->errors['name'] = $this->gettext('namereserved'); } else { if (!empty($kolab) && in_array($name_uc, array('MASTER', 'USER', 'MANAGEMENT'))) { $this->errors['name'] = $this->gettext('namereserved'); } else { if (in_array($name, $list)) { $this->errors['name'] = $this->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->gettext('setcreateerror'); } } else { // upload failed $err = $_FILES['_file']['error']; if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) { $msg = rcube_label(array('name' => 'filesizeerror', 'vars' => array('size' => show_bytes(parse_bytes(ini_get('upload_max_filesize')))))); } else { $this->errors['file'] = $this->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(get_input_value('_name', RCUBE_INPUT_POST, true)); $fid = trim(get_input_value('_fid', RCUBE_INPUT_POST)); $join = trim(get_input_value('_join', RCUBE_INPUT_POST)); // and arrays $headers = get_input_value('_header', RCUBE_INPUT_POST); $cust_headers = get_input_value('_custom_header', RCUBE_INPUT_POST); $ops = get_input_value('_rule_op', RCUBE_INPUT_POST); $sizeops = get_input_value('_rule_size_op', RCUBE_INPUT_POST); $sizeitems = get_input_value('_rule_size_item', RCUBE_INPUT_POST); $sizetargets = get_input_value('_rule_size_target', RCUBE_INPUT_POST); $targets = get_input_value('_rule_target', RCUBE_INPUT_POST, true); $mods = get_input_value('_rule_mod', RCUBE_INPUT_POST); $mod_types = get_input_value('_rule_mod_type', RCUBE_INPUT_POST); $body_trans = get_input_value('_rule_trans', RCUBE_INPUT_POST); $body_types = get_input_value('_rule_trans_type', RCUBE_INPUT_POST, true); $comparators = get_input_value('_rule_comp', RCUBE_INPUT_POST); $act_types = get_input_value('_action_type', RCUBE_INPUT_POST, true); $mailboxes = get_input_value('_action_mailbox', RCUBE_INPUT_POST, true); $act_targets = get_input_value('_action_target', RCUBE_INPUT_POST, true); $area_targets = get_input_value('_action_target_area', RCUBE_INPUT_POST, true); $reasons = get_input_value('_action_reason', RCUBE_INPUT_POST, true); $addresses = get_input_value('_action_addresses', RCUBE_INPUT_POST, true); $days = get_input_value('_action_days', RCUBE_INPUT_POST); $subject = get_input_value('_action_subject', RCUBE_INPUT_POST, true); $flags = get_input_value('_action_flags', RCUBE_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->gettext('cannotbeempty'); } else { foreach ($this->script as $idx => $rule) { if ($rule['name'] == $name && $idx != $fid) { $this->errors['name'] = $this->gettext('ruleexist'); break; } } } $i = 0; // rules if ($join == 'any') { $this->form['tests'][0]['test'] = 'true'; } else { foreach ($headers as $idx => $header) { $header = $this->strip_value($header); $target = $this->strip_value($targets[$idx], true); $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->gettext('cannotbeempty'); } else { if (!preg_match('/^[0-9]+(K|M|G)?$/i', $sizetarget . $sizeitem, $m)) { $this->errors['tests'][$i]['sizetarget'] = $this->gettext('forbiddenchars'); $this->form['tests'][$i]['item'] = $sizeitem; } else { $this->form['tests'][$i]['arg'] .= $m[1]; } } } 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 ($target == '' && $type != 'exists') { $this->errors['tests'][$i]['target'] = $this->gettext('cannotbeempty'); } else { if (preg_match('/^(value|count)-/', $type) && !preg_match('/[0-9]+/', $target)) { $this->errors['tests'][$i]['target'] = $this->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($cust_headers[$idx]); $mod = $this->strip_value($mods[$idx]); $mod_type = $this->strip_value($mod_types[$idx]); if (preg_match('/^not/', $operator)) { $this->form['tests'][$i]['not'] = true; } $type = preg_replace('/^not/', '', $operator); if ($header == '...') { $headers = preg_split('/[\\s,]+/', $cust_header, -1, PREG_SPLIT_NO_EMPTY); if (!count($headers)) { $this->errors['tests'][$i]['header'] = $this->gettext('cannotbeempty'); } else { foreach ($headers as $hr) { if (!preg_match('/^[a-z0-9-]+$/i', $hr)) { $this->errors['tests'][$i]['header'] = $this->gettext('forbiddenchars'); } } } if (empty($this->errors['tests'][$i]['header'])) { $cust_header = is_array($headers) && count($headers) == 1 ? $headers[0] : $headers; } } if ($type == 'exists') { $this->form['tests'][$i]['test'] = 'exists'; $this->form['tests'][$i]['arg'] = $header == '...' ? $cust_header : $header; } else { $test = 'header'; $header = $header == '...' ? $cust_header : $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 ($target == '') { $this->errors['tests'][$i]['target'] = $this->gettext('cannotbeempty'); } else { if (preg_match('/^(value|count)-/', $type) && !preg_match('/[0-9]+/', $target)) { $this->errors['tests'][$i]['target'] = $this->gettext('forbiddenchars'); } } if ($mod) { $this->form['tests'][$i]['part'] = $mod_type; } } } } if ($header != 'size' && $comparator) { if (preg_match('/^(value|count)/', $this->form['tests'][$i]['type'])) { $comparator = 'i;ascii-numeric'; } $this->form['tests'][$i]['comparator'] = $comparator; } $i++; } } $i = 0; // actions foreach ($act_types as $idx => $type) { $type = $this->strip_value($type); $target = $this->strip_value($act_targets[$idx]); switch ($type) { case 'fileinto': case 'fileinto_copy': $mailbox = $this->strip_value($mailboxes[$idx]); $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->gettext('cannotbeempty'); break; case 'redirect': case 'redirect_copy': $this->form['actions'][$i]['target'] = $target; if ($this->form['actions'][$i]['target'] == '') { $this->errors['actions'][$i]['target'] = $this->gettext('cannotbeempty'); } else { if (!check_email($this->form['actions'][$i]['target'])) { $this->errors['actions'][$i]['target'] = $this->gettext('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->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]); $this->form['actions'][$i]['reason'] = str_replace("\r\n", "\n", $reason); $this->form['actions'][$i]['days'] = $days[$idx]; $this->form['actions'][$i]['subject'] = $subject[$idx]; $this->form['actions'][$i]['addresses'] = explode(',', $addresses[$idx]); // @TODO: vacation :mime, :from, :handle if ($this->form['actions'][$i]['addresses']) { foreach ($this->form['actions'][$i]['addresses'] as $aidx => $address) { $address = trim($address); if (!$address) { unset($this->form['actions'][$i]['addresses'][$aidx]); } else { if (!check_email($address)) { $this->errors['actions'][$i]['addresses'] = $this->gettext('noemailwarning'); break; } else { $this->form['actions'][$i]['addresses'][$aidx] = $address; } } } } if ($this->form['actions'][$i]['reason'] == '') { $this->errors['actions'][$i]['reason'] = $this->gettext('cannotbeempty'); } if ($this->form['actions'][$i]['days'] && !preg_match('/^[0-9]+$/', $this->form['actions'][$i]['days'])) { $this->errors['actions'][$i]['days'] = $this->gettext('forbiddenchars'); } break; } $this->form['actions'][$i]['type'] = $type; $i++; } if (!$this->errors && !$error) { // zapis skryptu 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' => Q($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->managesieve_send(); }
/** * */ function import_events($silent = false) { // Upload progress update if (!empty($_GET['_progress'])) { rcube_upload_progress(); } @set_time_limit(0); // process uploaded file if there is no error $err = $_FILES['_data']['error']; if (!$err && $_FILES['_data']['tmp_name']) { $calendar = get_input_value('calendar', RCUBE_INPUT_GPC); $driver = $this->get_driver_by_cal($calendar); $rangestart = $_REQUEST['_range'] ? date_create("now -" . intval($_REQUEST['_range']) . " months") : 0; $user_email = $this->rc->user->get_username(); $ical = $this->get_ical(); $errors = !$ical->fopen($_FILES['_data']['tmp_name']); $count = $i = 0; foreach ($ical as $event) { if (isset($event['recurrence']['EXCEPTIONS'])) { foreach ($event['recurrence']['EXCEPTIONS'] as $idx => $exception) { $event['recurrence']['EXCEPTIONS'][$idx]['uid'] = $event['uid']; } } // End mod by Rosali // keep the browser connection alive on long import jobs if (++$i > 100 && $i % 100 == 0) { echo "<!-- -->"; ob_flush(); } // TODO: correctly handle recurring events which start before $rangestart if ($event['end'] && $event['end'] < $rangestart && (!$event['recurrence'] || $event['recurrence']['until'] && $event['recurrence']['until'] < $rangestart)) { continue; } $event['_owner'] = $user_email; $event['calendar'] = $calendar; if ($driver->new_event($event)) { $count++; } else { $errors++; } } // Begin mod by Rosali if ($silent) { return; } // End mod by Rosali if ($count) { $this->rc->output->command('display_message', $this->gettext(array('name' => 'importsuccess', 'vars' => array('nr' => $count))), 'confirmation'); $this->rc->output->command('plugin.import_success', array('source' => $calendar, 'refetch' => true)); } else { if (!$errors) { $this->rc->output->command('display_message', $this->gettext('importnone'), 'notice'); $this->rc->output->command('plugin.import_success', array('source' => $calendar)); } else { $this->rc->output->command('plugin.import_error', array('message' => $this->gettext('importerror') . ($msg ? ': ' . $msg : ''))); } } } else { if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) { $msg = rcube_label(array('name' => 'filesizeerror', 'vars' => array('size' => show_bytes(parse_bytes(ini_get('upload_max_filesize')))))); } else { $msg = rcube_label('fileuploaderror'); } $this->rc->output->command('plugin.import_error', array('message' => $msg)); $this->rc->output->command('plugin.unlock_saving', false); } $this->rc->output->send('iframe'); }
/** * Function to be executed in script shutdown * Registered with register_shutdown_function() */ public function shutdown() { if (is_object($this->imap)) { $this->imap->close(); } if (is_object($this->smtp)) { $this->smtp->disconnect(); } if (is_object($this->contacts)) { $this->contacts->close(); } // before closing the database connection, write session data if ($_SERVER['REMOTE_ADDR']) { session_write_close(); } // write performance stats to logs/console if ($this->config->get('devel_mode')) { if (function_exists('memory_get_usage')) { $mem = show_bytes(memory_get_usage()); } if (function_exists('memory_get_peak_usage')) { $mem .= '/' . show_bytes(memory_get_peak_usage()); } $log = $this->task . ($this->action ? '/' . $this->action : '') . ($mem ? " [{$mem}]" : ''); rcube_print_time(RCMAIL_START, $log); } }
/** * Key import page handler */ private function key_import() { // Import process if ($_FILES['_file']['tmp_name'] && is_uploaded_file($_FILES['_file']['tmp_name'])) { $this->enigma->load_engine(); $result = $this->enigma->engine->import_key($_FILES['_file']['tmp_name'], true); if (is_array($result)) { // reload list if any keys has been added if ($result['imported']) { $this->rc->output->command('parent.enigma_list', 1); } else { $this->rc->output->command('parent.enigma_loadframe'); } $this->rc->output->show_message('enigma.keysimportsuccess', 'confirmation', array('new' => $result['imported'], 'old' => $result['unchanged'])); $this->rc->output->send('iframe'); } else { $this->rc->output->show_message('enigma.keysimportfailed', 'error'); } } else { if ($err = $_FILES['_file']['error']) { if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) { $this->rc->output->show_message('filesizeerror', 'error', array('size' => show_bytes(parse_bytes(ini_get('upload_max_filesize'))))); } else { $this->rc->output->show_message('fileuploaderror', 'error'); } } } $this->rc->output->add_handlers(array('importform' => array($this, 'tpl_key_import_form'))); $this->rc->output->set_pagetitle($this->enigma->gettext('keyimport')); $this->rc->output->send('enigma.keyimport'); }
| | +-----------------------------------------------------------------------+ | Author: Thomas Bruederli <*****@*****.**> | +-----------------------------------------------------------------------+ */ // suppress php notices @ini_set('error_reporting', E_ALL & ~E_NOTICE); // include the converter class file require_once 'vcard_convert.php'; require_once 'utils.php'; if (!empty($_FILES['_vcards'])) { // instantiate a parser object $conv = new vcard_convert(array('mailonly' => !empty($_POST['_mailonly']), 'phoneonly' => !empty($_POST['_phoneonly']), 'accesscode' => preg_replace('/[^1-9]/', '', $_POST['_accesscode']))); // check for errors if ($err = $_FILES['_vcards']['error']) { $GLOBALS['error_msg'] = $err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE ? "The uploaded file was too big! Maximum file size allowed: " . show_bytes(parse_bytes(ini_get('upload_max_filesize'))) : "Upload failed, please try again"; } else { if ($conv->fromFile($_FILES['_vcards']['tmp_name'])) { $ext = $_POST['_format'] == 'gmail' ? 'csv' : ($_POST['_format'] == 'img' ? 'zip' : $_POST['_format']); $fname = asciiwords(preg_replace('/\\.[a-z]+$/i', '', $_FILES['_vcards']['name'])); header(sprintf('Content-Type: text/%s', $ext)); header(sprintf('Content-Disposition: attachment; filename="%s.%s"', $fname, $ext)); if ($_POST['_format'] == 'ldif') { print $conv->toLdif(); exit; } else { if ($_POST['_format'] == 'ldap') { // Clean the input dn modifier from dangerous chars $dnID = substr(preg_replace('/[^\\da-z=,_ -]/i', '', $_POST['_dn']), 0, 255); print $conv->toLdif($dnID ? $dnID : "", null, $_POST['_encoding']); exit;
/** * Function to be executed in script shutdown * Registered with register_shutdown_function() */ public function shutdown() { foreach ($this->shutdown_functions as $function) { call_user_func($function); } if (is_object($this->smtp)) { $this->smtp->disconnect(); } foreach ($this->address_books as $book) { if (is_object($book) && is_a($book, 'rcube_addressbook')) { $book->close(); } } foreach ($this->caches as $cache) { if (is_object($cache)) { $cache->close(); } } if (is_object($this->imap)) { $this->imap->close(); } // before closing the database connection, write session data if ($_SERVER['REMOTE_ADDR'] && is_object($this->session)) { session_write_close(); } // write performance stats to logs/console if ($this->config->get('devel_mode')) { if (function_exists('memory_get_usage')) { $mem = show_bytes(memory_get_usage()); } if (function_exists('memory_get_peak_usage')) { $mem .= '/' . show_bytes(memory_get_peak_usage()); } $log = $this->task . ($this->action ? '/' . $this->action : '') . ($mem ? " [{$mem}]" : ''); if (defined('RCMAIL_START')) { rcube_print_time(RCMAIL_START, $log); } else { console($log); } } }
/** * */ public function attachment_header($attrib = array()) { $table = new html_table(array('cols' => 3)); if (!empty($this->attachment['name'])) { $table->add('title', Q($this->rc->gettext('filename'))); $table->add('header', Q($this->attachment['name'])); $table->add('download-link', html::a('?' . str_replace('_frame=', '_download=', $_SERVER['QUERY_STRING']), Q($this->rc->gettext('download')))); } if (!empty($this->attachment['size'])) { $table->add('title', Q($this->rc->gettext('filesize'))); $table->add('header', Q(show_bytes($this->attachment['size']))); } return $table->show($attrib); }
/** * */ public function attachment_header($attrib = array()) { $rcmail = rcmail::get_instance(); $dl_link = strtolower($attrib['downloadlink']) == 'true'; $dl_url = $this->rc->url(array('_frame' => null, '_download' => 1) + $_GET); $table = new html_table(array('cols' => $dl_link ? 3 : 2)); if (!empty($this->attachment['name'])) { $table->add('title', Q($this->rc->gettext('filename'))); $table->add('header', Q($this->attachment['name'])); if ($dl_link) { $table->add('download-link', html::a($dl_url, Q($this->rc->gettext('download')))); } } if (!empty($this->attachment['mimetype'])) { $table->add('title', Q($this->rc->gettext('type'))); $table->add('header', Q($this->attachment['mimetype'])); } if (!empty($this->attachment['size'])) { $table->add('title', Q($this->rc->gettext('filesize'))); $table->add('header', Q(show_bytes($this->attachment['size']))); } $this->rc->output->set_env('attachment_download_url', $dl_url); return $table->show($attrib); }
function managesieve_save() { // Init plugin and handle managesieve connection $error = $this->managesieve_start(); // filters set add action if (!empty($_POST['_newset'])) { $name = get_input_value('_name', RCUBE_INPUT_POST); $copy = get_input_value('_copy', RCUBE_INPUT_POST); $from = get_input_value('_from', RCUBE_INPUT_POST); if (!$name) { $error = 'managesieve.emptyname'; } else { if (mb_strlen($name) > 128) { $error = 'managesieve.nametoolong'; } 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->sieve->save($name)) { $error = 'managesieve.setcreateerror'; } } else { // upload failed $err = $_FILES['_file']['error']; $error = true; if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) { $msg = rcube_label(array('name' => 'filesizeerror', 'vars' => array('size' => show_bytes(parse_bytes(ini_get('upload_max_filesize')))))); } else { $error = 'fileuploaderror'; } } } else { if (!$this->sieve->copy($name, $from == 'set' ? $copy : '')) { $error = 'managesieve.setcreateerror'; } } } } if (!$error) { $this->rc->output->show_message('managesieve.setcreated', 'confirmation'); $this->rc->output->command('parent.managesieve_reload', $name); } else { if ($msg) { $this->rc->output->command('display_message', $msg, 'error'); } else { $this->rc->output->show_message($error, 'error'); } } } else { if (isset($_POST['_name'])) { $name = trim(get_input_value('_name', RCUBE_INPUT_POST, true)); $fid = trim(get_input_value('_fid', RCUBE_INPUT_POST)); $join = trim(get_input_value('_join', RCUBE_INPUT_POST)); // and arrays $headers = $_POST['_header']; $cust_headers = $_POST['_custom_header']; $ops = $_POST['_rule_op']; $sizeops = $_POST['_rule_size_op']; $sizeitems = $_POST['_rule_size_item']; $sizetargets = $_POST['_rule_size_target']; $targets = $_POST['_rule_target']; $act_types = $_POST['_action_type']; $mailboxes = $_POST['_action_mailbox']; $act_targets = $_POST['_action_target']; $area_targets = $_POST['_action_target_area']; $reasons = $_POST['_action_reason']; $addresses = $_POST['_action_addresses']; $days = $_POST['_action_days']; // 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->gettext('cannotbeempty'); } else { foreach ($this->script as $idx => $rule) { if ($rule['name'] == $name && $idx != $fid) { $this->errors['name'] = $this->gettext('ruleexist'); break; } } } $i = 0; // rules if ($join == 'any') { $this->form['tests'][0]['test'] = 'true'; } else { foreach ($headers as $idx => $header) { $header = $this->strip_value($header); $target = $this->strip_value($targets[$idx], true); $op = $this->strip_value($ops[$idx]); // normal header if (in_array($header, $this->headers)) { if (preg_match('/^not/', $op)) { $this->form['tests'][$i]['not'] = true; } $type = preg_replace('/^not/', '', $op); if ($type == 'exists') { $this->form['tests'][$i]['test'] = 'exists'; $this->form['tests'][$i]['arg'] = $header; } else { $this->form['tests'][$i]['type'] = $type; $this->form['tests'][$i]['test'] = 'header'; $this->form['tests'][$i]['arg1'] = $header; $this->form['tests'][$i]['arg2'] = $target; if ($target == '') { $this->errors['tests'][$i]['target'] = $this->gettext('cannotbeempty'); } else { if (preg_match('/^(value|count)-/', $type) && !preg_match('/[0-9]+/', $target)) { $this->errors['tests'][$i]['target'] = $this->gettext('forbiddenchars'); } } } } else { switch ($header) { case '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 . $sizeitem; if ($sizetarget == '') { $this->errors['tests'][$i]['sizetarget'] = $this->gettext('cannotbeempty'); } else { if (!preg_match('/^[0-9]+(K|M|G)*$/i', $sizetarget)) { $this->errors['tests'][$i]['sizetarget'] = $this->gettext('forbiddenchars'); } } break; case '...': $cust_header = $headers = $this->strip_value($cust_headers[$idx]); if (preg_match('/^not/', $op)) { $this->form['tests'][$i]['not'] = true; } $type = preg_replace('/^not/', '', $op); if ($cust_header == '') { $this->errors['tests'][$i]['header'] = $this->gettext('cannotbeempty'); } else { $headers = preg_split('/[\\s,]+/', $cust_header, -1, PREG_SPLIT_NO_EMPTY); if (!count($headers)) { $this->errors['tests'][$i]['header'] = $this->gettext('cannotbeempty'); } else { foreach ($headers as $hr) { if (!preg_match('/^[a-z0-9-]+$/i', $hr)) { $this->errors['tests'][$i]['header'] = $this->gettext('forbiddenchars'); } } } } if (empty($this->errors['tests'][$i]['header'])) { $cust_header = is_array($headers) && count($headers) == 1 ? $headers[0] : $headers; } if ($type == 'exists') { $this->form['tests'][$i]['test'] = 'exists'; $this->form['tests'][$i]['arg'] = $cust_header; } else { $this->form['tests'][$i]['test'] = 'header'; $this->form['tests'][$i]['type'] = $type; $this->form['tests'][$i]['arg1'] = $cust_header; $this->form['tests'][$i]['arg2'] = $target; if ($target == '') { $this->errors['tests'][$i]['target'] = $this->gettext('cannotbeempty'); } else { if (preg_match('/^(value|count)-/', $type) && !preg_match('/[0-9]+/', $target)) { $this->errors['tests'][$i]['target'] = $this->gettext('forbiddenchars'); } } } break; } } $i++; } } $i = 0; // actions foreach ($act_types as $idx => $type) { $type = $this->strip_value($type); $target = $this->strip_value($act_targets[$idx]); switch ($type) { case 'fileinto': case 'fileinto_copy': $mailbox = $this->strip_value($mailboxes[$idx]); $this->form['actions'][$i]['target'] = $mailbox; 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->gettext('cannotbeempty'); break; case 'redirect': case 'redirect_copy': $this->form['actions'][$i]['target'] = $target; if ($this->form['actions'][$i]['target'] == '') { $this->errors['actions'][$i]['target'] = $this->gettext('cannotbeempty'); } else { if (!check_email($this->form['actions'][$i]['target'])) { $this->errors['actions'][$i]['target'] = $this->gettext('noemailwarning'); } } if ($type == 'redirect_copy') { $type = 'redirect'; $this->form['actions'][$i]['copy'] = true; } break; case 'vacation': $reason = $this->strip_value($reasons[$idx]); $this->form['actions'][$i]['reason'] = str_replace("\r\n", "\n", $reason); $this->form['actions'][$i]['days'] = $days[$idx]; $this->form['actions'][$i]['addresses'] = explode(',', $addresses[$idx]); // @TODO: vacation :subject, :mime, :from, :handle if ($this->form['actions'][$i]['addresses']) { foreach ($this->form['actions'][$i]['addresses'] as $aidx => $address) { $address = trim($address); if (!$address) { unset($this->form['actions'][$i]['addresses'][$aidx]); } else { if (!check_email($address)) { $this->errors['actions'][$i]['addresses'] = $this->gettext('noemailwarning'); break; } else { $this->form['actions'][$i]['addresses'][$aidx] = $address; } } } } if ($this->form['actions'][$i]['reason'] == '') { $this->errors['actions'][$i]['reason'] = $this->gettext('cannotbeempty'); } if ($this->form['actions'][$i]['days'] && !preg_match('/^[0-9]+$/', $this->form['actions'][$i]['days'])) { $this->errors['actions'][$i]['days'] = $this->gettext('forbiddenchars'); } break; } $this->form['actions'][$i]['type'] = $type; $i++; } if (!$this->errors) { // zapis skryptu 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->sieve->save(); } if ($save && $fid !== false) { $this->rc->output->show_message('managesieve.filtersaved', 'confirmation'); $this->rc->output->add_script(sprintf("rcmail.managesieve_updatelist('%s', '%s', %d, %d);", isset($new) ? 'add' : 'update', Q($this->form['name']), $fid, $this->form['disabled']), 'foot'); } else { $this->rc->output->show_message('managesieve.filtersaveerror', 'error'); // $this->rc->output->send(); } } } } $this->managesieve_send(); }