Author: Michael Slusarz (slusarz@horde.org)
Esempio n. 1
0
 /**
  * Constructor.
  *
  * @param mixed  Two possible inputs:
  *   - 1 argument: Horde_Variables object. These GET/POST parameters are
  *     reserved in IMP:
  *     - buid: (string) BUID [Browser UID].
  *     - mailbox: (string) Base64url encoded mailbox.
  *     - muid: (string) MUID [Mailbox + UID].
  *     - uid: (string) UID [Actual mail UID].
  *   - 2 arguments: IMP_Mailbox object, IMP_Indices argument
  */
 public function __construct()
 {
     $args = func_get_args();
     switch (func_num_args()) {
         case 1:
             if ($args[0] instanceof Horde_Variables) {
                 if (isset($args[0]->mailbox) && strlen($args[0]->mailbox)) {
                     $this->mailbox = IMP_Mailbox::formFrom($args[0]->mailbox);
                     if (isset($args[0]->buid)) {
                         $this->buids = new IMP_Indices($this->mailbox, $args[0]->buid);
                         parent::__construct($this->mailbox->fromBuids($this->buids));
                     } elseif (isset($args[0]->uid)) {
                         parent::__construct($this->mailbox, $args[0]->uid);
                     }
                 }
                 if (isset($args[0]->muid)) {
                     parent::__construct($args[0]->muid);
                 }
             }
             break;
         case 2:
             if ($args[0] instanceof IMP_Mailbox && $args[1] instanceof IMP_Indices) {
                 $this->mailbox = $args[0];
                 $this->buids = $args[0]->toBuids($args[1]);
                 parent::__construct($args[1]);
             }
             break;
     }
     if (!isset($this->buids)) {
         $this->buids = new IMP_Indices();
     }
     if (!isset($this->mailbox)) {
         $this->mailbox = IMP_Mailbox::get('INBOX');
     }
 }
Esempio n. 2
0
 /**
  */
 public function update(Horde_Core_Prefs_Ui $ui)
 {
     if ($GLOBALS['prefs']->isLocked(IMP_Mailbox::MBOX_TEMPLATES)) {
         return false;
     }
     return $this->_updateSpecialMboxes(IMP_Mailbox::MBOX_TEMPLATES, IMP_Mailbox::formFrom($ui->vars->templates), $ui->vars->templates_new, null, $ui);
 }
Esempio n. 3
0
 /**
  * AJAX action: Check access rights for creation of a submailbox.
  *
  * Variables used:
  *   - all: (integer) If 1, return all mailboxes. Otherwise, return only
  *          INBOX, special mailboxes, and polled mailboxes.
  *
  * @return string  HTML to use for the folder tree.
  */
 public function smartmobileFolderTree()
 {
     $ftree = $GLOBALS['injector']->getInstance('IMP_Ftree');
     /* Poll all mailboxes on initial display. */
     $this->_base->queue->poll($ftree->poll->getPollList(), true);
     $iterator = new AppendIterator();
     /* Add special mailboxes explicitly. INBOX should appear first. */
     $special = new ArrayIterator();
     $special->append($ftree['INBOX']);
     foreach (IMP_Mailbox::getSpecialMailboxesSort() as $val) {
         if (isset($ftree[$val])) {
             $special->append($ftree[$val]);
         }
     }
     $iterator->append($special);
     /* Now add polled mailboxes. */
     $filter = new IMP_Ftree_IteratorFilter($ftree);
     $filter->add(array($filter::CONTAINERS, $filter::REMOTE, $filter::SPECIALMBOXES));
     if (!$this->vars->all) {
         $filter->add($filter::POLLED);
     }
     $filter->mboxes = array('INBOX');
     $iterator->append($filter);
     return $ftree->createTree($this->vars->all ? 'smobile_folders_all' : 'smobile_folders', array('iterator' => $iterator, 'render_type' => 'IMP_Tree_Jquerymobile'))->getTree(true);
 }
Esempio n. 4
0
 /**
  * Purge the old sent-mail mailboxes.
  *
  * @return boolean  Whether any mailboxes were deleted.
  */
 public function execute()
 {
     global $injector, $notification, $prefs;
     $iterator = new IMP_Ftree_IteratorFilter($injector->getInstance('IMP_Ftree'));
     $iterator->add($iterator::CONTAINERS);
     $mbox_list = array();
     /* Get list of all mailboxes, parse through and get the list of all
      * old sent-mail mailboxes. Then sort this array according to the
      * date. */
     $sent_mail = $injector->getInstance('IMP_Identity')->getAllSentmail();
     foreach (array_map('strval', $iterator) as $k) {
         foreach ($sent_mail as $mbox) {
             if (preg_match('/^' . preg_quote($mbox, '/') . '-([^-]+)-([0-9]{4})$/i', $k, $regs)) {
                 $mbox_list[$k] = is_numeric($regs[1]) ? mktime(0, 0, 0, $regs[1], 1, $regs[2]) : strtotime("{$regs['1']} 1, {$regs['2']}");
             }
         }
     }
     arsort($mbox_list, SORT_NUMERIC);
     $return_val = false;
     /* See if any mailboxes need to be purged. */
     $purge = array_slice(array_keys($mbox_list), $prefs->getValue('delete_sentmail_monthly_keep'));
     if (count($purge)) {
         $notification->push(_("Old sent-mail mailboxes being purged."), 'horde.message');
         /* Delete the old mailboxes now. */
         foreach (IMP_Mailbox::get($purge) as $val) {
             if ($val->delete()) {
                 $return_val = true;
             }
         }
     }
     return $return_val;
 }
Esempio n. 5
0
 /**
  * Autocreate special mailboxes on login.
  */
 public function execute()
 {
     foreach (IMP_Mailbox::getSpecialMailboxes() as $key => $val) {
         if (is_null($val)) {
             continue;
         }
         switch ($key) {
             case IMP_Mailbox::SPECIAL_COMPOSETEMPLATES:
                 $val->create();
                 break;
             case IMP_Mailbox::SPECIAL_DRAFTS:
                 $val->create(array('special_use' => array(Horde_Imap_Client::SPECIALUSE_DRAFTS)));
                 break;
             case IMP_Mailbox::SPECIAL_SENT:
                 foreach ($val as $mbox) {
                     $mbox->create(array('special_use' => array(Horde_Imap_Client::SPECIALUSE_SENT)));
                 }
                 break;
             case IMP_Mailbox::SPECIAL_SPAM:
                 $val->create(array('special_use' => array(Horde_Imap_Client::SPECIALUSE_JUNK)));
                 break;
             case IMP_Mailbox::SPECIAL_TRASH:
                 $val->create(array('special_use' => array(Horde_Imap_Client::SPECIALUSE_TRASH)));
                 break;
         }
     }
 }
Esempio n. 6
0
 /**
  * Renames the old sent-mail mailboxes.
  *
  * Mailbox name: sent-mail-month-year
  *   month = English:         3 letter abbreviation
  *           Other Languages: Month value (01-12)
  *   year  = 4 digit year
  *
  * The mailbox name needs to be in this specific format (as opposed to a
  * user-defined one) to ensure that 'delete_sentmail_monthly' processing
  * can accurately find all the old sent-mail mailboxes.
  *
  * @return boolean  Whether all sent-mail mailboxes were renamed.
  */
 public function execute()
 {
     global $notification;
     $date_format = substr($GLOBALS['language'], 0, 2) == 'en' ? 'M-Y' : 'm-Y';
     $datetime = new DateTime();
     $now = $datetime->format($date_format);
     foreach ($this->_getSentmail() as $sent) {
         /* Display a message to the user and rename the mailbox.
          * Only do this if sent-mail mailbox currently exists. */
         if ($sent->exists) {
             $notification->push(sprintf(_("\"%s\" mailbox being renamed at the start of the month."), $sent->display), 'horde.message');
             $query = new Horde_Imap_Client_Fetch_Query();
             $query->imapDate();
             $query->uid();
             $imp_imap = $sent->imp_imap;
             $res = $imp_imap->fetch($sent, $query);
             $msgs = array();
             foreach ($res as $val) {
                 $date_string = $val->getImapDate()->format($date_format);
                 if (!isset($msgs[$date_string])) {
                     $msgs[$date_string] = $imp_imap->getIdsOb();
                 }
                 $msgs[$date_string]->add($val->getUid());
             }
             unset($msgs[$now]);
             foreach ($msgs as $key => $val) {
                 $new_mbox = IMP_Mailbox::get(strval($sent) . '-' . Horde_String::lower($key));
                 $imp_imap->copy($sent, $new_mbox, array('create' => true, 'ids' => $val, 'move' => true));
             }
         }
     }
     return true;
 }
Esempio n. 7
0
 /**
  * AJAX action: Expand mailboxes (saves expanded state in prefs).
  *
  * Variables used:
  *   - action: (string) [REQUIRED] Either 'collapse' or 'expand'.
  *   - all: (integer) 1 to toggle all mailboxes (mailbox information
  *          will not be returned).
  *   - mboxes: (string) The list of mailboxes to process (JSON encoded
  *             array; mailboxes are base64url encoded); required if 'all'
  *             is 0.
  *
  * @return boolean  True.
  */
 public function toggleMailboxes()
 {
     $ftree = $GLOBALS['injector']->getInstance('IMP_Ftree');
     if ($this->vars->all) {
         $old_track = $ftree->eltdiff->track;
         $ftree->eltdiff->track = false;
         switch ($this->vars->action) {
             case 'collapse':
                 $ftree->collapseAll();
                 break;
             case 'expand':
                 $ftree->expandAll();
                 break;
         }
         $ftree->eltdiff->track = $old_track;
     } elseif (!empty($this->vars->mboxes)) {
         $mboxes = IMP_Mailbox::formFrom(json_decode($this->vars->mboxes));
         switch ($this->vars->action) {
             case 'collapse':
                 $ftree->collapse($mboxes);
                 break;
             case 'expand':
                 $ftree->expand($mboxes);
                 break;
         }
     }
     return true;
 }
