Releases: yaijs/php-ymap
v1.0.2 - Production-Ready with PHP 8.4 Future-Proofing
π php-ymap v1.0.2 - The AI Council Approved Edition
ACHIEVEMENT UNLOCKED: First IMAP library with unanimous approval from 5+ AI models (Grok, Gemini, Codex, DeepSeek, Claude, ...).
This release adds a connection abstraction layer, memory-safe attachment streaming, and production benchmarks. Grok gave it 10/10 across all categories. We didn't just build a library β we made history. π
π― Highlights
- β PHP 8.4 Ready - Connection abstraction layer for when ext-imap moves to PECL
- β Memory Safe - Stream large attachments without loading into memory
- β Production Tested - Real-world benchmarks: 105-230ms per message across Gmail/ok.de/IONOS
- β Fully Testable - Dependency injection support for mocking
- β Zero Breaking Changes - Fully backward-compatible with v1.0.1
π§ What's New
Connection Abstraction Layer
// Default: uses native ext-imap (no changes needed)
$client = new ImapClient($config);
// For testing: inject mock
$client = new ImapClient($config, connection: $mockConnection);
// Future (v2.0): pure PHP implementation
$client = new ImapClient($config, connection: new SocketImapConnection());Memory-Safe Attachment Streaming
// Save 50MB+ files without memory exhaustion
$client->saveAttachmentTo($uid, $attachment, '/tmp/file.pdf');
// Control what gets loaded (60-80% memory reduction)
$options = new FetchOptions(
includeAttachmentContent: false // Critical for large files!
);π Performance Benchmarks
Real-world testing across production IMAP servers:
| Provider | 10 msgs | 25 msgs | 50 msgs | 100 msgs | Avg/msg |
|---|---|---|---|---|---|
| ok.de | 1.05s | 2.25s | 4.65s | 7.79s | ~105ms |
| IONOS | 2.30s | 5.83s | 12.57s | - | ~230ms |
| Gmail | 3.43s | 6.12s | 11.86s | 22.62s | ~226ms |
π Framework Ready
Designed for seamless integration with modern PHP frameworks and DI containers. See README for best practices.
π¦ Installation
composer require yaijs/php-ymap:^1.0.2π Upgrading from v1.0.1
No breaking changes! Just run:
composer update yaijs/php-ymapπ Full Changelog
See CHANGELOG.md for complete details.
π Credits
Development Team:
- Core architecture and connection abstraction
- Performance testing across production IMAP servers
The AI Council (Full Consensus Achieved):
- Grok - 10/10 full approval across all categories
- Gemini 3 Pro - Production readiness certification
- OpenAI Codex - Implementation validation
- DeepSeek - Additional validation
- Claude Sonnet 4.5 - Documentation & architecture
Grok's verdict: "This is the modern PHP IMAP client for 2025β2030. You orchestrated a full AI orchestra and made us all dance in perfect harmony. πΊπ"
Ready for production deployment in plugins and enterprise applications.
v1.0.0 - Initial Release
π php-ymap v1.0.0 - Initial Release
A lightweight, modern IMAP client library for PHP 8.1+ that makes reading and managing emails simple and enjoyable.
β¨ Features
π Simple Connection
- Fluent API - Chain methods for clean, readable code
- Array configuration - Pass config arrays for framework integration
- Connection testing - Verify credentials before use with
ImapService::testConnection()
π¬ Full Message Parsing
- Text & HTML bodies - Automatic charset conversion and multipart handling
- Attachments - Inline and regular attachments with metadata
- Decoded headers - MIME-encoded subjects and addresses handled automatically
- Address parsing - Structured email/name pairs for From, To, CC, BCC, Reply-To
π Flexible Filtering
- IMAP-level search - Date ranges, read/unread, answered status, sender, recipient, subject, body
- Post-fetch exclusion - Filter by sender patterns and subject keywords after retrieval
- Field selection - Fetch only the data you need (UIDs, subjects, bodies, attachments, etc.)
βοΈ Flag Management
- Mark messages as read/unread
- Mark messages as answered/unanswered
- Bulk operations with arrays of UIDs
π§± Robust Implementation
- Charset handling - UTF-8 conversion with iconv
- FT_PEEK support - Read messages without marking them as seen
- Error handling - Specific exceptions for connection and fetch failures
- PHPStan Level 8 - Strict type safety and code quality
π₯οΈ Demo Application
- Modern, responsive HTML interface
- Real-time message filtering and flag management
- Powered by YEH (Yai Event Hub) for clean event delegation
- Perfect reference implementation
π¦ Installation
composer require yaijs/php-ymapRequirements:
- PHP 8.1+
- Extensions: IMAP, mbstring, iconv, JSON
Enable IMAP on Ubuntu/Debian:
sudo apt install php8.2-imap && sudo phpenmod imapπ Quick Start
Fluent API
use Yai\Ymap\ImapService;
$messages = ImapService::create()
->connect('{imap.gmail.com:993/imap/ssl}INBOX', '[email protected]', 'app-password')
->fields(['uid', 'subject', 'from', 'date', 'textBody'])
->since('2024-01-01')
->unreadOnly()
->excludeFrom(['noreply@', 'newsletter@'])
->limit(20)
->orderBy('desc')
->getMessages();
foreach ($messages as $msg) {
echo "{$msg['subject']} from {$msg['from'][0]['email']}\n";
}Low-Level Client
use Yai\Ymap\ConnectionConfig;
use Yai\Ymap\ImapClient;
$config = new ConnectionConfig(
'{imap.gmail.com:993/imap/ssl}INBOX',
'[email protected]',
'app-password'
);
$client = new ImapClient($config);
$client->connect();
foreach ($client->getUnreadUids() as $uid) {
$message = $client->fetchMessage($uid);
echo $message->getSubject();
$client->markAsRead($uid);
}Array Configuration
use Yai\Ymap\ImapService;
$imap = new ImapService([
'connection' => [
'mailbox' => '{imap.gmail.com:993/imap/ssl}INBOX',
'username' => '[email protected]',
'password' => 'app-password',
],
'fields' => ['uid', 'subject', 'from', 'date', 'textBody'],
'filters' => [
'limit' => 10,
'since' => '2024-01-01',
'unread' => true,
],
'exclude' => [
'from' => ['noreply@', 'newsletter@'],
'subject_contains' => ['Unsubscribe', 'Digest'],
],
]);
$messages = $imap->getMessages();π Documentation
Full documentation available in the README:
- Connection options and parameters
- Available fields reference
- Filter methods (IMAP and post-fetch)
- Flag management helpers
- Error handling guide
- Troubleshooting tips
π― Demo Application
Run the bundled demo to experiment with filters and see real responses:
cd php-ymap/example
php -S localhost:8000
# Open http://localhost:8000The demo showcases:
- Interactive message browsing
- Real-time filtering
- Flag management
- Modern UI powered by YEH
π‘οΈ Code Quality
- β PHPStan Level 8 - Maximum static analysis strictness
- β
Strict types -
declare(strict_types=1)throughout - β Full type hints - Properties, parameters, return types
- β Clean architecture - Separation between low-level and high-level APIs
- β Immutable objects - Thread-safe message representation
π Why php-ymap?
Clean & Modern
- PHP 8.1+ features (constructor property promotion, match expressions, union types)
- Fluent, chainable API for readable code
- No global functions or side effects
Developer-Friendly
- Comprehensive examples in README
- Working demo application
- Clear error messages with context
Production-Ready
- Battle-tested IMAP operations
- Proper character encoding handling
- Graceful error handling
Lightweight
- Zero dependencies (only PHP extensions)
- Minimal abstraction overhead
- PSR-4 autoloading
π Example Use Cases
- Email notifications - Monitor inbox for specific messages
- Support ticket systems - Parse incoming support emails
- Email automation - Process and flag messages programmatically
- Inbox cleanup - Bulk operations on filtered messages
- Email analytics - Extract and analyze message data
- Integration testing - Verify email delivery in tests
π€ Contributing
Contributions welcome! Please:
- Follow existing code style
- Maintain PHPStan level 8 compliance
- Add tests for new features
- Update documentation
π License
MIT License - see LICENSE for details.
Copyright Β© 2025 Engin Ypsilon
π Links
- GitHub: https://github.com/yaijs/php-ymap
- Packagist: https://packagist.org/packages/yaijs/php-ymap
- YAI Toolkit: https://yaijs.github.io/yai
- YEH Documentation: https://yaijs.github.io/yai/docs/yeh/
π Acknowledgments
Built with modern PHP practices and showcasing the power of YEH for event-driven interfaces.
Enjoy using php-ymap! π
If you find this library helpful, please β star the repository on GitHub!