zbateson / mail-mime-parser

An email parser written in PHP
https://mail-mime-parser.org/
BSD 2-Clause "Simplified" License
441 stars 56 forks source link

Support question: How to parse mbox files with multiple messages? #201

Closed a-r-m-i-n closed 1 year ago

a-r-m-i-n commented 1 year ago

Hi! I'm currently trying to parse mail messages from a mbox file.

It works like charm, but only for the first message in mbox file. All other messages are being ignored. I'm using the following code:

<?php
$handle = fopen('/var/www/html/sent_mails.mbox', 'rb');
$message = $mailParser->parse($handle, false);
// Here I can access all info of the first message in mbox file
fclose($handle);

When I repeat the $mailParser->parse($handle, false); call on the same handle, I get weird results.

Do you have any hints, how to get multiple messages from mbox file? Or is it not possible with this library?

Thanks in advance! ~Armin

a-r-m-i-n commented 1 year ago

I've realized that every mail in mbox file starts with "To: ". When I split file contents this way, I can parse each message individually.