Esempio n. 8
0
 /**
  * @param array $opts  Options:
  *   - buid: (string) BUID of message.
  *   - full: (boolean) Full URL?
  *   - mailbox: (string) Mailbox of message.
  */
 public static function url(array $opts = array())
 {
     $url = Horde::url('basic.php')->add('page', 'listinfo')->unique()->setRaw(!empty($opts['full']));
     if (!empty($opts['mailbox'])) {
         $url->add(array('buid' => $opts['buid'], 'mailbox' => IMP_Mailbox::get($opts['mailbox'])->form_to));
     }
     return $url;
 }
Esempio n. 9
0
 /**
  * Tasks to perform on shutdown.
  */
 public function shutdown()
 {
     foreach ($this->_instances as $key => $val) {
         if ($val->changed) {
             $this->_getCache(IMP_Mailbox::get($key))->set($key, serialize($val));
         }
     }
 }
Esempio n. 10
0
 /**
  */
 public function update(Horde_Core_Prefs_Ui $ui)
 {
     global $injector;
     if (!$this->_updateSpecialMboxes(IMP_Mailbox::MBOX_SPAM, IMP_Mailbox::formFrom($ui->vars->spam), $ui->vars->spam_new, Horde_Imap_Client::SPECIALUSE_JUNK, $ui)) {
         return false;
     }
     $injector->getInstance('IMP_Factory_Imap')->create()->updateFetchIgnore();
     return true;
 }
Esempio n. 11
0
 /**
  * Constructor.
  *
  * @param array $opts  Optional parameters:
  *   - abbrev: (boolean) Abbreviate long mailbox names by replacing the
  *             middle of the name with '...'?
  *             DEFAULT: Yes
  *   - basename: (boolean)  Use raw basename instead of abbreviated label?
  *               DEFAULT: false
  *   - heading: (string) The label for an empty-value option at the top of
  *              the list.
  *              DEFAULT: ''
  *   - inc_notepads: (boolean) Include user's editable notepads in list?
  *                   DEFAULT: No
  *   - inc_tasklists: (boolean) Include user's editable tasklists in list?
  *                    DEFAULT: No
  *   - inc_vfolder: (boolean) Include user's virtual folders in list?
  *                  DEFAULT: No
  *   - iterator: (Iterator) Tree iterator to use.
  *   - new_mbox: (boolean) Display an option to create a new mailbox?
  *               DEFAULT: No
  *   - optgroup: (boolean) Whether to use <optgroup> elements to group
  *               mailbox types.
  *               DEFAULT: false
  *   - selected: (string) The mailbox to have selected by default.
  *               DEFAULT: None
  */
 public function __construct(array $opts = array())
 {
     global $injector;
     $this->_tree = $injector->getInstance('IMP_Ftree')->createTree(strval(new Horde_Support_Randomid()), array('basename' => !empty($opts['basename']), 'iterator' => empty($opts['iterator']) ? null : $opts['iterator'], 'render_type' => 'IMP_Tree_Flist'));
     if (!empty($opts['selected'])) {
         $this->_tree->addNodeParams(IMP_Mailbox::formTo($opts['selected']), array('selected' => true));
     }
     $this->_tree->setOption($opts);
 }
