Skip to content

Commit f273c75

Browse files
committed
Fetch all headers of all messages in the current folder
1 parent 812ed75 commit f273c75

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

src/Connection/Protocols/ImapProtocol.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Webklex\PHPIMAP\Exceptions\AuthFailedException;
1616
use Webklex\PHPIMAP\Exceptions\ConnectionFailedException;
1717
use Webklex\PHPIMAP\Exceptions\RuntimeException;
18+
use Webklex\PHPIMAP\Header;
1819

1920
/**
2021
* Class ImapProtocol
@@ -968,6 +969,32 @@ public function search(array $params) {
968969
return [];
969970
}
970971

972+
/**
973+
* Get a message overview
974+
* @param string $sequence
975+
* @return array
976+
*
977+
* @throws RuntimeException
978+
* @throws \Webklex\PHPIMAP\Exceptions\InvalidMessageDateException
979+
*/
980+
public function overview($sequence) {
981+
$result = [];
982+
list($from, $to) = explode(":", $sequence);
983+
984+
$uids = $this->getUid();
985+
$ids = [];
986+
foreach ($uids as $msgn => $v) {
987+
if ( ($to >= $msgn && $from <= $msgn) || ($to === "*" && $from <= $msgn) ){
988+
$ids[] = $msgn;
989+
}
990+
}
991+
$headers = $this->headers($ids);
992+
foreach ($headers as $msgn => $raw_header) {
993+
$result[$msgn] = (new Header($raw_header))->getAttributes();
994+
}
995+
return $result;
996+
}
997+
971998
/**
972999
* Enable the debug mode
9731000
*/

src/Connection/Protocols/LegacyProtocol.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ public function getMessageNumber($id) {
278278
}
279279

280280
/**
281-
* Get a message number for a uid
281+
* Get a message overview
282282
* @param string $sequence uid sequence
283283
*
284284
* @return array

src/Connection/Protocols/ProtocolInterface.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,14 @@ public function noop();
276276
*/
277277
public function search(array $params);
278278

279+
/**
280+
* Get a message overview
281+
* @param string $sequence uid sequence
282+
*
283+
* @return array
284+
*/
285+
public function overview($sequence);
286+
279287
/**
280288
* Enable the debug mode
281289
*/

src/Folder.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,19 @@ public function move($new_name, $expunge = true) {
241241
return $status;
242242
}
243243

244+
/**
245+
* Get a message overview
246+
* @param string|null $sequence uid sequence
247+
*
248+
* @return array
249+
* @throws ConnectionFailedException
250+
*/
251+
public function overview($sequence = null){
252+
$this->client->openFolder($this->path);
253+
$sequence = $sequence === null ? "1:*" : $sequence;
254+
return $this->client->getConnection()->overview($sequence);
255+
}
256+
244257
/**
245258
* Append a string message to the current mailbox
246259
* @param string $message

0 commit comments

Comments
 (0)