Mail_IMAPv2
[ class tree: Mail_IMAPv2 ] [ index: Mail_IMAPv2 ] [ all elements ]

Source for file ManageMB.php

Documentation is available at ManageMB.php

  1. <?php
  2.  
  3. //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  4. //\\\       \\\\\\\\|                                                      \\
  5. //\\\ @@    @@\\\\\\| Mail_IMAPv2                                            \\
  6. //\\ @@@@  @@@@\\\\\|______________________________________________________\\
  7. //\\\@@@@| @@@@\\\\\|                                                      \\
  8. //\\\ @@ |\\@@\\\\\\|(c) Copyright 2004 Richard York, All rights Reserved  \\
  9. //\\\\  ||   \\\\\\\|______________________________________________________\\
  10. //\\\\  \\_   \\\\\\|Redistribution and use in source and binary forms,    \\
  11. //\\\\\        \\\\\|with or without modification, are permitted provided  \\
  12. //\\\\\  ----  \@@@@|that the following conditions are met:                \\
  13. //@@@@@\       \@@@@|                                                      \\
  14. //@@@@@@\     \@@@@@| o Redistributions of source code must retain the     \\
  15. //\\\\\\\\\\\\\\\\\\|  above copyright notice, this list of conditions and \\
  16. //    the following disclaimer.                                            \\
  17. //  o Redistributions in binary form must reproduce the above copyright    \\
  18. //    notice, this list of conditions and the following disclaimer in the  \\
  19. //    documentation and/or other materials provided with the distribution. \\
  20. //  o The names of the authors may not be used to endorse or promote       \\
  21. //    products derived from this software without specific prior written   \\
  22. //    permission.                                                          \\
  23. //                                                                         \\
  24. //  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS    \\
  25. //  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT      \\
  26. //  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR  \\
  27. //  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT   \\
  28. //  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,  \\
  29. //  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT       \\
  30. //  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  \\
  31. //  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY  \\
  32. //  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT    \\
  33. //  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE  \\
  34. //  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.   \\
  35. //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  36.  
  37. /**
  38. * This class provides an extension to Mail_IMAPv2 that adds mailbox management
  39. * features. These features include the ability to create/rename/delete
  40. * (sub)mailboxes on the server, as well as the ability to move/copy mail
  41. * from one folder to another, and finally the ability to import messages
  42. * into the server.
  43. *
  44. @author       Richard York <rich_y@php.net>
  45. @category     Mail
  46. @package      Mail_IMAPv2
  47. @license      BSD
  48. @version      0.1.0 Beta
  49. @copyright    (c) Copyright 2004, Richard York, All Rights Reserved.
  50. @since        PHP 4.2.0
  51. @since        C-Client 2001
  52. @tutorial     http://www.smilingsouls.net/Mail_IMAP
  53. *
  54. @todo add simple message filter function
  55. */
  56. class Mail_IMAPv2_ManageMB extends Mail_IMAPv2 {
  57.  
  58.     /**
  59.     *
  60.     * @tutorial http://www.smilingsouls.net/Mail_IMAP?content=Mail_IMAP_ManageMB/Mail_IMAP_ManageMB
  61.     */
  62.     
  63.     function Mail_IMAPv2_ManageMB($connection$get_info = TRUE)
  64.     {
  65.         $this->Mail_IMAPv2($connection$get_info);
  66.     }
  67.  
  68.     /**
  69.     * This method creates, renames and deletes mailboxes from the server.
  70.     *
  71.     * @param    string $action 
  72.     *    One of create|rename|delete, this tells the method what you want to
  73.     *     do with a mailbox.
  74.     * @param    string $mb_name 
  75.     *    The name of the mailbox to create, delete or rename.
  76.     * @param    string $mb_rename 
  77.     *    (optional) New name for the mailbox, if it is being renamed.
  78.     *
  79.     * @return   BOOL 
  80.     * @access   public
  81.     * @see      imap_createmailbox
  82.     * @see      imap_renamemailbox
  83.     * @see      imap_deletemailbox
  84.     * @tutorial http://www.smilingsouls.net/Mail_IMAP?content=Mail_IMAP_ManageMB/manageMB
  85.     */
  86.     function manageMB($action$mb_name$mb_rename = NULL)
  87.     {
  88.         switch ($action{
  89.             case 'create':
  90.             {
  91.                 if (@imap_createmailbox($this->mailboximap_utf7_encode($this->mailboxInfo['host'].'INBOX.'.$mb_name))) {
  92.                     $ret = TRUE;
  93.                 else {
  94.                     $this->error->push(Mail_IMAPv2_ERROR'error'NULL'Unable to create MB: '.$mb_name);
  95.                     $ret = FALSE;
  96.                 }
  97.                 break;
  98.             }
  99.             case 'rename':
  100.             {
  101.                 if (empty($mb_rename)) {
  102.                     $this->error->push(Mail_IMAPv2_ERROR'error'NULL'No mailbox provided to rename.');
  103.                 }
  104.                 if (@imap_renamemailbox($this->mailbox$this->mailboxInfo['host'].'INBOX.'.$mb_name$this->mailboxInfo['host'].'INBOX.'.$mb_rename)) {
  105.                     $ret = TRUE;
  106.                 else {
  107.                     $this->error->push(Mail_IMAPv2_ERROR'error'NULL'Unable to rename MB: '.$mb_name);
  108.                     $ret = FALSE;
  109.                 }
  110.                 break;
  111.             }
  112.             case 'delete':
  113.             {
  114.                 if (@imap_deletemailbox($this->mailbox$this->mailboxInfo['host'].'INBOX.'.$mb_name)) {
  115.                     $ret = TRUE;
  116.                 else {
  117.                     $this->error->push(Mail_IMAPv2_ERROR'error'NULL'Unable to delete MB: '.$mb_name);
  118.                     $ret = FALSE;
  119.                 }
  120.                 break;
  121.             }
  122.             default:
  123.             {
  124.                 $this->error->push(Mail_IMAPv2_ERROR_INVALID_ACTION'error'array('action' => $action'arg' => '$action'));
  125.                 $ret = FALSE;
  126.             }
  127.             return $ret;
  128.         }
  129.     }
  130.  
  131.     /**
  132.     * This method manages the mail inside of a mailbox and allows mail to be
  133.     * copied or moved from the mailbox that the user is connected to to the
  134.     * specified mailbox.
  135.     *
  136.     * @param    string $action 
  137.     *    One of copy|move if copy, a copy of the message will remain in the
  138.     *    current mailbox. If move the message is permenently moved to the
  139.     *    specified mailbox.
  140.     * @param    array $msg_list 
  141.     *    An array of messages to move, see (@link imap_mail_copy} or {@link imap_mail_move}
  142.     *    for more options. The array is imploded into a comma separated list, therefore
  143.     *    other options such as 1:10 syntax or * syntax may be specified in the array.
  144.     * @param    string $dest_mb 
  145.     *    The destination mailbox, such as 'INBOX.Drafts' or 'INBOX.Sent'
  146.     *
  147.     * @return BOOL 
  148.     * @access public
  149.     * @see imap_mail_copy
  150.     * @see imap_mail_move
  151.     * @tutorial http://www.smilingsouls.net/Mail_IMAP?content=Mail_IMAP_ManageMB/manageMail
  152.     */
  153.     function manageMail($action$msg_list$dest_mb)
  154.     {
  155.         if (is_array($msg_list)) {
  156.             $msg_list implode($msg_list',');
  157.         else {
  158.             $this->error->push(Mail_IMAPv2_ERROR_ARGUMENT_REQUIRES_ARRAY'error'array('arg' => '$msg_list'));
  159.             return FALSE;
  160.         }
  161.         switch ($action{
  162.             case 'copy':
  163.             {
  164.                 $opt (isset($this->option['mail_move']))$this->option['mail_move': NULL;
  165.                 break;
  166.             }
  167.             case 'move':
  168.             {
  169.                 $opt (isset($this->option['mail_copy']))$this->option['mail_copy': NULL;
  170.                 break;
  171.             }
  172.             default:
  173.             {
  174.                 $this->error->push(Mail_IMAPv2_ERROR_INVALID_ACTION'error'array('action' => $action'arg' => '$action'));
  175.                 return FALSE;
  176.             }
  177.         }
  178.  
  179.         $action 'imap_mail_'.$action;
  180.  
  181.         if (@$action($this->mailbox$msg_list$dest_mb$opt)) {
  182.             $ret = TRUE;
  183.         else {
  184.             $this->error->push(Mail_IMAPv2_ERROR'error'NULL'Unable to copy or move messages, imap_mail_'.$action.' failed!');
  185.             $ret = FALSE;
  186.         }
  187.         return $ret;
  188.     }
  189.  
  190.     /**
  191.     * This method provides the functionality to import MIME messages into the server
  192.     * using the {@link imap_append} method.
  193.     *
  194.     * @param string $dest_mb 
  195.     *    The destination mailbox where the messages will be imported to.
  196.     * @param array $messages 
  197.     *    An array of MIME messages to import.
  198.     *
  199.     * @return BOOL 
  200.     * @access public
  201.     * @see imap_append
  202.     * @tutorial http://www.smilingsouls.net/Mail_IMAP?content=Mail_IMAP_ManageMB/importMail
  203.     */
  204.     function importMail($dest_mb$messages)
  205.     {
  206.         if (is_array($messages)) {
  207.             $opt (isset($this->option['append']))$this->option['append': NULL;
  208.  
  209.             foreach ($messages as $msg{
  210.                 if (!@imap_append($this->mailbox$this->mailboxInfo['host'].$dest_mb$msg$opt)) {
  211.                     $this->error->push(Mail_IMAPv2_ERROR'error'NULL'Unable to import message, imap_append failed!');
  212.                     $ret = FALSE;
  213.                 }
  214.             }
  215.  
  216.             if (!isset($ret)) {
  217.                 $ret = TRUE;
  218.             }
  219.         else {
  220.             $this->error->push(Mail_IMAPv2_ERROR_ARGUMENT_REQUIRES_ARRAY'error'array('arg' => '$messages'));
  221.             $ret = FALSE;
  222.         }
  223.         return $ret;
  224.     }
  225. }
  226. ?>

Documentation generated on Mon, 11 Mar 2019 14:30:27 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.