Esempio n. 12
0
 /**
  */
 protected function _init()
 {
     global $injector, $notification;
     if (!$this->indices->mailbox->access_search) {
         $notification->push(_("Searching is not available."), 'horde.error');
         $this->indices->mailbox->url('mailbox')->redirect();
     }
     $imp_flags = $injector->getInstance('IMP_Flags');
     $imp_search = $injector->getInstance('IMP_Search');
     /* If search_basic is set, we are processing the search query. */
     if ($this->vars->search_basic) {
         $c_list = array();
         if ($this->vars->search_criteria_text) {
             switch ($this->vars->search_criteria) {
                 case 'from':
                 case 'subject':
                     $c_list[] = new IMP_Search_Element_Header($this->vars->search_criteria_text, $this->vars->search_criteria, $this->vars->search_criteria_not);
                     break;
                 case 'recip':
                     $c_list[] = new IMP_Search_Element_Recipient($this->vars->search_criteria_text, $this->vars->search_criteria_not);
                     break;
                 case 'body':
                 case 'text':
                     $c_list[] = new IMP_Search_Element_Text($this->vars->search_criteria_text, $this->vars->search_criteria == 'body', $this->vars->search_criteria_not);
                     break;
             }
         }
         if ($this->vars->search_criteria_flag) {
             $formdata = $imp_flags->parseFormId($this->vars->search_criteria_flag);
             $c_list[] = new IMP_Search_Element_Flag($formdata['flag'], $formdata['set'] && !$this->vars->search_criteria_flag_not);
         }
         if (empty($c_list)) {
             $notification->push(_("No search criteria specified."), 'horde.error');
         } else {
             /* Store the search in the session. */
             $q_ob = $imp_search->createQuery($c_list, array('id' => IMP_Search::BASIC_SEARCH, 'mboxes' => array($this->indices->mailbox), 'type' => IMP_Search::CREATE_QUERY));
             /* Redirect to the mailbox screen. */
             IMP_Mailbox::get($q_ob)->url('mailbox')->redirect();
         }
     }
     $flist = $imp_flags->getList(array('imap' => true, 'mailbox' => $this->indices->mailbox));
     $flag_set = array();
     foreach ($flist as $val) {
         $flag_set[] = array('val' => $val->form_set, 'label' => $val->label);
     }
     /* Prepare the search template. */
     $view = new Horde_View(array('templatePath' => IMP_TEMPLATES . '/basic/search'));
     $view->addHelper('FormTag');
     $view->addHelper('Tag');
     $view->action = self::url();
     $view->advsearch = Horde::link($this->indices->mailbox->url(IMP_Basic_Search::url()));
     $view->mbox = $this->indices->mailbox->form_to;
     $view->search_title = sprintf(_("Search %s"), $this->indices->mailbox->display_html);
     $view->flist = $flag_set;
     $this->title = _("Search");
     $this->output = $view->render('search-basic');
 }
Esempio n. 13
0
File: Ui.php Progetto: horde/horde
 /**
  * Returns data needed to output quota.
  *
  * @param string $mailbox  Mailbox to query.
  * @param boolean $force   If true, ignore 'interval' config option and
  *                         force quota display.
  *
  * @return array|boolean  Array with these keys: class, message, percent.
  *                        Returns false if no updated quota information.
  */
 public function quota($mailbox = null, $force = true)
 {
     global $injector, $session;
     $qconfig = $injector->getInstance('IMP_Factory_Imap')->create()->config->quota;
     if (!$qconfig) {
         return false;
     }
     $qlist = array();
     if (!is_null($mailbox)) {
         $mailbox = IMP_Mailbox::get($mailbox);
         if ($mailbox->nonimap) {
             return false;
         }
         if (!$force) {
             $qlist = $session->get('imp', self::SESSION_INTERVAL_KEY, $session::TYPE_ARRAY);
             if (isset($qlist[strval($mailbox)]) && time() < $qlist[strval($mailbox)]) {
                 return false;
             }
         }
     }
     try {
         $quotaDriver = $injector->getInstance('IMP_Quota');
         $quota = $quotaDriver->getQuota($mailbox);
     } catch (IMP_Exception $e) {
         Horde::log($e, 'ERR');
         return false;
     }
     $qlist[strval($mailbox)] = $qconfig['params']['interval'] + time();
     $session->set('imp', self::SESSION_INTERVAL_KEY, $qlist);
     if (empty($quota)) {
         return false;
     }
     $strings = $quotaDriver->getMessages();
     list($calc, $unit) = $quotaDriver->getUnit();
     $ret = array('class' => '', 'percent' => 0);
     if ($quota['limit'] != 0) {
         $quota['usage'] = $quota['usage'] / $calc;
         $quota['limit'] = $quota['limit'] / $calc;
         $ret['percent'] = $quota['usage'] * 100 / $quota['limit'];
         if ($ret['percent'] >= 90) {
             $ret['class'] = 'quotaalert';
         } elseif ($ret['percent'] >= 75) {
             $ret['class'] = 'quotawarn';
         }
         $ret['message'] = sprintf($strings['short'], $ret['percent'], $quota['limit'], $unit);
         $ret['percent'] = sprintf("%.2f", $ret['percent']);
     } elseif ($quotaDriver->isHiddenWhenUnlimited()) {
         return false;
     } elseif ($quota['usage'] != 0) {
         $quota['usage'] = $quota['usage'] / $calc;
         $ret['message'] = sprintf($strings['nolimit_short'], $quota['usage'], $unit);
     } else {
         $ret['message'] = _("No limit");
     }
     return $ret;
 }
