CSS: Providing seven essential vitamins and minerals since 1996.
Have a steaming hot, delicious slice of Standards.

Mail_IMAPv2_ManageMB Source Code

* @category Mail * @package Mail_IMAPv2 * @license BSD * @version 0.1.0 Beta * @copyright (c) Copyright 2004, Richard York, All Rights Reserved. * @since PHP 4.2.0 * @since C-Client 2001 * @tutorial http://www.smilingsouls.net/Mail_IMAP * * @todo add simple message filter function */ class Mail_IMAPv2_ManageMB extends Mail_IMAPv2 { /** * * @tutorial http://www.smilingsouls.net/Mail_IMAP?content=Mail_IMAP_ManageMB/Mail_IMAP_ManageMB */ function Mail_IMAPv2_ManageMB($connection, $get_info = TRUE) { $this->Mail_IMAPv2($connection, $get_info); } /** * This method creates, renames and deletes mailboxes from the server. * * @param string $action * One of create|rename|delete, this tells the method what you want to * do with a mailbox. * @param string $mb_name * The name of the mailbox to create, delete or rename. * @param string $mb_rename * (optional) New name for the mailbox, if it is being renamed. * * @return BOOL * @access public * @see imap_createmailbox * @see imap_renamemailbox * @see imap_deletemailbox * @tutorial http://www.smilingsouls.net/Mail_IMAP?content=Mail_IMAP_ManageMB/manageMB */ function manageMB($action, $mb_name, $mb_rename = NULL) { switch ($action) { case 'create': { if (@imap_createmailbox($this->mailbox, imap_utf7_encode($this->mailboxInfo['host'].'INBOX.'.$mb_name))) { $ret = TRUE; } else { $this->error->push(Mail_IMAPv2_ERROR, 'error', NULL, 'Unable to create MB: '.$mb_name); $ret = FALSE; } break; } case 'rename': { if (empty($mb_rename)) { $this->error->push(Mail_IMAPv2_ERROR, 'error', NULL, 'No mailbox provided to rename.'); } if (@imap_renamemailbox($this->mailbox, $this->mailboxInfo['host'].'INBOX.'.$mb_name, $this->mailboxInfo['host'].'INBOX.'.$mb_rename)) { $ret = TRUE; } else { $this->error->push(Mail_IMAPv2_ERROR, 'error', NULL, 'Unable to rename MB: '.$mb_name); $ret = FALSE; } break; } case 'delete': { if (@imap_deletemailbox($this->mailbox, $this->mailboxInfo['host'].'INBOX.'.$mb_name)) { $ret = TRUE; } else { $this->error->push(Mail_IMAPv2_ERROR, 'error', NULL, 'Unable to delete MB: '.$mb_name); $ret = FALSE; } break; } default: { $this->error->push(Mail_IMAPv2_ERROR_INVALID_ACTION, 'error', array('action' => $action, 'arg' => '$action')); $ret = FALSE; } return $ret; } } /** * This method manages the mail inside of a mailbox and allows mail to be * copied or moved from the mailbox that the user is connected to to the * specified mailbox. * * @param string $action * One of copy|move if copy, a copy of the message will remain in the * current mailbox. If move the message is permenently moved to the * specified mailbox. * @param array $msg_list * An array of messages to move, see (@link imap_mail_copy} or {@link imap_mail_move} * for more options. The array is imploded into a comma separated list, therefore * other options such as 1:10 syntax or * syntax may be specified in the array. * @param string $dest_mb * The destination mailbox, such as 'INBOX.Drafts' or 'INBOX.Sent' * * @return BOOL * @access public * @see imap_mail_copy * @see imap_mail_move * @tutorial http://www.smilingsouls.net/Mail_IMAP?content=Mail_IMAP_ManageMB/manageMail */ function manageMail($action, $msg_list, $dest_mb) { if (is_array($msg_list)) { $msg_list = implode($msg_list, ','); } else { $this->error->push(Mail_IMAPv2_ERROR_ARGUMENT_REQUIRES_ARRAY, 'error', array('arg' => '$msg_list')); return FALSE; } switch ($action) { case 'copy': { $opt = (isset($this->option['mail_move']))? $this->option['mail_move'] : NULL; break; } case 'move': { $opt = (isset($this->option['mail_copy']))? $this->option['mail_copy'] : NULL; break; } default: { $this->error->push(Mail_IMAPv2_ERROR_INVALID_ACTION, 'error', array('action' => $action, 'arg' => '$action')); return FALSE; } } $action = 'imap_mail_'.$action; if (@$action($this->mailbox, $msg_list, $dest_mb, $opt)) { $ret = TRUE; } else { $this->error->push(Mail_IMAPv2_ERROR, 'error', NULL, 'Unable to copy or move messages, imap_mail_'.$action.' failed!'); $ret = FALSE; } return $ret; } /** * This method provides the functionality to import MIME messages into the server * using the {@link imap_append} method. * * @param string $dest_mb * The destination mailbox where the messages will be imported to. * @param array $messages * An array of MIME messages to import. * * @return BOOL * @access public * @see imap_append * @tutorial http://www.smilingsouls.net/Mail_IMAP?content=Mail_IMAP_ManageMB/importMail */ function importMail($dest_mb, $messages) { if (is_array($messages)) { $opt = (isset($this->option['append']))? $this->option['append'] : NULL; foreach ($messages as $msg) { if (!@imap_append($this->mailbox, $this->mailboxInfo['host'].$dest_mb, $msg, $opt)) { $this->error->push(Mail_IMAPv2_ERROR, 'error', NULL, 'Unable to import message, imap_append failed!'); $ret = FALSE; } } if (!isset($ret)) { $ret = TRUE; } } else { $this->error->push(Mail_IMAPv2_ERROR_ARGUMENT_REQUIRES_ARRAY, 'error', array('arg' => '$messages')); $ret = FALSE; } return $ret; } } ?>
Copyright © 1998-2012 Richard York, All Rights Reserved.