getPref() публичный статический Метод

Shortcut to obtaining a mailbox object from a preference name.
public static getPref ( $pref ) : IMP_Mailbox
Результат IMP_Mailbox The IMP_Mailbox object.
Пример #1
0
 /**
  * Update special mailbox preferences.
  *
  * @param string $pref             The pref name to update.
  * @param IMP_Mailbox $form        The form data.
  * @param string $new              The new mailbox name.
  * @param string $type             Special use attribute (RFC 6154).
  * @param Horde_Core_Prefs_Ui $ui  The UI object.
  *
  * @return boolean  True if preferences were updated.
  */
 protected function _updateSpecialMboxes($pref, $form, $new, $type, Horde_Core_Prefs_Ui $ui)
 {
     global $injector, $prefs;
     $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();
     if (!$imp_imap->access(IMP_Imap::ACCESS_FOLDERS) || $prefs->isLocked($pref)) {
         return false;
     }
     $cache = $injector->getInstance('IMP_Mailbox_SessionCache');
     if ($mbox_ob = IMP_Mailbox::getPref($pref)) {
         $cache->expire(array(IMP_Mailbox_SessionCache::CACHE_DISPLAY, IMP_Mailbox_SessionCache::CACHE_LABEL, IMP_Mailbox_SessionCache::CACHE_SPECIALMBOXES), $mbox_ob);
     }
     if ($form == self::PREF_NO_MBOX) {
         return $prefs->setValue($pref, '');
     }
     if (strpos($form, self::PREF_SPECIALUSE) === 0) {
         $mbox = IMP_Mailbox::get(substr($form, strlen(self::PREF_SPECIALUSE)));
     } elseif (!empty($new)) {
         $mbox = IMP_Mailbox::get($new)->namespace_append;
         $opts = is_null($type) ? array() : array('special_use' => array($type));
         if (!$mbox->create($opts)) {
             $mbox = null;
         }
     } else {
         $mbox = $form;
     }
     if (!$mbox) {
         return false;
     }
     $cache->expire(array(IMP_Mailbox_SessionCache::CACHE_DISPLAY, IMP_Mailbox_SessionCache::CACHE_LABEL), $mbox);
     return $prefs->setValue($pref, $mbox->pref_to);
 }
Пример #2
0
 /**
  */
 public function display(Horde_Core_Prefs_Ui $ui)
 {
     global $injector, $page_output;
     $page_output->addScriptFile('prefs/folder.js');
     $page_output->addInlineJsVars(array('ImpFolderPrefs.mboxes.drafts' => _("Enter the name for your new drafts mailbox.")));
     $view = new Horde_View(array('templatePath' => IMP_TEMPLATES . '/prefs'));
     $view->addHelper('Horde_Core_View_Helper_Label');
     $iterator = new IMP_Ftree_IteratorFilter($injector->getInstance('IMP_Ftree'));
     $iterator->add(array($iterator::NONIMAP, $iterator::REMOTE));
     $iterator->mboxes = array('INBOX');
     $view->flist = new IMP_Ftree_Select(array('basename' => true, 'iterator' => $iterator, 'new_mbox' => true, 'selected' => IMP_Mailbox::getPref(IMP_Mailbox::MBOX_DRAFTS)));
     $view->nombox = IMP_Mailbox::formTo(self::PREF_NO_MBOX);
     $view->special_use = $this->_getSpecialUse(Horde_Imap_Client::SPECIALUSE_DRAFTS);
     return $view->render('drafts');
 }
Пример #3
0
 /**
  */
 public function display(Horde_Core_Prefs_Ui $ui)
 {
     global $injector, $page_output, $prefs;
     if ($prefs->isLocked(IMP_Mailbox::MBOX_TEMPLATES)) {
         return '';
     }
     $page_output->addScriptFile('prefs/folder.js');
     $page_output->addInlineJsVars(array('ImpFolderPrefs.mboxes.templates' => _("Enter the name for your new compose templates mailbox.")));
     $view = new Horde_View(array('templatePath' => IMP_TEMPLATES . '/prefs'));
     $view->addHelper('Horde_Core_View_Helper_Label');
     $iterator = new IMP_Ftree_IteratorFilter($injector->getInstance('IMP_Ftree'));
     $iterator->add(array($iterator::NONIMAP, $iterator::REMOTE));
     $iterator->mboxes = array('INBOX');
     $view->mbox_flist = new IMP_Ftree_Select(array('iterator' => $iterator, 'new_mbox' => true, 'selected' => IMP_Mailbox::getPref(IMP_Mailbox::MBOX_TEMPLATES)));
     $view->mbox_nomailbox = IMP_Mailbox::formTo(self::PREF_NO_MBOX);
     return $view->render('composetemplates');
 }
Пример #4
0
 /**
  */
 public function update(Horde_Core_Prefs_Ui $ui)
 {
     global $injector, $prefs;
     $imp_search = $injector->getInstance('IMP_Search');
     $curr_vtrash = IMP_Mailbox::getPref(IMP_Mailbox::MBOX_TRASH)->vtrash;
     $trash = IMP_Mailbox::formFrom($ui->vars->trash);
     if (!$prefs->isLocked('vfolder')) {
         $vtrash = $imp_search['vtrash'];
         $vtrash->enabled = $trash->vtrash;
         $imp_search['vtrash'] = $vtrash;
     }
     if (!$this->_updateSpecialMboxes(IMP_Mailbox::MBOX_TRASH, $trash, $ui->vars->trash_new, Horde_Imap_Client::SPECIALUSE_TRASH, $ui)) {
         return false;
     }
     $injector->getInstance('IMP_Factory_Imap')->create()->updateFetchIgnore();
     /* Switching to/from Virtual Trash requires us to expire all currently
      * cached mailbox lists (hide deleted status may have changed). */
     if ($curr_vtrash || $trash->vtrash) {
         $injector->getInstance('IMP_Factory_MailboxList')->expireAll();
     }
     return true;
 }