Esempio n. 14
0
File: Sort.php Progetto: horde/horde
 /**
  * Garbage collection.
  */
 public function gc()
 {
     foreach (IMP_Mailbox::get(array_keys($this->_sortpref)) as $val) {
         /* Purge if mailbox doesn't exist or this is a search query (not
          * a virtual folder). */
         if (!$val->exists || $val->query) {
             unset($this[strval($val)]);
         }
     }
 }
Esempio n. 15
0
 /**
  * Generates a string that can be saved out to an mbox format mailbox file
  * for a mailbox (or set of mailboxes), optionally including all
  * subfolders of the selected mailbox(es) as well. All mailboxes will be
  * output in the same string.
  *
  * @param mixed $mboxes  A mailbox name (UTF-8), or list of mailbox names,
  *                       to generate a mbox file for.
  *
  * @return resource  A stream resource containing the text of a mbox
  *                   format mailbox file.
  */
 public function generate($mboxes)
 {
     $body = fopen('php://temp', 'r+');
     if (!is_array($mboxes)) {
         if (!strlen($mboxes)) {
             return $body;
         }
         $mboxes = array($mboxes);
     }
     if (empty($mboxes)) {
         return $body;
     }
     $query = new Horde_Imap_Client_Fetch_Query();
     $query->envelope();
     $query->imapDate();
     $query->headerText(array('peek' => true));
     $query->bodyText(array('peek' => true));
     foreach (IMP_Mailbox::get($mboxes) as $val) {
         $imp_imap = $val->imp_imap;
         $slices = $imp_imap->getSlices($val, $imp_imap->getIdsOb(Horde_Imap_Client_Ids::ALL, true));
         foreach ($slices as $slice) {
             try {
                 $res = $imp_imap->fetch($val, $query, array('ids' => $slice, 'nocache' => true));
             } catch (IMP_Imap_Exception $e) {
                 continue;
             }
             foreach ($res as $ptr) {
                 $from_env = $ptr->getEnvelope()->from;
                 $from = count($from_env) ? $from_env[0]->bare_address : '<>';
                 /* We need this long command since some MUAs (e.g. pine)
                  * require a space in front of single digit days. */
                 $imap_date = $ptr->getImapDate();
                 $date = sprintf('%s %2s %s', $imap_date->format('D M'), $imap_date->format('j'), $imap_date->format('H:i:s Y'));
                 fwrite($body, 'From ' . $from . ' ' . $date . "\r\n");
                 /* Remove spurious 'From ' line in headers. */
                 $stream = $ptr->getHeaderText(0, Horde_Imap_Client_Data_Fetch::HEADER_STREAM);
                 while (!feof($stream)) {
                     $line = fgets($stream);
                     if (substr($line, 0, 5) != 'From ') {
                         fwrite($body, $line);
                     }
                 }
                 fwrite($body, "\r\n");
                 /* Add Body text. */
                 $stream = $ptr->getBodyText(0, true);
                 while (!feof($stream)) {
                     fwrite($body, fread($stream, 8192));
                 }
                 fwrite($body, "\r\n");
             }
         }
     }
     return $body;
 }
Esempio n. 16
0
 /**
  * Return the mailboxes that can be searched to find the sent message.
  *
  * @return array  Array of mailboxes to search in order of priority.
  */
 public function searchMailboxes()
 {
     $special = IMP_Mailbox::getSpecialMailboxes();
     /* Check for sent-mail mailbox(es) first. */
     $out = $special[IMP_Mailbox::SPECIAL_SENT];
     /* Add trash mailbox as backup. */
     if (!empty($special[IMP_Mailbox::SPECIAL_TRASH]) && !$special[IMP_Mailbox::SPECIAL_TRASH]->vtrash) {
         $out[] = $special[IMP_Mailbox::SPECIAL_TRASH];
     }
     return $out;
 }
