Версия: 6.x
burger close
Класс Mailbox

Подробное описание

См. также
https://github.com/barbushin/php-imap
Автор
Barbushin Sergey http://linkedin.com/in/barbushin

-type PARTSTRUCTURE_PARAM = object{attribute:string, value?:string}

-type PARTSTRUCTURE = object{ id?:string, encoding:int|mixed, partStructure:object[], parameters:PARTSTRUCTURE_PARAM[], dparameters:object{attribute:string, value:string}[], parts:array<int, object{disposition?:string}>, type:int, subtype:string } -type HOSTNAMEANDADDRESS_ENTRY = object{host?:string, personal?:string, mailbox:string} -type HOSTNAMEANDADDRESS = array{0:HOSTNAMEANDADDRESS_ENTRY, 1?:HOSTNAMEANDADDRESS_ENTRY} -type COMPOSE_ENVELOPE = array{ subject?:string } -type COMPOSE_BODY = list<array{ type?:int, encoding?:int, charset?:string, subtype?:string, description?:string, disposition?:array{filename:string} }>

Открытые члены

 __construct (string $imapPath, string $login, string $password, string $attachmentsDir=null, string $serverEncoding= 'UTF-8', bool $trimImapPath=true, bool $attachmentFilenameMode=false)
 
 __destruct ()
 
 setPathDelimiter (string $delimiter)
 
 getPathDelimiter ()
 
 validatePathDelimiter (string $delimiter)
 
 getServerEncoding ()
 
 setServerEncoding (string $serverEncoding)
 
 getAttachmentFilenameMode ()
 
 setAttachmentFilenameMode (bool $attachmentFilenameMode)
 
 getImapSearchOption ()
 
 setImapSearchOption (int $imapSearchOption)
 
 setAttachmentsIgnore (bool $attachmentsIgnore)
 
 getAttachmentsIgnore ()
 
 getLogin ()
 
 setConnectionArgs (int $options=0, int $retriesNum=0, array $params=null)
 
 setAttachmentsDir (string $attachmentsDir)
 
 getAttachmentsDir ()
 
 setConnectionRetry (int $maxAttempts)
 
 setConnectionRetryDelay (int $milliseconds)
 
 hasImapStream ()
 
 encodeStringToUtf7Imap (string $str)
 
 decodeStringFromUtf7ImapToUtf8 (string $str)
 
 setMailboxFolder ()
 
 switchMailbox (string $imapPath, bool $absolute=true)
 
 disconnect ()
 
 setExpungeOnDisconnect (bool $isEnabled)
 
 checkMailbox ()
 
 createMailbox (string $name)
 
 deleteMailbox (string $name, bool $absolute=false)
 
 renameMailbox (string $oldName, string $newName)
 
 statusMailbox ()
 
 getListingFolders (string $pattern= '*')
 
 searchMailbox (string $criteria= 'ALL', bool $disableServerEncoding=false)
 
 searchMailboxFrom (string $criteria, string $sender, string...$senders)
 
 searchMailboxFromDisableServerEncoding (string $criteria, string $sender, string...$senders)
 
 searchMailboxMergeResults ($single_criteria,...$criteria)
 
 searchMailboxMergeResultsDisableServerEncoding ($single_criteria,...$criteria)
 
 saveMail (int $mailId, string $filename= 'email.eml')
 
 deleteMail (int $mailId)
 
 moveMail ($mailId, string $mailBox)
 
 copyMail ($mailId, string $mailBox)
 
 expungeDeletedMails ()
 
 markMailAsRead (int $mailId)
 
 markMailAsUnread (int $mailId)
 
 markMailAsImportant (int $mailId)
 
 markMailsAsRead (array $mailId)
 
 markMailsAsUnread (array $mailId)
 
 markMailsAsImportant (array $mailId)
 
 flagIsSet (int $mailId, string $flag)
 
 setFlag (array $mailsIds, string $flag)
 
 clearFlag (array $mailsIds, string $flag)
 
 getMailboxHeaders ()
 
 getMailboxInfo ()
 
 sortMails (int $criteria=SORTARRIVAL, bool $reverse=true,?string $searchCriteria= 'ALL', string $charset=null)
 
 countMails ()
 
 getRawMail (int $msgId, bool $markAsSeen=true)
 
 getMailHeaderFieldValue (string $headersRaw, string $header_field_name)
 
 convertToUtf8 (string $string, string $fromCharset)
 
 isUrlEncoded (string $string)
 
 parseDateTime (string $dateHeader)
 
 getImapPath ()
 
 getMailMboxFormat (int $mailId)
 
 getMailboxes (string $search= '*')
 
 getSubscribedMailboxes (string $search= '*')
 
 subscribeMailbox (string $mailbox)
 
 unsubscribeMailbox (string $mailbox)
 
 appendMessageToMailbox ($message, string $mailbox= '', string $options=null, string $internal_date=null)
 