Пример #5
0
 /**
  * URL Parameters:
  *   - a: (string) The action ID.
  *   - action: (string) The action ID (used on redirect page).
  *   - bcc: (string) BCC address(es).
  *   - bcc_expand_[1-5]: (string) Expand matches for BCC addresses.
  *   - cc: (string) CC address(es).
  *   - cc_expand_[1-5]: (string) Expand matches for BCC addresses.
  *   - composeCache: (string) Compose object cache ID.
  *   - from: (string) From address to use.
  *   - identity: (integer) The identity to use for composing.
  *   - message: (string) Message text.
  *   - subject: (string) Message subject.
  *   - to: (string) To address(es).
  *   - to_expand_[1-5]: (string) Expand matches for To addresses.
  *   - u: (string) Unique ID (cache buster).
  */
 protected function _init()
 {
     global $injector, $notification, $prefs, $registry;
     /* The message text and headers. */
     $expand = array();
     $header = array('to' => '', 'cc' => '', 'bcc' => '');
     $msg = '';
     $this->title = _("Compose Message");
     /* Get the list of headers to display. */
     $display_hdrs = array('to' => _("To: "), 'cc' => _("Cc: "), 'bcc' => "Bcc: ");
     /* Set the current identity. */
     $identity = $injector->getInstance('IMP_Identity');
     if (!$prefs->isLocked('default_identity') && isset($this->vars->identity)) {
         $identity->setDefault($this->vars->identity);
     }
     /* Determine if mailboxes are readonly. */
     $drafts = IMP_Mailbox::getPref(IMP_Mailbox::MBOX_DRAFTS);
     $readonly_drafts = $drafts && $drafts->readonly;
     $sent_mail = $identity->getValue(IMP_Mailbox::MBOX_SENT);
     $save_sent_mail = !$sent_mail || $sent_mail->readonly ? false : $prefs->getValue('save_sent_mail');
     /* Determine if compose mode is disabled. */
     $compose_disable = !IMP_Compose::canCompose();
     /* Initialize objects. */
     $imp_compose = $injector->getInstance('IMP_Factory_Compose')->create($this->vars->composeCache);
     /* Are attachments allowed? */
     $attach_upload = $imp_compose->canUploadAttachment();
     foreach (array_keys($display_hdrs) as $val) {
         $header[$val] = $this->vars->{$val};
         /* If we are reloading the screen, check for expand matches. */
         if ($this->vars->composeCache) {
             $expanded = array();
             for ($i = 0; $i < 5; ++$i) {
                 if ($tmp = $this->vars->get($val . '_expand_' . $i)) {
                     $expanded[] = $tmp;
                 }
             }
             if (!empty($expanded)) {
                 $header['to'] = strlen($header['to']) ? implode(', ', $expanded) . ', ' . $header['to'] : implode(', ', $expanded);
             }
         }
     }
     /* Add attachment. */
     if ($attach_upload && isset($_FILES['upload_1']) && strlen($_FILES['upload_1']['name'])) {
         try {
             $atc_ob = $imp_compose->addAttachmentFromUpload('upload_1');
             if ($atc_ob[0] instanceof IMP_Compose_Exception) {
                 throw $atc_ob[0];
             }
             if ($this->vars->a == _("Expand Names")) {
                 $notification->push(sprintf(_("Added \"%s\" as an attachment."), $atc_ob[0]->getPart()->getName()), 'horde.success');
             }
         } catch (IMP_Compose_Exception $e) {
             $this->vars->a = null;
             $notification->push($e, 'horde.error');
         }
     }
     /* Run through the action handlers. */
     switch ($this->vars->a) {
         // 'd' = draft
         // 'en' = edit as new
         // 't' = template
         case 'd':
         case 'en':
         case 't':
             try {
                 switch ($this->vars->a) {
                     case 'd':
                         $result = $imp_compose->resumeDraft($this->indices, array('format' => 'text'));
                         $this->view->resume = true;
                         break;
                     case 'en':
                         $result = $imp_compose->editAsNew($this->indices, array('format' => 'text'));
                         break;
                     case 't':
                         $result = $imp_compose->useTemplate($this->indices, array('format' => 'text'));
                         break;
                 }
                 $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);
                 }
             } catch (IMP_Compose_Exception $e) {
                 $notification->push($e);
             }
             break;
         case _("Expand Names"):
             foreach (array_keys($display_hdrs) as $val) {
                 if ($val == 'to' || $this->vars->action != 'rc') {
                     $res = $this->_expandAddresses($header[$val]);
                     if (is_string($res)) {
                         $header[$val] = $res;
                     } else {
                         $header[$val] = $res[0];
                         $expand[$val] = array_slice($res, 1);
                     }
                 }
             }
             if (isset($this->vars->action)) {
                 $this->vars->a = $this->vars->action;
             }
             break;
             // 'r' = reply
             // 'rl' = reply to list
             // 'ra' = reply to all
         // 'r' = reply
         // 'rl' = reply to list
         // 'ra' = reply to all
         case 'r':
         case 'ra':
         case 'rl':
             $actions = array('r' => IMP_Compose::REPLY_SENDER, 'ra' => IMP_Compose::REPLY_ALL, 'rl' => IMP_Compose::REPLY_LIST);
             try {
                 $reply_msg = $imp_compose->replyMessage($actions[$this->vars->a], $this->_getContents(), array('format' => 'text', 'to' => $header['to']));
             } catch (IMP_Exception $e) {
                 $notification->push($e, 'horde.error');
                 break;
             }
             $header = $this->_convertToHeader($reply_msg);
             $notification->push(_("Reply text will be automatically appended to your outgoing message."), 'horde.message');
             $this->title = _("Reply");
             break;
             // 'f' = forward
         // 'f' = forward
         case 'f':
             try {
                 $fwd_msg = $imp_compose->forwardMessage(IMP_Compose::FORWARD_ATTACH, $this->_getContents(), false);
             } catch (IMP_Exception $e) {
                 $notification->push($e, 'horde.error');
                 break;
             }
             $header = $this->_convertToHeader($fwd_msg);
             $notification->push(_("Forwarded message will be automatically added to your outgoing message."), 'horde.message');
             $this->title = _("Forward");
             break;
             // 'rc' = redirect compose
         // 'rc' = redirect compose
         case 'rc':
             $imp_compose->redirectMessage($this->indices);
             $this->title = _("Redirect");
             break;
         case _("Redirect"):
             try {
                 $num_msgs = $imp_compose->sendRedirectMessage($header['to']);
                 $imp_compose->destroy('send');
                 $notification->push(ngettext("Message redirected successfully.", "Messages redirected successfully.", count($num_msgs)), 'horde.success');
                 IMP_Minimal_Mailbox::url(array('mailbox' => $this->indices->mailbox))->redirect();
             } catch (Horde_Exception $e) {
                 $this->vars->a = 'rc';
                 $notification->push($e);
             }
             break;
         case _("Save Draft"):
         case _("Send"):
             switch ($this->vars->a) {
                 case _("Save Draft"):
                     if ($readonly_drafts) {
                         break 2;
                     }
                     break;
                 case _("Send"):
                     if ($compose_disable) {
                         break 2;
                     }
                     break;
             }
             $message = strval($this->vars->message);
             $f_to = $header['to'];
             $old_header = $header;
             $header = array();
             switch ($imp_compose->replyType(true)) {
                 case IMP_Compose::REPLY:
                     try {
                         $reply_msg = $imp_compose->replyMessage(IMP_Compose::REPLY_SENDER, $imp_compose->getContentsOb(), array('to' => $f_to));
                         $msg = $reply_msg['body'];
                     } catch (IMP_Exception $e) {
                         $notification->push($e, 'horde.error');
                         $msg = '';
                     }
                     $message .= "\n" . $msg;
                     break;
                 case IMP_Compose::FORWARD:
                     try {
                         $fwd_msg = $imp_compose->forwardMessage(IMP_Compose::FORWARD_ATTACH, $imp_compose->getContentsOb());
                         $msg = $fwd_msg['body'];
                     } catch (IMP_Exception $e) {
                         $notification->push($e, 'horde.error');
                     }
                     $message .= "\n" . $msg;
                     break;
             }
             try {
                 $header['from'] = strval($identity->getFromLine(null, $this->vars->from));
             } catch (Horde_Exception $e) {
                 $header['from'] = '';
             }
             $header['replyto'] = $identity->getValue('replyto_addr');
             $header['subject'] = strval($this->vars->subject);
             foreach (array_keys($display_hdrs) as $val) {
                 $header[$val] = $old_header[$val];
             }
             switch ($this->vars->a) {
                 case _("Save Draft"):
                     try {
                         $notification->push($imp_compose->saveDraft($header, $message), 'horde.success');
                         if ($prefs->getValue('close_draft')) {
                             $imp_compose->destroy('save_draft');
                             IMP_Minimal_Mailbox::url(array('mailbox' => $this->indices->mailbox))->redirect();
                         }
                     } catch (IMP_Compose_Exception $e) {
                         $notification->push($e);
                     }
                     break;
                 case _("Send"):
                     try {
                         $imp_compose->buildAndSendMessage($message, $header, $identity, array('readreceipt' => $prefs->getValue('request_mdn') == 'always', 'save_sent' => $save_sent_mail, 'sent_mail' => $sent_mail));
                         $imp_compose->destroy('send');
                         $notification->push(_("Message sent successfully."), 'horde.success');
                         IMP_Minimal_Mailbox::url(array('mailbox' => $this->indices->mailbox))->redirect();
                     } catch (IMP_Compose_Exception $e) {
                         $notification->push($e);
                         /* 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."));
                         }
                     }
                     break;
             }
             break;
         case _("Cancel"):
             $imp_compose->destroy('cancel');
             IMP_Minimal_Mailbox::url(array('mailbox' => $this->indices->mailbox))->redirect();
             exit;
         case _("Discard Draft"):
             $imp_compose->destroy('discard');
             IMP_Minimal_Mailbox::url(array('mailbox' => $this->indices->mailbox))->redirect();
             exit;
     }
     /* Grab any data that we were supplied with. */
     if (empty($msg)) {
         $msg = strval($this->vars->message);
     }
     if (empty($header['subject'])) {
         $header['subject'] = strval($this->vars->subject);
     }
     $this->view->cacheid = $imp_compose->getCacheId();
     $this->view->hmac = $imp_compose->getHmac();
     $this->view->menu = $this->getMenu('compose');
     $this->view->url = self::url();
     $this->view->user = $registry->getAuth();
     switch ($this->vars->a) {
         case 'rc':
             $this->_pages[] = 'redirect';
             $this->_pages[] = 'menu';
             unset($display_hdrs['cc'], $display_hdrs['bcc']);
             break;
         default:
             $this->_pages[] = 'compose';
             $this->_pages[] = 'menu';
             $this->view->compose_enable = !$compose_disable;
             $this->view->msg = $msg;
             $this->view->save_draft = $injector->getInstance('IMP_Factory_Imap')->create()->access(IMP_Imap::ACCESS_DRAFTS) && !$readonly_drafts;
             $this->view->subject = $header['subject'];
             $select_list = $identity->getSelectList();
             $default_identity = $identity->getDefault();
             if ($prefs->isLocked('default_identity')) {
                 $select_list = array($default_identity => $select_list[$default_identity]);
             }
             $tmp = array();
             foreach ($select_list as $key => $val) {
                 $tmp[] = array('key' => $key, 'sel' => $key == $default_identity, 'val' => $val);
             }
             $this->view->identities = $tmp;
             if ($attach_upload) {
                 $this->view->attach = true;
                 if (count($imp_compose)) {
                     $atc_part = $imp_compose[0]->getPart();
                     $this->view->attach_name = $atc_part->getName();
                     $this->view->attach_size = IMP::sizeFormat($atc_part->getBytes());
                     $this->view->attach_type = $atc_part->getType();
                 }
             }
             $this->title = _("Message Composition");
     }
     $hdrs = array();
     foreach ($display_hdrs as $key => $val) {
         $tmp = array('key' => $key, 'label' => $val, 'val' => $header[$key]);
         if (isset($expand[$key])) {
             $tmp['matchlabel'] = count($expand[$key][1]) > 5 ? sprintf(_("Ambiguous matches for \"%s\" (first 5 matches displayed):"), $expand[$key][0]) : sprintf(_("Ambiguous matches for \"%s\":"), $expand[$key][0]);
             $tmp['match'] = array();
             foreach ($expand[$key][1] as $key2 => $val2) {
                 if ($key2 == 5) {
                     break;
                 }
                 $tmp['match'][] = array('id' => $key . '_expand_' . $key2, 'val' => $val2);
             }
         }
         $hdrs[] = $tmp;
     }
     $this->view->hdrs = $hdrs;
     $this->view->title = $this->title;
 }
Пример #6
0
 /**
  * Empties the entire mailbox.
  */
 public function emptyMailbox()
 {
     global $notification, $prefs;
     if (!$this->access_empty) {
         $notification->push(sprintf(_("Could not delete messages from %s. This mailbox is read-only."), $this->display), 'horde.error');
         return;
     }
     if ($this->vtrash) {
         foreach (IMP_Mailbox::get($this->getSearchOb()->mboxes) as $val) {
             $val->expunge();
         }
         $notification->push(_("Emptied all messages from Virtual Trash Folder."), 'horde.success');
         return;
     }
     /* Make sure there is at least 1 message before attempting to
      * delete. */
     try {
         $imp_imap = $this->imp_imap;
         $status = $imp_imap->status($this, Horde_Imap_Client::STATUS_MESSAGES);
         if (empty($status['messages'])) {
             $notification->push(sprintf(_("The mailbox %s is already empty."), $this->display), 'horde.message');
             return;
         }
         $trash = $prefs->getValue('use_trash') ? IMP_Mailbox::getPref(IMP_Mailbox::MBOX_TRASH) : null;
         if (!$trash || $trash == $this) {
             $imp_imap->store($this, array('add' => array(Horde_Imap_Client::FLAG_DELETED)));
             $this->expunge();
         } else {
             $ret = $imp_imap->search($this);
             $this->getIndicesOb($ret['match'])->delete();
         }
         $notification->push(sprintf(_("Emptied all messages from %s."), $this->display), 'horde.success');
     } catch (IMP_Imap_Exception $e) {
     }
 }
Пример #7
0
 /**
  * Return the list of special mailboxes.
  *
  * @return array  A list of mailboxes, with the SPECIAL_* constants
  *                as keys and values containing the IMP_Mailbox objects or
  *                null if the mailbox doesn't exist (SPECIAL_SENT
  *                contains an array of objects).
  */
 public function getSpecialMailboxes()
 {
     global $injector, $prefs;
     if (!isset($this->_temp[self::CACHE_SPECIALMBOXES])) {
         $sm = array(IMP_Mailbox::SPECIAL_COMPOSETEMPLATES => IMP_Mailbox::getPref(IMP_Mailbox::MBOX_TEMPLATES), IMP_Mailbox::SPECIAL_DRAFTS => IMP_Mailbox::getPref(IMP_Mailbox::MBOX_DRAFTS), IMP_Mailbox::SPECIAL_SENT => $injector->getInstance('IMP_Identity')->getAllSentmail(), IMP_Mailbox::SPECIAL_SPAM => IMP_Mailbox::getPref(IMP_Mailbox::MBOX_SPAM), IMP_Mailbox::SPECIAL_TRASH => $prefs->getValue('use_trash') ? IMP_Mailbox::getPref(IMP_Mailbox::MBOX_TRASH) : null, IMP_Mailbox::SPECIAL_USER => array());
         foreach ($injector->getInstance('IMP_Factory_Imap')->create()->config->user_special_mboxes as $key => $val) {
             $ob = IMP_Mailbox::get($key);
             $ob->display = $val;
             $sm[IMP_Mailbox::SPECIAL_USER][strval($key)] = $ob;
         }
         $this->_temp[self::CACHE_SPECIALMBOXES] = $sm;
     }
     return $this->_temp[self::CACHE_SPECIALMBOXES];
 }
Пример #8
0
 /**
  * Return the spam mailbox.
  *
  * @return IMP_Mailbox  The spam mailbox, if it exists. Otherwise, false.
  */
 protected function _spamMbox()
 {
     return ($spam = IMP_Mailbox::getPref(IMP_Mailbox::MBOX_SPAM)) && $spam->exists ? $spam : false;
 }
Пример #9
0
 /**
  */
 protected function _initPages()
 {
     global $injector, $registry, $session;
     $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();
     $this->view->allowFolders = $imp_imap->access(IMP_Imap::ACCESS_FOLDERS);
     $this->view->canInnocent = !empty($imp_imap->config->innocent_params);
     $this->view->canSearch = $imp_imap->access(IMP_Imap::ACCESS_SEARCH);
     $this->view->canSpam = !empty($imp_imap->config->spam_params);
     if ($this->view->canCompose = IMP_Compose::canCompose()) {
         /* Setting up identities. */
         $identity = $injector->getInstance('IMP_Identity');
         $this->view->identities = array();
         foreach ($identity->getSelectList() as $id => $from) {
             $this->view->identities[] = array('label' => $from, 'sel' => $id == $identity->getDefault(), 'val' => $id);
         }
         $this->view->user = $registry->getAuth();
         $this->view->draft = $imp_imap->access(IMP_Imap::ACCESS_DRAFTS) && ($draft = IMP_Mailbox::getPref(IMP_Mailbox::MBOX_DRAFTS)) && !$draft->readonly;
         if (IMP_Compose::canUploadAttachment()) {
             $this->view->attach = true;
             $this->view->max_size = $session->get('imp', 'file_upload');
         }
     }
 }
Пример #10
0
 /**
  * As of IMP 6, special mailboxes are stored in UTF-8, not UTF7-IMAP.
  */
 protected function _upgradeMailboxPrefs()
 {
     global $injector, $prefs;
     $special_mboxes = array('drafts_folder', 'spam_folder', 'trash_folder');
     foreach ($special_mboxes as $val) {
         if (!$prefs->isDefault($val)) {
             $old_pref = strval(IMP_Mailbox::getPref($val));
             if (!Horde_Mime::is8bit($old_pref)) {
                 $mbox = IMP_Mailbox::get(new Horde_Imap_Client_Mailbox($old_pref, true));
                 $prefs->setValue($val, $mbox->pref_to);
             }
         }
     }
     $imp_identity = $injector->getInstance('IMP_Identity');
     foreach ($imp_identity->getAll('sent_mail_folder') as $key => $val) {
         if (!is_null($val) && !Horde_Mime::is8bit($val)) {
             $mbox = IMP_Mailbox::get(new Horde_Imap_Client_Mailbox($val, true));
             $imp_identity->setValue(IMP_Mailbox::MBOX_SENT, $mbox, $key);
         }
     }
 }
Пример #11
0
 /**
  * As of IMP 6, special mailboxes are stored in UTF-8, not UTF7-IMAP.
  */
 protected function _upgradeMailboxPrefs()
 {
     global $injector, $prefs;
     $special_mboxes = array('drafts_folder', 'spam_folder', 'trash_folder');
     foreach ($special_mboxes as $val) {
         if (!$prefs->isDefault($val)) {
             $old_pref = strval(IMP_Mailbox::getPref($val));
             if (!Horde_Mime::is8bit($old_pref, 'UTF-8')) {
                 $mbox = IMP_Mailbox::get(Horde_String::convertCharset($old_pref, 'UTF7-IMAP', 'UTF-8'));
                 $prefs->setValue($val, $old_pref->{$mbox}->pref_to);
             }
         }
     }
     $imp_identity = $injector->getInstance('IMP_Identity');
     foreach ($imp_identity->getAll('sent_mail_folder') as $key => $val) {
         if (!is_null($val) && !Horde_Mime::is8bit($val, 'UTF-8')) {
             $mbox = IMP_Mailbox::get(Horde_String::convertCharset(strval($val), 'UTF7-IMAP', 'UTF-8'));
             $imp_identity->setValue(IMP_Mailbox::MBOX_SENT, $mbox, $key);
         }
     }
 }
Пример #12
0
 /**
  * Save a template message on the IMAP server.
  *
  * @param array $headers  List of message headers (UTF-8).
  * @param mixed $message  Either the message text (string) or a
  *                        Horde_Mime_Part object that contains the text
  *                        to save.
  * @param array $opts     An array of options w/the following keys:
  *   - html: (boolean) Is this an HTML message?
  *   - priority: (string) The message priority ('high', 'normal', 'low').
  *   - readreceipt: (boolean) Add return receipt headers?
  *
  * @return string  Notification text on success.
  *
  * @throws IMP_Compose_Exception
  */
 public function saveTemplate($headers, $message, array $opts = array())
 {
     if (!($mbox = IMP_Mailbox::getPref(IMP_Mailbox::MBOX_TEMPLATES))) {
         throw new IMP_Compose_Exception(_("Saving the template failed: no template mailbox exists."));
     }
     /* Check for access to mailbox. */
     if (!$mbox->create()) {
         throw new IMP_Compose_Exception(_("Saving the template failed: could not create the templates mailbox."));
     }
     $append_flags = array(Horde_Imap_Client::FLAG_SEEN);
     $old_uid = $this->getMetadata('template_uid_edit');
     /* Add the message to the mailbox. */
     try {
         $mbox->imp_imap->append($mbox, array(array('data' => $this->_saveDraftMsg($headers, $message, $opts), 'flags' => $append_flags, 'verify_email' => true)));
         if ($old_uid) {
             $old_uid->delete(array('nuke' => true));
         }
     } catch (IMP_Imap_Exception $e) {
         return _("The template was not successfully saved.");
     }
     return _("The template has been saved.");
 }
Пример #13
0
 /**
  */
 public function menu($menu)
 {
     global $injector, $prefs, $registry, $session;
     $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();
     if ($imp_imap->access(IMP_Imap::ACCESS_TRASH) && $prefs->getValue('use_trash') && $prefs->getValue('empty_trash_menu') && ($trash = IMP_Mailbox::getPref(IMP_Mailbox::MBOX_TRASH)) && ($trash->vtrash || $trash->access_expunge)) {
         $menu->addArray(array('class' => '__noselection', 'icon' => 'imp-empty-trash', 'onclick' => 'return window.confirm(' . json_encode(_("Are you sure you wish to empty your trash mailbox?")) . ')', 'text' => _("Empty _Trash"), 'url' => $trash->url('mailbox')->add(array('actionID' => 'empty_mailbox', 'token' => $session->getToken()))));
     }
     if ($imp_imap->access(IMP_Imap::ACCESS_FOLDERS) && $prefs->getValue('empty_spam_menu') && ($spam = IMP_Mailbox::getPref(IMP_Mailbox::MBOX_SPAM)) && $spam->access_expunge) {
         $menu->addArray(array('class' => '__noselection', 'icon' => 'imp-empty-spam', 'onclick' => 'return window.confirm(' . json_encode(_("Are you sure you wish to empty your spam mailbox?")) . ')', 'text' => _("Empty _Spam"), 'url' => $spam->url('mailbox')->add(array('actionID' => 'empty_mailbox', 'token' => $session->getToken()))));
     }
     if ($imp_imap->access(IMP_Imap::ACCESS_FOLDERS)) {
         $menu->addArray(array('icon' => 'imp-folder', 'text' => _("_Folders"), 'url' => IMP_Basic_Folders::url()));
     }
     if ($imp_imap->access(IMP_Imap::ACCESS_SEARCH)) {
         $menu->addArray(array('icon' => 'imp-search', 'text' => _("_Search"), 'url' => IMP_Basic_Search::url()));
     }
     if ($prefs->getValue('filter_menuitem')) {
         $menu->addArray(array('icon' => 'imp-filters', 'text' => _("Fi_lters"), 'url' => $registry->getServiceLink('prefs', 'imp')->add('group', 'filters')));
     }
 }
Пример #14
0
    $ui->prefs['reply_lang']['enum'] = $enum;
});
// The list of buttons to show in CKeditor
// See http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Toolbar for
// details on configuration
$_prefs['ckeditor_buttons'] = array('value' => "[['Bold','Italic','Underline'],['Font','FontSize'],['TextColor','BGColor'],['Cut','Copy','Paste'],['Undo','Redo'],['NumberedList','BulletedList'],['Link','Unlink'],['Image','Table','Smiley','SpecialChar']]");
$_prefs['signature_expanded'] = array('value' => 0, 'type' => 'implicit');
// *** Compose Templates Preferences ***
$prefGroups['composetemplates'] = array('column' => _("Compose"), 'label' => _("Compose Templates"), 'desc' => _("Edit compose templates."), 'members' => array('composetemplates_management', 'composetemplates_new'), 'suppress' => function () {
    return !$GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->isImap();
});
// Compose templates configuration widget
$_prefs['composetemplates_management'] = array('type' => 'special', 'handler' => 'IMP_Prefs_Special_ComposeTemplates');
// Link to compose templates mailbox.
$_prefs['composetemplates_new'] = array('type' => 'link', 'xurl' => '', 'img' => 'edit.png', 'desc' => _("Create new Template"), 'suppress' => function () {
    return !IMP_Mailbox::getPref('composetemplates_mbox');
}, 'on_init' => function ($ui) {
    $clink = new IMP_Compose_Link();
    $ui->prefs['composetemplates_new']['xurl'] = $clink->link()->add(array('actionID' => 'template_new', 'type' => 'template_new'));
});
// Compose templates mailbox
$_prefs['composetemplates_mbox'] = array('value' => 'Templates');
// *** Compose Reply Preferences ***
$prefGroups['reply'] = array('column' => _("Compose"), 'label' => _("Replies"), 'desc' => _("Configure how you reply to mail."), 'members' => array('reply_format', 'reply_charset', 'reply_headers', 'reply_quote', 'attrib_text', 'reply_strip_sig'));
$_prefs['reply_format'] = array('value' => 0, 'type' => 'checkbox', 'desc' => _("When replying, use the same format as the original message?"));
$_prefs['reply_charset'] = array('desc' => _("Use the charset of the original message when replying?"), 'advanced' => true, 'value' => 0, 'type' => 'checkbox');
$_prefs['reply_headers'] = array('desc' => _("Include a brief summary of the original message's header in a reply?"), 'value' => 0, 'type' => 'checkbox');
$_prefs['reply_quote'] = array('value' => 1, 'advanced' => true, 'type' => 'checkbox', 'desc' => _("Include original message in a reply?"));
$_prefs['attrib_text'] = array('value' => _("Quoting %f:"), 'advanced' => true, 'type' => 'text', 'desc' => _("How to attribute quoted lines in a reply?"), 'help' => 'prefs-attrib_text', 'requires' => array('reply_quote'));
$_prefs['reply_strip_sig'] = array('desc' => _("Strip the sender's signature from plaintext replies?"), 'advanced' => true, 'value' => 0, 'type' => 'checkbox', 'requires' => array('reply_quote'));
// *** Compose Forward Preferences ***
Пример #15
0
 /**
  * Return information for the login task.
  *
  * @return string  Description of what the operation is going to do during
  *                 this login.
  */
 public function describe()
 {
     return sprintf(_("All messages in your \"%s\" mailbox older than %s days will be permanently deleted."), IMP_Mailbox::getPref(IMP_Mailbox::MBOX_TRASH)->display_html, $GLOBALS['prefs']->getValue('purge_trash_keep'));
 }
