Skip to content

Commit ad12170

Browse files
committed
Merge remote-tracking branch 'origin/master' into release/1.2.1
2 parents 0a8654c + 10b243d commit ad12170

File tree

5 files changed

+113
-31
lines changed

5 files changed

+113
-31
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ $oFolder = $aMessage->getContainingFolder();
291291
| setConfig | array $config | self | Set the Client configuration. Take a look at `config/imap.php` for more inspiration. |
292292
| getConnection | resource $connection | resource | Get the current imap resource |
293293
| setReadOnly | bool $readOnly | self | Set read only property and reconnect if it's necessary. |
294-
| setFetchOption | integer $option | self | Fail proof setter for $fetch_option |
295294
| isReadOnly | | bool | Determine if connection is in read only mode. |
296295
| isConnected | | bool | Determine if connection was established. |
297296
| checkConnection | | | Determine if connection was established and connect if not. |
@@ -303,9 +302,9 @@ $oFolder = $aMessage->getContainingFolder();
303302
| createFolder | string $name | boolean | Create a new folder. |
304303
| renameFolder | string $old_name, string $new_name | boolean | Rename a folder. |
305304
| deleteFolder | string $name | boolean | Delete a folder. |
306-
| getMessages | Folder $folder, string $criteria, bool $fetch_body, bool $fetch_attachment | MessageCollection | Get messages from folder. |
307-
| getUnseenMessages | Folder $folder, string $criteria, bool $fetch_body, bool $fetch_attachment | MessageCollection | Get Unseen messages from folder. |
308-
| searchMessages | array $where, Folder $folder, $fetch_options, bool $fetch_body, string $charset, bool $fetch_attachment | MessageCollection | Get specific messages from a given folder. |
305+
| getMessages | Folder $folder, string $criteria, bool $fetch_body, bool $fetch_attachment, bool $fetch_flags | MessageCollection | Get messages from folder. |
306+
| getUnseenMessages | Folder $folder, string $criteria, bool $fetch_body, bool $fetch_attachment, bool $fetch_flags | MessageCollection | Get Unseen messages from folder. |
307+
| 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. |
309308
| getQuota | | array | Retrieve the quota level settings, and usage statics per mailbox |
310309
| getQuotaRoot | string $quota_root | array | Retrieve the quota settings per user |
311310
| countMessages | | int | Gets the number of messages in the current mailbox |
@@ -354,17 +353,18 @@ $oFolder = $aMessage->getContainingFolder();
354353
| getSender | | array | Get the current sender information |
355354
| getBodies | | mixed | Get the current bodies |
356355
| getRawBody | | mixed | Get the current raw message body |
356+
| getFlags | | array | Get the current message flags |
357357
| is | | boolean | Does this message match another one? |
358358

359359
### [Folder::class](src/IMAP/Folder.php)
360360
| Method | Arguments | Return | Description |
361361
| ----------------- | ----------------------------------------------------------------------------------- | :---------------: | ---------------------------------------------- |
362362
| hasChildren | | bool | Determine if folder has children. |
363363
| setChildren | array $children | self | Set children. |
364-
| getMessage | integer $uid, integer or null $msglist, int or null fetch_options, bool $fetch_body, bool $fetch_attachment | Message | Get a specific message from folder. |
365-
| getMessages | string $criteria, bool $fetch_body, bool $fetch_attachment | MessageCollection | Get messages from folder. |
366-
| getUnseenMessages | string $criteria, bool $fetch_body, bool $fetch_attachment | MessageCollection | Get Unseen messages from folder. |
367-
| searchMessages | array $where, $fetch_options, bool $fetch_body, string $charset, bool $fetch_attachment | MessageCollection | Get specific messages from a given folder. |
364+
| 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. |
365+
| getMessages | string $criteria, int or null $fetch_options, bool $fetch_body, bool $fetch_attachment, bool $fetch_flags | MessageCollection | Get messages from folder. |
366+
| getUnseenMessages | string $criteria, int or null $fetch_options, bool $fetch_body, bool $fetch_attachment, bool $fetch_flags | MessageCollection | Get Unseen messages from folder. |
367+
| 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. |
368368
| delete | | | Delete the current Mailbox |
369369
| move | string $mailbox | | Move or Rename the current Mailbox |
370370
| getStatus | integer $options | object | Returns status information on a mailbox |

