Print inline javascript to output buffer after wrapping with necessary
javascript tags.
public static wrapInlineScript ( array $script ) : string | ||
$script | array | The script to output. |
Résultat | string | The script with the necessary HTML javascript tags appended. |
/** */ protected function _init() { global $injector, $notification, $page_output, $registry; if (!$registry->hasMethod('images/selectGalleries') || !$registry->hasMethod('images/saveImage')) { $e = new IMP_Exception('Image saving is not available.'); $e->logged = true; throw $e; } /* Run through the action handlers. */ switch ($this->vars->actionID) { case 'save_image': $contents = $injector->getInstance('IMP_Factory_Contents')->create($this->indices); if (!($mime_part = $contents->getMimePart($this->vars->id))) { $notification->push(_("Could not load message.")); break; } $image_data = array('data' => $mime_part->getContents(), 'description' => $mime_part->getDescription(true), 'filename' => $mime_part->getName(true), 'type' => $mime_part->getType()); try { $registry->images->saveImage($this->vars->gallery, $image_data); } catch (Horde_Exception $e) { $notification->push($e); break; } echo Horde::wrapInlineScript(array('window.close();')); exit; } /* Build the view. */ $view = new Horde_View(array('templatePath' => IMP_TEMPLATES . '/saveimage')); $view->addHelper('Horde_Core_View_Helper_Image'); $view->addHelper('Text'); $view->action = self::url(); $view->gallerylist = $registry->images->selectGalleries(array('perm' => Horde_Perms::EDIT)); $view->id = $this->vars->id; $view->muid = strval($this->indices); $page_output->topbar = $page_output->sidebar = false; $page_output->addInlineScript(array('$$("INPUT.horde-cancel").first().observe("click", function() { window.close(); })'), true); $this->title = _("Save Image"); $this->output = $view->render('saveimage'); }
/** * @throws IMP_Exception */ protected function _init() { global $conf, $injector, $notification, $page_output; if (!$this->indices) { throw new IMP_Exception(_("No message index given.")); } $page_output->addScriptFile('message-dimp.js'); $page_output->addScriptFile('textarearesize.js', 'horde'); $page_output->addScriptFile('toggle_quotes.js', 'horde'); $page_output->addScriptPackage('IMP_Script_Package_Imp'); $js_vars = array(); switch ($this->vars->actionID) { case 'strip_attachment': try { $this->indices = new IMP_Indices_Mailbox($this->indices->mailbox, $injector->getInstance('IMP_Message')->stripPart($this->indices, $this->vars->id)); $js_vars['-DimpMessage.strip'] = 1; $notification->push(_("Attachment successfully stripped."), 'horde.success'); } catch (IMP_Exception $e) { $notification->push($e); } break; } try { $show_msg = new IMP_Ajax_Application_ShowMessage($this->indices); $msg_res = $show_msg->showMessage(array('headers' => array_diff(array_keys($injector->getInstance('IMP_Message_Ui')->basicHeaders()), array('subject')), 'preview' => false)); } catch (IMP_Exception $e) { $notification->notify(array('listeners' => array('status', 'audio'))); echo Horde::wrapInlineScript(array('parent.close()')); exit; } $ajax_queue = $injector->getInstance('IMP_Ajax_Queue'); $ajax_queue->poll($this->indices->mailbox); list(, $buid) = $this->indices->buids->getSingle(); foreach (array('from', 'to', 'cc', 'bcc', 'replyTo', 'log') as $val) { if (!empty($msg_res[$val])) { $js_vars['DimpMessage.' . $val] = $msg_res[$val]; } } if (!empty($msg_res['list_info']['exists'])) { $js_vars['DimpMessage.reply_list'] = true; $this->view->listinfo = Horde::popupJs(IMP_Basic_Listinfo::url(array('buid' => $buid, 'mailbox' => $this->indices->mailbox)), array('urlencode' => true)); } $js_vars['DimpMessage.buid'] = $buid; $js_vars['DimpMessage.mbox'] = $this->indices->mailbox->form_to; $js_vars['DimpMessage.tasks'] = $injector->getInstance('Horde_Core_Factory_Ajax')->create('imp', $this->vars)->getTasks(); $page_output->addInlineJsVars($js_vars); if (isset($msg_res['js'])) { $page_output->addInlineScript(array_filter($msg_res['js']), true); } $this->_pages[] = 'message'; /* Determine if compose mode is disabled. */ if (IMP_Compose::canCompose()) { $this->view->qreply = $injector->getInstance('IMP_Dynamic_Compose_Common')->compose($this, array('title' => _("Message") . ': ' . $msg_res['subject'])); $this->_pages[] = 'qreply'; $this->js_conf['qreply'] = 1; } $page_output->noDnsPrefetch(); $this->view->show_delete = $this->indices->mailbox->access_deletemsgs; list($real_mbox, ) = $this->indices->getSingle(); $this->view->show_innocent = $real_mbox->innocent_show; $this->view->show_spam = $real_mbox->spam_show; $this->view->show_view_all = empty($msg_res['onepart']); $this->view->show_view_source = !empty($conf['user']['allow_view_source']); $this->view->save_as = $msg_res['save_as']; $this->view->subject = isset($msg_res['subjectlink']) ? $msg_res['subjectlink'] : $msg_res['subject']; $hdrs = array(); foreach ($msg_res['headers'] as $val) { $hdrs[] = array_filter(array('id' => isset($val['id']) ? 'msgHeader' . $val['id'] : null, 'label' => $val['name'], 'val' => $val['value'])); } $this->view->hdrs = $hdrs; if (isset($msg_res['atc_label'])) { $this->view->atc_label = $msg_res['atc_label']; if (isset($msg_res['atc_list'])) { $this->view->atc_list = $msg_res['atc_list']; } else { $this->view->atc_list = array(); } if (isset($msg_res['atc_download'])) { $this->view->atc_download = $msg_res['atc_download']; } } else { $this->view->atc_list = array(); } $this->view->msgtext = $msg_res['msgtext']; Horde::startBuffer(); $notification->notify(array('listeners' => array('status', 'audio'))); $this->view->status = Horde::endBuffer(); $this->title = $msg_res['title']; $this->view->title = $this->title; }
<?php /** * Copyright 2005-2015 Horde LLC (http://www.horde.org/) * * See the enclosed file LICENSE for license information (BSD). If you * did not receive this file, see http://www.horde.org/licenses/bsdl.php. * * @author Chuck Hagenbuch <*****@*****.**> * @author Jan Schneider <*****@*****.**> */ require_once __DIR__ . '/lib/Application.php'; $hermes = Horde_Registry::appInit('hermes'); $vars = Horde_Variables::getDefaultVariables(); $form = new Horde_Form($vars, _("Stop Watch")); $form->addVariable(_("Stop watch description"), 'description', 'text', true); if ($form->validate($vars)) { Hermes::newTimer($vars->get('description')); echo Horde::wrapInlineScript(array('var t = ' . Horde_Serialize::serialize(sprintf(_("The stop watch \"%s\" has been started and will appear in the menu at the next refresh."), $vars->get('description')), Horde_Serialize::JSON) . ';', 'alert(t);', 'window.close();')); exit; } $page_output->topbar = $page_output->sidebar = false; $page_output->header(array('title' => _("Stop Watch"))); $form->renderActive(new Horde_Form_Renderer(), $vars, Horde::url('start.php'), 'post'); $page_output->footer();
<?php /** * Copyright 2002-2015 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.horde.org/licenses/gpl. */ require_once __DIR__ . '/lib/Application.php'; Horde_Registry::appInit('kronolith'); if (Kronolith::showAjaxView()) { Horde::url('', true)->redirect(); } if (!$GLOBALS['registry']->getAuth()) { echo Horde::wrapInlineScript(array('window.close();')); exit; } /* Get the lists of address books through API */ $source_list = $registry->call('contacts/sources'); /* If we self-submitted, use that source. Otherwise, choose a good * source. */ $source = Horde_Util::getFormData('source'); if (empty($source) || !isset($source_list[$source])) { /* We don't just pass the second argument to getFormData() because * we want to trap for invalid sources, not just no source. */ $source = key($source_list); } /* Get the search as submitted (defaults to '' which should list everyone). */ $search = Horde_Util::getFormData('search'); if ($search || $prefs->getValue('display_contact')) { $searchpref = Kronolith::getAddressbookSearchParams();
if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) { continue; } } $newDate = new Horde_Date($vars->get('image_originalDate')); $image->originalDate = (int) $newDate->timestamp(); $image->save(); ++$count; } catch (Ansel_Exception $e) { $notification->push(sprintf(_("There was an error editing the dates: %s"), $e->getMessage()), 'horde.error'); echo Horde::wrapInlineScript(array('window.opener.location.href = window.opener.location.href;', 'window.close();')); exit; } } $notification->push(sprintf(_("Successfully modified the date on %d photos."), $count), 'horde.success'); echo Horde::wrapInlineScript(array('window.opener.location.href = window.opener.location.href;', 'window.close();')); exit; } $keys = array_keys($images); $html = ''; foreach ($keys as $key) { $html .= '<img src="' . Ansel::getImageUrl($key, 'mini', false) . '" style="margin:2px;" alt="[thumbnail]" />'; } $image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage(array_pop($keys)); /* Display the form */ $vars->set('image', $images); $vars->set('gallery', $gallery_id); $vars->set('page', $page); $vars->set('actionID', 'edit_dates'); $vars->set('image_list', $html); $vars->set('image_originalDate', $image->originalDate);
/** * URL Parameters: * <pre> * - criteria_form: (string) JSON representation of the search query. * - edit_query: (integer) If true, edit a search query (contained in * 'mailbox' parameter). * - edit_query_filter: (string) The name of the filter being edited. * - edit_query_vfolder: (string) The name of the virtual folder being * edited. * - mailbox: (string) Mailbox parameter. * - mailbox_list: (array) A list of mailboxes to process (base64url * encoded) If empty, uses 'mailbox' parameter. * - mboxes_form: (string) JSON representation of the list of mailboxes * for the query. Hash containing 2 keys: mbox & * subfolder. Both values are base64url encoded. * - search_label: (string) The label to use when saving the search. * - search_type: (string) The type of saved search ('filter', * 'vfolder'). If empty, the search should not be saved. * - subfolder: (boolean) If set, search mailbox will default to * subfolder search. * </pre> */ protected function _init() { global $injector, $notification, $page_output, $prefs, $registry; /* Define the criteria list. */ $criteria = array('from' => array('label' => _("From"), 'type' => 'header'), 'recip' => array('label' => _("Recipients (To/Cc/Bcc)"), 'type' => 'header'), 'to' => array('label' => _("To"), 'type' => 'header'), 'cc' => array('label' => _("Cc"), 'type' => 'header'), 'bcc' => array('label' => _("Bcc"), 'type' => 'header'), 'subject' => array('label' => _("Subject"), 'type' => 'header'), 'customhdr' => array('label' => _("Custom Header"), 'type' => 'customhdr'), 'body' => array('label' => _("Body"), 'type' => 'text'), 'text' => array('label' => _("Entire Message"), 'type' => 'text'), 'date_range' => array('label' => _("Date"), 'type' => 'date'), 'older' => array('label' => _("Older Than"), 'type' => 'within'), 'younger' => array('label' => _("Younger Than"), 'type' => 'within'), 'size_smaller' => array('label' => _("Size (KB) <"), 'type' => 'size'), 'size_larger' => array('label' => _("Size (KB) >"), 'type' => 'size')); $filters = array('bulk' => array('label' => _("Bulk Messages"), 'type' => 'filter'), 'attach' => array('label' => _("Contains Attachment(s)"), 'type' => 'filter'), 'mailinglist' => array('label' => _("Mailing List Messages"), 'type' => 'filter'), 'personal' => array('label' => _("Personal Messages"), 'type' => 'filter')); /* Define some constants. */ $constants = array('within' => array('d' => IMP_Search_Element_Within::INTERVAL_DAYS, 'm' => IMP_Search_Element_Within::INTERVAL_MONTHS, 'y' => IMP_Search_Element_Within::INTERVAL_YEARS)); if (isset($this->vars->mailbox_list)) { if (is_array($this->vars->mailbox_list)) { $default_mailbox = IMP_Mailbox::get('INBOX'); $search_mailbox = IMP_Mailbox::formFrom($this->vars->mailbox_list); } else { $default_mailbox = IMP_Mailbox::formFrom($this->vars->mailbox_list); $search_mailbox = array($default_mailbox); } } elseif (isset($this->vars->mailbox)) { $default_mailbox = IMP_Mailbox::formFrom($this->vars->mailbox); $search_mailbox = array($default_mailbox); } else { $default_mailbox = IMP_Mailbox::get('INBOX'); $search_mailbox = array($default_mailbox); } /* Check that searching is allowed. */ if (!$injector->getInstance('IMP_Factory_Imap')->create()->access(IMP_Imap::ACCESS_SEARCH)) { $default_mailbox->url('mailbox')->redirect(); } $imp_flags = $injector->getInstance('IMP_Flags'); $imp_search = $injector->getInstance('IMP_Search'); $dynamic_view = $registry->getView() == Horde_Registry::VIEW_DYNAMIC; $js_vars = array(); /* Generate the search query if 'criteria_form' is present in the form * data. */ if ($this->vars->criteria_form) { $c_list = array(); foreach (json_decode($this->vars->criteria_form) as $val) { switch ($val->t) { case 'from': case 'to': case 'cc': case 'bcc': case 'subject': $c_list[] = new IMP_Search_Element_Header($val->v, $val->t, $val->n); break; case 'recip': $c_list[] = new IMP_Search_Element_Recipient($val->v, $val->n); break; case 'customhdr': $c_list[] = new IMP_Search_Element_Header($val->v->s, $val->v->h, $val->n); break; case 'body': case 'text': $c_list[] = new IMP_Search_Element_Text($val->v, $val->t == 'body', $val->n); break; case 'date_range': $c_list[] = new IMP_Search_Element_Daterange($val->b ? new DateTime($val->b) : 0, $val->e ? new DateTime($val->e) : 0, $val->n); break; case 'older': case 'younger': $c_list[] = new IMP_Search_Element_Within($val->v->v, $constants['within'][$val->v->l], $val->t == 'older'); break; case 'size_smaller': case 'size_larger': $c_list[] = new IMP_Search_Element_Size($val->v, $val->t == 'size_larger'); break; case 'or': $c_list[] = new IMP_Search_Element_Or(); break; case 'bulk': $c_list[] = new IMP_Search_Element_Bulk($val->n); break; case 'attach': $c_list[] = new IMP_Search_Element_Attachment($val->n); break; case 'mailinglist': $c_list[] = new IMP_Search_Element_Mailinglist($val->n); break; case 'personal': $c_list[] = new IMP_Search_Element_Personal($val->n); break; case 'flag': /* Flag search. */ $formdata = $imp_flags->parseFormId(rawurldecode($val->v)); $c_list[] = new IMP_Search_Element_Flag($formdata['flag'], $formdata['set'] && !$val->n); break; } } $redirect_dynamic = true; $redirect_target = false; switch ($this->vars->search_type) { case 'filter': $q_ob = $imp_search->createQuery($c_list, array('id' => IMP_Mailbox::formFrom($this->vars->edit_query_filter), 'label' => $this->vars->search_label, 'type' => IMP_Search::CREATE_FILTER)); if ($this->vars->edit_query_filter) { $notification->push(sprintf(_("Filter \"%s\" edited successfully."), $this->vars->search_label), 'horde.success'); $redirect_dynamic = false; $redirect_target = 'prefs'; } else { $notification->push(sprintf(_("Filter \"%s\" created succesfully."), $this->vars->search_label), 'horde.success'); } break; case 'vfolder': $form = json_decode($this->vars->mboxes_form); $q_ob = $imp_search->createQuery($c_list, array('id' => IMP_Mailbox::formFrom($this->vars->edit_query_vfolder), 'label' => $this->vars->search_label, 'mboxes' => IMP_Mailbox::formFrom($form->mbox), 'subfolders' => IMP_Mailbox::formFrom($form->subfolder), 'type' => IMP_Search::CREATE_VFOLDER)); if ($this->vars->edit_query_vfolder) { $notification->push(sprintf(_("Virtual Folder \"%s\" edited successfully."), $this->vars->search_label), 'horde.success'); $redirect_target = 'prefs'; } else { $notification->push(sprintf(_("Virtual Folder \"%s\" created succesfully."), $this->vars->search_label), 'horde.success'); $redirect_target = 'mailbox'; } break; default: $form = json_decode($this->vars->mboxes_form); $q_ob = $imp_search->createQuery($c_list, array('mboxes' => IMP_Mailbox::formFrom($form->mbox), 'subfolders' => IMP_Mailbox::formFrom($form->subfolder))); $redirect_target = 'mailbox'; break; } /* Redirect to the mailbox page. */ if ($redirect_target) { if ($dynamic_view && $redirect_dynamic) { echo '<html><head>' . Horde::wrapInlineScript(array('window.parent.DimpBase.go("mbox", "' . $q_ob->mbox_ob->form_to . '")')) . '</head></html>'; exit; } switch ($redirect_target) { case 'mailbox': $q_ob->mbox_ob->url('mailbox')->redirect(); break; case 'prefs': $registry->getServiceLink('prefs', 'imp')->add('group', 'searches')->redirect(); break; } exit; } } /* Prepare the search view. */ $view = new Horde_View(array('templatePath' => IMP_TEMPLATES . '/search')); $view->addHelper('Text'); $view->addHelper('Tag'); $view->addHelper('FormTag'); $view->action = self::url(); /* Determine if we are editing a search query. */ $q_ob = $default_mailbox->getSearchOb(); if ($this->vars->edit_query && $default_mailbox->search) { if ($default_mailbox->vfolder) { if (!$default_mailbox->editvfolder) { $notification->push(_("Built-in Virtual Folders cannot be edited."), 'horde.error'); $registry->getServiceLink('prefs', 'imp')->add('group', 'searches')->redirect(); } $view->edit_query = true; $view->edit_query_vfolder = $default_mailbox->form_to; } elseif ($imp_search->isFilter($q_ob)) { if (!$imp_search->isFilter($q_ob, true)) { $notification->push(_("Built-in Filters cannot be edited."), 'horde.error'); $registry->getServiceLink('prefs', 'imp')->add('group', 'searches')->redirect(); } $view->edit_query = true; $view->edit_query_filter = $default_mailbox->form_to; } if ($view->edit_query) { $view->search_label = $q_ob->label; $js_vars['ImpSearch.prefsurl'] = strval($registry->getServiceLink('prefs', 'imp')->add('group', 'searches')->setRaw(true)); } } else { /* Process list of recent searches. */ $iterator = IMP_Search_IteratorFilter::create(IMP_Search_IteratorFilter::QUERY); $rs = array(); foreach ($iterator as $val) { $rs[$val->formid] = array('c' => $val->criteria, 'f' => array('m' => IMP_Mailbox::formTo($val->all ? array(IMP_Search_Query::ALLSEARCH) : array_map('strval', $val->mbox_list)), 's' => IMP_Mailbox::formTo(array_map('strval', $val->subfolder_list))), 'l' => Horde_String::truncate($val->querytext)); } if (!empty($rs)) { $js_vars['ImpSearch.i_recent'] = $rs; } $s_mboxes = IMP_Mailbox::formTo($search_mailbox); $js_vars['ImpSearch.i_mboxes'] = array('m' => $this->vars->subfolder ? array() : $s_mboxes, 's' => $this->vars->subfolder ? $s_mboxes : array()); } if ($default_mailbox->search) { $js_vars['ImpSearch.i_criteria'] = $q_ob->criteria; $js_vars['ImpSearch.i_mboxes'] = array('m' => IMP_Mailbox::formTo($q_ob->all ? array(IMP_Search_Query::ALLSEARCH) : $q_ob->mbox_list), 's' => IMP_Mailbox::formTo($q_ob->subfolder_list)); } /* Create the criteria list. */ $c_list = $types = array(); foreach ($criteria as $key => $val) { $c_list[] = array('l' => $val['label'], 'v' => $key); $types[$key] = $val['type']; } $view->clist = $c_list; /* Create the filter list. These are all-or-nothing searches. */ $f_list = array(); foreach ($filters as $key => $val) { $f_list[] = array('l' => $val['label'], 'v' => $key); $types[$key] = 'filter'; } $view->filterlist = $f_list; /* Create the flag list. */ $flist = $imp_flags->getList(array('imap' => true, 'mailbox' => $default_mailbox)); $flag_set = array(); foreach ($flist as $val) { $flag_set[] = array('l' => $val->label, 'v' => rawurlencode($val->form_set)); $types[rawurlencode($val->form_set)] = 'flag'; } $view->flist = $flag_set; /* Generate master mailbox list. */ $mbox_list = array(); if (!$view->edit_query_filter) { $js_vars['ImpSearch.allsearch'] = IMP_Mailbox::formTo(IMP_Search_Query::ALLSEARCH); $ob = $injector->getInstance('IMP_Search_Ui')->getSearchMboxList(); $mbox_list = $ob->mbox_list; $view->subscribe = $prefs->getValue('subscribe'); $view->tree = $ob->tree->getTree(); } /* Prepare the topbar. */ if (!$dynamic_view) { $injector->getInstance('Horde_View_Topbar')->subinfo = $injector->getInstance('IMP_View_Subinfo')->render(); } Horde_Core_Ui_JsCalendar::init(); $page_output->addScriptFile('hordecore.js', 'horde'); $page_output->addScriptFile('horde.js', 'horde'); $page_output->addScriptFile('search.js'); $page_output->addInlineJsVars(array_merge($js_vars, array('ImpSearch.data' => array('constants' => $constants, 'dynamic_view' => $dynamic_view, 'inbox' => IMP_Mailbox::get('INBOX')->form_to, 'mbox_list' => $mbox_list, 'months' => Horde_Core_Ui_JsCalendar::months(), 'searchmbox' => $default_mailbox->form_to, 'types' => $types), 'ImpSearch.text' => array('and' => _("and"), 'customhdr' => _("Custom Header:"), 'datereset' => _("Date Reset"), 'dateselection' => _("Date Selection"), 'flag' => _("Flag:"), 'loading' => _("Loading..."), 'need_criteria' => _("Please select at least one search criteria."), 'need_date' => _("Need at least one date in the date range search."), 'need_mbox' => _("Please select at least one mailbox to search."), 'need_label' => _("Saved searches require a label."), 'not_match' => _("Do NOT Match"), 'or' => _("OR"), 'search_all' => _("Search All Mailboxes"), 'search_term' => _("Search Term:"), 'subfolder_search' => _("Search all subfolders?"), 'to' => _("to")))), array('onload' => true)); if ($dynamic_view) { if (!$this->vars->edit_query) { $view->return_mailbox_val = sprintf(_("Return to %s"), $default_mailbox->display_html); } $page_output->topbar = $page_output->sidebar = false; $this->header_params = array('html_id' => 'htmlAllowScroll'); } $this->title = _("Search"); $this->output = $view->render('search'); }
/** * Reload the window. */ protected function _reloadWindow() { echo Horde::wrapInlineScript(array('opener.focus();' . 'opener.location.href="' . base64_decode($this->vars->reload) . '";', 'window.close();')); exit; }
/** * Print pending inline javascript to the output buffer. * * @param boolean $raw Return the raw script (not wrapped in CDATA tags * or observe wrappers)? */ public function outputInlineScript($raw = false) { if (empty($this->inlineScript)) { return; } $script = array(); foreach ($this->inlineScript as $key => $val) { $val = implode('', $val); $script[] = !$raw && $key ? 'document.observe("dom:loaded",function(){' . $val . '});' : $val; } echo $raw ? implode('', $script) : Horde::wrapInlineScript($script); $this->inlineScript = array(); }
/** * AJAX action: Add an attachment to a compose message (from the ckeditor * plugin). * * Variables used: * - CKEditorFuncNum: (integer) CKEditor function identifier to call * when returning URL data * - composeCache: (string) The IMP_Compose cache identifier. * * @return Horde_Core_Ajax_Response_Raw text/html return containing * javascript code to update the * URL parameter in CKEditor. */ public function addAttachmentCkeditor() { global $injector; $data = $url = null; if (isset($this->vars->composeCache)) { $imp_compose = $injector->getInstance('IMP_Factory_Compose')->create($this->vars->composeCache); if ($imp_compose->canUploadAttachment()) { try { $atc_ob = $imp_compose->addAttachmentFromUpload('upload'); if ($atc_ob[0] instanceof IMP_Compose_Exception) { throw $atc_ob[0]; } $atc_ob[0]->related = true; $data = array(IMP_Compose::RELATED_ATTR => 'src;' . $atc_ob[0]->id); $url = strval($atc_ob[0]->viewUrl()); } catch (IMP_Compose_Exception $e) { $data = $e->getMessage(); } } else { $data = _("Uploading attachments has been disabled on this server."); } } else { $data = _("Your attachment was not uploaded. Most likely, the file exceeded the maximum size allowed by the server configuration."); } return new Horde_Core_Ajax_Response_Raw('<html>' . Horde::wrapInlineScript(array('window.parent.CKEDITOR.tools.callFunction(' . $this->vars->CKEditorFuncNum . ',' . json_encode($url) . ',' . json_encode($data) . ')')) . '</html>', 'text/html'); }
/** * @throws IMP_Exception */ protected function _init() { global $injector, $notification, $page_output; if (!$this->indices) { throw new IMP_Exception(_("No message index given.")); } $page_output->addScriptFile('message.js'); $page_output->addScriptFile('external/CustomElements.js'); $page_output->addScriptFile('external/time-elements.js'); $page_output->addScriptFile('textarearesize.js', 'horde'); $page_output->addScriptFile('toggle_quotes.js', 'horde'); $page_output->addScriptPackage('IMP_Script_Package_Imp'); $page_output->addThemeStylesheet('message.css'); $page_output->addThemeStylesheet('message_view.css'); $js_vars = array(); switch ($this->vars->actionID) { case 'strip_attachment': try { $this->indices = new IMP_Indices_Mailbox($this->indices->mailbox, $this->indices->stripPart($this->vars->id)); $js_vars['-ImpMessage.strip'] = 1; $notification->push(_("Attachment successfully stripped."), 'horde.success'); } catch (IMP_Exception $e) { $notification->push($e); } break; } try { $show_msg = new IMP_Contents_Message($this->indices); $msg_res = $show_msg->showMessage(); } catch (IMP_Exception $e) { $notification->notify(array('listeners' => array('status', 'audio'))); echo Horde::wrapInlineScript(array('parent.close()')); exit; } /* Add 'maillog' and 'poll' data to the AJAX queue. */ $ajax_queue = $injector->getInstance('IMP_Ajax_Queue'); $ajax_queue->maillog($this->indices); $ajax_queue->poll($this->indices->mailbox); list(, $buid) = $this->indices->buids->getSingle(); /* Need to be dynamically added, since formatting needs to be applied * via javascript. */ foreach (array('from', 'to', 'cc', 'bcc') as $val) { if ($tmp = $show_msg->getAddressHeader($val)) { $js_vars['ImpMessage.' . $val] = $tmp; } } if ($resent = $show_msg->getResentData()) { $resent_js = array(); foreach ($resent as $val) { $resent_js[] = array('date' => $val['date']->format($val['date']::DATE_LOCAL), 'from' => $show_msg->getAddressHeader($val['from'])); } $js_vars['ImpMessage.resent'] = $resent_js; } if (isset($msg_res['log'])) { $js_vars['ImpMessage.log'] = $msg_res['log']; } $list_info = $show_msg->contents->getListInformation(); if (!empty($list_info['exists'])) { $js_vars['ImpMessage.reply_list'] = true; $this->view->listinfo = Horde::popupJs(IMP_Basic_Listinfo::url(array('buid' => $buid, 'mailbox' => $this->indices->mailbox)), array('urlencode' => true)); } $js_vars['ImpMessage.buid'] = $buid; $js_vars['ImpMessage.mbox'] = $this->indices->mailbox->form_to; if (isset($msg_res['atc'])) { $js_vars['ImpMessage.msg_atc'] = $msg_res['atc']; $this->js_text['atc_downloadall'] = _("Download All (%s)"); } if (isset($msg_res['md'])) { $js_vars['ImpMessage.msg_md'] = $msg_res['md']; } $js_vars['ImpMessage.tasks'] = $injector->getInstance('Horde_Core_Factory_Ajax')->create('imp', $this->vars)->getTasks(); $page_output->addInlineJsVars($js_vars); if (isset($msg_res['js'])) { $page_output->addInlineScript(array_filter($msg_res['js']), true); } $this->_pages[] = 'message'; $subject = $show_msg->getSubject(); $this->view->subject = isset($subject['subjectlink']) ? $subject['subjectlink'] : $subject['subject']; $this->title = $subject['title']; /* Determine if compose mode is disabled. */ if (IMP_Compose::canCompose()) { $this->view->qreply = $injector->getInstance('IMP_Dynamic_Compose_Common')->compose($this, array('title' => _("Message") . ': ' . $subject['subject'])); $this->_pages[] = 'qreply'; $this->js_conf['qreply'] = 1; } $page_output->noDnsPrefetch(); $this->view->show_delete = $this->indices->mailbox->access_deletemsgs; list($real_mbox, ) = $this->indices->getSingle(); $this->view->show_innocent = $real_mbox->innocent_show; $this->view->show_spam = $real_mbox->spam_show; $this->view->show_view_all = empty($msg_res['onepart']); $this->view->show_view_source = $injector->getInstance('Horde_Core_Perms')->hasAppPermission('view_msg_source'); $this->view->save_as = $show_msg->getSaveAs(); if ($date = $show_msg->getDateOb()) { $this->view->datestamp = $date->format($date::DATE_ISO_8601); $this->view->fulldate = $date->format($date::DATE_FORCE); $this->view->localdate = $date->format($date::DATE_LOCAL); $this->view->addHelper('Text'); } if ($this->view->user_hdrs = $show_msg->getUserHeaders()) { $this->view->addHelper('Text'); } $this->view->msgtext = $msg_res['msgtext']; Horde::startBuffer(); $notification->notify(array('listeners' => array('status', 'audio'))); $this->view->status = Horde::endBuffer(); $this->view->title = $this->title; }
/** */ protected function _init() { global $browser, $injector, $notification, $page_output, $prefs, $registry, $session; /* Mailto link handler: redirect based on current view. */ if ($this->vars->actionID == 'mailto_link') { switch ($registry->getView()) { case Horde_Registry::VIEW_DYNAMIC: IMP_Dynamic_Compose::url()->add($_GET)->redirect(); exit; case Horde_Registry::VIEW_MINIMAL: IMP_Minimal_Compose::url()->add($_GET)->redirect(); exit; } } /* The message headers and text. */ $header = array(); $msg = ''; $redirect = $resume = $spellcheck = false; $oldrtemode = $rtemode = null; /* Is this a popup window? */ if ($isPopup = $prefs->getValue('compose_popup') || $this->vars->popup) { $page_output->topbar = $page_output->sidebar = false; } /* Set the current identity. */ $identity = $injector->getInstance('IMP_Identity'); if (!$prefs->isLocked('default_identity') && !is_null($this->vars->identity)) { $identity->setDefault($this->vars->identity); } if ($this->vars->actionID) { switch ($this->vars->actionID) { case 'draft': case 'editasnew': case 'forward_attach': case 'forward_auto': case 'forward_body': case 'forward_both': case 'fwd_digest': case 'mailto': case 'mailto_link': case 'reply': case 'reply_all': case 'reply_auto': case 'reply_list': case 'redirect_compose': case 'template': case 'template_edit': case 'template_new': /* These are all safe actions that might be invoked without a * token. */ break; default: try { $session->checkToken($this->vars->compose_requestToken); } catch (Horde_Exception $e) { $notification->push($e); $this->vars->actionID = null; } } } /* Check for duplicate submits. */ if ($reload = $this->vars->compose_formToken) { try { $session->checkNonce($reload); } catch (Horde_Exception $e) { $notification->push(_("You have already submitted this page."), 'horde.error'); $this->vars->actionID = null; } } /* Determine if compose mode is disabled. */ $compose_disable = !IMP_Compose::canCompose(); /* Determine if mailboxes are readonly. */ $draft = IMP_Mailbox::getPref(IMP_Mailbox::MBOX_DRAFTS); $readonly_drafts = $draft && $draft->readonly; $sent_mail = $identity->getValue(IMP_Mailbox::MBOX_SENT); if (!$sent_mail) { $readonly_sentmail = $save_sent_mail = false; } elseif ($sent_mail->readonly) { $readonly_sentmail = true; $save_sent_mail = false; } else { $readonly_sentmail = false; $save_sent_mail = $reload ? (bool) $this->vars->save_sent_mail : true; } /* Initialize the IMP_Compose:: object. */ $imp_compose = $injector->getInstance('IMP_Factory_Compose')->create($this->vars->composeCache); /* Init objects. */ $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create(); $imp_ui = new IMP_Compose_Ui(); /* Determine the composition type - text or HTML. $rtemode is null if browser does not support it. */ if ($session->get('imp', 'rteavail')) { if ($prefs->isLocked('compose_html')) { $rtemode = $prefs->getValue('compose_html'); } else { $rtemode = $this->vars->rtemode; if (is_null($rtemode)) { $rtemode = $prefs->getValue('compose_html'); } else { $rtemode = intval($rtemode); $oldrtemode = intval($this->vars->oldrtemode); } } } /* Update the file attachment information. */ $attach_upload = $imp_compose->canUploadAttachment(); if ($attach_upload) { /* Only notify if we are reloading the compose screen. */ $notify = !in_array($this->vars->actionID, array('send_message', 'save_draft')); $deleteList = Horde_Util::getPost('delattachments', array()); /* Update the attachment information. */ foreach ($imp_compose as $key => $val) { if (!in_array($key, $deleteList)) { $val->getPart()->setDescription($this->vars->filter('file_description_' . $key)); $imp_compose[$key] = $val; } } /* Delete attachments. */ foreach ($deleteList as $val) { if ($notify) { $notification->push(sprintf(_("Deleted attachment \"%s\"."), $imp_compose[$val]->getPart()->getName(true)), 'horde.success'); } unset($imp_compose[$val]); } /* Add attachments. */ for ($i = 1, $fcount = count($_FILES); $i <= $fcount; ++$i) { if (isset($_FILES['upload_' . $i]) && strlen($_FILES['upload_' . $i]['name'])) { try { $atc_ob = $imp_compose->addAttachmentFromUpload('upload_' . $i); if ($atc_ob[0] instanceof IMP_Compose_Exception) { throw $atc_ob[0]; } if ($notify) { $notification->push(sprintf(_("Added \"%s\" as an attachment."), $atc_ob[0]->getPart()->getName()), 'horde.success'); } } catch (IMP_Compose_Exception $e) { /* Any error will cancel the current action. */ $this->vars->actionID = null; $notification->push($e, 'horde.error'); } } } } /* Get message priority. */ $priority = $this->vars->get('priority', 'normal'); /* Request read receipt? */ $request_read_receipt = (bool) $this->vars->request_read_receipt; /* Run through the action handlers. */ $this->title = _("New Message"); switch ($this->vars->actionID) { case 'mailto': try { $contents = $this->_getContents(); } catch (IMP_Exception $e) { $notification->push($e, 'horde.error'); break; } $imp_headers = $contents->getHeader(); $header['to'] = ''; if ($this->vars->mailto) { $header['to'] = $imp_headers->getValue('to'); } if (empty($header['to'])) { ($header['to'] = strval($imp_headers->getOb('from'))) || ($header['to'] = strval($imp_headers->getOb('reply-to'))); } break; case 'mailto_link': $clink = new IMP_Compose_Link($this->vars); if (isset($clink->args['body'])) { $msg = $clink->args['body']; } foreach (array('to', 'cc', 'bcc', 'subject') as $val) { if (isset($clink->args[$val])) { $header[$val] = $clink->args[$val]; } } break; case 'draft': case 'editasnew': case 'template': case 'template_edit': try { switch ($this->vars->actionID) { case 'draft': $result = $imp_compose->resumeDraft($this->indices); $resume = true; break; case 'editasnew': $result = $imp_compose->editAsNew($this->indices); break; case 'template': $result = $imp_compose->useTemplate($this->indices); break; case 'template_edit': $result = $imp_compose->editTemplate($this->indices); $this->vars->template_mode = true; break; } if (!is_null($rtemode)) { $rtemode = $result['format'] == 'html'; } $msg = $result['body']; $header = array_merge($header, $this->_convertToHeader($result)); if (!is_null($result['identity']) && $result['identity'] != $identity->getDefault() && !$prefs->isLocked('default_identity')) { $identity->setDefault($result['identity']); $sent_mail = $identity->getValue(IMP_Mailbox::MBOX_SENT); } $priority = $result['priority']; $request_read_receipt = $result['readreceipt']; } catch (IMP_Compose_Exception $e) { $notification->push($e); } break; case 'reply': case 'reply_all': case 'reply_auto': case 'reply_list': try { $contents = $this->_getContents(); } catch (IMP_Exception $e) { $notification->push($e, 'horde.error'); break; } $reply_map = array('reply' => IMP_Compose::REPLY_SENDER, 'reply_all' => IMP_Compose::REPLY_ALL, 'reply_auto' => IMP_Compose::REPLY_AUTO, 'reply_list' => IMP_Compose::REPLY_LIST); $reply_msg = $imp_compose->replyMessage($reply_map[$this->vars->actionID], $contents, array('to' => $this->vars->to)); $msg = $reply_msg['body']; $header = $this->_convertToHeader($reply_msg); $format = $reply_msg['format']; switch ($reply_msg['type']) { case IMP_Compose::REPLY_SENDER: $this->vars->actionID = 'reply'; $this->title = _("Reply:"); break; case IMP_Compose::REPLY_ALL: if ($this->vars->actionID == 'reply_auto') { $recip_list = $imp_compose->recipientList($header); if (!empty($recip_list['list'])) { $replyauto_all = count($recip_list['list']); } } $this->vars->actionID = 'reply_all'; $this->title = _("Reply to All:"); break; case IMP_Compose::REPLY_LIST: if ($this->vars->actionID == 'reply_auto') { $replyauto_list = true; if (($parse_list = $injector->getInstance('Horde_ListHeaders')->parse('list-id', $contents->getHeader()->getValue('list-id'))) && !is_null($parse_list->label)) { $replyauto_list_id = $parse_list->label; } } $this->vars->actionID = 'reply_list'; $this->title = _("Reply to List:"); break; } if (!empty($reply_msg['lang'])) { $reply_lang = array_values($reply_msg['lang']); } $this->title .= ' ' . $header['subject']; if (!is_null($rtemode)) { $rtemode = $rtemode || $format == 'html'; } break; case 'replyall_revert': case 'replylist_revert': try { $reply_msg = $imp_compose->replyMessage(IMP_Compose::REPLY_SENDER, $imp_compose->getContentsOb()); $header = $this->_convertToHeader($reply_msg); } catch (IMP_Exception $e) { $notification->push($e, 'horde.error'); } break; case 'forward_attach': case 'forward_auto': case 'forward_body': case 'forward_both': $fwd_map = array('forward_attach' => IMP_Compose::FORWARD_ATTACH, 'forward_auto' => IMP_Compose::FORWARD_AUTO, 'forward_body' => IMP_Compose::FORWARD_BODY, 'forward_both' => IMP_Compose::FORWARD_BOTH); try { $fwd_msg = $imp_compose->forwardMessage($fwd_map[$this->vars->actionID], $this->_getContents()); } catch (IMP_Exception $e) { $notification->push($e, 'horde.error'); break; } $msg = $fwd_msg['body']; $header = $this->_convertToHeader($fwd_msg); $format = $fwd_msg['format']; $rtemode = $rtemode || !is_null($rtemode) && $format == 'html'; $this->title = $fwd_msg['title']; break; case 'redirect_compose': try { $imp_compose->redirectMessage($this->indices); $redirect = true; $this->title = ngettext("Redirect", "Redirect Messages", count($this->indices)); } catch (IMP_Compose_Exception $e) { $notification->push($e, 'horde.error'); } break; case 'redirect_send': try { $num_msgs = $imp_compose->sendRedirectMessage($this->vars->to); $imp_compose->destroy('send'); if ($isPopup) { if ($prefs->getValue('compose_confirm')) { $notification->push(ngettext("Message redirected successfully.", "Messages redirected successfully", count($num_msgs)), 'horde.success'); $this->_popupSuccess(); return; } echo Horde::wrapInlineScript(array('window.close();')); } else { $notification->push(ngettext("Message redirected successfully.", "Messages redirected successfully", count($num_msgs)), 'horde.success'); $this->_mailboxReturnUrl()->redirect(); } exit; } catch (Horde_Exception $e) { $notification->push($e); $this->vars->actionID = 'redirect_compose'; } break; case 'auto_save_draft': case 'save_draft': case 'save_template': case 'send_message': // Drafts readonly is handled below. if ($compose_disable && $this->vars->actionID == 'send_message') { break; } try { $header['from'] = strval($identity->getFromLine(null, $this->vars->from)); } catch (Horde_Exception $e) { $header['from'] = ''; $notification->push($e); break; } $header['to'] = $this->vars->to; $header['cc'] = $this->vars->cc; $header['bcc'] = $this->vars->bcc; $header['subject'] = strval($this->vars->subject); $message = strval($this->vars->message); /* Save the draft. */ switch ($this->vars->actionID) { case 'auto_save_draft': case 'save_draft': case 'save_template': if (!$readonly_drafts || $this->vars->actionID == 'save_template') { $save_opts = array('html' => $rtemode, 'priority' => $priority, 'readreceipt' => $request_read_receipt); try { switch ($this->vars->actionID) { case 'save_template': $result = $imp_compose->saveTemplate($header, $message, $save_opts); break; default: $result = $imp_compose->saveDraft($header, $message, $save_opts); break; } /* Closing draft if requested by preferences. */ switch ($this->vars->actionID) { case 'save_draft': if ($isPopup) { if ($prefs->getValue('close_draft')) { $imp_compose->destroy('save_draft'); echo Horde::wrapInlineScript(array('window.close();')); exit; } $notification->push($result, 'horde.success'); } else { $notification->push($result, 'horde.success'); if ($prefs->getValue('close_draft')) { $imp_compose->destroy('save_draft'); $this->_mailboxReturnUrl()->redirect(); } } break; case 'save_template': if ($isPopup) { echo Horde::wrapInlineScript(array('window.close();')); exit; } $notification->push($result, 'horde.success'); $this->_mailboxReturnUrl()->redirect(); break; } } catch (IMP_Compose_Exception $e) { if ($this->vars->actionID == 'save_draft') { $notification->push($e); } } } if ($this->vars->actionID == 'auto_save_draft') { $r = new stdClass(); $r->requestToken = $session->getToken(); $r->formToken = $session->getNonce(); $response = new Horde_Core_Ajax_Response_HordeCore($r); $response->sendAndExit(); } break; default: $header['replyto'] = $identity->getValue('replyto_addr'); if ($this->vars->sent_mail) { $sent_mail = IMP_Mailbox::formFrom($this->vars->sent_mail); } try { $imp_compose->buildAndSendMessage($message, $header, $identity, array('encrypt' => $prefs->isLocked('default_encrypt') ? $prefs->getValue('default_encrypt') : $this->vars->encrypt_options, 'html' => $rtemode, 'pgp_attach_pubkey' => $this->vars->pgp_attach_pubkey, 'priority' => $priority, 'save_sent' => $save_sent_mail, 'sent_mail' => $sent_mail, 'signature' => $this->vars->signature, 'strip_attachments' => !$this->vars->save_attachments_select, 'readreceipt' => $request_read_receipt, 'vcard_attach' => $this->vars->vcard ? $identity->getValue('fullname') : null)); $imp_compose->destroy('send'); if ($isPopup) { if ($prefs->getValue('compose_confirm')) { $notification->push(_("Message sent successfully."), 'horde.success'); $this->_popupSuccess(); return; } echo Horde::wrapInlineScript(array('window.close();')); } else { $notification->push(_("Message sent successfully."), 'horde.success'); $this->_mailboxReturnUrl()->redirect(); } exit; } catch (IMP_Compose_Exception $e) { $code = $e->getCode(); $notification->push($e->getMessage(), strpos($code, 'horde.') === 0 ? $code : 'horde.error'); /* Switch to tied identity. */ if (!is_null($e->tied_identity)) { $identity->setDefault($e->tied_identity); $notification->push(_("Your identity has been switched to the identity associated with the current recipient address. The identity will not be checked again during this compose action.")); } switch ($e->encrypt) { case 'pgp_symmetric_passphrase_dialog': $imp_ui->passphraseDialog('pgp_symm', $imp_compose->getCacheId()); break; case 'pgp_passphrase_dialog': $imp_ui->passphraseDialog('pgp'); break; case 'smime_passphrase_dialog': $imp_ui->passphraseDialog('smime'); break; } } break; } break; case 'fwd_digest': if (count($this->indices)) { try { $res = $imp_compose->forwardMultipleMessages($this->indices); $header['subject'] = $res['subject']; $fwd_msg = array('type' => IMP_Compose::FORWARD_ATTACH); } catch (IMP_Compose_Exception $e) { $notification->push($e, 'horde.error'); } } break; case 'cancel_compose': case 'discard_compose': $imp_compose->destroy($this->vars->actionID == 'cancel_compose' ? 'cancel' : 'discard'); if ($isPopup) { echo Horde::wrapInlineScript(array('window.close();')); } else { $this->_mailboxReturnUrl()->redirect(); } exit; case 'template_new': $this->vars->template_mode = true; break; } /* Get the message cache ID. */ $composeCacheID = filter_var($imp_compose->getCacheId(), FILTER_SANITIZE_STRING); /* Attach autocompleters to the compose form elements. */ if ($redirect) { $imp_ui->attachAutoCompleter(array('to')); } else { $imp_ui->attachAutoCompleter(array('to', 'cc', 'bcc')); $spellcheck = $imp_ui->attachSpellChecker(); $page_output->addScriptFile('ieescguard.js', 'horde'); } $max_attach = $imp_compose->additionalAttachmentsAllowed(); /* Get the URL to use for the cancel action. If the attachments cache * is not empty, or this is the resume drafts page, we must reload * this page and delete the attachments and/or the draft message. */ if ($isPopup) { if ($resume || count($imp_compose)) { $cancel_url = self::url()->setRaw(true)->add(array('actionID' => 'cancel_compose', 'compose_requestToken' => $session->getToken(), 'composeCache' => $composeCacheID, 'popup' => 1)); $discard_url = clone $cancel_url; $discard_url->add('actionID', 'discard_compose'); } else { $cancel_url = $discard_url = ''; } } elseif ($resume || count($imp_compose)) { $cancel_url = $this->_mailboxReturnUrl(self::url()->setRaw(true))->setRaw(true)->add(array('actionID' => 'cancel_compose', 'compose_requestToken' => $session->getToken(), 'composeCache' => $composeCacheID)); $discard_url = clone $cancel_url; $discard_url->add('actionID', 'discard_compose'); } else { $cancel_url = $discard_url = $this->_mailboxReturnUrl(false)->setRaw(true); } /* Grab any data that we were supplied with. */ if (!strlen($msg)) { $msg = $this->vars->get('message', strval($this->vars->body)); if ($browser->hasQuirk('double_linebreak_textarea')) { $msg = preg_replace('/(\\r?\\n){3}/', '$1', $msg); } $msg = "\n" . $msg; } if (isset($this->vars->signature)) { $signature = $this->vars->signature; if ($browser->hasQuirk('double_linebreak_textarea')) { $signature = preg_replace('/(\\r?\\n){3}/', '$1', $signature); } $signatureChanged = $signature != $identity->getSignature($oldrtemode ? 'html' : 'text'); } else { $signatureChanged = false; } /* Convert from Text -> HTML or vice versa if RTE mode changed. */ if (!is_null($oldrtemode) && $oldrtemode != $rtemode) { $msg = $imp_ui->convertComposeText($msg, $rtemode ? 'html' : 'text'); if ($signatureChanged) { $signature = $imp_ui->convertComposeText($signature, $rtemode ? 'html' : 'text'); } } /* If this is the first page load for this compose item, add auto BCC * addresses. */ if (!$reload && !$resume) { $header['bcc'] = strval($identity->getBccAddresses()); } foreach (array('to', 'cc', 'bcc') as $val) { if (!isset($header[$val])) { $header[$val] = $this->vars->{$val}; } } if (!isset($header['subject'])) { $header['subject'] = $this->vars->subject; } /* If PGP encryption is set by default, and we have a recipient list * on first load, make sure we have public keys for all recipients. */ $encrypt_options = $prefs->isLocked('default_encrypt') ? $prefs->getValue('default_encrypt') : $this->vars->encrypt_options; if ($prefs->getValue('use_pgp') && !$prefs->isLocked('default_encrypt') && $prefs->getValue('pgp_reply_pubkey')) { $default_encrypt = $prefs->getValue('default_encrypt'); if (!$reload && in_array($default_encrypt, array(IMP_Crypt_Pgp::ENCRYPT, IMP_Crypt_Pgp::SIGNENC))) { $addrs = $imp_compose->recipientList($header); if (!empty($addrs['list'])) { $imp_pgp = $injector->getInstance('IMP_Crypt_Pgp'); try { foreach ($addrs['list'] as $val) { $imp_pgp->getPublicKey(strval($val)); } } catch (Horde_Exception $e) { $notification->push(_("PGP encryption cannot be used by default as public keys cannot be found for all recipients."), 'horde.warning'); $encrypt_options = $default_encrypt == IMP_Crypt_Pgp::ENCRYPT ? IMP::ENCRYPT_NONE : IMP_Crypt_Pgp::SIGN; } } } } /* Define some variables used in the javascript code. */ $js_vars = array('ImpComposeBase.editor_on' => $rtemode, 'ImpCompose.auto_save' => intval($prefs->getValue('auto_save_drafts')), 'ImpCompose.cancel_url' => strval($cancel_url), 'ImpCompose.cursor_pos' => $rtemode ? null : $prefs->getValue('compose_cursor'), 'ImpCompose.discard_url' => strval($discard_url), 'ImpCompose.max_attachments' => $max_attach === true ? null : $max_attach, 'ImpCompose.popup' => intval($isPopup), 'ImpCompose.redirect' => intval($redirect), 'ImpCompose.reloaded' => intval($reload), 'ImpCompose.sm_check' => intval(!$prefs->isLocked(IMP_Mailbox::MBOX_SENT)), 'ImpCompose.spellcheck' => intval($spellcheck && $prefs->getValue('compose_spellcheck')), 'ImpCompose.text' => array('cancel' => _("Cancelling this message will permanently discard its contents.") . "\n" . _("Are you sure you want to do this?"), 'change_identity' => _("You have edited your signature. Change the identity and lose your changes?"), 'discard' => _("Doing so will discard this message permanently."), 'file' => _("File"), 'nosubject' => _("The message does not have a Subject entered.") . "\n" . _("Send message without a Subject?"), 'recipient' => _("You must specify a recipient."))); /* Set up the base view now. */ $view = $injector->createInstance('Horde_View'); $view->addHelper('FormTag'); $view->addHelper('Horde_Core_View_Helper_Accesskey'); $view->addHelper('Horde_Core_View_Helper_Help'); $view->addHelper('Horde_Core_View_Helper_Image'); $view->addHelper('Horde_Core_View_Helper_Label'); $view->addHelper('Tag'); $view->allow_compose = !$compose_disable; $view->post_action = self::url(); $blank_url = new Horde_Url('#'); if ($redirect) { /* Prepare the redirect template. */ $view->cacheid = $composeCacheID; $view->title = $this->title; $view->token = $session->getToken(); if ($registry->hasMethod('contacts/search')) { $view->abook = $blank_url->copy()->link(array('class' => 'widget', 'id' => 'redirect_abook', 'title' => _("Address Book"))); $js_vars['ImpCompose.redirect_contacts'] = strval(IMP_Basic_Contacts::url()->add(array('to_only' => 1))->setRaw(true)); } $view->input_value = $header['to']; $this->output = $view->render('basic/compose/redirect'); } else { /* Prepare the compose template. */ $view->file_upload = $attach_upload; $hidden = array('actionID' => '', 'attachmentAction' => '', 'compose_formToken' => $session->getNonce(), 'compose_requestToken' => $session->getToken(), 'composeCache' => $composeCacheID, 'composeHmac' => $imp_compose->getHmac(), 'oldrtemode' => $rtemode, 'rtemode' => $rtemode, 'user' => $registry->getAuth()); if ($attach_upload) { $hidden['MAX_FILE_SIZE'] = $session->get('imp', 'file_upload'); } foreach (array('page', 'start', 'popup', 'template_mode') as $val) { $hidden[$val] = $this->vars->{$val}; } $view->hidden = $hidden; $view->tabindex = 1; $view->title = $this->title; if (!$this->vars->template_mode) { $view->send_msg = true; $view->save_draft = $imp_imap->access(IMP_Imap::ACCESS_DRAFTS) && !$readonly_drafts; } $view->resume = $resume; $view->di_locked = $prefs->isLocked('default_identity'); if ($view->di_locked) { $view->fromaddr_locked = $prefs->isLocked('from_addr'); try { $view->from = $identity->getFromLine(null, $this->vars->from); } catch (Horde_Exception $e) { } } else { $select_list = $identity->getSelectList(); $view->last_identity = $identity->getDefault(); if (count($select_list) > 1) { $view->count_select_list = true; $t_select_list = array(); foreach ($select_list as $key => $select) { $t_select_list[] = array('label' => $select, 'selected' => $key == $identity->getDefault(), 'value' => $key); } $view->select_list = $t_select_list; } else { $view->identity_default = $identity->getDefault(); $view->identity_text = $select_list[0]; } } $view->signature = $identity->hasSignature(true); $addr_array = array('to' => _("_To"), 'cc' => _("_Cc"), 'bcc' => _("_Bcc")); $address_array = array(); foreach ($addr_array as $val => $label) { $address_array[] = array('id' => $val, 'label' => $label, 'val' => $header[$val]); } $view->addr = $address_array; $view->subject = $header['subject']; if ($prefs->getValue('set_priority')) { $view->set_priority = true; $priorities = array('high' => _("High"), 'normal' => _("Normal"), 'low' => _("Low")); $priority_option = array(); foreach ($priorities as $key => $val) { $priority_option[] = array('label' => $val, 'selected' => $priority == $key, 'val' => $key); } $view->pri_opt = $priority_option; } $compose_options = array(); if ($registry->hasMethod('contacts/search')) { $compose_options[] = array('url' => $blank_url->copy()->link(array('class' => 'widget', 'id' => 'addressbook_popup')), 'img' => Horde_Themes_Image::tag('addressbook_browse.png'), 'label' => _("Address Book")); $js_vars['ImpCompose.contacts_url'] = strval(IMP_Basic_Contacts::url()->setRaw(true)); } if ($spellcheck) { $compose_options[] = array('url' => $blank_url->copy()->link(array('class' => 'widget', 'id' => 'spellcheck')), 'img' => '', 'label' => ''); } if ($attach_upload) { $url = new Horde_Url('#attachments'); $compose_options[] = array('url' => $url->link(array('class' => 'widget')), 'img' => Horde_Themes_Image::tag('attachment.png'), 'label' => _("Attachments")); } $view->compose_options = $compose_options; if ($imp_imap->access(IMP_Imap::ACCESS_FOLDERS) && !$prefs->isLocked('save_sent_mail')) { $view->ssm = true; if ($readonly_sentmail) { $notification->push(sprintf(_("Cannot save sent-mail message to \"%s\" as that mailbox is read-only.", $sent_mail->display), 'horde.warning')); } $view->ssm_selected = $reload ? $save_sent_mail : $sent_mail && $identity->saveSentmail(); if ($this->vars->sent_mail) { $sent_mail = IMP_Mailbox::formFrom($this->vars->sent_mail); } if (!$prefs->isLocked(IMP_Mailbox::MBOX_SENT)) { $iterator = new IMP_Ftree_IteratorFilter($injector->getInstance('IMP_Ftree')); $iterator->add($iterator::NONIMAP); $iterator->mboxes = array('INBOX'); $ssm_options = array('abbrev' => false, 'basename' => true, 'iterator' => $iterator, 'selected' => $sent_mail); /* Check to make sure the sent-mail mailbox is created - * it needs to exist to show up in drop-down list. */ if ($sent_mail) { $sent_mail->create(); } $view->ssm_mboxes = new IMP_Ftree_Select($ssm_options); } else { if ($sent_mail) { $sent_mail = '"' . $sent_mail->display_html . '"'; } $view->ssm_mbox = $sent_mail; } } $view->rrr_selected = $prefs->isLocked('request_mdn') ? null : $prefs->getValue('request_mdn') == 'always' || $request_read_receipt; if (!is_null($rtemode) && !$prefs->isLocked('compose_html')) { $view->compose_html = true; $view->html_switch = $blank_url->copy()->link(array('id' => 'rte_toggle', 'title' => _("Switch Composition Method"))); $view->rtemode = $rtemode; } if (isset($replyauto_all)) { $view->replyauto_all = $replyauto_all; } elseif (isset($replyauto_list)) { $view->replyauto_list = true; if (isset($replyauto_list_id)) { $view->replyauto_list_id = $replyauto_list_id; } } if (isset($reply_lang)) { $view->reply_lang = implode(',', $reply_lang); } $view->message = $msg; if ($signatureChanged) { $view->signatureContent = $signature; } if ($prefs->getValue('use_pgp') || $prefs->getValue('use_smime')) { if ($prefs->isLocked('default_encrypt')) { $view->use_encrypt = false; } else { $view->use_encrypt = true; $view->encrypt_options = $imp_ui->encryptList($encrypt_options); } if ($prefs->getValue('use_pgp') && $prefs->getValue('pgp_public_key')) { $view->pgp_options = true; $view->pgp_attach_pubkey = $reload ? $this->vars->pgp_attach_pubkey : $prefs->getValue('pgp_attach_pubkey'); } } if ($registry->hasMethod('contacts/ownVCard')) { $view->vcard = true; $view->attach_vcard = $this->vars->vcard; } if ($attach_upload) { $view->attach_size = IMP::numberFormat($imp_compose->maxAttachmentSize(), 0); $view->maxattachmentnumber = !$max_attach; $save_attach = $prefs->getValue('save_attachments'); if ($view->ssm && !$prefs->isLocked('save_attachments')) { $view->show_link_save_attach = true; $view->attach_options = array(array('label' => _("Save attachments with message in sent-mail mailbox?"), 'name' => 'save_attachments_select', 'val' => $reload ? $this->vars->save_attachments_select : $save_attach == 'always')); } if (count($imp_compose)) { $view->numberattach = true; $atc = array(); $v = $injector->getInstance('IMP_Factory_MimeViewer'); foreach ($imp_compose as $data) { $mime = $data->getPart(); $type = $mime->getType(); $entry = array('name' => $mime->getName(true), 'icon' => $v->getIcon($type), 'number' => $data->id, 'type' => $type, 'size' => $mime->getSize(), 'description' => $mime->getDescription(true)); if (!(isset($fwd_msg) && $fwd_msg['type'] != IMP_Compose::FORWARD_BODY) && $type != 'application/octet-stream') { $entry['name'] = $data->viewUrl()->link(array('class' => 'link', 'target' => 'compose_preview_window', 'title' => _("Preview"))) . htmlspecialchars($entry['name']) . '</a>'; } $atc[] = $entry; } $view->atc = $atc; } } $this->output = $view->render('basic/compose/compose'); } $page_output->addScriptPackage('IMP_Script_Package_ComposeBase'); $page_output->addScriptFile('compose.js'); $page_output->addScriptFile('editor.js'); $page_output->addScriptFile('imp.js'); $page_output->addInlineJsVars($js_vars); if (!$redirect) { $imp_ui->addIdentityJs(); } if ($rtemode && !$redirect) { $page_output->addScriptPackage('IMP_Script_Package_Editor'); } }