Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Mail Mime Parser

Mail Mime Parser Laravel Package

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+.

View on GitHub
Deep Wiki
Context7

MIME email message parser

Frequently asked questions about Mail Mime Parser
How do I integrate this package into a Laravel application to parse incoming emails securely?
Use Laravel's service container to bind the parser with custom limits. Register it in `AppServiceProvider` with `app()->singleton()` and inject it into controllers or middleware. For example, enforce a `maxMimePartDepth` of 64 for public-facing endpoints to prevent deeply nested MIME attacks. Parse emails via `$parser->parse($emailContent, ['maxMimePartDepth' => 64])`.
Does this package support Laravel's Mailables for outgoing emails?
No, this package focuses exclusively on parsing incoming emails. For outgoing emails, continue using Laravel's built-in `Mailable` classes or libraries like `spatie/laravel-mailables`. This package is designed for reading and inspecting raw email content, not composing or sending.
What Laravel versions are compatible with zbateson/mail-mime-parser?
This package requires PHP 8.1+, so it works with Laravel 9.x and later. If you're using Laravel 8.x or older, you’ll need to upgrade PHP first. The package is tested with Laravel 9, 10, and 11, but ensure your Laravel version supports PHP 8.1+.
How can I handle attachments from parsed emails in Laravel?
Access attachments via `$message->getAttachmentParts()`. Validate each attachment’s size and filename before saving. For example, check `$attachment->getSize()` against `config('email.max_attachment_size')` and sanitize filenames with `$attachment->getFilename()->stripControlChars()`. Store attachments using Laravel’s `Storage` facade.
What are the risks of parsing untrusted emails with this package?
While the package mitigates risks like CRLF injection and resource exhaustion with configurable limits (e.g., `maxHeaderSizeBytes`), untrusted emails can still expose vulnerabilities if limits aren’t set strictly. Always validate parsed data, log parsing errors, and combine with Laravel middleware to reject malformed emails early.
Can I use this package to replace PHP’s imap_* functions in Laravel?
Yes, this package is a secure alternative to PHP’s `imap_*` functions, which are vulnerable to injection and parsing issues. It’s ideal for replacing `imap_fetchbody()` or `mailparse_msg()` in Laravel applications, especially for handling user-uploaded or third-party emails where security is critical.
How do I configure parsing limits for different Laravel environments (e.g., production vs. staging)?
Define environment-specific limits in your `config/services.php` or `.env` file. Use Laravel’s `config()` helper to dynamically pass limits to the parser. For example, set `MAX_MIME_DEPTH=128` in production but `MAX_MIME_DEPTH=256` in staging. Inject these values via dependency injection in your service providers.
Does this package support encrypted emails (e.g., PGP or S/MIME)?
No, the core package does not handle encryption. For encrypted emails, you’ll need additional plugins like `mmp-crypt-*`, which require OpenSSL or PEAR dependencies. These plugins are optional and not included by default, adding complexity for teams without cryptographic tooling.
How can I test email parsing in Laravel with this package?
Use Laravel’s testing tools to mock email content and verify parsing behavior. Test edge cases like deeply nested MIME structures, oversized headers, or malformed attachments by passing synthetic email strings to `$parser->parse()`. Validate that configurable limits (e.g., `maxHeaderCount`) trigger expected exceptions or fallbacks.
What alternatives exist for parsing emails in Laravel, and why choose this package?
Alternatives include PHP’s `mailparse` extension, `swiftmailer`, or `symfony/mime`. This package stands out for its RFC compliance, configurable security limits, and PSR-7 alignment, making it ideal for Laravel apps requiring strict parsing rules. Unlike `imap_*`, it avoids injection vulnerabilities and supports modern PHP features like dependency injection.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony