Download the PHP package yaijs/php-ymap without Composer

On this page you can find all versions of the php package yaijs/php-ymap. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-ymap

php-ymap

A lightweight fluent IMAP client for PHP 8.1+. Decode bodies, attachments, and headers, filter in one call, toggle flags, and preview everything via the included UI demo.

Table of Contents

  1. Features
  2. Requirements
  3. Installation
  4. Usage
    • Low-Level Client
    • ImapService Fluent API
    • Array / Config-Driven Setup
    • Connection Options
  5. Field & Filter Reference
  6. Performance & Production Readiness
    • Real-World Benchmarks
    • Memory Optimization with FetchOptions
    • Shopware 6.7 Integration
  7. Advanced Usage
  8. Demo Application
  9. Error Handling
  10. Security
  11. Development & Testing
  12. Contributing
  13. Troubleshooting
  14. License

Packagist Version PHP Version Require PHPStan

🏆 v1.0.3 - Socket Mode Stabilized! php-ymap now runs reliably without ext-imap, including restored multipart body parsing and persisted read/answered flags in real inbox workflows. See what's new →

Features


Requirements


Installation

The package ships with PSR‑4 autoloading (Yai\Ymap\*) and no global functions.


Usage

Low-Level Client

ImapService Fluent API

Array / Config-Driven Setup

Connection Options

ImapService::connect() (and the connection config section) keep imap_open()-compatible parameters so existing configs continue to work in both connector modes:

Option Description
mailbox IMAP path, e.g. {imap.gmail.com:993/imap/ssl}INBOX
username, password Credentials or app password
options imap_open() bitmask compatibility field
retries Retry count compatibility field
parameters Optional connector parameters (TLS/auth behavior where supported)
encoding Target encoding for decoded bodies (default UTF-8)

Need a lightweight “Test Credentials” button? Call the static helper:


Field & Filter Reference

Available Fields

Field Description
uid Message UID (always included)
subject Decoded subject
date, dateRaw Formatted string (Y-m-d H:i:s) or original DateTimeImmutable\|null
from, to, cc, bcc, replyTo Address arrays (email + optional name)
textBody, htmlBody Plain text and HTML bodies (decoded, concatenated per part)
preview Plain text summary (auto-generated from text or stripped HTML)
attachments Filename, MIME type, size (inline + regular attachments)
headers Normalized header map
seen, answered Boolean flags mirrored from IMAP
size Total message size (bytes)

Use fields([...]) and/or excludeFields([...]) to tailor responses. uid is injected automatically.

Note on Attachments: The attachments field returns metadata by default. Payloads are decoded lazily to keep memory usage small, and you can opt into array payloads with includeAttachmentContent() or stream the bytes straight to disk with ImapClient::saveAttachmentTo().

Filter Methods

Method IMAP Criteria
since($date) SINCE
before($date) BEFORE (inclusive)
unreadOnly() / readOnly() UNSEEN / SEEN
from($email) / to($email) FROM / TO
subjectContains($text) SUBJECT
bodyContains($text) BODY
limit($n), orderBy('asc'|'desc') Result shaping
answeredOnly(), unansweredOnly() ANSWERED / UNANSWERED

Post-fetch exclusions (evaluated after message parsing) help drop noisy senders or subjects:

Flag Helpers

Under the hood this proxies to imap_setflag_full() / imap_clearflag_full() using UIDs.


Performance & Production Readiness

php-ymap has been tested in production environments and optimized for enterprise use, including message queue workers and scheduled tasks.

Real-World Benchmarks

Performance tested across three production IMAP servers in both connector modes.

ext-imap mode (reference):

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

Socket mode (default in v1.0.3):

Provider 10 msgs 25 msgs 50 msgs 100 msgs Avg/msg
ok.de 1.4282s 3.0770s 5.8331s 11.3149s ~113ms
IONOS 3.5413s 5.8178s 16.9986s - ~340ms
Gmail 5.7557s 13.0100s 22.1389s 37.4546s ~375ms

Note: IONOS mailbox had 61 messages, so no 100-message run in either mode.

Key Takeaways:

Memory Optimization with FetchOptions

Control exactly what gets loaded into memory to prevent exhaustion in long-running processes:

Performance Impact:

Plugin Integration Example

php-ymap is designed for seamless integration with modern PHP frameworks and DI containers:

Best Practices for Background Processing:

  1. Use limit() to process emails in batches (recommend 20-50)
  2. Always set includeAttachmentContent: false unless needed
  3. Use saveAttachmentTo() for files larger than 5MB
  4. Register ImapService in DI container, not static calls
  5. Handle ConnectionException gracefully to avoid task crashes

Advanced Usage

Working with Attachment Content

Attachments are decoded lazily so you only pay for what you touch. You can still grab bytes directly or stream them to disk without ever holding them in memory:

Including Attachment Content in JSON APIs

Opt-in when you truly need the payload:

Note: Including attachment content in JSON responses can significantly increase response size. Enable it only when necessary or stream to disk with saveAttachmentTo() for very large files.


Demo Application

Run the bundled dashboard to experiment with filters and see real responses:

The frontend (built with YEH) posts to get.php, which uses ImapService exclusively. The JSON API is a good reference if you want to plug php-ymap into another UI.


Dependency Injection & Testing

php-ymap is built with testability in mind. The connection layer is fully abstracted via ImapConnectionInterface, making it easy to mock for tests.

Mock Connection for Unit Tests

Swap IMAP Transport at Service Level

You can also call withClientFactory() to inject a factory that builds clients per connection config.

Connector Selection (PHP 8.4+ Ready)

The ImapConnectionInterface abstraction keeps php-ymap portable across environments with and without ext-imap:

Current implementations:


Error Handling

ImapService::disconnect() lets you explicitly close the IMAP stream ($imap->disconnect(true) to expunge).


Security

Important: Never hardcode IMAP credentials in your source code.

Secure Credential Management

Secure Connections

Always use SSL/TLS when connecting over untrusted networks:

Additional Security Practices

Secure Attachment Handling

Always sanitize attachment filenames to prevent path traversal attacks:

Memory Safety: For attachments larger than your memory_limit, always use saveAttachmentTo() which streams directly to disk without loading into memory.

For detailed security guidelines, vulnerability reporting, and best practices, see SECURITY.md.


Development & Testing

No additional tooling is required. PHPStan level is configured in phpstan.neon.


Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines on:

For security vulnerabilities, please see our Security Policy instead of opening a public issue.


Troubleshooting

Issue Hint
“Can't connect to mailbox” Double-check mailbox path, host firewall, TLS flags, and credentials
Gmail authentication fails Use an App Password; basic auth is blocked
Empty textBody Some emails are HTML-only – read htmlBody or strip tags yourself (see example app)
Self-signed certs Provide stream context via parameters (e.g. ['DISABLE_AUTHENTICATOR' => 'PLAIN'], or TLS context)
Need ext-imap anyway sudo apt install php8.2-imap && sudo phpenmod imap (optional, not required for default socket mode)

License

MIT. Portions of the IMAP protocol implementation and message helpers are derived from the MIT-licensed Webklex/php-imap and ddeboer/imap projects; see THIRD_PARTY_LICENSES.md for the preserved upstream notices you must include when redistributing this library or products that bundle it.


All versions of php-ymap with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
ext-iconv Version *
ext-json Version *
ext-mbstring Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package yaijs/php-ymap contains the following files

Loading the files please wait ...