note 89735 added to function.imap-createmailbox
| From: | tiznull at osu1 dot php dot net | Date: | Fri, 20 Mar 2009 19:44:07 +0000 |
| Subject: | note 89735 added to function.imap-createmailbox | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-152226@lists.php.net to get a copy of this message | ||
One should understand that even though it says "create mailbox", you are really creating a
FOLDER. Now, as a imap admin you can create mailboxes and more with this function.
So in reality, you are always creating folders when creating "mailboxes". Mail
admin's get this, but programmers may not understand the concept completely.
If you auth a single user account and use these functions, they will not create mailboxes where mail
is delivered, they will actually create a folder where you can copy messages to.
Here is a translation:
imap_createmailbox = create a folder in the account for the current authenticated user's imap
session (imap_open)
imap_deletemailbox = delete a folder (and the email in it) for the current authenticated user's
imap session (imap_open)
imap_getmailboxes = get all your folders for the current authenticated user's imap session
(imap_open)
imap_renamemailbox = Rename a folder for the current authenticated user's imap session
(imap_open)
================
Here is a quick class to login to an account, generate all of your base folders, and return the
connection, success message and returns all the base folders for an imap account using PHP5:
<?php
class Imap {
public $folders;
public $connection;
public function login($user, $pass) {
$mbox = @imap_open("{imap.example.org:143}", $user, $pass);
if(!$mbox)
return ('Your login failed for user <strong>'.$user.'</strong>. Please
try to enter your username and password again.<br />');
// Login worked, let us begin!!!!....
// gather folder lost...
$fldrs_made = 0;
$folders = imap_listmailbox($mbox, "{localhost:143}", "*");
// create the default folders....
if(1 === mailgui::create_default_folders($mbox,$folders)) {
$folders = imap_listmailbox($mbox, "{localhost:143}", "*");
$fldrs_made = 1;
}
sort($folders);
$this->folders = $folders;
$this->connection = $mbox;
if(1 === $fldrs_made)
return ('User logged in successfully as '.$user.'. This is your first time logging
in, welcome to our webmail!!!<br />');
else
return ('User logged in successfully as '.$user.'.<br />');
}
private function create_default_folders($imap_stream, $folders) {
$change=0;
if(!in_array('{imap.example.org}TRASH',$folders)) {
@imap_createmailbox($imap_stream, imap_utf7_encode("{imap.example.org:143}TRASH"));
$change=1;
}
if(!in_array('{imap.example.org}SENT',$folders)) {
@imap_createmailbox($imap_stream, imap_utf7_encode("{imap.example.org:143}SENT"));
$change=1;
}
if(!in_array('{imap.example.org}SPAM',$folders)) {
@imap_createmailbox($imap_stream, imap_utf7_encode("{imap.example.org:143}SPAM"));
$change=1;
}
if(!in_array('{imap.example.org}SENT',$folders)) {
@imap_createmailbox($imap_stream, imap_utf7_encode("{imap.example.org:143}SENT"));
$change=1;
}
if(!in_array('{imap.example.org}SENT',$folders)) {
@imap_createmailbox($imap_stream, imap_utf7_encode("{imap.example.org:143}DRAFTS"));
$change=1;
}
if(!in_array('{imap.example.org}MY_FOLDERS',$folders)) {
@imap_createmailbox($imap_stream, imap_utf7_encode("{imap.example.org:143}PERSONAL
EMAIL"));
$change=1;
}
return $change;
}
public function close_mail_connection() {
@imap_close($this->connection);
}
}
// usage, create a form, post it....
if($_POST['imap_username'] && $_POST['imap_password']) {
$imap_login = new Imap();
$imap_login->login($_POST['imap_username'],$_POST['imap_password']);
// Do some mail stuff here, like get headers...., use obj connection
$message_headers = imap_mailboxmsginfo($imap_login->connection);
// show the folders....
print_r($imap_login->folders, true);
print '<br /><hr size="1" noshade />';
print_r($message_headers, true);
// close the connection
$imap_login->close_mail_connection();
}
?>
----
Server IP: 209.41.74.194
Probable Submitter: 71.109.103.218
----
Manual Page -- http://www.php.net/manual/en/function.imap-createmailbox.php
Edit -- https://master.php.net/note/edit/89735
Del: integrated -- https://master.php.net/note/delete/89735/integrated
Del: useless -- https://master.php.net/note/delete/89735/useless
Del: bad code -- https://master.php.net/note/delete/89735/bad+code
Del: spam -- https://master.php.net/note/delete/89735/spam
Del: non-english -- https://master.php.net/note/delete/89735/non-english
Del: in docs -- https://master.php.net/note/delete/89735/in+docs
Del: other reasons-- https://master.php.net/note/delete/89735
Reject -- https://master.php.net/note/reject/89735
Search -- https://master.php.net/manage/user-notes.php