Skip to content

Commit c211bef

Browse files
authored
Merge pull request #44 from DirectoryTree/improve-mbox-matching
Improve mbox matching with Google Takeout format
2 parents bae34e6 + 726be5b commit c211bef

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/Mbox.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ public function __construct(
1818
* Get the messages from the mbox file.
1919
*/
2020
public function messages(
21-
string $delimiter = '/^From \\S+\\s+(Mon|Tue|Wed|Thu|Fri|Sat|Sun)\\s+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\s+\\d{1,2}\\s+\\d{2}:\\d{2}:\\d{2}\\s+\\d{4}/'
21+
string $delimiter = '/^From\s+\S+\s+' // From
22+
.'(Mon|Tue|Wed|Thu|Fri|Sat|Sun)\s+' // Day
23+
.'(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+' // Month
24+
.'\d{1,2}\s+\d{2}:\d{2}:\d{2}' // Time (HH:MM:SS)
25+
.'(?:\s+[+-]\d{4})?' // Optional Timezone ("+0000")
26+
.'\s+\d{4}/' // Year
2227
): Generator {
2328
if (! $handle = fopen($this->filepath, 'r')) {
2429
throw new RuntimeException('Failed to open mbox file: '.$this->filepath);

tests/Stubs/mailbox.mbox

+1-1
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ Seattle, WA 98195-5065
495495
496496

497497

498-
From nobody Thu May 5 21:08:05 2011
498+
From nobody Tue Mar 11 01:31:25 +0000 2025
499499
Return-Path: <[email protected]>
500500
Received: from mx1.cac.washington.edu (mx1.cac.washington.edu [140.142.32.206])
501501
by mailman2.u.washington.edu (8.14.4+UW11.03/8.14.4+UW11.03) with ESMTP

0 commit comments

Comments
 (0)