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