Пример #16
0
 /**
  * Deletes a list of messages.
  *
  * @param array $opts  Additional options:
  * <pre>
  *   - keeplog: (boolean) Should any history information of the message be
  *              kept?
  *              DEFAULT: false
  *   - nuke: (boolean) Override user preferences and nuke (i.e.
  *           permanently delete) the messages instead?
  *           DEFAULT: false
  * </pre>
  *
  * @return integer|boolean  The number of messages deleted if successful,
  *                          false if not successful.
  */
 public function delete(array $opts = array())
 {
     global $injector, $notification, $prefs;
     if (!count($this)) {
         return false;
     }
     $trash = IMP_Mailbox::getPref(IMP_Mailbox::MBOX_TRASH);
     $use_trash = $prefs->getValue('use_trash');
     if ($use_trash && !$trash) {
         $notification->push(_("Cannot move messages to Trash - no Trash mailbox set in preferences."), 'horde.error');
         return false;
     }
     $ajax_queue = $injector->getInstance('IMP_Ajax_Queue');
     $maillog = empty($opts['keeplog']) ? $injector->getInstance('IMP_Maillog') : null;
     $return_value = 0;
     /* Check for Trash mailbox. */
     $no_expunge = $use_trash_mbox = $use_vtrash = false;
     if ($use_trash && empty($opts['nuke']) && $injector->getInstance('IMP_Factory_Imap')->create()->access(IMP_Imap::ACCESS_TRASH)) {
         $use_vtrash = $trash->vtrash;
         $use_trash_mbox = !$use_vtrash;
     }
     /* Check whether we are marking messages as seen.
      * If using virtual trash, we must mark the message as seen or else it
      * will appear as an 'unseen' message for purposes of new message
      * counts. */
     $mark_seen = empty($opts['nuke']) && ($use_vtrash || $prefs->getValue('delete_mark_seen'));
     if ($use_trash_mbox && !$trash->create()) {
         /* If trash mailbox could not be created, just mark message as
          * deleted. */
         $no_expunge = true;
         $return_value = $use_trash_mbox = false;
     }
     foreach ($this as $ob) {
         try {
             if (!$ob->mbox->access_deletemsgs) {
                 throw new IMP_Exception(_("This mailbox is read-only."));
             }
             $ob->mbox->uidvalid;
         } catch (IMP_Exception $e) {
             $notification->push(sprintf(_("There was an error deleting messages from the mailbox \"%s\"."), $ob->mbox->display) . ' ' . $e->getMessage(), 'horde.error');
             $return_value = false;
             continue;
         }
         if ($return_value !== false) {
             $return_value += count($ob->uids);
         }
         $imp_imap = $ob->mbox->imp_imap;
         $ids_ob = $imp_imap->getIdsOb($ob->uids);
         /* Trash is only valid for IMAP mailboxes. */
         if ($use_trash_mbox && $ob->mbox != $trash && !$ob->mbox->remote_mbox) {
             if ($ob->mbox->access_expunge) {
                 try {
                     if ($mark_seen) {
                         $imp_imap->store($ob->mbox, array('add' => array(Horde_Imap_Client::FLAG_SEEN), 'ids' => $ids_ob));
                     }
                     $imp_imap->copy($ob->mbox, $trash, array('ids' => $ids_ob, 'move' => true));
                 } catch (IMP_Imap_Exception $e) {
                     if ($e->getCode() == $e::OVERQUOTA) {
                         $notification->push(_("You are over your quota, so your messages will be permanently deleted instead of moved to the Trash mailbox."), 'horde.warning');
                         $idx = new IMP_Indices($ob->mbox, $ob->uids);
                         return $idx->delete(array('keeplog' => !empty($opts['keeplog']), 'nuke' => true));
                     }
                     return false;
                 }
             }
         } else {
             /* Delete message logs now. This may result in loss of message
              * log data for messages that might not be deleted - i.e. if
              * an error occurs. But 1) the user has already indicated they
              * don't care about this data and 2) message IDs (used by some
              * maillog backends) won't be available after deletion. */
             if ($maillog) {
                 $maillog->deleteLog(new IMP_Maillog_Messages($ob->mbox, $ids_ob));
             }
             /* Delete the messages. */
             $expunge_now = false;
             $del_flags = array(Horde_Imap_Client::FLAG_DELETED);
             if (!$use_vtrash && (!$imp_imap->access(IMP_Imap::ACCESS_TRASH) || !empty($opts['nuke']) || ($use_trash && $ob->mbox == $trash || $ob->mbox->remote_mbox))) {
                 /* Purge messages immediately. */
                 $expunge_now = !$no_expunge;
             } elseif ($mark_seen) {
                 $del_flags[] = Horde_Imap_Client::FLAG_SEEN;
             }
             try {
                 $imp_imap->store($ob->mbox, array('add' => $del_flags, 'ids' => $ids_ob));
                 if ($expunge_now) {
                     $ob->mbox->expunge($ids_ob);
                 } else {
                     $ajax_queue->flag($del_flags, true, new IMP_Indices($ob->mbox, $ids_ob));
                 }
             } catch (IMP_Imap_Exception $e) {
             }
         }
     }
     return $return_value;
 }
