You are here

function MailhandlerPhpImapRetrieve::purge_message in Mailhandler 6.2

Same name and namespace in other branches
  1. 7.2 modules/mailhandler_php_imap/plugins/mailhandler/retrieve/MailhandlerPhpImapRetrieve.class.php \MailhandlerPhpImapRetrieve::purge_message()

Purge (mark as read or delete) a message.

Parameters

object $mailbox: Mailbox configuration.

array $message: Message to purge.

Overrides MailhandlerRetrieve::purge_message

File

modules/mailhandler_php_imap/plugins/mailhandler/retrieve/MailhandlerPhpImapRetrieve.class.php, line 96
Definition of MailhandlerPhpImapRetrieve class.

Class

MailhandlerPhpImapRetrieve
Retrieve messages using PHP IMAP library.

Code

function purge_message($mailbox, $message) {
  if (!isset($message['imap_uid'])) {
    return;
  }
  if (!($result = $this
    ->open_mailbox($mailbox))) {
    mailhandler_report('error', 'Unable to connect to %mail. Following errors may provide details.', array(
      '%mail' => $mailbox->mail,
    ));
    $this
      ->report_errors($mailbox);
  }
  if ($mailbox->settings['delete_after_read']) {
    imap_delete($result, $message['imap_uid'], FT_UID);
  }
  elseif (!isset($mailbox->settings['flag_after_read']) || $mailbox->settings['flag_after_read']) {
    imap_setflag_full($result, (string) $message['imap_uid'], '\\Seen', FT_UID);
  }
  $this
    ->close_mailbox($result, $mailbox);
}