{"id":15529388,"url":"https://github.com/mnapoli/imapi","last_synced_at":"2025-06-25T15:04:20.005Z","repository":{"id":57018493,"uuid":"21906388","full_name":"mnapoli/imapi","owner":"mnapoli","description":"[EXPERIMENTAL] High level IMAP API for PHP","archived":false,"fork":false,"pushed_at":"2018-09-24T21:56:04.000Z","size":20,"stargazers_count":24,"open_issues_count":1,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-29T23:41:22.715Z","etag":null,"topics":["imap","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mnapoli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-16T15:27:15.000Z","updated_at":"2024-01-04T15:45:41.000Z","dependencies_parsed_at":"2022-08-22T12:00:23.327Z","dependency_job_id":null,"html_url":"https://github.com/mnapoli/imapi","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnapoli%2Fimapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnapoli%2Fimapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnapoli%2Fimapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnapoli%2Fimapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mnapoli","download_url":"https://codeload.github.com/mnapoli/imapi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250436823,"owners_count":21430564,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["imap","php"],"created_at":"2024-10-02T11:17:45.897Z","updated_at":"2025-04-23T12:42:40.099Z","avatar_url":"https://github.com/mnapoli.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# imapi\n\n**This library is experimental and not meant to be reused.**\n\nimapi is a high level IMAP API for PHP.\n\nIt aims to be different from other implementations:\n\n- **be very high level**: you don't have to know how IMAP works (because IMAP is very ugly)\n- take care of related problems like **parse MIME email content** or **sanitize HTML in emails**\n- based on Horde's IMAP library rather than on PHP's IMAP extension (explained below)\n- be full featured, yet leave the door open for low-level calls to Horde's library for uncovered features\n- be maintained (unfortunately IMAP is not a very active topic and many good projects are unfinished or dead)\n\nIt is not based on PHP's IMAP extension, but rather on the amazing Horde library. The reason is well explained\non [Horde's library page](http://dev.horde.org/imap_client/):\n\n\u003e Horde/Imap_Client is significantly faster, more feature-rich, and extensible when compared to PHP's imap (c-client) extension.\n\n\u003e Don't be confused: almost every so-called \"PHP IMAP Library\" out there is nothing more than a thin-wrapper around the imap extension, so NONE of these libraries can fix the basic limitations of that extension.\n\n## Getting started\n\n```\ncomposer require mnapoli/imapi\n```\n\nThe easy way:\n\n```php\n$client = Imapi\\Client::connect('imap.host.com', 'user', 'password');\n```\n\nIf you want full control on the connection, you can use Horde's constructor:\n\n```php\n$hordeClient = new Horde_Imap_Client_Socket([\n    'username' =\u003e $username,\n    'password' =\u003e $password,\n    'hostspec' =\u003e $host,\n    'port'     =\u003e '143',\n    'secure'   =\u003e 'tls',\n]);\n\n$client = new Imapi\\Client($hordeClient);\n```\n\n\n## Reading\n\n### Reading the inbox\n\nFetching all the messages from the inbox:\n\n```php\n$emails = $client-\u003egetEmails();\n\nforeach ($emails as $email) {\n    echo $email-\u003egetSubject();\n}\n```\n\nYes it's that easy. Emails are objects (`Imapi\\Email`) that expose all the information of the email.\n\nIf you need to synchronize emails stored locally with the IMAP server, you will probably not want to fetch the emails,\ni.e. their content. You can fetch only their ID, which is much faster:\n\n```php\n$ids = $client-\u003egetEmailIds();\n\nforeach ($ids as $id) {\n    if (/* this email needs to be synced */) {\n        $email = $client-\u003egetEmailFromId($id);\n        // ...\n    }\n}\n```\n\n### Advanced queries\n\nBoth `getEmails()` and `getEmailIds()` can take an optional `Query` object.\n\n```php\n// Read from the `INBOX.Sent` folder\n$query = QueryBuilder::create('INBOX.Sent')\n    -\u003eyoungerThan(3600) // 1 hour\n    -\u003eflagSeen(true) // return messages with \\\\seen flag set, or false for messages with seen flag off. \n                     // more options are flagAnswered(boolean), flagDeleted(boolean),flagDraft(boolean),flagFlaged(boolean),flagRecent(boolean)\n    -\u003egetQuery();\n\n$emails = $client-\u003egetEmails($query);\n```\n\n### Reading folders\n\n```php\n$folders = $client-\u003egetFolders();\n```\n\n\n## Operations\n\n### Moving emails\n\n```php\n$emailIds = ['123', '456'];\n\n// Moving from the INBOX to the Archive folder\n$client-\u003emoveEmails($emailIds, 'INBOX', 'Archive');\n```\n\n### Deleting emails\n\n\"Deleting\" means simply moving to the trash folder. Unfortunately, the trash folder is custom to each provider,\nso you need to explicitly provide it:\n\n```php\n$emailIds = ['123', '456'];\n\n$client-\u003edeleteEmails($emailIds, 'Deleted Messages');\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmnapoli%2Fimapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmnapoli%2Fimapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmnapoli%2Fimapi/lists"}