Skip to content

Commit 06baaf0

Browse files
author
Malte Goldenbaum
committed
Merge branch 'master' of https://github.com/Webklex/laravel-imap
2 parents 9525772 + add1a03 commit 06baaf0

File tree

5 files changed

+105
-62
lines changed

5 files changed

+105
-62
lines changed

CHANGELOG.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,37 @@ All notable changes to `webklex/laravel-imap` will be documented in this file.
55
Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
66

77
## [UNRELEASED]
8-
-Wrong documentation removed
98
-New config parameter added
109
-Typo fixed
1110

11+
### Affected Classes
12+
\Webklex\IMAP\Client
13+
14+
## [1.0.2.8] - 2017-06-25
15+
### Added
16+
-Message attribute is now case insensitive
17+
-Readme file extended
18+
-Changelog typo fixed
19+
20+
### Affected Classes
21+
\Webklex\IMAP\Message
22+
23+
24+
## [1.0.2.7] - 2017-04-23
25+
### Added
26+
-imap_fetchheader(): Bad message number - merged
27+
-Changed the default options in imap_fetchbody function - merged
28+
-Attachment handling fixed (Plain text files are no longer ignored)
29+
-Optional config parameter added.
30+
-Readme file extended
31+
32+
### Changes
33+
\Webklex\IMAP\Client
34+
\Webklex\IMAP\Message
35+
\Webklex\IMAP\Folder
36+
37+
>>>>>>> add1a03fed0574f7a738b049b19e329896020c24
38+
1239
## [1.0.2.3] - 2017-03-09
1340
### Added
1441
-Code commented

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ You can define your accounts inside the `config/imap.php` file:
133133
```
134134

135135
## Documentation
136-
### \Webklex\IMAP\Client
136+
### [Client::class](src/IMAP/Client.php)
137137
| Method | Arguments | Return | Description |
138138
| --------------------- | ------------------------------------------------- | :-----: | ---------------------------------------------------------------------------------------------------------------------------- |
139139
| setConfig | array $config | self | Set the Client configuration. Take a look at `config/imap.php` for more inspiration. |
@@ -157,7 +157,7 @@ You can define your accounts inside the `config/imap.php` file:
157157
| expunge | | bool | Delete all messages marked for deletion |
158158
| checkCurrentMailbox | | object | Check current mailbox |
159159

160-
### \Webklex\IMAP\Message
160+
### [Message::class](src/IMAP/Message.php)
161161
| Method | Arguments | Return | Description |
162162
| -------------- | ----------------------------- | :---------: | -------------------------------------- |
163163
| delete | | | Delete the current Message |
@@ -171,7 +171,7 @@ You can define your accounts inside the `config/imap.php` file:
171171
| getHTMLBody | | string | Get the Message html body |
172172
| getAttachments | | collection | Get all message attachments |
173173

174-
### \Webklex\IMAP\Folder
174+
### [Folder::class](src/IMAP/Folder.php)
175175
| Method | Arguments | Return | Description |
176176
| ------------- | ------------------------------------------------------- | :-----: | ---------------------------------------------- |
177177
| hasChildren | | bool | Determine if folder has children. |

src/IMAP/Client.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Webklex\IMAP\Exceptions\GetMessagesFailedException;
1919

2020
class Client {
21+
2122
/**
2223
* @var bool|resource
2324
*/

src/IMAP/Message.php

Lines changed: 70 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,10 @@ private function parseBody() {
311311
* Fetch the Message structure
312312
*
313313
* @param $structure
314-
*
315314
* @param mixed $partNumber
316315
*/
317316
private function fetchStructure($structure, $partNumber = null) {
318-
if ($structure->type == self::TYPE_TEXT && $partNumber == null) {
317+
if ($structure->type == self::TYPE_TEXT) {
319318
if ($structure->subtype == "PLAIN") {
320319
if (!$partNumber) {
321320
$partNumber = 1;
@@ -333,6 +332,8 @@ private function fetchStructure($structure, $partNumber = null) {
333332

334333
$this->bodies['text'] = $body;
335334

335+
$this->fetchAttachment($structure, $partNumber);
336+
336337
} elseif ($structure->subtype == "HTML") {
337338
if (!$partNumber) {
338339
$partNumber = 1;
@@ -359,72 +360,83 @@ private function fetchStructure($structure, $partNumber = null) {
359360
$this->fetchStructure($subStruct, $prefix . ($index + 1));
360361
}
361362
} else {
362-
switch ($structure->type) {
363-
case self::TYPE_APPLICATION:
364-
$type = 'application';
365-
break;
366-
case self::TYPE_AUDIO:
367-
$type = 'audio';
368-
break;
369-
case self::TYPE_IMAGE:
370-
$type = 'image';
371-
break;
372-
case self::TYPE_VIDEO:
373-
$type = 'video';
374-
break;
375-
case self::TYPE_MODEL:
376-
$type = 'model';
377-
break;
378-
case self::TYPE_OTHER:
379-
$type = 'other';
380-
break;
381-
default:
382-
$type = 'other';
383-
break;
384-
}
363+
$this->fetchAttachment($structure, $partNumber);
364+
}
365+
}
385366

386-
$content = imap_fetchbody($this->client->connection, $this->uid, ($partNumber) ? $partNumber : 1, $this->fetch_options);
387367

388-
$attachment = new \stdClass;
389-
$attachment->type = $type;
390-
$attachment->content_type = $type.'/'.strtolower($structure->subtype);
391-
$attachment->content = $this->decodeString($content, $structure->encoding);
368+
/**
369+
* Fetch the Message attachment
370+
*
371+
* @param object $structure
372+
* @param mixed $partNumber
373+
*/
374+
protected function fetchAttachment($structure, $partNumber){
375+
switch ($structure->type) {
376+
case self::TYPE_APPLICATION:
377+
$type = 'application';
378+
break;
379+
case self::TYPE_AUDIO:
380+
$type = 'audio';
381+
break;
382+
case self::TYPE_IMAGE:
383+
$type = 'image';
384+
break;
385+
case self::TYPE_VIDEO:
386+
$type = 'video';
387+
break;
388+
case self::TYPE_MODEL:
389+
$type = 'model';
390+
break;
391+
case self::TYPE_OTHER:
392+
$type = 'other';
393+
break;
394+
default:
395+
$type = 'other';
396+
break;
397+
}
392398

393-
$attachment->id = false;
394-
if (property_exists($structure, 'id')) {
395-
$attachment->id = str_replace(['<', '>'], '', $structure->id);
396-
}
399+
$content = imap_fetchbody($this->client->connection, $this->uid, ($partNumber) ? $partNumber : 1, $this->fetch_options);
400+
401+
$attachment = new \stdClass;
402+
$attachment->type = $type;
403+
$attachment->content_type = $type.'/'.strtolower($structure->subtype);
404+
$attachment->content = $this->decodeString($content, $structure->encoding);
405+
406+
$attachment->id = false;
407+
if (property_exists($structure, 'id')) {
408+
$attachment->id = str_replace(['<', '>'], '', $structure->id);
409+
}
397410

398-
$attachment->name = false;
399-
if (property_exists($structure, 'dparameters')) {
400-
foreach ($structure->dparameters as $parameter) {
401-
if ($parameter->attribute == "filename") {
402-
$attachment->name = $parameter->value;
403-
break;
404-
}
411+
$attachment->name = false;
412+
if (property_exists($structure, 'dparameters')) {
413+
foreach ($structure->dparameters as $parameter) {
414+
if (strtolower($parameter->attribute) == "filename") {
415+
$attachment->name = $parameter->value;
416+
break;
405417
}
406418
}
419+
}
407420

408-
if (!$attachment->name && property_exists($structure, 'parameters')) {
409-
foreach ($structure->parameters as $parameter) {
410-
if ($parameter->attribute == "name") {
411-
$attachment->name = $parameter->value;
412-
break;
413-
}
421+
if (!$attachment->name && property_exists($structure, 'parameters')) {
422+
foreach ($structure->parameters as $parameter) {
423+
if (strtolower($parameter->attribute) == "name") {
424+
$attachment->name = $parameter->value;
425+
break;
414426
}
415427
}
428+
}
416429

417-
if ($attachment->type == 'image') {
418-
$attachment->img_src = 'data:'.$attachment->content_type.';base64,'.base64_encode($attachment->content);
419-
}
430+
if ($attachment->type == 'image') {
431+
$attachment->img_src = 'data:'.$attachment->content_type.';base64,'.base64_encode($attachment->content);
432+
}
420433

421-
if(property_exists($attachment, 'name')){
422-
if($attachment->name != false){
423-
if ($attachment->id) {
424-
$this->attachments[$attachment->id] = $attachment;
425-
} else {
426-
$this->attachments[] = $attachment;
427-
}
434+
if(property_exists($attachment, 'name')){
435+
if($attachment->name != false){
436+
if ($attachment->id) {
437+
$this->attachments[$attachment->id] = $attachment;
438+
} else {
439+
$this->attachments[] = $attachment;
428440
}
429441
}
430442
}
@@ -483,7 +495,7 @@ private function convertEncoding($str, $from = "ISO-8859-2", $to = "UTF-8") {
483495
private function getEncoding($structure) {
484496
if (property_exists($structure, 'parameters')) {
485497
foreach ($structure->parameters as $parameter) {
486-
if ($parameter->attribute == "charset") {
498+
if (strtolower($parameter->attribute) == "charset") {
487499
return strtoupper($parameter->value);
488500
}
489501
}

src/config/imap.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
|--------------------------------------------------------------------------
7070
|
7171
| Available php imap config parameters are listed below
72+
| -Fetch option:
73+
| FT_UID => Message marked as read by fetching the message
74+
| FT_PEEK => Fetch the message without setting the "read" flag
7275
|
7376
*/
7477
'options' => [

0 commit comments

Comments
 (0)