Author: Michael Slusarz (slusarz@horde.org)
Inheritance: extends IMP_Indices_Copy
Example #1
0
 /**
  * Copies or moves a list of messages to a new mailbox.
  * Also handles moves to the tasklist and/or notepad applications.
  *
  * @param string $targetMbox  The mailbox to move/copy messages to
  *                            (UTF-8).
  * @param string $action      Either 'copy' or 'move'.
  * @param array $opts         Additional options:
  * <pre>
  *   - create: (boolean) Should the target mailbox be created?
  *             DEFAULT: false
  * </pre>
  *
  * @return boolean  True if successful, false if not.
  */
 public function copy($targetMbox, $action, array $opts = array())
 {
     global $notification;
     if (!count($this)) {
         return false;
     }
     $targetMbox = IMP_Mailbox::get($targetMbox);
     /* If the target is a tasklist, handle the move/copy specially. */
     $tasks = new IMP_Indices_Copy_Tasklist();
     if ($tasks->match($targetMbox)) {
         return $tasks->copy($targetMbox, $this, $action == 'copy');
     }
     /* If the target is a notepad, handle the move/copy specially. */
     $note = new IMP_Indices_Copy_Notepad();
     if ($note->match($targetMbox)) {
         return $note->copy($targetMbox, $this, $action == 'copy');
     }
     if (!empty($opts['create']) && !$targetMbox->create()) {
         return false;
     }
     $imap_move = false;
     $return_value = true;
     switch ($action) {
         case 'move':
             $imap_move = true;
             $message = _("There was an error moving messages from \"%s\" to \"%s\". This is what the server said");
             break;
         case 'copy':
             $message = _("There was an error copying messages from \"%s\" to \"%s\". This is what the server said");
             break;
     }
     foreach ($this as $ob) {
         try {
             if ($targetMbox->readonly) {
                 throw new IMP_Exception(_("The target directory is read-only."));
             }
             if ($action == 'move' && $ob->mbox->readonly) {
                 throw new IMP_Exception(_("The source directory is read-only."));
             }
             /* Throws Exception on error. */
             $ob->mbox->uidvalid;
             /* Attempt to copy/move messages to new mailbox. */
             $imp_imap = $ob->mbox->imp_imap;
             $imp_imap->copy($ob->mbox, $targetMbox, array('ids' => $imp_imap->getIdsOb($ob->uids), 'move' => $imap_move));
         } catch (Exception $e) {
             $error_msg = sprintf($message, $ob->mbox->display, $targetMbox->display) . ': ' . $e->getMessage();
             if ($e instanceof IMP_Imap_Exception) {
                 $e->notify($error_msg);
             } else {
                 $notification->push($error_msg, 'horde.error');
             }
             $return_value = false;
         }
     }
     return $return_value;
 }
Example #2
0
 /**
  * @param boolean $static  Ignored in this driver.
  */
 public function getTree($static = false)
 {
     global $injector;
     $this->_nodes = $this->_tree->getNodes();
     $filter = $injector->createInstance('Horde_Text_Filter');
     $view = new Horde_View(array('templatePath' => IMP_TEMPLATES . '/flist'));
     $view->addHelper('FormTag');
     $view->addHelper('Tag');
     $view->optgroup = $this->getOption('optgroup');
     /* Custom HTML. */
     if ($customhtml = $this->getOption('customhtml')) {
         $view->customhtml = $customhtml;
     }
     /* Heading. */
     if (($heading = $this->getOption('heading')) && strlen($heading) > 0) {
         $view->heading = $heading;
     }
     /* New mailbox entry. */
     if ($this->getOption('new_mbox')) {
         $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();
         if ($imp_imap->access(IMP_Imap::ACCESS_CREATEMBOX) && $imp_imap->access(IMP_Imap::ACCESS_CREATEMBOX_MAX)) {
             $view->new_mbox = true;
         }
     }
     /* Virtual folders. */
     if ($this->getOption('inc_vfolder')) {
         $iterator = IMP_Search_IteratorFilter::create(IMP_Search_IteratorFilter::VFOLDER);
         $vfolder_list = array();
         foreach ($iterator as $val) {
             $form_to = IMP_Mailbox::formTo($val);
             $vfolder_list[] = array('l' => $filter->filter($val->label, 'space2html', array('encode' => true)), 'sel' => !empty($this->_nodes[$form_to]['selected']), 'v' => $form_to);
         }
         if (!empty($vfolder_list)) {
             $view->vfolder = $vfolder_list;
         }
     }
     /* Add the list of editable tasklists to the list. */
     if ($this->getOption('inc_tasklists')) {
         $tasklist = new IMP_Indices_Copy_Tasklist();
         $view->tasklist = array();
         foreach ($tasklist->getTasklists() as $key => $val) {
             $view->tasklist[] = array('l' => $filter->filter($val->get('name'), 'space2html', array('encode' => true)), 'v' => $key);
         }
     }
     /* Add the list of editable notepads to the list. */
     if ($this->getOption('inc_notepads')) {
         $notepad = new IMP_Indices_Copy_Notepad();
         $view->notepad = array();
         foreach ($notepad->getNotepads() as $key => $val) {
             $view->notepad[] = array('l' => $filter->filter($val->get('name'), 'space2html', array('encode' => true)), 'v' => $key);
         }
     }
     /* Prepare filter list. */
     $this->_filter = ($filter = $this->getOption('filter')) ? array_flip($filter) : array();
     $tree = '';
     foreach ($this->_tree->getRootNodes() as $node_id) {
         $tree .= $this->_buildTree($node_id);
     }
     $view->tree = $tree;
     return $view->render('flist');
 }