imap_deletemailbox
(PHP 4, PHP 5, PHP 7)
imap_deletemailbox — Delete a mailbox
Описание
bool imap_deletemailbox
( resource
$imap_stream
, string $mailbox
)
Deletes the specified mailbox
.
Список параметров
-
imap_stream
-
Поток IMAP, полученный из imap_open().
-
mailbox
-
The mailbox name, see imap_open() for more information
Возвращаемые значения
Возвращает TRUE
в случае успешного завершения или FALSE
в случае возникновения ошибки.
Смотрите также
- imap_createmailbox() - Create a new mailbox
- imap_renamemailbox() - Rename an old mailbox to new mailbox
-
imap_open() - Open an IMAP stream to a mailbox for the format of
mbox
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с почтой
- IMAP, POP3 и NNTP
- imap_8bit
- imap_alerts
- imap_append
- imap_base64
- imap_binary
- imap_body
- imap_bodystruct
- imap_check
- imap_clearflag_full
- imap_close
- imap_create
- imap_createmailbox
- imap_delete
- imap_deletemailbox
- imap_errors
- imap_expunge
- imap_fetch_overview
- imap_fetchbody
- imap_fetchheader
- imap_fetchmime
- imap_fetchstructure
- imap_fetchtext
- imap_gc
- imap_get_quota
- imap_get_quotaroot
- imap_getacl
- imap_getmailboxes
- imap_getsubscribed
- imap_header
- imap_headerinfo
- imap_headers
- imap_last_error
- imap_list
- imap_listmailbox
- imap_listscan
- imap_listsubscribed
- imap_lsub
- imap_mail_compose
- imap_mail_copy
- imap_mail_move
- imap_mail
- imap_mailboxmsginfo
- imap_mime_header_decode
- imap_msgno
- imap_num_msg
- imap_num_recent
- imap_open
- imap_ping
- imap_qprint
- imap_rename
- imap_renamemailbox
- imap_reopen
- imap_rfc822_parse_adrlist
- imap_rfc822_parse_headers
- imap_rfc822_write_address
- imap_savebody
- imap_scan
- imap_scanmailbox
- imap_search
- imap_set_quota
- imap_setacl
- imap_setflag_full
- imap_sort
- imap_status
- imap_subscribe
- imap_thread
- imap_timeout
- imap_uid
- imap_undelete
- imap_unsubscribe
- imap_utf7_decode
- imap_utf7_encode
- imap_utf8
Коментарии
I want to clarify a few technicalities to spare others the aggravation I had with imap_deletemailbox().
First off your first imap_open() should be to the folder to then imap_search() to ensure that the user isn't inadvertently deleting messages they're not yet aware of.
Secondly if !imap_search() you want to disconnect before executing imap_deletemailbox(). If you don't then you won't be able to avoid the following error:
PHP Request Shutdown: [CLOSED] IMAP connection broken (server response) (errflg=1)
That is because you just deleted the folder and the server doesn't know what to do with the connection so it triggers the error. So again, you want to delete the folder while you're connected to a different connection/folder combination instead.
A short example of how to cleanly delete a mail folder in PHP without triggering errors (presuming your connection configuration is correct):
<?php
$user = 'user@domain.tld';
$pass = '[pass here]';
$mail_server = '{imap.example.com:993/ssl/imap}';
$mail_connection_folder = imap_open($mail_server.$folder_string, $user, $pass);
if ($mail_connection_folder)
{
$mail_box_messages = imap_search($mail_connection_folder, 'ALL', SE_UID);
if (!$mail_box_messages)
{
$result = imap_close($mail_connection_folder);
$mail_connection_folder = imap_open($mail_server, $user, $pass);
$result = imap_deletemailbox($mail_connection_folder, imap_utf7_encode($mail_server.$folder_string));
}
else {}//messages in folder error.
}
else {}//Failed connection error.
?>