delete() public method

Deletes a list of messages.
public delete ( array $opts = [] ) : integer | boolean
$opts array Additional options:
  - 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
return integer | boolean The number of messages deleted if successful, false if not successful.
Exemplo n.º 1
0
Arquivo: Copy.php Projeto: horde/horde
 /**
  * Copy/move messages.
  *
  * @param string $mbox          The mailbox name to copy/move the task to.
  * @param IMP_Indices $indices  An indices object.
  * @param boolean $move         Move if true, copy if false.
  *
  * @return boolean  True on success.
  */
 public function copy($mbox, IMP_Indices $indices, $move)
 {
     global $injector;
     $success = true;
     foreach ($indices as $ob) {
         foreach ($ob->uids as $uid) {
             /* Fetch the message contents. */
             $imp_contents = $injector->getInstance('IMP_Factory_Contents')->create($ob->mbox->getIndicesOb($uid));
             /* Fetch the message headers. */
             $subject = strval($imp_contents->getHeader()->getHeader('Subject'));
             /* Re-flow the message for prettier formatting. */
             $body_part = $imp_contents->getMimePart($imp_contents->findBody());
             if (!$body_part) {
                 $success = false;
                 continue;
             }
             $flowed = new Horde_Text_Flowed($body_part->getContents());
             if ($body_part->getContentTypeParameter('delsp') == 'yes') {
                 $flowed->setDelSp(true);
             }
             $body = $flowed->toFlowed(false);
             /* Convert to current charset */
             /* TODO: When Horde_Icalendar supports setting of charsets
              * we need to set it there instead of relying on the fact
              * that both Nag and IMP use the same charset. */
             $body = Horde_String::convertCharset($body, $body_part->getCharset(), 'UTF-8');
             if (!$this->_create($mbox, $subject, $body)) {
                 $success = false;
             }
         }
     }
     /* Delete the original messages if this is a "move" operation. */
     if ($move) {
         $indices->delete();
     }
     return $success;
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
0
 /**
  * Deletes messages from a mailbox.
  *
  * @param string $mailbox  The name of the mailbox (UTF-8).
  * @param array $indices   The list of UIDs to delete.
  *
  * @return integer|boolean  The number of messages deleted if successful,
  *                          false if not.
  */
 public function deleteMessages($mailbox, $indices)
 {
     $i = new IMP_Indices($mailbox, $indices);
     return $i->delete(array('nuke' => true));
 }
Exemplo n.º 4
0
 /**
  * Destroys an IMP_Compose instance.
  *
  * @param string $action  The action performed to cause the end of this
  *                        instance.  Either 'cancel', 'discard',
  *                        'save_draft', or 'send'.
  */
 public function destroy($action)
 {
     switch ($action) {
         case 'discard':
         case 'send':
             /* Delete the draft. */
             $i = new IMP_Indices($this->getMetadata('draft_uid'));
             $i->delete(array('nuke' => true));
             break;
         case 'save_draft':
             /* Don't delete any drafts. */
             $this->changed = 'deleted';
             return;
         case 'cancel':
             if ($this->getMetadata('draft_auto')) {
                 $this->destroy('discard');
                 return;
             }
             // Fall-through
         // Fall-through
         default:
             // No-op
             break;
     }
     $this->deleteAllAttachments();
     $this->changed = 'deleted';
 }