zbateson/mail-mime-parser
PSR-compliant, testable MIME email parser for PHP (RFC 822/2822/5322). A standards-based but forgiving alternative to imap* and Pear for reading and inspecting messages, headers, parts, and attachments. Requires PHP 8.1+.
Strengths:
Gaps:
ErrorBag), Laravel’s validation rules (e.g., Validator) may need to be layered on top.Laravel Compatibility:
Illuminate\Http\Request streams) or storage adapters (e.g., S3, local files).laravel-di).parseEmailJob.php), leveraging Laravel’s queue system.Data Flow:
Symfony\Component\Mailer or SwiftMailer).Message, AttachmentPart) can map to Laravel Eloquent models (e.g., Email, Attachment) or API responses.getContentStream()) enables efficient storage (e.g., S3) without loading entire files into memory.Medium:
imap_* or PEAR libraries will require refactoring, but the API is intuitive (e.g., Message::from() mirrors Laravel’s Model::find()).Log facade).Mitigation:
imap_* for legacy systems, migrate incrementally).Horizon or Laravel Debugbar to track failures.Illuminate\Mail\Events\MessageSent) or decoupled (e.g., standalone service)?Laravel Ecosystem:
$app->singleton(MailMimeParser::class, function ($app) {
return new MailMimeParser($app->make(LoggerInterface::class));
});
Symfony\Component\Mailer) or storage adapters (e.g., League\Flysystem).ParseEmailJob::dispatch($emailStream)->onQueue('emails');
Validator on parsed data (e.g., validate email addresses, attachment sizes).Dependencies:
zbateson/mail-mime-parser (PHP 8.1+).zbateson/mmp-crypt-smime or zbateson/mmp-crypt-gpg (if encryption is needed).php-di/laravel-di (if using PHP-DI) or custom container bindings.Phase 1: Prototype
imap_* or PEAR-based parser with MailMimeParser in a non-critical module.Phase 2: Core Integration
EmailParserService):
class EmailParserService {
public function parseFromStream(StreamInterface $stream): Message {
return app(MailMimeParser::class)->parse($stream);
}
}
EmailParsed event) or queue workers.Phase 3: Full Rollout
imap_*/PEAR code with feature flags.zbateson/mail-mime-parser:3.x.ext-fileinfo for better MIME type detection.emails table with subject, body, headers JSON columns; attachments table with stream or path fields).zbateson/mail-mime-parser, optional plugins).config/app.php or a service provider.EmailParserService facade/class.laravel-imap package).Illuminate\Http\Request streams)./storage/emails/).laravel-slack).required|email for from address).Log facade.How can I help you explore Laravel packages today?