Поля данных

const EXPECTED_SIZE_OF_MESSAGE_AS_ARRAY = 2
 
const MAX_LENGTH_FILEPATH = 255
 
const PART_TYPE_TWO = 2
 
const IMAP_OPTIONS_SUPPORTED_VALUES
 
 $decodeMimeStrDefaultCharset = 'default'
 

Защищенные члены

 lowercase_mb_list_encodings ()
 
 initImapStreamWithRetry ()
 
 getQuota (string $quota_root= 'INBOX')
 
 initImapStream ()
 
 decodeRFC2231 (string $string)
 
 getCombinedPath (string $folder, bool $absolute=false)
 
 pingOrDisconnect ()
 
 searchMailboxFromWithOrWithoutDisablingServerEncoding (string $criteria, bool $disableServerEncoding, string $sender, string...$senders)
 
 searchMailboxMergeResultsWithOrWithoutDisablingServerEncoding ($disableServerEncoding, $single_criteria,...$criteria)
 

Защищенные данные

 $imapPath
 
 $imapLogin
 
 $imapPassword
 
 $imapSearchOption = SE_UID
 
 $connectionRetry = 0
 
 $connectionRetryDelay = 100
 
 $imapOptions = 0
 
 $imapRetriesNum = 0
 
 $imapParams = []
 
 $serverEncoding = 'UTF-8'
 
 $attachmentsDir = null
 
 $expungeOnDisconnect = true
 
 $timeouts = []
 
 $attachmentsIgnore = false
 
 $pathDelimiter = '.'
 
 $mailboxFolder
 
 $attachmentFilenameMode = false
 

Конструктор(ы)

__construct ( string  $imapPath,
string  $login,
string  $password,
string  $attachmentsDir = null,
string  $serverEncoding = 'UTF-8',
bool  $trimImapPath = true,
bool  $attachmentFilenameMode = false 
)
Исключения
InvalidParameterException
__destruct ( )

Disconnects from the IMAP server / mailbox.

Методы

appendMessageToMailbox (   $message,
string  $mailbox = '',
string  $options = null,
string  $internal_date = null 
)

Appends $message to $mailbox.

Аргументы
string | array$message-param string|array{0:COMPOSE_ENVELOPE, 1:COMPOSE_BODY} $message
Возвращает
true
См. также
Imap::append()
checkMailbox ( )

Get information about the current mailbox.

Returns the information in an object with following properties: Date - current system time formatted according to RFC2822 Driver - protocol used to access this mailbox: POP3, IMAP, NNTP Mailbox - the mailbox name Nmsgs - number of mails in the mailbox Recent - number of recent mails in the mailbox

См. также
imap_check
clearFlag ( array  $mailsIds,
string  $flag 
)

Causes a store to delete the specified flag to the flags set for the mails in the specified sequence.

Аргументы
array$mailsIdsArray of mail IDs
string$flagWhich you can delete are , , , , and as defined by RFC2060
convertToUtf8 ( string  $string,
string  $fromCharset 
)

Converts a string to UTF-8.

Аргументы
string$stringMIME string to decode
string$fromCharsetCharset to convert from
Возвращает
string Converted string if conversion was successful, or the original string if not
copyMail (   $mailId,
string  $mailBox 
)

Copies mails listed in mailId into new mailbox.

Аргументы
string | int$mailIda range or message number
string$mailBoxMailbox name
См. также
imap_mail_copy()
countMails ( )

Get mails count in mail box.

См. также
imap_num_msg()
createMailbox ( string  $name)

Creates a new mailbox.

Аргументы
string$nameName of new mailbox (eg. 'PhpImap')
См. также
imap_createmailbox()
decodeRFC2231 ( string  $string)
protected
decodeStringFromUtf7ImapToUtf8 ( string  $str)

Returns the provided string in UTF-8 encoded format.

Возвращает
string $str UTF-7 encoded string or same as before, when it's no string

-pure

deleteMail ( int  $mailId)

Marks mails listed in mailId for deletion.

Аргументы
int$mailIdmessage number
См. также
imap_delete()
deleteMailbox ( string  $name,
bool  $absolute = false 
)

Deletes a specific mailbox.

Аргументы
string$nameName of mailbox, which you want to delete (eg. 'PhpImap')
См. также
imap_deletemailbox()
disconnect ( )

Disconnects from IMAP server / mailbox.

