File tree Expand file tree Collapse file tree 4 files changed +8632
-0
lines changed
Expand file tree Collapse file tree 4 files changed +8632
-0
lines changed Original file line number Diff line number Diff line change 2525 "egulias/email-validator" : " ^4.0"
2626 },
2727 "require-dev" : {
28+ "spatie/ray" : " ^1.0" ,
2829 "pestphp/pest" : " ^2.0|^3.0"
2930 },
3031 "autoload" : {
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace DirectoryTree \ImapEngine ;
4+
5+ use DirectoryTree \ImapEngine \Exceptions \RuntimeException ;
6+ use Generator ;
7+
8+ class Mbox
9+ {
10+ /**
11+ * Constructor.
12+ */
13+ public function __construct (
14+ protected string $ filepath
15+ ) {}
16+
17+ /**
18+ * Get the messages from the mbox file.
19+ */
20+ public function messages (): Generator
21+ {
22+ if (! $ handle = fopen ($ this ->filepath , 'r ' )) {
23+ throw new RuntimeException ('Failed to open mbox file: ' .$ this ->filepath );
24+ }
25+
26+ $ buffer = '' ;
27+
28+ while (($ line = fgets ($ handle )) !== false ) {
29+ if (str_starts_with ($ line , 'From ' ) && $ buffer !== '' ) {
30+ yield new FileMessage ($ buffer );
31+
32+ $ buffer = '' ;
33+ }
34+
35+ $ buffer .= $ line ;
36+ }
37+
38+ if ($ buffer !== '' ) {
39+ yield new FileMessage ($ buffer );
40+ }
41+
42+ fclose ($ handle );
43+ }
44+ }
You can’t perform that action at this time.
0 commit comments