- How do I integrate this package into a Laravel application for parsing incoming emails?
- Use Laravel’s service container to bind the parser in `AppServiceProvider`. Inject it into controllers or middleware, then parse raw email strings or streams. For example, in middleware, parse the email and attach it to the request for downstream use. This works seamlessly with Laravel’s dependency injection system.
- Does this package support parsing emails from Laravel’s Mail events (e.g., `Sent` or `Failed`)?
- No, it doesn’t have built-in Laravel Mail event hooks, but you can manually parse emails in event listeners or middleware. For example, create a custom event listener for `MailSent` and pass the raw email to the parser. Alternatively, use middleware to intercept requests containing raw email data.
- Can I use this package with Laravel Queues to process large volumes of emails asynchronously?
- Yes, offload parsing to a queue job like `ParseEmailJob`. The package supports parsing from strings, resources, or PSR-7 streams, making it ideal for background processing. Use Laravel’s queue workers (e.g., Horizon) to handle retries and failures gracefully.
- What Laravel versions are compatible with this package, and do I need PHP 8.1+?
- This package requires **PHP 8.1+**, so it works with Laravel 9+ (LTS) and Laravel 10+. If you’re using Laravel 8.x (PHP 8.0), you’ll need to downgrade to v3.x of the package, but note that v4.x introduces API improvements and stricter typing. Always check the [upgrade guide](https://mail-mime-parser.org/upgrade-4.0) for migration steps.
- How do I handle encrypted emails (S/MIME or PGP) with this package?
- The core package doesn’t decrypt emails, but you can use optional plugins like `zbateson/mmp-crypt-*` for S/MIME or PGP support. These require the `openssl` or `gpg` PHP extensions. For Laravel, bind the decryption logic in a service provider or job, then parse the decrypted content with the main parser.
- Is there a fallback if parsing fails in production? Can I mix this with PHP’s imap_* functions?
- The package is designed to be forgiving with malformed emails, but for critical failures, you can wrap parsing in a `try-catch` block and fall back to `imap_*` or PEAR libraries. However, the package’s PSR-compliance and modern API make it a more reliable choice for most use cases in Laravel.
- How do I store email attachments parsed with this package in Laravel’s filesystem?
- Use Laravel’s `Storage` facade to save attachments. For example, iterate over the parsed message’s parts, check for attachments, and use `Storage::put()` to store them. For advanced features like thumbnails or metadata, integrate with packages like Spatie’s Media Library.
- Can I use this package to parse webhook emails (e.g., Stripe, GitHub) in Laravel Echo/Pusher?
- Yes, parse the raw email content in a middleware or job, then trigger real-time events using Laravel Echo. For example, extract webhook payloads from email bodies and dispatch them to Pusher channels. This works well for converting email-based notifications into live updates.
- What’s the performance impact of parsing large emails or attachments (e.g., >10MB)?
- The package efficiently handles streams, so memory usage remains low even for large attachments. For very large files, use `getContentStream()` to process data in chunks. However, ensure your server’s `memory_limit` and PHP settings (e.g., `upload_max_filesize`) are configured to handle the expected file sizes.
- Are there alternatives to this package for Laravel, and when should I choose them?
- Alternatives include PHP’s native `imap_*` functions (less modern, harder to test) or PEAR’s `Mail_mimeDecode` (legacy). Choose this package if you need PSR compliance, testability, and a clean API. Use `imap_*` only for quick scripts or if you’re constrained by PHP version. For Laravel-specific integrations, consider packages like `spatie/laravel-mail` for outbound emails, but this package excels at parsing inbound or raw emails.