encodeStringToUtf7Imap ( string  $str)

Returns the provided string in UTF7-IMAP encoded format.

Возвращает
string $str UTF-7 encoded string

-pure

expungeDeletedMails ( )

Deletes all the mails marked for deletion by imap_delete(), imap_mail_move(), or imap_setflag_full().

См. также
imap_expunge()
flagIsSet ( int  $mailId,
string  $flag 
)

Check, if the specified flag for the mail is set or not.

Аргументы
int$mailIdA single mail ID
string$flagWhich you can get are , , , , and as defined by RFC2060
Возвращает
bool True, when the flag is set, false when not

-param int $mailId

getAttachmentFilenameMode ( )

Returns the current set attachment filename mode.

Возвращает
bool Attachment filename mode (e.g. true)
getAttachmentsDir ( )

Get current saving folder for attachments.

Возвращает
string|null Attachments dir
getAttachmentsIgnore ( )

Get $this->attachmentsIgnore param.

Возвращает
bool $attachmentsIgnore
getCombinedPath ( string  $folder,
bool  $absolute = false 
)
protected

Combine Subfolder or Folder to the connection. Have the imapPath a folder added to the connection info, then will the $folder added as subfolder. If the parameter $absolute TRUE, then will the connection new builded only with this folder as root element.

Аргументы
string$folderFolder, the will added to the path
bool$absoluteAdd folder as root element to the connection and remove all other from this
Возвращает
string Return the new path
getImapPath ( )

Gets IMAP path.

getImapSearchOption ( )

Returns the current set IMAP search option.

Возвращает
int IMAP search option (eg. 'SE_UID')
getListingFolders ( string  $pattern = '*')

Gets listing the folders.

This function returns an object containing listing the folders. The object has the following properties: messages, recent, unseen, uidnext, and uidvalidity.

Возвращает
string[] listing the folders

-return list<string>

getLogin ( )

Returns the IMAP login (usually an email address).

Возвращает
string IMAP login
getMailboxes ( string  $search = '*')

Get folders list.

Возвращает
(false|mixed|string)[][]

-return list<array{fullpath: string, attributes: mixed, delimiter: mixed, shortpath: false|string}>

-var array<int, scalar|array|object{name?:string}|resource|null>

getMailboxHeaders ( )

Get headers for all messages in the defined mailbox, returns an array of string formatted with header info, one element per mail message.

См. также
imap_headers()
getMailboxInfo ( )

Get information about the current mailbox.

Returns an object with following properties: Date - last change (current datetime) Driver - driver Mailbox - name of the mailbox Nmsgs - number of messages Recent - number of recent messages Unread - number of unread messages Deleted - number of deleted messages Size - mailbox size

Возвращает
stdClass Object with info
См. также
mailboxmsginfo
getMailHeaderFieldValue ( string  $headersRaw,
string  $header_field_name 
)

Get mail header field value.

Аргументы
string$headersRawRAW headers as single string
string$header_field_nameName of the required header field
Возвращает
string Value of the header field
getMailMboxFormat ( int  $mailId)

Get message in MBOX format.

Аргументы
int$mailIdmessage number
getPathDelimiter ( )

Returns the current set path delimiter character.

Возвращает
string Path delimiter
getQuota ( string  $quota_root = 'INBOX')
protected

Retrieve the quota settings per user.

Аргументы
string$quota_rootShould normally be in the form of which mailbox (i.e. INBOX)
См. также
imap_get_quotaroot()
getRawMail ( int  $msgId,
bool  $markAsSeen = true 
)

Get raw mail data.

Аргументы
int$msgIdID of the message
bool$markAsSeenMark the email as seen, when set to true
Возвращает
string Message of the fetched body
getServerEncoding ( )

Returns the current set server encoding.

Возвращает
string Server encoding (eg. 'UTF-8')
getSubscribedMailboxes ( string  $search = '*')

Get folders list.

Возвращает
(false|mixed|string)[][]

-return list<array{fullpath: string, attributes: mixed, delimiter: mixed, shortpath: false|string}>

-var array<int, scalar|array|object{name?:string}|resource|null>

hasImapStream ( )
initImapStream ( )
protected

Open an IMAP stream to a mailbox.

Исключения
Exceptionif an error occured
Возвращает
resource IMAP stream on success
initImapStreamWithRetry ( )
protected
Возвращает
resource
isUrlEncoded ( string  $string)

-pure

lowercase_mb_list_encodings ( )
protected

Returns the list of available encodings in lower case.

Возвращает
string[]

-return list<string>

markMailAsImportant ( int  $mailId)

Add the flag to a mail.

