Skip to content

Commit eb75db4

Browse files
committed
Allow to change the fetch options
1 parent f2543b6 commit eb75db4

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/IMAP/Client.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,12 @@ public function createFolder($name){
265265
*
266266
* @param Folder $folder
267267
* @param string $criteria
268+
* @param integer $fetch_options
268269
*
269270
* @return array
270271
* @throws GetMessagesFailedException
271272
*/
272-
public function getMessages(Folder $folder, $criteria = 'ALL')
273+
public function getMessages(Folder $folder, $criteria = 'ALL', $fetch_options = null)
273274
{
274275
$this->checkConnection();
275276

@@ -281,7 +282,7 @@ public function getMessages(Folder $folder, $criteria = 'ALL')
281282
if ($availableMessages !== false) {
282283
$msglist = 1;
283284
foreach ($availableMessages as $msgno) {
284-
$message = new Message($msgno, $msglist, $this);
285+
$message = new Message($msgno, $msglist, $this, $fetch_options);
285286

286287
$messages[$message->message_id] = $message;
287288
$msglist++;

src/IMAP/Folder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ public function setChildren($children = []) {
143143
*
144144
* @return \Illuminate\Support\Collection
145145
*/
146-
public function getMessages($criteria = 'ALL') {
147-
return collect($this->client->getMessages($this, $criteria));
146+
public function getMessages($criteria = 'ALL', $fetch_options = null) {
147+
return collect($this->client->getMessages($this, $criteria, $fetch_options));
148148
}
149149

150150
/**

src/IMAP/Message.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ class Message {
3232
*/
3333
public $uid = '';
3434

35+
/**
36+
* Fetch body options
37+
*
38+
* @var string
39+
*/
40+
public $fetch_options = null;
41+
3542
/**
3643
* @var int $msglist
3744
*/
@@ -118,11 +125,13 @@ class Message {
118125
* @param $uid
119126
* @param $msglist
120127
* @param \Webklex\IMAP\Client $client
128+
* @param $fetch_options
121129
*/
122-
public function __construct($uid, $msglist, Client $client) {
130+
public function __construct($uid, $msglist, Client $client, $fetch_options = null) {
123131
$this->uid = $uid;
124132
$this->msglist = $msglist;
125133
$this->client = $client;
134+
$this->fetch_options = ($fetch_options) ? $fetch_options : FT_UID;
126135

127136
$this->parseHeader();
128137
$this->parseBody();
@@ -314,7 +323,7 @@ private function fetchStructure($structure, $partNumber = null) {
314323

315324
$encoding = $this->getEncoding($structure);
316325

317-
$content = imap_fetchbody($this->client->connection, $this->uid, $partNumber, FT_PEEK);
326+
$content = imap_fetchbody($this->client->connection, $this->uid, $partNumber, $this->fetch_options);
318327
$content = $this->decodeString($content, $structure->encoding);
319328
$content = $this->convertEncoding($content, $encoding);
320329

@@ -331,7 +340,7 @@ private function fetchStructure($structure, $partNumber = null) {
331340

332341
$encoding = $this->getEncoding($structure);
333342

334-
$content = imap_fetchbody($this->client->connection, $this->uid, $partNumber, FT_PEEK);
343+
$content = imap_fetchbody($this->client->connection, $this->uid, $partNumber, $this->fetch_options);
335344
$content = $this->decodeString($content, $structure->encoding);
336345
$content = $this->convertEncoding($content, $encoding);
337346

@@ -374,7 +383,7 @@ private function fetchStructure($structure, $partNumber = null) {
374383
break;
375384
}
376385

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

379388
$attachment = new \stdClass;
380389
$attachment->type = $type;

0 commit comments

Comments
 (0)