Пример #17
0
 /**
  * Add compose javascript variables to the page.
  */
 protected function _addComposeVars($base)
 {
     global $browser, $conf, $injector, $prefs, $registry;
     /* Context menu definitions. */
     $base->js_context['ctx_other'] = new stdClass();
     if (!$prefs->isLocked('request_mdn')) {
         $base->js_context['ctx_other']->rr = _("Read Receipt");
     }
     $base->js_context['ctx_atc'] = new stdClass();
     if (IMP_Compose::canUploadAttachment()) {
         if (!$prefs->isLocked('save_attachments') && (!$prefs->isLocked('save_sent_mail') || $prefs->getValue('save_sent_mail'))) {
             $base->js_context['ctx_atc']->save = _("Save Attachments in Sent Mailbox");
         }
         $atcfile = new stdClass();
         $atcfile->delete = _("Delete");
         $base->js_context['ctx_atcfile'] = $atcfile;
     }
     if ($prefs->getValue('use_pgp') && $prefs->getValue('pgp_public_key')) {
         $base->js_context['ctx_atc']->pgppubkey = _("Attach Personal PGP Public Key");
     }
     if ($registry->hasMethod('contacts/ownVCard')) {
         $base->js_context['ctx_atc']->vcard = _("Attach contact information");
     }
     /* Variables used in compose page. */
     $compose_cursor = $prefs->getValue('compose_cursor');
     $templates_mbox = IMP_Mailbox::getPref(IMP_Mailbox::MBOX_TEMPLATES);
     $base->js_conf += array_filter(array('compose_cursor' => $compose_cursor ? $compose_cursor : 'top', 'rte_avail' => intval($browser->hasFeature('rte')), 'spellcheck' => intval($prefs->getValue('compose_spellcheck')), 'templates_mbox' => $templates_mbox ? $templates_mbox->form_to : null));
     if ($injector->getInstance('IMP_Factory_Imap')->create()->access(IMP_Imap::ACCESS_DRAFTS) && ($drafts_mbox = IMP_Mailbox::getPref(IMP_Mailbox::MBOX_DRAFTS)) && !$drafts_mbox->readonly) {
         $base->js_conf += array_filter(array('auto_save_interval_val' => intval($prefs->getValue('auto_save_drafts')), 'close_draft' => intval($prefs->getValue('close_draft')), 'drafts_mbox' => $drafts_mbox->form_to));
     }
     if ($registry->hasMethod('contacts/search')) {
         $base->js_conf['URI_ABOOK'] = strval(IMP_Basic_Contacts::url()->setRaw(true));
         $base->js_conf['ac_delete'] = strval(Horde_Themes::img('delete-small.png'));
         $base->js_conf['ac_minchars'] = intval($conf['compose']['ac_threshold']) ?: 1;
     }
     if ($prefs->getValue('set_priority')) {
         $base->js_conf['priority'] = array(array('l' => _("High"), 'v' => 'high'), array('l' => _("Normal"), 's' => true, 'v' => 'normal'), array('l' => _("Low"), 'v' => 'low'));
     }
     if (!$prefs->isLocked('default_encrypt')) {
         $encrypt = array();
         foreach ($injector->getInstance('IMP_Compose_Ui')->encryptList(null, true) as $key => $val) {
             $encrypt[] = array('l' => htmlspecialchars($val), 'v' => $key);
         }
         if (!empty($encrypt)) {
             $base->js_conf['encrypt'] = $encrypt;
         }
     }
     /* Gettext strings used in compose page. */
     $base->js_text += array('change_identity' => _("You have edited your signature. Change the identity and lose your changes?"), 'compose_cancel' => _("Cancelling this message will permanently discard its contents and will delete auto-saved drafts.\nAre you sure you want to do this?"), 'compose_close' => _("Compose action completed. You may now safely close this window."), 'data' => _("Data"), 'dragdropimg_error' => _("Could not add %d file(s) to message: only images are supported."), 'group_expand' => _("Expand Group"), 'image_data' => _("Image Data"), 'loading' => _("Loading..."), 'max_atc_size' => _("Your attachment(s) are too large and cannot be uploaded."), 'max_atc_num' => _("You have reached the limit for the number of attachments in this message."), 'noresults' => _("No Results Found"), 'nosubject' => _("The message does not have a subject entered.") . "\n" . _("Send message without a subject?"), 'paste_error' => _("Could not paste image as the clipboard data is invalid."), 'replyall' => _("%d recipients"), 'spell_noerror' => _("No spelling errors found."), 'toggle_html' => _("Discard all text formatting information (by converting from HTML to plain text)? This conversion cannot be reversed."), 'uploading' => _("Uploading..."));
 }
