/** * Deliver an event/task attachment to the client * (similar as in Roundcube core program/steps/mail/get.inc) */ public function attachment_get($attachment) { ob_end_clean(); if ($attachment && $attachment['body']) { // allow post-processing of the attachment body $part = new rcube_message_part(); $part->filename = $attachment['name']; $part->size = $attachment['size']; $part->mimetype = $attachment['mimetype']; $plugin = $this->rc->plugins->exec_hook('message_part_get', array('body' => $attachment['body'], 'mimetype' => strtolower($attachment['mimetype']), 'download' => !empty($_GET['_download']), 'part' => $part)); if ($plugin['abort']) { exit; } $mimetype = $plugin['mimetype']; list($ctype_primary, $ctype_secondary) = explode('/', $mimetype); $browser = $this->rc->output->browser; // send download headers if ($plugin['download']) { header("Content-Type: application/octet-stream"); if ($browser->ie) { header("Content-Type: application/force-download"); } } else { if ($ctype_primary == 'text') { header("Content-Type: text/{$ctype_secondary}"); } else { header("Content-Type: {$mimetype}"); header("Content-Transfer-Encoding: binary"); } } // display page, @TODO: support text/plain (and maybe some other text formats) if ($mimetype == 'text/html' && empty($_GET['_download'])) { $OUTPUT = new rcmail_html_page(); // @TODO: use washtml on $body $OUTPUT->write($plugin['body']); } else { // don't kill the connection if download takes more than 30 sec. @set_time_limit(0); $filename = $attachment['name']; $filename = preg_replace('[\\r\\n]', '', $filename); if ($browser->ie && $browser->ver < 7) { $filename = rawurlencode(abbreviate_string($filename, 55)); } else { if ($browser->ie) { $filename = rawurlencode($filename); } else { $filename = addcslashes($filename, '"'); } } $disposition = !empty($_GET['_download']) ? 'attachment' : 'inline'; header("Content-Disposition: {$disposition}; filename=\"{$filename}\""); echo $plugin['body']; } exit; } // if we arrive here, the requested part was not found header('HTTP/1.1 404 Not Found'); exit; }
/** * Return html for a flat list <select> for the mailbox tree */ public function render_folder_tree_select(&$arrFolders, &$mbox_name, $maxlength, &$select, $realnames = false, $nestLevel = 0, $opts = array()) { $out = ''; foreach ($arrFolders as $folder) { // skip exceptions (and its subfolders) if (!empty($opts['exceptions']) && in_array($folder['id'], $opts['exceptions'])) { continue; } // skip folders in which it isn't possible to create subfolders if (!empty($opts['skip_noinferiors'])) { $attrs = $this->storage->folder_attributes($folder['id']); if ($attrs && in_array_nocase('\\Noinferiors', $attrs)) { continue; } } if (!$realnames && ($folder_class = $this->folder_classname($folder['id']))) { $foldername = $this->gettext($folder_class); } else { $foldername = $folder['name']; // shorten the folder name to a given length if ($maxlength && $maxlength > 1) { $foldername = abbreviate_string($foldername, $maxlength); } } $select->add(str_repeat(' ', $nestLevel * 4) . html::quote($foldername), $folder['id']); if (!empty($folder['folders'])) { $out .= $this->render_folder_tree_select($folder['folders'], $mbox_name, $maxlength, $select, $realnames, $nestLevel + 1, $opts); } } return $out; }
function actions() { $error = $this->start(); // Handle user requests if ($action = rcube_utils::get_input_value('_act', rcube_utils::INPUT_GPC)) { $fid = (int) rcube_utils::get_input_value('_fid', rcube_utils::INPUT_POST); if ($action == 'delete' && !$error) { if (isset($this->script[$fid])) { if ($this->sieve->script->delete_rule($fid)) { $result = $this->save_script(); } if ($result === true) { $this->rc->output->show_message('managesieve.filterdeleted', 'confirmation'); $this->rc->output->command('managesieve_updatelist', 'del', array('id' => $fid)); } else { $this->rc->output->show_message('managesieve.filterdeleteerror', 'error'); } } } else { if ($action == 'move' && !$error) { if (isset($this->script[$fid])) { $to = (int) rcube_utils::get_input_value('_to', rcube_utils::INPUT_POST); $rule = $this->script[$fid]; // remove rule unset($this->script[$fid]); $this->script = array_values($this->script); // add at target position if ($to >= count($this->script)) { $this->script[] = $rule; } else { $script = array(); foreach ($this->script as $idx => $r) { if ($idx == $to) { $script[] = $rule; } $script[] = $r; } $this->script = $script; } $this->sieve->script->content = $this->script; $result = $this->save_script(); if ($result === true) { $result = $this->list_rules(); $this->rc->output->show_message('managesieve.moved', 'confirmation'); $this->rc->output->command('managesieve_updatelist', 'list', array('list' => $result, 'clear' => true, 'set' => $to)); } else { $this->rc->output->show_message('managesieve.moveerror', 'error'); } } } else { if ($action == 'act' && !$error) { if (isset($this->script[$fid])) { $rule = $this->script[$fid]; $disabled = $rule['disabled'] ? true : false; $rule['disabled'] = !$disabled; $result = $this->sieve->script->update_rule($fid, $rule); if ($result !== false) { $result = $this->save_script(); } if ($result === true) { if ($rule['disabled']) { $this->rc->output->show_message('managesieve.deactivated', 'confirmation'); } else { $this->rc->output->show_message('managesieve.activated', 'confirmation'); } $this->rc->output->command('managesieve_updatelist', 'update', array('id' => $fid, 'disabled' => $rule['disabled'])); } else { if ($rule['disabled']) { $this->rc->output->show_message('managesieve.deactivateerror', 'error'); } else { $this->rc->output->show_message('managesieve.activateerror', 'error'); } } } } else { if ($action == 'setact' && !$error) { $script_name = rcube_utils::get_input_value('_set', rcube_utils::INPUT_GPC, true); $result = $this->activate_script($script_name); $kep14 = $this->rc->config->get('managesieve_kolab_master'); if ($result === true) { $this->rc->output->set_env('active_sets', $this->active); $this->rc->output->show_message('managesieve.setactivated', 'confirmation'); $this->rc->output->command('managesieve_updatelist', 'setact', array('name' => $script_name, 'active' => true, 'all' => !$kep14)); } else { $this->rc->output->show_message('managesieve.setactivateerror', 'error'); } } else { if ($action == 'deact' && !$error) { $script_name = rcube_utils::get_input_value('_set', rcube_utils::INPUT_GPC, true); $result = $this->deactivate_script($script_name); if ($result === true) { $this->rc->output->set_env('active_sets', $this->active); $this->rc->output->show_message('managesieve.setdeactivated', 'confirmation'); $this->rc->output->command('managesieve_updatelist', 'setact', array('name' => $script_name, 'active' => false)); } else { $this->rc->output->show_message('managesieve.setdeactivateerror', 'error'); } } else { if ($action == 'setdel' && !$error) { $script_name = rcube_utils::get_input_value('_set', rcube_utils::INPUT_GPC, true); $result = $this->remove_script($script_name); if ($result === true) { $this->rc->output->show_message('managesieve.setdeleted', 'confirmation'); $this->rc->output->command('managesieve_updatelist', 'setdel', array('name' => $script_name)); $this->rc->session->remove('managesieve_current'); } else { $this->rc->output->show_message('managesieve.setdeleteerror', 'error'); } } else { if ($action == 'setget') { $script_name = rcube_utils::get_input_value('_set', rcube_utils::INPUT_GPC, true); $script = $this->sieve->get_script($script_name); if (PEAR::isError($script)) { exit; } $browser = new rcube_browser(); // send download headers header("Content-Type: application/octet-stream"); header("Content-Length: " . strlen($script)); if ($browser->ie) { header("Content-Type: application/force-download"); } if ($browser->ie && $browser->ver < 7) { $filename = rawurlencode(abbreviate_string($script_name, 55)); } else { if ($browser->ie) { $filename = rawurlencode($script_name); } else { $filename = addcslashes($script_name, '\\"'); } } header("Content-Disposition: attachment; filename=\"{$filename}.txt\""); echo $script; exit; } else { if ($action == 'list') { $result = $this->list_rules(); $this->rc->output->command('managesieve_updatelist', 'list', array('list' => $result)); } else { if ($action == 'ruleadd') { $rid = rcube_utils::get_input_value('_rid', rcube_utils::INPUT_GPC); $id = $this->genid(); $content = $this->rule_div($fid, $id, false); $this->rc->output->command('managesieve_rulefill', $content, $id, $rid); } else { if ($action == 'actionadd') { $aid = rcube_utils::get_input_value('_aid', rcube_utils::INPUT_GPC); $id = $this->genid(); $content = $this->action_div($fid, $id, false); $this->rc->output->command('managesieve_actionfill', $content, $id, $aid); } } } } } } } } } } $this->rc->output->send(); } else { if ($this->rc->task == 'mail') { // Initialize the form $rules = rcube_utils::get_input_value('r', rcube_utils::INPUT_GET); if (!empty($rules)) { $i = 0; foreach ($rules as $rule) { list($header, $value) = explode(':', $rule, 2); $tests[$i] = array('type' => 'contains', 'test' => 'header', 'arg1' => $header, 'arg2' => $value); $i++; } $this->form = array('join' => count($tests) > 1 ? 'allof' : 'anyof', 'name' => '', 'tests' => $tests, 'actions' => array(0 => array('type' => 'fileinto'), 1 => array('type' => 'stop'))); } } } $this->send(); }
/** * Helper method to send the zip archive to the browser */ private function _deliver_zipfile($tmpfname, $filename) { $browser = new rcube_browser(); $rcmail = rcmail::get_instance(); $rcmail->output->nocacheing_headers(); if ($browser->ie && $browser->ver < 7) { $filename = rawurlencode(abbreviate_string($filename, 55)); } else { if ($browser->ie) { $filename = rawurlencode($filename); } else { $filename = addcslashes($filename, '"'); } } // send download headers header("Content-Type: application/octet-stream"); if ($browser->ie) { header("Content-Type: application/force-download"); } // don't kill the connection if download takes more than 30 sec. @set_time_limit(0); header("Content-Disposition: attachment; filename=\"" . $filename . "\""); header("Content-length: " . filesize($tmpfname)); readfile($tmpfname); }
private function _gen_addressbooks_list($arrBooks, $command) { $rcmail = rcmail::get_instance(); $groupTotal = 0; $maxlength = 35; $maxlength_grp = 33; $out = ''; // address books foreach ($arrBooks as $j => $source) { $title = null; $id = $source['id'] ? $source['id'] : $j; $bookname = !empty($source['name']) ? Q($source['name']) : Q($id); // shorten the address book name to a given length if ($maxlength && $maxlength > 1) { $bname = abbreviate_string($bookname, $maxlength); if ($bname != $bookname) { $title = $bookname; } $bookname = $bname; } if ($source['readonly']) { $out .= html::tag('li', array('id' => 'rcm_contextaddr_' . $id, 'class' => 'addressbook disabled'), html::a(array('href' => $command, 'id' => 'rcm_contextgrps_' . JQ($id), 'onclick' => "rcm_set_dest_book('" . JQ($id) . "', '" . JQ($id) . "', null)", 'class' => 'active', 'title' => $title), Q($bookname))); } else { $out .= html::tag('li', array('id' => 'rcm_contextaddr_' . $id, 'class' => 'addressbook'), html::a(array('href' => $command, 'id' => 'rcm_contextgrps_' . JQ($id), 'onclick' => "rcm_set_dest_book('" . JQ($id) . "', '" . JQ($id) . "', null)", 'class' => 'active', 'title' => $title), Q($bookname))); } // contact groups if ($source['groups']) { $groups = $rcmail->get_address_book($source['id'])->list_groups(); foreach ($groups as $group) { $title = null; $gid = 'G' . $id . $group['ID']; $groupname = !empty($group['name']) ? Q($group['name']) : Q($gid); // shorten the address book name to a given length if ($maxlength_grp && $maxlength_grp > 1) { $gname = abbreviate_string($groupname, $maxlength_grp); if ($gname != $groupname) { $title = $groupname; } $groupname = $gname; } if ($source['readonly']) { $out .= html::tag('li', array('class' => 'contactgroup disabled'), html::a(array('href' => $command, 'id' => 'rcm_contextgrps_' . JQ($gid), 'onclick' => "rcm_set_dest_book('" . JQ($gid) . "', '" . JQ($id) . "', '" . JQ($group['ID']) . "')", 'class' => 'active', 'title' => $title), Q(' ' . $groupname))); } else { $out .= html::tag('li', array('class' => 'contactgroup'), html::a(array('href' => $command, 'id' => 'rcm_contextgrps_' . JQ($gid), 'onclick' => "rcm_set_dest_book('" . JQ($gid) . "', '" . JQ($id) . "', '" . JQ($group['ID']) . "')", 'class' => 'active', 'title' => $title), Q(' ' . $groupname))); } $groupTotal++; } } $groupTotal++; } if ($groupTotal > 5) { $out = html::tag('ul', array('id' => 'rcm_contextgrps', 'class' => 'toolbarmenu folders scrollable'), $out); $out = html::tag('div', array('class' => 'scroll_up_pas'), '') . $out . html::tag('div', array('class' => 'scroll_down_act'), ''); $out = html::tag('div', array('class' => 'popupmenu'), $out); } else { $out = html::tag('ul', array('id' => 'rcm_contextgrps', 'class' => 'popupmenu toolbarmenu folders'), $out); } return $out; }
/** * Helper method to serialize the given event for storing in invitations table */ private static function serialize_event($event) { $ev = $event; $ev['description'] = abbreviate_string($ev['description'], 100); unset($ev['attachments']); return serialize($ev); }
function action_div($fid, $id, $div = true) { $action = isset($this->form) ? $this->form['actions'][$id] : $this->script[$fid]['actions'][$id]; $rows_num = isset($this->form) ? sizeof($this->form['actions']) : sizeof($this->script[$fid]['actions']); $out = $div ? '<div class="actionrow" id="actionrow' . $id . '">' . "\n" : ''; $out .= '<table><tr><td class="rowactions">'; // action select $select_action = new html_select(array('name' => "_action_type[]", 'id' => 'action_type' . $id, 'onchange' => 'action_type_select(' . $id . ')')); if (in_array('fileinto', $this->exts)) { $select_action->add(Q($this->gettext('messagemoveto')), 'fileinto'); } $select_action->add(Q($this->gettext('messageredirect')), 'redirect'); if (in_array('reject', $this->exts)) { $select_action->add(Q($this->gettext('messagediscard')), 'reject'); } elseif (in_array('ereject', $this->exts)) { $select_action->add(Q($this->gettext('messagediscard')), 'ereject'); } if (in_array('vacation', $this->exts)) { $select_action->add(Q($this->gettext('messagereply')), 'vacation'); } $select_action->add(Q($this->gettext('messagedelete')), 'discard'); $select_action->add(Q($this->gettext('rulestop')), 'stop'); $out .= $select_action->show($action['type']); $out .= '</td>'; // actions target inputs $out .= '<td class="rowtargets">'; // shared targets $out .= '<input type="text" name="_action_target[]" id="action_target' . $id . '" ' . 'value="' . ($action['type'] == 'redirect' ? Q($action['target'], 'strict', false) : '') . '" size="40" ' . 'style="display:' . ($action['type'] == 'redirect' ? 'inline' : 'none') . '" ' . $this->error_class($id, 'action', 'target') . ' />'; $out .= '<textarea name="_action_target_area[]" id="action_target_area' . $id . '" ' . 'rows="3" cols="40" ' . $this->error_class($id, 'action', 'targetarea') . 'style="display:' . (in_array($action['type'], array('reject', 'ereject')) ? 'inline' : 'none') . '">' . (in_array($action['type'], array('reject', 'ereject')) ? Q($action['target'], 'strict', false) : '') . "</textarea>\n"; // vacation $out .= '<div id="action_vacation' . $id . '" style="display:' . ($action['type'] == 'vacation' ? 'inline' : 'none') . '">'; $out .= '<span class="label">' . Q($this->gettext('vacationreason')) . '</span><br />' . '<textarea name="_action_reason[]" id="action_reason' . $id . '" ' . 'rows="3" cols="40" ' . $this->error_class($id, 'action', 'reason') . '>' . Q($action['reason'], 'strict', false) . "</textarea>\n"; $out .= '<br /><span class="label">' . Q($this->gettext('vacationaddresses')) . '</span><br />' . '<input type="text" name="_action_addresses[]" ' . 'value="' . (is_array($action['addresses']) ? Q(implode(', ', $action['addresses']), 'strict', false) : $action['addresses']) . '" size="40" ' . $this->error_class($id, 'action', 'addresses') . ' />'; $out .= '<br /><span class="label">' . Q($this->gettext('vacationdays')) . '</span><br />' . '<input type="text" name="_action_days[]" ' . 'value="' . Q($action['days'], 'strict', false) . '" size="2" ' . $this->error_class($id, 'action', 'days') . ' />'; $out .= '</div>'; // mailbox select $out .= '<select id="action_mailbox' . $id . '" name="_action_mailbox[]" style="display:' . (!isset($action) || $action['type'] == 'fileinto' ? 'inline' : 'none') . '">'; $this->rc->imap_init(true); $a_folders = $this->rc->imap->list_mailboxes(); $delimiter = $this->rc->imap->get_hierarchy_delimiter(); // set mbox encoding $mbox_encoding = $this->rc->config->get('managesieve_mbox_encoding', 'UTF7-IMAP'); if ($action['type'] == 'fileinto') { $mailbox = $action['target']; } else { $mailbox = ''; } foreach ($a_folders as $folder) { $utf7folder = $this->rc->imap->mod_mailbox($folder); $names = explode($delimiter, rcube_charset_convert($folder, 'UTF7-IMAP')); $name = $names[sizeof($names) - 1]; if ($replace_delimiter = $this->rc->config->get('managesieve_replace_delimiter')) { $utf7folder = str_replace($delimiter, $replace_delimiter, $utf7folder); } // convert to Sieve implementation encoding $utf7folder = $this->mbox_encode($utf7folder, $mbox_encoding); if ($folder_class = rcmail_folder_classname($name)) { $foldername = $this->gettext($folder_class); } else { $foldername = $name; } $out .= sprintf('<option value="%s"%s>%s%s</option>' . "\n", htmlspecialchars($utf7folder), $mailbox == $utf7folder ? ' selected="selected"' : '', str_repeat(' ', 4 * (sizeof($names) - 1)), Q(abbreviate_string($foldername, 40 - (2 * sizeof($names) - 1)))); } $out .= '</select>'; $out .= '</td>'; // add/del buttons $out .= '<td class="rowbuttons">'; $out .= '<input type="button" id="actionadd' . $id . '" value="' . Q($this->gettext('add')) . '" onclick="rcmail.managesieve_actionadd(' . $id . ')" class="button" /> '; $out .= '<input type="button" id="actiondel' . $id . '" value="' . Q($this->gettext('del')) . '" onclick="rcmail.managesieve_actiondel(' . $id . ')" class="button' . ($rows_num < 2 ? ' disabled' : '') . '"' . ($rows_num < 2 ? ' disabled="disabled"' : '') . ' />'; $out .= '</td>'; $out .= '</tr></table>'; $out .= $div ? "</div>\n" : ''; return $out; }