Download the PHP package seedgabo/laravel-imap without Composer
On this page you can find all versions of the php package seedgabo/laravel-imap. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download seedgabo/laravel-imap
More information about seedgabo/laravel-imap
Files in seedgabo/laravel-imap
Package laravel-imap
Short Description Laravel IMAP client
License MIT
Homepage https://github.com/webklex/laravel-imap
Informations about the package laravel-imap
IMAP Library for Laravel
Description
Laravel IMAP is an easy way to integrate the native php imap library into your Laravel app.
If you want to use this library outside of Laravel, please head over to webklex/php-imap
Table of Contents
- Installation
- Configuration
- Usage
- Basic usage example
- Facade
- Folder / Mailbox
- Search
- Counting messages
- Result limiting
- Pagination
- View examples
- Fetch a specific message
- Message flags
- Attachments
- Advanced fetching
- Masking
- Specials
- Support
- Documentation
- Client::class
- Message::class
- Folder::class
- Query::class
- Attachment::class
- Mask::class
- MessageMask::class
- AttachmentMask::class
- MessageCollection::class
- AttachmentCollection::class
- FolderCollection::class
- FlagCollection::class
- Known issues
- Milestones & upcoming features
- Security
- Credits
- Supporters
- License
Installation
1) Install the php-imap library if it isn't already installed:
You might also want to check phpinfo()
if the extension is enabled.
2) Now install the Laravel IMAP package by running the following command:
3) If you're running Laravel >= 5.5, package discovery will configure the service provider and Client
alias out of the box.
Otherwise, for Laravel <= 5.4, edit your `config/app.php` file and:
- add the following to the `providers` array:
- add the following to the `aliases` array:
4) Run the command below to publish the package config file config/imap.php:
Configuration
If you are planning to use a single account, you might want to add the following to
your .env
file.
Supported protocols:
imap
— Use IMAP [default]pop3
— Use POP3nntp
— Use NNTP
The following encryption methods are supported:
false
— Disable encryptionssl
— Use SSLtls
— Use TLSstarttls
— Use STARTTLS (alias TLS)notls
— Use NoTLS
Detailed config/imap.php configuration:
default
— used default account. It will be used as default for any missing account parameters. If however the default account is missing a parameter the package default will be used. Set tofalse
to disable this functionality.accounts
— all available accountsdefault
— The account identifier (in this casedefault
but could also befooBar
etc).host
— imap hostport
— imap portencryption
— desired encryption methodvalidate_cert
— decide weather you want to verify the certificate or notusername
— imap account usernamepassword
— imap account password
date_format
— The default date format is used to convert any given Carbon::class object into a valid date string. (d-M-Y
,d-M-y
,d M y
)options
— additional fetch optionsdelimiter
— you can use any supported char such as ".", "/", etcfetch
—IMAP::FT_UID
(message marked as read by fetching the message) orIMAP::FT_PEEK
(fetch the message without setting the "read" flag)fetch_body
— If set tofalse
all messages will be fetched without the body and any potential attachmentsfetch_attachment
— If set tofalse
all messages will be fetched without any attachmentsfetch_flags
— If set tofalse
all messages will be fetched without any flagsmessage_key
— Message key identifier optionfetch_order
— Message fetch orderopen
— special configuration for imap_open()DISABLE_AUTHENTICATOR
— Disable authentication properties.
decoder
— Currently only the message subject and attachment name decoder can be setmasks
— Default masking configmessage
— Default message maskattachment
— Default attachment mask
Usage
Basic usage example
This is a basic example, which will echo out all Mails within all imap folders and will move every message into INBOX.read. Please be aware that this should not ben tested in real live but it gives an impression on how things work.
Facade
If you use the Facade \Webklex\IMAP\Facades\Client::class please select an account first:
Folder / Mailbox
There is an experimental function available to get a Folder instance by name.
For an easier access please take a look at the new config option imap.options.delimiter
however the getFolder
method takes three options: the required (string) $folder_name and two optional variables. An integer $attributes which
seems to be sometimes 32 or 64 (I honestly have no clue what this number does, so feel free to enlighten me and anyone
else) and a delimiter which if it isn't set will use the default option configured inside the config/imap.php file.
If you are using Exchange you might want to set all parameter and the last
$prefix_address
tofalse
e.g.$oClient->getFolder('name', 32, null, false)
#234
List all available folders:
Search for messages
Search for specific emails:
Available search aliases for a better code reading:
All available query / search methods can be found here: Query::class
Available search criteria:
ALL
— return all messages matching the rest of the criteriaANSWERED
— match messages with the \ANSWERED flag setBCC
"string" — match messages with "string" in the Bcc: fieldBEFORE
"date" — match messages with Date: before "date"BODY
"string" — match messages with "string" in the body of the messageCC
"string" — match messages with "string" in the Cc: fieldDELETED
— match deleted messagesFLAGGED
— match messages with the \FLAGGED (sometimes referred to as Important or Urgent) flag setFROM
"string" — match messages with "string" in the From: fieldKEYWORD
"string" — match messages with "string" as a keywordNEW
— match new messagesNOT
— not matchingOLD
— match old messagesON
"date" — match messages with Date: matching "date"RECENT
— match messages with the \RECENT flag setSEEN
— match messages that have been read (the \SEEN flag is set)SINCE
"date" — match messages with Date: after "date"SUBJECT
"string" — match messages with "string" in the Subject:TEXT
"string" — match messages with text "string"TO
"string" — match messages with "string" in the To:UNANSWERED
— match messages that have not been answeredUNDELETED
— match messages that are not deletedUNFLAGGED
— match messages that are not flaggedUNKEYWORD
"string" — match messages that do not have the keyword "string"UNSEEN
— match messages which have not been read yet
Further information:
- http://php.net/manual/en/function.imap-search.php
- https://tools.ietf.org/html/rfc1176
- https://tools.ietf.org/html/rfc1064
- https://tools.ietf.org/html/rfc822
- https://gist.github.com/martinrusev/6121028
Result limiting
Limiting the request emails:
Counting messages
Count all available messages matching the current search criteria:
Pagination
Paginate a query:
Paginate a message collection:
Blade example for a paginated list:
You can also paginate a Folder-, Attachment- or FlagCollection instance.
View examples
You can find a few blade examples under /examples.
Fetch a specific message
Get a specific message by uid (Please note that the uid is not unique and can change):
Message flags
Flag or "unflag" a message:
Mark all messages as "read" while fetching:
Don't mark all messages as "read" while fetching:
Attachments
Save message attachments:
Advanced fetching
Fetch messages without body fetching (decrease load):
Fetch messages without body, flag and attachment fetching (decrease load):
Masking
Laravel-IMAP already comes with two default masks AttachmentMask::class.
The masked instance has to be called manually and is designed to add custom functionality.
You can call the default mask by calling the mask method without any arguments.
There are several methods available to set the default mask:
The last one wont set the mask but generate a masked instance using the provided mask.
You could also set the default masks inside your config/imap.php
file under masks
.
You can also apply a mask on attachments:
If you want to implement your own mask just extend AttachmentMask::class or Mask::class and implement your desired logic:
Additional examples can be found here:
Specials
Find the folder containing a message:
Support
If you encounter any problems or if you find a bug, please don't hesitate to create a new issue. However please be aware that it might take some time to get an answer.
If you need immediate or commercial support, feel free to send me a mail at [email protected].
A little notice
If you write source code in your issue, please consider to format it correctly. This makes it so much nicer to read and people are more likely to comment and help :)
``` php
echo 'your php code...';
```
will turn into:
Features & pull requests
Everyone can contribute to this project. Every pull request will be considered but it can also happen to be declined. To prevent unnecessary work, please consider to create a feature issue first, if you're planning to do bigger changes. Of course you can also create a new feature issue if you're just wishing a feature ;)
Off topic, rude or abusive issues will be deleted without any notice.
Documentation
Client::class
Method | Arguments | Return | Description |
---|---|---|---|
setConfig | array $config | self | Set the Client configuration. Take a look at config/imap.php for more inspiration. |
getConnection | resource $connection | resource | Get the current imap resource |
setReadOnly | bool $readOnly | self | Set read only property and reconnect if it's necessary. |
isReadOnly | bool | Determine if connection is in read only mode. | |
isConnected | bool | Determine if connection was established. | |
checkConnection | Determine if connection was established and connect if not. | ||
connect | int $attempts | Connect to server. | |
disconnect | Disconnect from server. | ||
getFolder | string $folder_name, int $attributes = 32, int or null $delimiter, bool $prefix_address | Folder | Get a Folder instance by name |
getFolders | bool $hierarchical, string or null $parent_folder | FolderCollection | Get folders list. If hierarchical order is set to true, it will make a tree of folders, otherwise it will return flat array. |
openFolder | string or Folder $folder, integer $attempts | Open a given folder. | |
createFolder | string $name | boolean | Create a new folder. |
renameFolder | string $old_name, string $new_name | boolean | Rename a folder. |
deleteFolder | string $name | boolean | Delete a folder. |
getMessages | Folder $folder, string $criteria, bool $fetch_body, bool $fetch_attachment, bool $fetch_flags | MessageCollection | Get messages from folder. |
getUnseenMessages | Folder $folder, string $criteria, bool $fetch_body, bool $fetch_attachment, bool $fetch_flags | MessageCollection | Get Unseen messages from folder. |
searchMessages | array $where, Folder $folder, $fetch_options, bool $fetch_body, string $charset, bool $fetch_attachment, bool $fetch_flags | MessageCollection | Get specific messages from a given folder. |
getQuota | array | Retrieve the quota level settings, and usage statics per mailbox | |
getQuotaRoot | string $quota_root | array | Retrieve the quota settings per user |
countMessages | int | Gets the number of messages in the current mailbox | |
countRecentMessages | int | Gets the number of recent messages in current mailbox | |
getAlerts | array | Returns all IMAP alert messages that have occurred | |
getErrors | array | Returns all of the IMAP errors that have occurred | |
getLastError | string | Gets the last IMAP error that occurred during this page request | |
expunge | bool | Delete all messages marked for deletion | |
checkCurrentMailbox | object | Check current mailbox | |
setTimeout | string or int $type, int $timeout | boolean | Set the timeout for certain imap operations: 1: Open, 2: Read, 3: Write, 4: Close |
getTimeout | string or int $type | int | Check current mailbox |
setDefaultMessageMask | string $mask | self | Set the default message mask class |
getDefaultMessageMask | string | Get the current default message mask class name | |
setDefaultAttachmentMask | string $mask | self | Set the default attachment mask class |
getDefaultAttachmentMask | string | Get the current default attachment mask class name | |
getFolderPath | string | Get the current folder path |
Message::class
Method | Arguments | Return | Description |
---|---|---|---|
parseBody | Message | Parse the Message body | |
delete | boolean $expunge | boolean | Delete the current Message |
restore | boolean $expunge | boolean | Restore a deleted Message |
copy | string $mailbox, int $options | boolean | Copy the current Messages to a mailbox |
move | string $mailbox, int $options | boolean | Move the current Messages to a mailbox |
getContainingFolder | Folder or null $folder | Folder or null | Get the folder containing the message |
moveToFolder | string $mailbox, boolean $expunge, boolean $create_folder | Message | Move the Message into an other Folder |
setFlag | string or array $flag | boolean | Set one or many flags |
unsetFlag | string or array $flag | boolean | Unset one or many flags |
hasTextBody | Check if the Message has a text body | ||
hasHTMLBody | Check if the Message has a html body | ||
getTextBody | string | Get the Message text body | |
getHTMLBody | string | Get the Message html body | |
getAttachments | AttachmentCollection | Get all message attachments | |
hasAttachments | boolean | Checks if there are any attachments present | |
getClient | Client | Get the current Client instance | |
getUid | string | Get the current UID | |
getFetchOptions | string | Get the current fetch option | |
getMsglist | integer | Get the current message list | |
getHeaderInfo | object | Get the current header_info object | |
getHeader | string | Get the current raw header | |
getMessageId | string | Get the current message ID | |
getMessageNo | integer | Get the current message number | |
getPriority | integer | Get the current message priority | |
getSubject | string | Get the current subject | |
getReferences | mixed | Get any potentially present references | |
getDate | Carbon | Get the current date object | |
getFrom | array | Get the current from information | |
getTo | array | Get the current to information | |
getCc | array | Get the current cc information | |
getBcc | array | Get the current bcc information | |
getReplyTo | array | Get the current reply to information | |
getInReplyTo | string | Get the current In-Reply-To | |
getSender | array | Get the current sender information | |
getBodies | mixed | Get the current bodies | |
getRawBody | mixed | Get the current raw message body | |
getFlags | FlagCollection | Get the current message flags | |
is | boolean | Does this message match another one? | |
getStructure | object | The raw message structure | |
getFolder | Folder | The current folder | |
mask | string $mask = null | Mask | Get a masked instance |
setMask | string $mask | Message | Set the mask class |
getMask | string | Get the current mask class name |
Folder::class
Method | Arguments | Return | Description |
---|---|---|---|
hasChildren | bool | Determine if folder has children. | |
setChildren | array $children | self | Set children. |
getMessage | integer $uid, integer or null $msglist, int or null fetch_options, bool $fetch_body, bool $fetch_attachment, bool $fetch_flags | Message | Get a specific message from folder. |
getMessages | string $criteria, int or null $fetch_options, bool $fetch_body, bool $fetch_attachment, bool $fetch_flags | MessageCollection | Get messages from folder. |
getUnseenMessages | string $criteria, int or null $fetch_options, bool $fetch_body, bool $fetch_attachment, bool $fetch_flags | MessageCollection | Get Unseen messages from folder. |
searchMessages | array $where, int or null $fetch_options, bool $fetch_body, string $charset, bool $fetch_attachment, bool $fetch_flags | MessageCollection | Get specific messages from a given folder. |
delete | Delete the current Mailbox | ||
move | string $mailbox | Move or Rename the current Mailbox | |
getStatus | integer $options | object | Returns status information on a mailbox |
appendMessage | string $message, string $options, string $internal_date | bool | Append a string message to the current mailbox |
getClient | Client | Get the current Client instance | |
query | string $charset = 'UTF-8' | WhereQuery | Get the current Client instance |
messages | string $charset = 'UTF-8' | WhereQuery | Alias for Folder::query() |
search | string $charset = 'UTF-8' | WhereQuery | Alias for Folder::query() |
Query::class
Method | Arguments | Return | Description |
---|---|---|---|
where | mixed $criteria, $value = null | WhereQuery | Add new criteria to the current query |
orWhere | Closure $closure | WhereQuery | If supported you can perform extended search requests |
andWhere | Closure $closure | WhereQuery | If supported you can perform extended search requests |
all | WhereQuery | Select all available messages | |
answered | WhereQuery | Select answered messages | |
deleted | WhereQuery | Select deleted messages | |
new | WhereQuery | Select new messages | |
not | WhereQuery | Not select messages | |
old | WhereQuery | Select old messages | |
recent | WhereQuery | Select recent messages | |
seen | WhereQuery | Select seen messages | |
unanswered | WhereQuery | Select unanswered messages | |
undeleted | WhereQuery | Select undeleted messages | |
unflagged | WhereQuery | Select unflagged messages | |
unseen | WhereQuery | Select unseen messages | |
noXSpam | WhereQuery | Select as no xspam flagged messages | |
isXSpam | WhereQuery | Select as xspam flagged messages | |
language | string $value | WhereQuery | Select messages matching a given language |
unkeyword | string $value | WhereQuery | Select messages matching a given unkeyword |
messageId | string $value | WhereQuery | Select messages matching a given message id |
to | string $value | WhereQuery | Select messages matching a given receiver (To:) |
text | string $value | WhereQuery | Select messages matching a given text body |
subject | string $value | WhereQuery | Select messages matching a given subject |
since | string $value | WhereQuery | Select messages since a given date |
on | string $value | WhereQuery | Select messages on a given date |
keyword | string $value | WhereQuery | Select messages matching a given keyword |
from | string $value | WhereQuery | Select messages matching a given sender (From:) |
flagged | string $value | WhereQuery | Select messages matching a given flag |
cc | string $value | WhereQuery | Select messages matching a given receiver (CC:) |
body | string $value | WhereQuery | Select messages matching a given HTML body |
before | string $value | WhereQuery | Select messages before a given date |
bcc | string $value | WhereQuery | Select messages matching a given receiver (BCC:) |
count | integer | Count all available messages matching the current search criteria | |
get | MessageCollection | Fetch messages with the current query | |
limit | integer $limit, integer $page = 1 | WhereQuery | Limit the amount of messages being fetched |
setFetchOptions | boolean $fetch_options | WhereQuery | Set the fetch options |
setFetchBody | boolean $fetch_body | WhereQuery | Set the fetch body option |
getFetchAttachment | boolean $fetch_attachment | WhereQuery | Set the fetch attachment option |
setFetchFlags | boolean $fetch_flags | WhereQuery | Set the fetch flags option |
leaveUnread | WhereQuery | Don't mark all messages as "read" while fetching: | |
markAsRead | WhereQuery | Mark all messages as "read" while fetching | |
paginate | int $perPage = 5, $page = null, $pageName = 'imap_page' | LengthAwarePaginator | Paginate the current query. |
Attachment::class
Method | Arguments | Return | Description |
---|---|---|---|
getContent | string or null | Get attachment content | |
getMimeType | string or null | Get attachment mime type | |
getExtension | string or null | Get a guessed attachment extension | |
getName | string or null | Get attachment name | |
getType | string or null | Get attachment type | |
getDisposition | string or null | Get attachment disposition | |
getContentType | string or null | Get attachment content type | |
getImgSrc | string or null | Get attachment image source as base64 encoded data url | |
save | string $path, string $filename | boolean | Save the attachment content to your filesystem |
mask | string $mask = null | Mask | Get a masked instance |
setMask | string $mask | Attachment | Set the mask class |
getMask | string | Get the current mask class name |
Mask::class
Method | Arguments | Return | Description |
---|---|---|---|
getParent | Masked parent | Get the masked parent object | |
getAttributes | array | Get all cloned attributes | |
__get | mixed | Access any cloned parent attribute | |
__set | mixed | Set any cloned parent attribute | |
__inherit | mixed | All public methods of the given parent are callable |
MessageMask::class
Method | Arguments | Return | Description |
---|---|---|---|
getHtmlBody | string or null | Get HTML body | |
getCustomHTMLBody | callable or bool $callback | string or null | Get a custom HTML body |
getHTMLBodyWithEmbeddedBase64Images | string or null | Get HTML body with embedded base64 images | |
getHTMLBodyWithEmbeddedUrlImages | string $route_name, array $params = [] | string or null | Get HTML body with embedded routed images |
AttachmentMask::class
Method | Arguments | Return | Description |
---|---|---|---|
getContentBase64Encoded | string or null | Get attachment content | |
getImageSrc | string or null | Get attachment mime type |
MessageCollection::class
Extends Illuminate\Support\Collection::class
Method | Arguments | Return | Description |
---|---|---|---|
paginate | int $perPage = 15, $page = null, $pageName = 'page' | LengthAwarePaginator | Paginate the current collection. |
FlagCollection::class
Extends Illuminate\Support\Collection::class
Method | Arguments | Return | Description |
---|---|---|---|
paginate | int $perPage = 15, $page = null, $pageName = 'page' | LengthAwarePaginator | Paginate the current collection. |
AttachmentCollection::class
Extends Illuminate\Support\Collection::class
Method | Arguments | Return | Description |
---|---|---|---|
paginate | int $perPage = 15, $page = null, $pageName = 'page' | LengthAwarePaginator | Paginate the current collection. |
FolderCollection::class
Extends Illuminate\Support\Collection::class
Method | Arguments | Return | Description |
---|---|---|---|
paginate | int $perPage = 15, $page = null, $pageName = 'page' | LengthAwarePaginator | Paginate the current collection. |
Known issues
Error | Solution |
---|---|
Kerberos error: No credentials cache file found (try running kinit) (...) | Uncomment "DISABLE_AUTHENTICATOR" inside config/imap.php |
imap_fetchbody() expects parameter 4 to be long, string given (...) | Make sure that imap.options.fetch is a valid integer |
Use of undefined constant FT_UID - assumed 'FT_UID' (...) | Please take a look at #14 #30 |
DateTime::__construct(): Failed to parse time string (...) | Please report any new invalid timestamps to #45 |
imap_open(): Couldn't open (...) Please log in your web browser: (...) | In order to use IMAP on some services (such as Gmail) you need to enable it first. Google help page |
imap_headerinfo(): Bad message number | This happens if no Message number is available. Please make sure Message::parseHeader() has run before |
imap_open(): Couldn't open stream {outlook.office365.com:993/imap/s (...) | Can be caused by a lot of things: head over to these issues for more information: #153 #100 #78 |
Milestones & upcoming features
- Wiki!!
Change log
Please see CHANGELOG for more information what has changed recently.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
Supporters
A special thanks to Jetbrains for supporting this project through their open source license program.
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-imap with dependencies
ext-imap Version *
ext-mbstring Version *
ext-iconv Version *
ext-fileinfo Version *
laravel/framework Version >=5.0.0