Skip to content

Commit e4b03f5

Browse files
committed
Create a fast count method for queries #216
1 parent 7eda73b commit e4b03f5

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
1212

1313
### Added
1414
- Message::getFolder() method
15+
- Create a fast count method for queries #216
1516

1617
### Affected Classes
1718
- [Message::class](src/IMAP/Message.php)

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Laravel IMAP is an easy way to integrate the native php imap library into your *
2020
- [Facade](#facade)
2121
- [Folder / Mailbox](#folder--mailbox)
2222
- [Search](#search-for-messages)
23+
- [Counting messages](#counting-messages)
2324
- [Result limiting](#result-limiting)
2425
- [Pagination](#pagination)
2526
- [View examples](#view-examples)
@@ -332,6 +333,19 @@ Limiting the request emails:
332333
$aMessage = $oFolder->query()->since('15.03.2018')->limit(10, 2)->get();
333334
```
334335

336+
#### Counting messages
337+
Count all available messages matching the current search criteria:
338+
``` php
339+
/** @var \Webklex\IMAP\Folder $oFolder */
340+
341+
//Count all messages
342+
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
343+
$count = $oFolder->query()->all()->count();
344+
345+
//Count all messages since march 15 2018
346+
$count = $oFolder->query()->since('15.03.2018')->count();
347+
```
348+
335349
#### Pagination
336350
Paginate a query:
337351
``` php
@@ -707,6 +721,7 @@ if you're just wishing a feature ;)
707721
| body | string $value | WhereQuery | Select messages matching a given HTML body |
708722
| before | string $value | WhereQuery | Select messages before a given date |
709723
| bcc | string $value | WhereQuery | Select messages matching a given receiver (BCC:) |
724+
| count | | integer | Count all available messages matching the current search criteria |
710725
| get | | MessageCollection | Fetch messages with the current query |
711726
| limit | integer $limit, integer $page = 1 | WhereQuery | Limit the amount of messages being fetched |
712727
| setFetchOptions | boolean $fetch_options | WhereQuery | Set the fetch options |

src/IMAP/Query/Query.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,16 @@ protected function search(){
165165
return collect();
166166
}
167167

168+
/**
169+
* Count all available messages matching the current search criteria
170+
*
171+
* @return int
172+
* @throws \Webklex\IMAP\Exceptions\ConnectionFailedException
173+
*/
174+
public function count() {
175+
return $this->search()->count();
176+
}
177+
168178
/**
169179
* Fetch the current query and return all found messages
170180
*

0 commit comments

Comments
 (0)