Esempio n. 17
0
 /**
  * Constructor.
  *
  * @param mixed  Two possible inputs:
  *   - 1 argument: Horde_Variables object. These GET/POST parameters are
  *     reserved in IMP:
  *     - buid: (string) BUID [Browser UID].
  *     - mailbox: (string) Base64url encoded mailbox.
  *     - muid: (string) MUID [Mailbox + UID].
  *     - uid: (string) UID [Actual mail UID].
  *   - 2 arguments: IMP_Mailbox object, IMP_Indices argument
  */
 public function __construct()
 {
     $args = func_get_args();
     switch (func_num_args()) {
         case 1:
             if ($args[0] instanceof Horde_Variables) {
                 if (isset($args[0]->mailbox) && strlen($args[0]->mailbox)) {
                     $this->mailbox = IMP_Mailbox::formFrom($args[0]->mailbox);
                     if (isset($args[0]->buid)) {
                         /* BUIDs are always integers. Do conversion here since
                          * POP3 won't work otherwise. */
                         $tmp = new Horde_Imap_Client_Ids($args[0]->buid);
                         $this->buids = new IMP_Indices($this->mailbox, $tmp->ids);
                         parent::__construct($this->mailbox->fromBuids($this->buids));
                     } elseif (isset($args[0]->uid)) {
                         parent::__construct($this->mailbox, $args[0]->uid);
                     }
                 }
                 if (isset($args[0]->muid)) {
                     parent::__construct($args[0]->muid);
                 }
             }
             break;
         case 2:
             if ($args[0] instanceof IMP_Mailbox && $args[1] instanceof IMP_Indices) {
                 $this->mailbox = $args[0];
                 $this->buids = $args[0]->toBuids($args[1]);
                 parent::__construct($args[1]);
             }
             break;
     }
     if (!isset($this->buids)) {
         $this->buids = new IMP_Indices($this->_indices);
     }
     if (!isset($this->mailbox)) {
         $this->mailbox = IMP_Mailbox::get('INBOX');
     }
 }
Esempio n. 18
0
 /**
  * @return array
  */
 public function getTasklists($notify = false)
 {
     global $conf, $notification, $registry;
     if ($conf['tasklist']['use_tasklist'] && $registry->hasMethod('tasks/listTasklists')) {
         try {
             $lists = $registry->call('tasks/listTasklists', array(false, Horde_Perms::EDIT));
             $out = array();
             foreach ($lists as $key => $val) {
                 $mbox = IMP_Mailbox::formTo(self::TASKLIST_EDIT . $key);
                 $out[$mbox] = $val;
             }
             return $out;
         } catch (Horde_Exception $e) {
             if ($notify) {
                 $notification->push($e);
             }
         }
     }
     return array();
 }
Esempio n. 19
0
 /**
  */
 public function update(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(IMP_Mailbox::MBOX_SENT)) {
         return false;
     }
     if (!$ui->vars->sent_mail && $ui->vars->sent_mail_new) {
         $sent_mail = IMP_Mailbox::get($ui->vars->sent_mail_new)->namespace_append;
     } else {
         $sent_mail = IMP_Mailbox::formFrom($ui->vars->sent_mail);
         if (strpos($sent_mail, self::PREF_SPECIALUSE) === 0) {
             $sent_mail = IMP_Mailbox::get(substr($sent_mail, strlen(self::PREF_SPECIALUSE)));
         } elseif ($sent_mail == self::PREF_DEFAULT && ($sm_default = $prefs->getDefault(IMP_Mailbox::MBOX_SENT))) {
             $sent_mail = IMP_Mailbox::get($sm_default)->namespace_append;
         }
     }
     if ($sent_mail && !$sent_mail->create()) {
         return false;
     }
     return $injector->getInstance('IMP_Identity')->setValue(IMP_Mailbox::MBOX_SENT, $sent_mail);
 }
Esempio n. 20
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;
 }
Esempio n. 21
0
 /**
  */
 protected function _content()
 {
     $inbox = IMP_Mailbox::get('INBOX');
     /* Filter on INBOX display, if requested. */
     $inbox->filterOnDisplay();
     $query = new Horde_Imap_Client_Search_Query();
     $query->flag(Horde_Imap_Client::FLAG_SEEN, false);
     $ids = $inbox->runSearchQuery($query, Horde_Imap_Client::SORT_SEQUENCE, 1);
     $indices = $ids['INBOX'];
     $html = '<table cellspacing="0" width="100%">';
     $text = _("Go to your Inbox...");
     if (empty($indices)) {
         $html .= '<tr><td><em>' . _("No unread messages") . '</em></td></tr>';
     } else {
         $imp_ui = new IMP_Mailbox_Ui($inbox);
         $shown = empty($this->_params['msgs_shown']) ? 3 : $this->_params['msgs_shown'];
         $query = new Horde_Imap_Client_Fetch_Query();
         $query->envelope();
         try {
             $imp_imap = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create($inbox);
             $fetch_ret = $imp_imap->fetch($inbox, $query, array('ids' => $imp_imap->getIdsOb(array_slice($indices, 0, $shown))));
         } catch (IMP_Imap_Exception $e) {
             $fetch_ret = new Horde_Imap_Client_Fetch_Results();
         }
         foreach ($fetch_ret as $uid => $ob) {
             $envelope = $ob->getEnvelope();
             $date = $imp_ui->getDate(isset($envelope->date) ? $envelope->date : null);
             $from = $imp_ui->getFrom($envelope);
             $subject = $imp_ui->getSubject($envelope->subject, true);
             $html .= '<tr style="cursor:pointer" class="text"><td>' . $inbox->url('message', $uid)->link() . '<strong>' . htmlspecialchars($from['from'], ENT_QUOTES, 'UTF-8') . '</strong><br />' . $subject . '</a></td>' . '<td>' . htmlspecialchars($date, ENT_QUOTES, 'UTF-8') . '</td></tr>';
         }
         $more_msgs = count($indices) - $shown;
         if ($more_msgs > 0) {
             $text = sprintf(ngettext("%d more unseen message...", "%d more unseen messages...", $more_msgs), $more_msgs);
         }
     }
     return $html . '<tr><td colspan="2" style="cursor:pointer" align="right">' . $inbox->url('mailbox')->link() . $text . '</a></td></tr>' . '</table>';
 }