markMailAsRead ( int  $mailId)

Add the flag to a mail.

markMailAsUnread ( int  $mailId)

Remove the flag from a mail.

markMailsAsImportant ( array  $mailId)

Add the flag to some mails.

Аргументы
int[]$mailId

-param list<int> $mailId

markMailsAsRead ( array  $mailId)

Add the flag to a mails.

Аргументы
int[]$mailId

-param list<int> $mailId

markMailsAsUnread ( array  $mailId)

Remove the flag from some mails.

Аргументы
int[]$mailId

-param list<int> $mailId

moveMail (   $mailId,
string  $mailBox 
)

Moves mails listed in mailId into new mailbox.

Аргументы
string | int$mailIda range or message number
string$mailBoxMailbox name
См. также
imap_mail_move()
parseDateTime ( string  $dateHeader)

Converts the datetime to a RFC 3339 compliant format.

Аргументы
string$dateHeaderHeader datetime
Возвращает
string RFC 3339 compliant format or original (unchanged) format, if conversation is not possible

-pure

pingOrDisconnect ( )
protected
renameMailbox ( string  $oldName,
string  $newName 
)

Rename an existing mailbox from $oldName to $newName.

Аргументы
string$oldNameCurrent name of mailbox, which you want to rename (eg. 'PhpImap')
string$newNameNew name of mailbox, to which you want to rename it (eg. 'PhpImapTests')
saveMail ( int  $mailId,
string  $filename = 'email.eml' 
)

Save a specific body section to a file.

Аргументы
int$mailIdmessage number
См. также
imap_savebody()
searchMailbox ( string  $criteria = 'ALL',
bool  $disableServerEncoding = false 
)

This function uses imap_search() to perform a search on the mailbox currently opened in the given IMAP stream. For example, to match all unanswered mails sent by Mom, you'd use: "UNANSWERED FROM mom".

Аргументы
string$criteriaSee http://php.net/imap_search for a complete list of available criteria
bool$disableServerEncodingDisables server encoding while searching for mails (can be useful on Exchange servers)
Возвращает
int[] mailsIds (or empty array)

-return list<int>

-var list<int>

-var list<int>

searchMailboxFrom ( string  $criteria,
string  $sender,
string...  $senders 
)

Search the mailbox for emails from multiple, specific senders.

См. также
Mailbox::searchMailboxFromWithOrWithoutDisablingServerEncoding()
Возвращает
int[]

-return list<int>

searchMailboxFromDisableServerEncoding ( string  $criteria,
string  $sender,
string...  $senders 
)

Search the mailbox for emails from multiple, specific senders whilst not using server encoding.

См. также
Mailbox::searchMailboxFromWithOrWithoutDisablingServerEncoding()
Возвращает
int[]

-return list<int>

searchMailboxFromWithOrWithoutDisablingServerEncoding ( string  $criteria,
bool  $disableServerEncoding,
string  $sender,
string...  $senders 
)
protected

Search the mailbox for emails from multiple, specific senders.

This function wraps Mailbox::searchMailbox() to overcome a shortcoming in ext-imap

Возвращает
int[]

-return list<int>

Аргументы
string$sender
Возвращает
string
searchMailboxMergeResults (   $single_criteria,
  $criteria 
)

Search the mailbox using multiple criteria merging the results.

Аргументы
string$single_criteria
string...$criteria
Возвращает
int[]

-return list<int>

searchMailboxMergeResultsDisableServerEncoding (   $single_criteria,
  $criteria 
)

Search the mailbox using multiple criteria merging the results.

Аргументы
string$single_criteria
string...$criteria
Возвращает
int[]

-return list<int>

searchMailboxMergeResultsWithOrWithoutDisablingServerEncoding (   $disableServerEncoding,
  $single_criteria,
  $criteria 
)
protected

Search the mailbox using different criteria, then merge the results.

Аргументы
bool$disableServerEncoding
string$single_criteria
string...$criteria
Возвращает
int[]

-return list<int>

-var list<int>

setAttachmentFilenameMode ( bool  $attachmentFilenameMode)

Sets / Changes the attachment filename mode.

Аргументы
bool$attachmentFilenameModeAttachment filename mode (e.g. false)
Исключения
InvalidParameterException
setAttachmentsDir ( string  $attachmentsDir)

Set custom folder for attachments in case you want to have tree of folders for each email i.e. a/1 b/1 c/1 where a,b,c - senders, i.e. john@.nosp@m.smit.nosp@m.h.com.

Аргументы
string$attachmentsDirFolder where to save attachments
Исключения
InvalidParameterException
setAttachmentsIgnore ( bool  $attachmentsIgnore)

