webklex/php-imap
PHP-IMAP is a pure-PHP IMAP client wrapper that works without the php-imap extension, supporting IMAP IDLE and OAuth auth. Optionally use php-imap for better decoding, edge cases, and legacy POP3 support.
Pros:
imap extension, making it viable for environments where the extension is unavailable (e.g., shared hosting, Docker containers).webklex/laravel-imap wrapper provides seamless integration with Laravel’s service container, event system, and configuration management.since(), paginate()).Cons:
imap_* functions (e.g., imap_open(), imap_fetch_overview()).Laravel Ecosystem:
webklex/laravel-imap) provides a ServiceProvider for easy registration, configuration, and dependency injection.imap.message.fetched) for reactive programming.ClientInterface), enabling unit/integration tests without live IMAP servers.Non-Laravel PHP:
webklex/php-imap is viable but lacks Laravel’s conveniences (e.g., no built-in queue integration).High:
imap_* functions will need significant refactoring.Mitigation:
imap extension for critical paths (e.g., legacy systems) and php-imap for new features.Use Case Alignment:
imap_* functions that would block migration?Environment Constraints:
php-imap extension be installed as a fallback for edge cases?Scalability:
Team Expertise:
Compliance:
Laravel:
webklex/laravel-imap wrapper aligns with Laravel’s conventions (config files, service providers, events).EmailParsed, AttachmentSaved) for reactivity.Mockery) to test without live IMAP servers.Non-Laravel:
Assessment Phase:
imap_* functions, OAuth flows, and edge cases).imap extension for critical paths.Pilot Integration:
ServiceProvider to register the client in the container.// config/imap.php
return [
'accounts' => [
'gmail' => [
'host' => 'imap.gmail.com',
'port' => 993,
'encryption' => 'ssl',
'auth' => 'oauth',
'oauth_user' => 'user@example.com',
'oauth_token' => env('GMAIL_OAUTH_TOKEN'),
],
],
];
// AppServiceProvider
use Webklex\PHPIMAP\ClientManager;
public function register()
{
$this->app->singleton(ClientManager::class, function ($app) {
return new ClientManager(config('imap.path'));
});
}
Incremental Replacement:
imap_open() with ClientManager::account()->connect().imap_fetch_overview() with folder->messages()->get().Message model methods (e.g., getHTMLBody(), getAttachments()) instead of parsing raw IMAP responses.Fallback Strategy:
if (extension_loaded('imap')) {
return useNativeImap();
}
return usePhpImap();
Phase 1: Authentication & Connection
Phase 2: Core Operations
getFolders(), createFolder()).messages()->get(), paginate()).getSubject(), getHTMLBody()).Phase 3: Advanced Features
since(), where()).Phase 4: Optimization
Phase 5: Monitoring & Fallbacks
imap_alerts).imap extension).Pros:
Cons:
Best Practices:
composer.json to avoid surprises.config:cache toHow can I help you explore Laravel packages today?