{"id":27734510,"url":"https://github.com/anod/gmail-imap-php","last_synced_at":"2025-04-28T13:11:56.338Z","repository":{"id":7463252,"uuid":"8809634","full_name":"anod/gmail-imap-php","owner":"anod","description":"API to work with Gmail using IMAP built on top of Zend Imap Library","archived":false,"fork":false,"pushed_at":"2020-01-27T10:55:51.000Z","size":39,"stargazers_count":67,"open_issues_count":0,"forks_count":10,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-08T15:03:40.301Z","etag":null,"topics":["gmail","imap","php","zend-imap-library"],"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/anod.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":"2013-03-15T21:47:12.000Z","updated_at":"2024-12-20T16:54:50.000Z","dependencies_parsed_at":"2022-09-01T16:40:22.960Z","dependency_job_id":null,"html_url":"https://github.com/anod/gmail-imap-php","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anod%2Fgmail-imap-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anod%2Fgmail-imap-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anod%2Fgmail-imap-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anod%2Fgmail-imap-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anod","download_url":"https://codeload.github.com/anod/gmail-imap-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251319594,"owners_count":21570428,"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":["gmail","imap","php","zend-imap-library"],"created_at":"2025-04-28T13:11:53.588Z","updated_at":"2025-04-28T13:11:55.797Z","avatar_url":"https://github.com/anod.png","language":"PHP","readme":"GMAIL IMAP API in PHP\n=============================\n\nWrapper library above Gmail IMAP API.\n\n## Features\n\nThe library extends Zend Imap Library, this way it provides all basic IMAP functionality.\nIn addition it provides simple Gmail specific API for:\n * OAUTH2 Authentication\n * get UID of the message\n * work with GMail labels: retrive, apply, remove\n * Getting Gmail thread id\n * Utility to convert Gmail message id representation: from big int to hex and opposite\n * Archive message\n\n## TODO\n\n* move to inbox\n* mark as read/unread\n\n## Requirements\n\nComposer\n  * Zend Imap Library\n\n## Usage example\n\n```php\n\u003c?php\n// \\Anod\\Gmail\\Math::bchexdec(\"FMfcgxwGCkZzGTlZHvpgXBHPvqzkLKtC\") == \"1430824723191418813\"\n$msgId = \"1430824723191418813\";\n$email = \"alex.gavrishev@gmail.com\";\n\n$protocol = new \\Anod\\Gmail\\Imap(true /* debug */);\n$gmail = new \\Anod\\Gmail\\Gmail($protocol);\n$gmail-\u003esetId(\"Example App\", \"0.1\", \"Alex Gavrishev\", \"alex.gavrishev@gmail.com\");\n\n$gmail-\u003econnect();\n$gmail-\u003eauthenticate($email, $token);\n$gmail-\u003esendId();\n$gmail-\u003eselectInbox();\n$uid = $gmail-\u003egetUID($msgId);\n\n$gmail-\u003eapplyLabel($uid, \"Very Important\"); // Apply label to a message with specific UID\n$gmail-\u003eremoveLabel($uid, \"Not Important\"); // Remove label to a message with specific UID\n\n$message = $gmail-\u003egetMessageData($uid); // Retrieve message content\n$details = array(\n    'subject' =\u003e $message-\u003egetHeader('subject', 'string'),\n    'body' =\u003e  $message-\u003egetContent(),\n    'from' =\u003e $message-\u003egetHeader('from', 'string'),\n    'to' =\u003e $message-\u003egetHeader('to', 'string'),\n    'thrid' =\u003e \\Anod\\Gmail\\Math::bcdechex($message-\u003egetThreadId()),\n    'labels' =\u003e $message-\u003egetLabels()\n);\n\n$gmail-\u003earchive($uid); // Archive the message\n```\n\nExample of fetching token with local server `php -S localhost:8000`\n\n```php\n\u003c?php\nsession_start();\nrequire_once __DIR__ . '/vendor/autoload.php';\n\n// Based on https://developers.google.com/identity/protocols/OAuth2\n$clientId = Clien Id from google console;\n$clientSecret = Client secret from google console;\n$redirectUri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];\n\n$client = new Google_Client([\n    'client_id' =\u003e $clientId,\n    'client_secret' =\u003e $clientSecret,\n    'redirect_uri' =\u003e $redirectUri\n]);\n// Scope for IMAP access\n$client-\u003eaddScope(\"https://mail.google.com/\");\nif (isset($_GET['code'])) {\n    $token = $client-\u003efetchAccessTokenWithAuthCode($_GET['code']);\n    $_SESSION['gmail_token'] = $token;\n\n    // redirect back to the example\n    header('Location: ' . filter_var($redirectUri, FILTER_SANITIZE_URL));\n    exit;\n}\n\nif (!empty($_SESSION['gmail_token'])) {\n    $client-\u003esetAccessToken($_SESSION['gmail_token']);\n    if ($client-\u003eisAccessTokenExpired()) {\n        unset($_SESSION['gmail_token']);\n    }\n} else {\n    $authUrl = $client-\u003ecreateAuthUrl();\n}\n\nif ($authUrl) {\n    $authUrl = $client-\u003ecreateAuthUrl();\n    header(\"Location: $authUrl\");\n    exit;\n}\n\n$token = $client-\u003egetAccessToken()['access_token'];\necho \"Token: $token\\n\\n\";\n```\n\n## Author\n\nAlex Gavrishev, 2013\n\n## License\n\nLibrary is licensed under the MIT license.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanod%2Fgmail-imap-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanod%2Fgmail-imap-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanod%2Fgmail-imap-php/lists"}