zbateson/mail-mime-parser
PSR-compliant, testable MIME email parser for PHP 8.1+ as an alternative to imap* and PEAR. Parses RFC 822/2822/5322 messages from strings, resources, or PSR-7 streams; standards-compliant yet forgiving, with a cleaned-up 4.x API.
Strengths:
MailMimeParser, Message, Header classes) enable granular adoption.Gaps:
High:
composer require zbateson/mail-mime-parser.Request objects).Challenges:
fopen, Psr7\StreamInterface) for large emails.ErrorBag may need adaptation to Laravel’s exception handling (e.g., Reportable interfaces).Use Case Alignment:
SwiftMailer/Mail facade for parsing, or supplement it (e.g., for inbound emails)?spatie/laravel-mail) that could conflict or overlap?Performance Requirements:
Storage Strategy:
Security:
mmp-crypt-*) add complexity.Laravel-Specific Needs:
EmailParsed) or queue jobs?Maintenance:
Laravel Core:
parseEmail job).EmailParsed) after parsing for downstream services.Dependencies:
Psr7\StreamInterface aligns with Laravel’s HTTP layer.storage/app/emails/.Email, Attachment) for structured data.Redis) to avoid reprocessing.Extensions:
zbateson/mmp-crypt-smime or zbateson/mmp-crypt-gpg for secure emails (requires OpenSSL/GPG).egulias/email-validator for additional header/address validation.Pilot Phase:
imap_* functions).Incremental Adoption:
Deprecation:
imap_open, mail_parse) in favor of this package.deprecate() helper to warn users of custom parsing code.Laravel Versions:
Existing Code:
imap_* or Pear::Mail, rewrite parsing logic to use MailMimeParser.EmailParser facade for consistency:
// app/Providers/AppServiceProvider.php
public function register()
{
$this->app->bind('email.parser', function () {
return new \ZBateson\MailMimeParser\MailMimeParser();
});
}
Third-Party Packages:
imap_* or other MIME parsers (e.g., spatie/laravel-mail).Setup:
composer require zbateson/mail-mime-parser.openssl for encryption).Core Integration:
EmailParser service class to wrap the package:
class EmailParserService
{
public function __construct(private MailMimeParser $parser) {}
public function parse(string|resource|\Psr\Http\Message\StreamInterface $email): Message
{
return $this->parser->parse($email);
}
}
AppServiceProvider.Storage Layer:
EmailRepository to persist parsed emails:
class EmailRepository
{
public function save(Message $message): Email
{
return Email::create([
'subject' => $message->getSubject(),
'from' => $message->getHeaderValue(HeaderConsts::FROM),
// ...
]);
}
}
Event/Queue Integration:
event(new EmailParsed($message));
// OR
ParseEmailJob::dispatch($message)->onQueue('emails');
Testing:
Monitoring:
ErrorBag or Laravel’s logging).How can I help you explore Laravel packages today?