directorytree/imapengine
IMAPEngine is a Laravel-friendly PHP package for working with IMAP mailboxes. Connect to servers, list folders, fetch messages and attachments, search and manage mail, and handle common IMAP operations through a clean, high-level API.
Strengths:
ext-imap), making it portable across environments (e.g., Docker, serverless, or platforms without native IMAP support).illuminate/collections, symfony/mime) and Carbon for date handling, reducing friction in integration.BackedEnum support), PHPStan compliance, and RFC822 compliance ensure robustness.Gaps:
idle() and polling exist, they lack native Laravel queue integration (e.g., Horizon or async workers).Laravel Compatibility:
Collection and Carbon natively. Can be injected into Laravel services via IoC.SwiftMailer/Mailgun for IMAP-based workflows (e.g., parsing inbound emails).Email).LARGER/SMALLER, SENT SINCE) for reporting.Email::createFromImapMessage($message)).Non-Laravel Dependencies:
symfony/mime, nesbot/carbon, zbateson/mail-mime-parser are Laravel-compatible but may require version alignment.spatie/ray for debugging (optional but useful).Low-Medium:
BODY[HEADER] vs. BODY[TEXT]) suggest server-specific quirks may require testing against target providers (e.g., Gmail, Exchange).flag()) could strain connections. Mitigate with connection pooling (e.g., pimple/container)..eml files) may need custom validation.$folder->poll() requires persistent connections; ensure your Laravel app can handle keep-alive timeouts.Mitigation:
spatie/ray or Laravel Telescope to log IMAP operations.ImapConnectionFailedException).laravel-imapengine) for reusability?EmailProcessed) for downstream actions?.env, Vault)?X-Sensitive) that need redaction?Laravel Core:
ImapEngine as a singleton or context-bound service.
$app->singleton(ImapClient::class, fn() => new ImapClient([
'host' => config('imap.host'),
'port' => config('imap.port'),
'ssl' => config('imap.ssl'),
]));
Email):
class Email extends Model {
public static function fromImapMessage(Message $message) {
return self::create([
'subject' => $message->subject,
'body' => $message->text,
'attachments' => $message->attachments()->map(fn($a) => $a->path),
]);
}
}
EmailFetched, EmailProcessed).Third-Party Synergy:
symfony/mime and zbateson/mail-mime-parser align with Laravel’s MimeMessage (if using laravel/framework).egulias/email-validator can validate From/To addresses.spatie/ray integrates with Laravel’s exception handling.ImapEngine.$message->attachments()->each(fn($attachment) =>
Storage::put("emails/{$message->uid}/{$attachment->filename}", $attachment->content)
);
SORT, QUOTA).illuminate/collections compatibility.illuminate/support v9+ for collections.pimple/container for multiple IMAP clients).class ImapRepository {
public function fetchEmails(Folder $folder, int $limit) {
return $folder->messages()->limit($limit)->get();
}
}
$folder->poll()).Redis for folder metadata).ext-imap for different PHP versions.symfony/mime, zbateson/mail-mime-parser may require version bumps.How can I help you explore Laravel packages today?