Esempio n. 22
0
 /**
  */
 protected function _content()
 {
     global $injector;
     /* Filter on INBOX display.  INBOX is always polled. */
     IMP_Mailbox::get('INBOX')->filterOnDisplay();
     /* Get list of mailboxes to poll. */
     $poll = $injector->getInstance('IMP_Ftree')->poll->getPollList(true);
     $status = $injector->getInstance('IMP_Factory_Imap')->create()->status($poll, Horde_Imap_Client::STATUS_UNSEEN | Horde_Imap_Client::STATUS_MESSAGES | Horde_Imap_Client::STATUS_RECENT_TOTAL);
     $anyUnseen = false;
     $out = '';
     foreach ($poll as $mbox) {
         $mbox_str = strval($mbox);
         if (isset($status[$mbox_str]) && (empty($this->_params['show_unread']) || !empty($status[$mbox_str]['unseen']))) {
             $mbox_status = $status[$mbox_str];
             $label = $mbox->url('mailbox')->link() . $mbox->display_html . '</a>';
             if (!empty($mbox_status['unseen'])) {
                 $label = '<strong>' . $label . '</strong>';
                 $anyUnseen = true;
             }
             $out .= '<tr><td>' . $label . '</td>';
             if (empty($mbox_status['unseen'])) {
                 $out .= '<td>-</td>';
             } else {
                 $out .= '<td><strong>' . intval($mbox_status['unseen']) . '</strong>';
                 if (!empty($mbox_status['recent_total'])) {
                     $out .= ' (<span style="color:red">' . sprintf(ngettext("%d new", "%d new", $mbox_status['recent_total']), $mbox_status['recent_total']) . '</span>)';
                 }
                 $out .= '</td>';
             }
             $out .= '<td>' . intval($mbox_status['messages']) . '</td></tr>';
         }
     }
     if (!empty($this->_params['show_unread']) && !$anyUnseen) {
         return '<em>' . _("No mailboxes with unseen messages") . '</em>';
     }
     return '<table class="impBlockSummary"><thead><tr><th>' . _("Mailbox") . '</th><th>' . _("Unseen") . '</th><th>' . _("Total") . '</th></tr></thead><tbody>' . $out . '</tbody></table>';
 }
Esempio n. 23
0
 /**
  * Create SELECT list of mailboxes for advanced search page.
  *
  * @param boolean $unsub  Include unsubcribed mailboxes?
  *
  * @return object  Object with the following properties:
  *   - mbox_list: (array) Mapping of mailbox name (key) to display
  *                string (values).
  *   - tree: (IMP_Tree_Flist) Tree object.
  */
 public function getSearchMboxList($unsub = false)
 {
     global $injector, $registry;
     $ob = new stdClass();
     $view = new Horde_View(array('templatePath' => IMP_TEMPLATES . '/search'));
     $view->allsearch = IMP_Mailbox::formTo(IMP_Search_Query::ALLSEARCH);
     $ftree = $injector->getInstance('IMP_Ftree');
     $iterator = new IMP_Ftree_IteratorFilter($ftree);
     if ($unsub) {
         $ftree->loadUnsubscribed();
         $iterator->remove($iterator::UNSUB);
     }
     if ($registry->getView() != $registry::VIEW_DYNAMIC) {
         $iterator->add($iterator::REMOTE);
     }
     $ob->tree = $ftree->createTree('imp_search', array('iterator' => $iterator, 'render_params' => array('abbrev' => 0, 'container_select' => true, 'customhtml' => $view->render('search-all'), 'heading' => _("Add search mailbox:")), 'render_type' => 'IMP_Tree_Flist'));
     $mbox_list = array();
     foreach ($iterator as $val) {
         $mbox_ob = $val->mbox_ob;
         $mbox_list[$mbox_ob->form_to] = $mbox_ob->display;
     }
     $ob->mbox_list = $mbox_list;
     return $ob;
 }
