{"id":15984954,"url":"https://github.com/divineomega/email-structure-parser","last_synced_at":"2025-03-18T01:30:31.201Z","repository":{"id":54533762,"uuid":"143934184","full_name":"DivineOmega/email-structure-parser","owner":"DivineOmega","description":"📧 Parses the structure of multipart emails","archived":false,"fork":false,"pushed_at":"2021-02-12T12:35:13.000Z","size":14,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-28T06:04:39.297Z","etag":null,"topics":["email","email-parser","email-parsing","php","php-library"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DivineOmega.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-07T22:45:32.000Z","updated_at":"2021-02-12T12:33:45.000Z","dependencies_parsed_at":"2022-08-13T19:00:25.765Z","dependency_job_id":null,"html_url":"https://github.com/DivineOmega/email-structure-parser","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/DivineOmega%2Femail-structure-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DivineOmega%2Femail-structure-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DivineOmega%2Femail-structure-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DivineOmega%2Femail-structure-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DivineOmega","download_url":"https://codeload.github.com/DivineOmega/email-structure-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243893857,"owners_count":20364918,"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":["email","email-parser","email-parsing","php","php-library"],"created_at":"2024-10-08T02:11:38.638Z","updated_at":"2025-03-18T01:30:30.872Z","avatar_url":"https://github.com/DivineOmega.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Email Structure Parser\nGiven an IMAP stream and a message number, this library will parse the \nstructure of multipart emails.\n\n## Installation\n\nYou can easily install the Email Structure Parser package using the following \nComposer command.\n\n```bash\ncomposer require divineomega/email-structure-parser\n```\n\n## Usage\n\nTo use this parser, you must have first connect to a mail server using PHP's built-in \n`imap_open` function. Once connected, you then need to retrieve a message number, \nvia the `imap_search` function.\n\nOnce you have a message number, you can pass it, along with the IMAP stream object, \ninto the `EmailStructureParser`. You can then call the `getParts()` method to \nretrieve an array of parsed email parts split up by mime type.\n\nSee the example usage code below.\n\n```php\nuse DivineOmega\\EmailStructureParser\\EmailStructureParser;\n\n// Connect to mailbox\n$imapStream = imap_open('{outlook.office365.com:993/ssl/novalidate-cert}INBOX', getenv('USERNAME'), getenv('PASSWORD'));\n\n// Get a message number (in this example, just get the first)\n$msgNums = imap_search($imapStream, 'ALL');\n$msgNum = $msgNums[0];\n\n// Load message into parser\n$parser = new EmailStructureParser($imapStream, $msgNum);\n\n// Get parsed multipart email parts - including plain text and/or HTML content, and any attachments\n$parts = $parser-\u003egetParts();\n\n// Output HTML email content\nvar_dump($parts['TEXT/HTML']);\n\n// Save attached PNG images\nforeach($parts['IMAGE/PNG'] as $image) {\n    file_put_contents($image-\u003ename, $image-\u003econtent);\n}\n```\n\n## Content IDs\n\nSome emails embed images into the HTML content using `cid:` urls. These URLs link to the content ID of another part within the email, rather than being an absolute `https://` URL that can be resolved normally.\n\nIf one exists, this content ID will be exposed via the `contentId` property of the `Part`:\n\n```php\nforeach($parts['IMAGE/PNG'] as $image) {\n    // Store the file as in the above example:\n    file_put_contents($image-\u003ename, $image-\u003econtent);\n    // You would then want to store this relationship in your database:    \n    echo \"{$image-\u003econtentId} =\u003e {$image-\u003ename}\\n\";\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdivineomega%2Femail-structure-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdivineomega%2Femail-structure-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdivineomega%2Femail-structure-parser/lists"}