Set $this->attachmentsIgnore param. Allow to ignore attachments when they are not required and boost performance.

setConnectionArgs ( int  $options = 0,
int  $retriesNum = 0,
array  $params = null 
)

Set custom connection arguments of imap_open method. See http://php.net/imap_open.

Аргументы
string[]|null$params

-param array{DISABLE_AUTHENTICATOR?:string}|array<empty, empty>|null $params

Исключения
InvalidParameterException
setConnectionRetry ( int  $maxAttempts)

Sets / Changes the attempts / retries to connect.

setConnectionRetryDelay ( int  $milliseconds)

Sets / Changes the delay between each attempt / retry to connect.

setExpungeOnDisconnect ( bool  $isEnabled)

Sets 'expunge on disconnect' parameter.

setFlag ( array  $mailsIds,
string  $flag 
)

Causes a store to add the specified flag to the flags set for the mails in the specified sequence.

Аргументы
array$mailsIdsArray of mail IDs
string$flagWhich you can set are , , , , and as defined by RFC2060

-param list<int> $mailsIds

setImapSearchOption ( int  $imapSearchOption)

Sets / Changes the IMAP search option.

Аргументы
int$imapSearchOptionIMAP search option (eg. 'SE_UID')

-param 1|2 $imapSearchOption

Исключения
InvalidParameterException
setMailboxFolder ( )

Sets the folder of the current mailbox.

setPathDelimiter ( string  $delimiter)

Sets / Changes the path delimiter character (Supported values: '.', '/').

Аргументы
string$delimiterPath delimiter
Исключения
InvalidParameterException
setServerEncoding ( string  $serverEncoding)

Sets / Changes the server encoding.

Аргументы
string$serverEncodingServer encoding (eg. 'UTF-8')
Исключения
InvalidParameterException
sortMails ( int  $criteria = SORTARRIVAL,
bool  $reverse = true,
?string  $searchCriteria = 'ALL',
string  $charset = null 
)

Gets mails ids sorted by some criteria.

Criteria can be one (and only one) of the following constants: SORTDATE - mail Date SORTARRIVAL - arrival date (default) SORTFROM - mailbox in first From address SORTSUBJECT - mail subject SORTTO - mailbox in first To address SORTCC - mailbox in first cc address SORTSIZE - size of mail in octets

Аргументы
int$criteriaSorting criteria (eg. SORTARRIVAL)
bool$reverseSort reverse or not
string | null$searchCriteriaSee http://php.net/imap_search for a complete list of available criteria

-param value-of<Imap::SORT_CRITERIA> $criteria

Возвращает
int[] Mails ids

-return list<int>

statusMailbox ( )

Gets status information about the given mailbox.

This function returns an object containing status information. The object has the following properties: messages, recent, unseen, uidnext, and uidvalidity.

subscribeMailbox ( string  $mailbox)

Subscribe to a mailbox.

Исключения
Exception
switchMailbox ( string  $imapPath,
bool  $absolute = true 
)

Switch mailbox without opening a new connection.

Исключения
Exception
unsubscribeMailbox ( string  $mailbox)

Unsubscribe from a mailbox.

Исключения
Exception
validatePathDelimiter ( string  $delimiter)

Validates the given path delimiter character.

Аргументы
string$delimiterPath delimiter
Возвращает
bool true (supported) or false (unsupported)

-pure

Поля

$attachmentFilenameMode = false
protected
$attachmentsDir = null
protected
$attachmentsIgnore = false
protected
$connectionRetry = 0
protected
$connectionRetryDelay = 100
protected
$decodeMimeStrDefaultCharset = 'default'
$expungeOnDisconnect = true
protected
$imapLogin
protected
$imapOptions = 0
protected
$imapParams = []
protected

-var array{DISABLE_AUTHENTICATOR?:string}

$imapPassword
protected
$imapPath
protected
$imapRetriesNum = 0
protected
$imapSearchOption = SE_UID
protected
$mailboxFolder
protected
$pathDelimiter = '.'
protected
$serverEncoding = 'UTF-8'
protected
$timeouts = []
protected
const EXPECTED_SIZE_OF_MESSAGE_AS_ARRAY = 2
const IMAP_OPTIONS_SUPPORTED_VALUES
Инициализатор
=
OP_READONLY
| OP_ANONYMOUS
| OP_HALFOPEN
| CL_EXPUNGE
| OP_DEBUG
| OP_SHORTCACHE
| OP_SILENT
| OP_PROTOTYPE
| OP_SECURE
const MAX_LENGTH_FILEPATH = 255
const PART_TYPE_TWO = 2