src/IMAP/Client.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ public function deleteFolder($name) {
374374
* @deprecated 1.0.5.2:2.0.0 No longer needed. Use Folder::getMessages() instead
375375
* @see Folder::getMessages()
376376
*/
377-
public function getMessages(Folder $folder, $criteria = 'ALL', $fetch_options = null, $fetch_body = true, $fetch_attachment = true) {
378-
return $folder->getMessages($criteria, $fetch_options, $fetch_body, $fetch_attachment);
377+
public function getMessages(Folder $folder, $criteria = 'ALL', $fetch_options = null, $fetch_body = true, $fetch_attachment = true, $fetch_flags = false) {
378+
return $folder->getMessages($criteria, $fetch_options, $fetch_body, $fetch_attachment, $fetch_flags);
379379
}
380380

381381
/**
@@ -395,8 +395,8 @@ public function getMessages(Folder $folder, $criteria = 'ALL', $fetch_options =
395395
* @deprecated 1.0.5:2.0.0 No longer needed. Use Folder::getMessages('UNSEEN') instead
396396
* @see Folder::getMessages()
397397
*/
398-
public function getUnseenMessages(Folder $folder, $criteria = 'UNSEEN', $fetch_options = null, $fetch_body = true, $fetch_attachment = true) {
399-
return $folder->getUnseenMessages($criteria, $fetch_options, $fetch_body, $fetch_attachment);
398+
public function getUnseenMessages(Folder $folder, $criteria = 'UNSEEN', $fetch_options = null, $fetch_body = true, $fetch_attachment = true, $fetch_flags = false) {
399+
return $folder->getUnseenMessages($criteria, $fetch_options, $fetch_body, $fetch_attachment, $fetch_flags);
400400
}
401401

402402
/**
@@ -418,8 +418,8 @@ public function getUnseenMessages(Folder $folder, $criteria = 'UNSEEN', $fetch_o
418418
* @see Folder::searchMessages()
419419
*
420420
*/
421-
public function searchMessages(array $where, Folder $folder, $fetch_options = null, $fetch_body = true, $charset = "UTF-8", $fetch_attachment = true) {
422-
return $folder->searchMessages($where, $fetch_options, $fetch_body, $charset, $fetch_attachment);
421+
public function searchMessages(array $where, Folder $folder, $fetch_options = null, $fetch_body = true, $charset = "UTF-8", $fetch_attachment = true, $fetch_flags = false) {
422+
return $folder->searchMessages($where, $fetch_options, $fetch_body, $charset, $fetch_attachment, $fetch_flags);
423423
}
424424

425425
/**

src/IMAP/Folder.php

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ public function setChildren($children = []) {
156156
*
157157
* @return Message|null
158158
*/
159-
public function getMessage($uid, $msglist = null, $fetch_options = null, $fetch_body = false, $fetch_attachment = false) {
159+
public function getMessage($uid, $msglist = null, $fetch_options = null, $fetch_body = false, $fetch_attachment = false, $fetch_flags = false) {
160160
if (imap_msgno($this->getClient()->getConnection(), $uid) > 0) {
161-
return new Message($uid, $msglist, $this->getClient(), $fetch_options, $fetch_body, $fetch_attachment);
161+
return new Message($uid, $msglist, $this->getClient(), $fetch_options, $fetch_body, $fetch_attachment, $fetch_flags);
162162
}
163163

164164
return null;
@@ -177,8 +177,8 @@ public function getMessage($uid, $msglist = null, $fetch_options = null, $fetch_
177177
* @throws GetMessagesFailedException
178178
* @throws MessageSearchValidationException
179179
*/
180-
public function getMessages($criteria = 'ALL', $fetch_options = null, $fetch_body = true, $fetch_attachment = true) {
181-
return $this->searchMessages([[$criteria]], $fetch_options, $fetch_body, $fetch_attachment);
180+
public function getMessages($criteria = 'ALL', $fetch_options = null, $fetch_body = true, $fetch_attachment = true, $fetch_flags = false, $limit = null, $page = 1) {
181+
return $this->searchMessages([[$criteria]], $fetch_options, $fetch_body, $fetch_attachment, $limit, $page);
182182
}
183183

184184
/**
@@ -197,8 +197,8 @@ public function getMessages($criteria = 'ALL', $fetch_options = null, $fetch_bod
197197
* @deprecated 1.0.5:2.0.0 No longer needed. Use Folder::getMessages('UNSEEN') instead
198198
* @see Folder::getMessages()
199199
*/
200-
public function getUnseenMessages($criteria = 'UNSEEN', $fetch_options = null, $fetch_body = true, $fetch_attachment = true) {
201-
return $this->getMessages($criteria, $fetch_options, $fetch_body, $fetch_attachment);
200+
public function getUnseenMessages($criteria = 'UNSEEN', $fetch_options = null, $fetch_body = true, $fetch_attachment = true, $fetch_flags = false) {
201+
return $this->getMessages($criteria, $fetch_options, $fetch_body, $fetch_attachment, $fetch_flags);
202202
}
203203

204204
/**
@@ -262,7 +262,7 @@ public function getUnseenMessages($criteria = 'UNSEEN', $fetch_options = null, $
262262
* / ( ("+" / "-") 4DIGIT ) ; Local differential
263263
* ; hours+min. (HHMM)
264264
*/
265-
public function searchMessages(array $where, $fetch_options = null, $fetch_body = true, $charset = "UTF-8", $fetch_attachment = true) {
265+
public function searchMessages(array $where, $fetch_options = null, $fetch_body = true, $fetch_attachment = true, $fetch_flags = false, $charset = "UTF-8", $limit = null, $page = 1) {
266266

267267
$this->getClient()->checkConnection();
268268

@@ -290,15 +290,19 @@ public function searchMessages(array $where, $fetch_options = null, $fetch_body
290290

291291
$query = trim($query);
292292

293-
$availableMessages = imap_search($this->getClient()->getConnection(), $query, SE_UID, $charset);
293+
$availableMessages = array_reverse(imap_search($this->getClient()->getConnection(), $query, SE_UID, $charset));
294294

295+
$numMessages = imap_num_msg($this->getClient()->getConnection());
296+
if($limit == null || $limit > $numMessages){
297+
$maxMessages = $numMessages;
298+
}else{
299+
$maxMessages = $limit;
300+
}
295301
if ($availableMessages !== false) {
296-
$msglist = 1;
297-
foreach ($availableMessages as $msgno) {
298-
$message = new Message($msgno, $msglist, $this->getClient(), $fetch_options, $fetch_body, $fetch_attachment);
299-
302+
for ($msglist = ($page * $maxMessages) - $limit; $msglist < $page * $maxMessages; $msglist++){
303+
$msgno = $availableMessages[$msglist];
304+
$message = new Message($msgno, $msglist, $this->getClient(), $fetch_options, $fetch_body, $fetch_attachment, $fetch_flags);
300305
$messages->put($message->getMessageId(), $message);
301-
$msglist++;
302306
}
303307
}
304308

@@ -444,4 +448,4 @@ public function appendMessage($message, $options = null, $internal_date = null)
444448
public function getClient() {
445449
return $this->client;
446450
}
447-
}
451+
}

0 commit comments

Comments
 (0)