Esempio n. 24
0
 /**
  */
 public function update(Horde_Core_Prefs_Ui $ui)
 {
     global $injector, $notification;
     if ($ui->vars->change_acl_mbox) {
         return false;
     }
     $acl = $injector->getInstance('IMP_Imap_Acl');
     $mbox = IMP_Mailbox::formFrom($ui->vars->mbox);
     try {
         $curr_acl = $acl->getACL($mbox);
     } catch (IMP_Exception $e) {
         $notification->push($e);
         return;
     }
     if (!($acl_list = $ui->vars->acl)) {
         $acl_list = array();
     }
     $new_user = $ui->vars->new_user;
     if (strlen($new_user) && $ui->vars->new_acl) {
         if (isset($acl_list[$new_user])) {
             $acl_list[$new_user] = $ui->vars->new_acl;
         } else {
             try {
                 $acl->addRights($mbox, $new_user, implode('', $ui->vars->new_acl));
                 $notification->push(sprintf(_("ACL for \"%s\" successfully created for the mailbox \"%s\"."), $new_user, $mbox->label), 'horde.success');
             } catch (IMP_Exception $e) {
                 $notification->push($e);
             }
         }
     }
     foreach ($curr_acl as $index => $rule) {
         if (isset($acl_list[$index])) {
             /* Check to see if ACL changed, but only compare rights we
              * understand. */
             $acldiff = $rule->diff(implode('', $acl_list[$index]));
             $update = false;
             try {
                 if ($acldiff['added']) {
                     $acl->addRights($mbox, $index, $acldiff['added']);
                     $update = true;
                 }
                 if ($acldiff['removed']) {
                     $acl->removeRights($mbox, $index, $acldiff['removed']);
                     $update = true;
                 }
                 if ($update) {
                     $notification->push(sprintf(_("ACL rights for \"%s\" updated for the mailbox \"%s\"."), $index, $mbox->label), 'horde.success');
                 }
             } catch (IMP_Exception $e) {
                 $notification->push($e);
             }
         } else {
             /* If we dont see ANY form params, the user deleted all
              * rights. */
             try {
                 $acl->removeRights($mbox, $index, null);
                 $notification->push(sprintf(_("All rights on mailbox \"%s\" successfully removed for \"%s\"."), $mbox->label, $index), 'horde.success');
             } catch (IMP_Exception $e) {
                 $notification->push($e);
             }
         }
     }
     return false;
 }
Esempio n. 25
0
 /**
  * Returns the appropriate link to call the message composition script.
  *
  * @param string $simplejs  Use simple JS (instead of HordePopup JS)?
  *
  * @return Horde_Url  The link to the message composition script.
  */
 public function link($simplejs = false)
 {
     global $browser, $prefs, $registry;
     $args = $this->args;
     $callback = $raw = false;
     $view = $registry->getView();
     if ($view == Horde_Registry::VIEW_SMARTMOBILE) {
         $url = new Horde_Core_Smartmobile_Url(Horde::url('smartmobile.php'));
         $url->setAnchor('compose');
     } elseif ($simplejs || $view == Horde_Registry::VIEW_DYNAMIC) {
         $args['popup'] = 1;
         $url = $view == Horde_Registry::VIEW_DYNAMIC ? IMP_Dynamic_Compose::url() : IMP_Basic_Compose::url();
         $raw = true;
         $callback = array($this, 'composeLinkSimpleCallback');
     } elseif ($view != Horde_Registry::VIEW_MINIMAL && $prefs->getValue('compose_popup') && $browser->hasFeature('javascript')) {
         $url = IMP_Basic_Compose::url();
         $callback = array($this, 'composeLinkJsCallback');
     } else {
         $url = $view == Horde_Registry::VIEW_MINIMAL ? IMP_Minimal_Compose::url() : IMP_Basic_Compose::url();
     }
     if (isset($args['mailbox'])) {
         $url = IMP_Mailbox::get($args['mailbox'])->url($url, $args['buid']);
         unset($args['buid'], $args['mailbox']);
     } elseif (!$url instanceof Horde_Url) {
         $url = Horde::url($url);
     }
     $url->setRaw($raw)->add($args);
     if ($callback) {
         $url->toStringCallback = $callback;
     }
     return $url;
 }
Esempio n. 26
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;
 }
Esempio n. 27
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;
 }
Esempio n. 28
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'));
 }
Esempio n. 29
0
 /**
  */
 public function update(Horde_Core_Prefs_Ui $ui)
 {
     return $this->_updateSpecialMboxes(IMP_Mailbox::MBOX_DRAFTS, IMP_Mailbox::formFrom($ui->vars->drafts), $ui->vars->drafts_new, Horde_Imap_Client::SPECIALUSE_DRAFTS, $ui);
 }
Esempio n. 30
0
 public function current()
 {
     if (!$this->valid()) {
         return null;
     }
     $ret = new stdClass();
     $ret->mbox = IMP_Mailbox::get($this->key());
     $ret->uids = current($this->_indices);
     return $ret;
 }