Skip to content

Commit cfd6f55

Browse files
committed
Snippits updated
1 parent a4f8781 commit cfd6f55

File tree

1 file changed

+29
-59
lines changed

1 file changed

+29
-59
lines changed

README.md

Lines changed: 29 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ Detailed [config/imap.php](src/config/imap.php) configuration:
9191
- `validate_cert` — decide weather you want to verify the certificate or not
9292
- `username` — imap account username
9393
- `password` — imap account password
94-
- `options` — additional fetch options
95-
- `delimiter` — you can use any supported char such as ".", "/", etc
96-
- `fetch` — `FT_UID` (message marked as read by fetching the message) or `FT_PEEK` (fetch the message without setting the "read" flag)
97-
- `open` — special configuration for imap_open()
98-
- `DISABLE_AUTHENTICATOR` — Disable authentication properties.
94+
- `options` — additional fetch options
95+
- `delimiter` — you can use any supported char such as ".", "/", etc
96+
- `fetch` — `FT_UID` (message marked as read by fetching the message) or `FT_PEEK` (fetch the message without setting the "read" flag)
97+
- `open` — special configuration for imap_open()
98+
- `DISABLE_AUTHENTICATOR` — Disable authentication properties.
9999

100100
## Usage
101101

@@ -126,8 +126,11 @@ $aMailboxes = $oClient->getFolders();
126126
foreach($aMailboxes as $oMailbox){
127127

128128
//Get all Messages of the current Mailbox
129+
/** @var \Webklex\IMAP\Support\MessageCollection $oMessage */
130+
$aMessage = $oMailbox->getMessages();
131+
129132
/** @var \Webklex\IMAP\Message $oMessage */
130-
foreach($oMailbox->getMessages() as $oMessage){
133+
foreach($aMessage as $oMessage){
131134
echo $oMessage->subject.'<br />';
132135
echo 'Attachments: '.$oMessage->getAttachments()->count().'<br />';
133136
echo $oMessage->getHTMLBody(true);
@@ -157,11 +160,7 @@ method takes three options: the required (string) $folder_name and two optional
157160
seems to be sometimes 32 or 64 (I honestly have no clue what this number does, so feel free to enlighten me and anyone
158161
else) and a delimiter which if it isn't set will use the default option configured inside the [config/imap.php](src/config/imap.php) file.
159162
``` php
160-
use Webklex\IMAP\Facades\Client;
161-
162163
/** @var \Webklex\IMAP\Client $oClient */
163-
$oClient = Client::account('default');
164-
$oClient->connect();
165164

166165
/** @var \Webklex\IMAP\Folder $oFolder */
167166
$oFolder = $oClient->getFolder('INBOX.name');
@@ -179,25 +178,19 @@ foreach($aMessage as $oMessage){
179178

180179
Search for specific emails:
181180
``` php
182-
use Webklex\IMAP\Facades\Client;
183-
184-
/** @var \Webklex\IMAP\Client $oClient */
185-
$oClient = Client::account('default');
186-
$oClient->connect();
187-
188181
/** @var \Webklex\IMAP\Folder $oFolder */
189-
$oFolder = $oClient->getFolder('INBOX.name');
190182

191183
//Get all messages since march 15 2018
192184
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
193185
$aMessage = $oFolder->searchMessages([['SINCE', Carbon::parse('15.03.2018')->format('d M y')]]);
194186

195-
/** @var \Webklex\IMAP\Message $oMessage */
196-
foreach($aMessage as $oMessage){
197-
echo $oMessage->subject.'<br />';
198-
echo 'Attachments: '.$oMessage->getAttachments()->count().'<br />';
199-
echo $oMessage->getHTMLBody(true);
200-
}
187+
//Get all messages containing "hello world"
188+
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
189+
$aMessage = $oFolder->searchMessages([['TEXT', 'hello world']]);
190+
191+
//Get all unseen messages containing "hello world"
192+
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
193+
$aMessage = $oFolder->searchMessages([['UNSEEN'], ['TEXT', 'hello world']]);
201194
```
202195

203196
Available search criteria:
@@ -234,34 +227,15 @@ Further information:
234227

235228
Paginate a message collection:
236229
``` php
237-
use Webklex\IMAP\Facades\Client;
238-
239-
/** @var \Webklex\IMAP\Client $oClient */
240-
$oClient = Client::account('default');
241-
$oClient->connect();
242-
243-
/** @var \Webklex\IMAP\Folder $oFolder */
244-
$oFolder = $oClient->getFolder('INBOX.name');
245-
246-
//Get all messages containing "hello world"
247230
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
248-
$aMessage = $oFolder->searchMessages([['TEXT', 'hello world']]);
249231

250232
/** @var \Illuminate\Pagination\LengthAwarePaginator $paginator */
251233
$paginator = $aMessage->paginate();
252234
```
253235

254236
Get a specific message by uid (Please note that the uid is not unique and can change):
255237
``` php
256-
use Webklex\IMAP\Facades\Client;
257-
258-
/** @var \Webklex\IMAP\Client $oClient */
259-
$oClient = Client::account('default');
260-
$oClient->connect();
261-
262238
/** @var \Webklex\IMAP\Folder $oFolder */
263-
$oFolder = $oClient->getFolder('INBOX.name');
264-
265239
/** @var \Webklex\IMAP\Message $oMessage */
266240
$oMessage = $oFolder->getMessage($uid = 1);
267241
```
@@ -276,23 +250,19 @@ $oMessage->unsetFlag('Spam');
276250
Save message attachments:
277251
``` php
278252
/** @var \Webklex\IMAP\Message $oMessage */
279-
$oMessage->getAttachments()->each(function ($oAttachment) use ($oMessage) {
253+
254+
/** @var \Webklex\IMAP\Support\AttachmentCollection $aAttachment */
255+
$aAttachment = $oMessage->getAttachments();
256+
257+
$aAttachment->each(function ($oAttachment) use ($oMessage) {
280258
/** @var \Webklex\IMAP\Attachment $oAttachment */
281-
file_put_contents($oAttachment->getName(), $oAttachment->getContent());
282259
$oAttachment->save();
283260
});
284261
```
285262

286263
Fetch messages without body parsing (decrease load):
287264
``` php
288-
use Webklex\IMAP\Facades\Client;
289-
290-
/** @var \Webklex\IMAP\Client $oClient */
291-
$oClient = Client::account('default');
292-
$oClient->connect();
293-
294265
/** @var \Webklex\IMAP\Folder $oFolder */
295-
$oFolder = $oClient->getFolder('INBOX.name');
296266

297267
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
298268
$aMessage = $oFolder->searchMessages([['TEXT', 'Hello world']], null, false);
@@ -383,14 +353,14 @@ $aMessage = $oFolder->getMessages('ALL', null, false);
383353
| getClient | | Client | Get the current Client instance |
384354

385355
### [Attachment::class](src/IMAP/Attachment.php)
386-
| Method | Arguments | Return | Description |
387-
| -------------- | ---------- | :------------: | ------------------------------------------------------ |
388-
| getContent | | string or null | Get attachment content |
389-
| getName | | string or null | Get attachment name |
390-
| getType | | string or null | Get attachment type |
391-
| getDisposition | | string or null | Get attachment disposition |
392-
| getContentType | | string or null | Get attachment content type |
393-
| getImgSrc | | string or null | Get attachment image source as base64 encoded data url |
356+
| Method | Arguments | Return | Description |
357+
| -------------- | ------------------------------ | :------------: | ------------------------------------------------------ |
358+
| getContent | | string or null | Get attachment content |
359+
| getName | | string or null | Get attachment name |
360+
| getType | | string or null | Get attachment type |
361+
| getDisposition | | string or null | Get attachment disposition |
362+
| getContentType | | string or null | Get attachment content type |
363+
| getImgSrc | | string or null | Get attachment image source as base64 encoded data url |
394364
| save | string $path, string $filename | boolean | Save the attachment content to your filesystem |
395365

396366
### [MessageCollection::class](src/IMAP/Support/MessageCollection.php)

0 commit comments

Comments
 (0)