Пример #18
0
 /**
  * Reports a list of messages as innocent/spam.
  *
  * @param IMP_Indices $indices  An indices object.
  * @param array $opts           Additional options:
  *   - mailboxob: (IMP_Mailbox_List) Update this mailbox list object.
  *                DEFAULT: No update.
  *
  * @return integer  1 if messages have been deleted, 2 if messages have
  *                  been moved.
  */
 public function report(IMP_Indices $indices, array $opts = array())
 {
     global $injector, $notification, $prefs;
     /* Abort immediately if spam reporting has not been enabled, or if
      * there are no messages. */
     if (empty($this->_drivers) || !count($indices)) {
         return 0;
     }
     $imp_contents = $injector->getInstance('IMP_Factory_Contents');
     $report_count = 0;
     foreach ($indices as $ob) {
         try {
             $ob->mbox->uidvalid;
         } catch (IMP_Exception $e) {
             continue;
         }
         foreach ($ob->uids as $idx) {
             try {
                 $contents = $imp_contents->create($ob->mbox->getIndicesOb($idx));
             } catch (IMP_Exception $e) {
                 continue;
             }
             $report_flag = false;
             foreach ($this->_drivers as $val) {
                 if ($val->report($contents, $this->_action)) {
                     $report_flag = true;
                 }
             }
             if ($report_flag) {
                 ++$report_count;
             }
         }
     }
     if (!$report_count) {
         return 0;
     }
     /* Report what we've done. */
     if ($report_count == 1) {
         $hdrs = $contents->getHeader();
         if ($subject = $hdrs->getValue('subject')) {
             $subject = Horde_String::truncate($subject, 30);
         } elseif ($from = $hdrs->getValue('from')) {
             $from = Horde_String::truncate($from, 30);
         } else {
             $subject = '[' . _("No Subject") . ']';
         }
         switch ($this->_action) {
             case self::INNOCENT:
                 $msg = $subject ? sprintf(_("The message \"%s\" has been reported as innocent."), $subject) : sprintf(_("The message from \"%s\" has been reported as innocent."), $from);
                 break;
             case self::SPAM:
                 $msg = $subject ? sprintf(_("The message \"%s\" has been reported as spam."), $subject) : sprintf(_("The message from \"%s\" has been reported as spam."), $from);
                 break;
         }
     } else {
         switch ($this->_action) {
             case self::INNOCENT:
                 $msg = sprintf(_("%d messages have been reported as innocent."), $report_count);
                 break;
             case self::SPAM:
                 $msg = sprintf(_("%d messages have been reported as spam."), $report_count);
                 break;
         }
     }
     $notification->push($msg, 'horde.message');
     $mbox_args = array();
     if (isset($opts['mailboxob'])) {
         $mbox_args['mailboxob'] = $opts['mailboxob'];
     }
     /* Run post-reporting hook. */
     try {
         $injector->getInstance('Horde_Core_Hooks')->callHook('post_spam', 'imp', array($this->_action == self::SPAM ? 'spam' : 'innocent', $indices));
     } catch (Horde_Exception_HookNotSet $e) {
     }
     /* Delete/move message after report. */
     switch ($this->_action) {
         case self::INNOCENT:
             /* Always flag messages as NotJunk. */
             $imp_message = $injector->getInstance('IMP_Message');
             $imp_message->flag(array('add' => array(Horde_Imap_Client::FLAG_NOTJUNK), 'remove' => array(Horde_Imap_Client::FLAG_JUNK)), $indices);
             if (($result = $prefs->getValue('move_innocent_after_report')) && !$imp_message->copy('INBOX', 'move', $indices, $mbox_args)) {
                 $result = 0;
             }
             break;
         case self::SPAM:
             /* Always flag messages as Junk. */
             $imp_message = $injector->getInstance('IMP_Message');
             $imp_message->flag(array('add' => array(Horde_Imap_Client::FLAG_JUNK), 'remove' => array(Horde_Imap_Client::FLAG_NOTJUNK)), $indices);
             switch ($result = $prefs->getValue('delete_spam_after_report')) {
                 case 1:
                     $msg_count = $imp_message->delete($indices, $mbox_args);
                     if ($msg_count === false) {
                         $result = 0;
                     } else {
                         if ($msg_count == 1) {
                             $notification->push(_("The message has been deleted."), 'horde.message');
                         } else {
                             $notification->push(sprintf(_("%d messages have been deleted."), $msg_count), 'horde.message');
                         }
                     }
                     break;
                 case 2:
                     if ($targetMbox = IMP_Mailbox::getPref(IMP_Mailbox::MBOX_SPAM)) {
                         if (!$imp_message->copy($targetMbox, 'move', $indices, array_merge($mbox_args, array('create' => true)))) {
                             $result = 0;
                         }
                     } else {
                         $notification->push(_("Could not move message to spam mailbox - no spam mailbox defined in preferences."), 'horde.error');
                         $result = 0;
                     }
                     break;
             }
             break;
     }
     return $result;
 }
Пример #19
0
 /**
  */
 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 = '&quot;' . $sent_mail->display_html . '&quot;';
                 }
                 $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');
     }
 }