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', 'user@example.com', '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',
'user@example.com',
'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' => 'user@example.com',
'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!