{"id":15021994,"url":"https://github.com/php/pecl-mail-mailparse","last_synced_at":"2025-08-20T01:13:52.212Z","repository":{"id":30619292,"uuid":"34174677","full_name":"php/pecl-mail-mailparse","owner":"php","description":"Email message manipulation","archived":false,"fork":false,"pushed_at":"2024-10-04T12:49:18.000Z","size":1214,"stargazers_count":32,"open_issues_count":4,"forks_count":30,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-28T04:23:13.558Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://pecl.php.net/package/mailparse","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/php.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-04-18T17:07:48.000Z","updated_at":"2025-02-01T18:43:13.000Z","dependencies_parsed_at":"2023-12-19T01:01:21.728Z","dependency_job_id":"75da4d9a-c64a-4139-be83-740785c83ed5","html_url":"https://github.com/php/pecl-mail-mailparse","commit_stats":{"total_commits":279,"total_committers":32,"mean_commits":8.71875,"dds":0.7096774193548387,"last_synced_commit":"6dabdf40616be6c2cab0c0d0587b9131d6e35352"},"previous_names":[],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php%2Fpecl-mail-mailparse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php%2Fpecl-mail-mailparse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php%2Fpecl-mail-mailparse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php%2Fpecl-mail-mailparse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php","download_url":"https://codeload.github.com/php/pecl-mail-mailparse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246629614,"owners_count":20808359,"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":[],"created_at":"2024-09-24T19:57:18.536Z","updated_at":"2025-04-02T13:03:09.213Z","avatar_url":"https://github.com/php.png","language":"C","readme":"# mailparse library for PHP\n\nMailparse is an extension for parsing and working with email messages.\n\nIt can deal with rfc822 and rfc2045 (MIME) compliant messages.\n\nMailparse is stream based, which means that it does not keep in-memory\ncopies of the files it processes - so it is very resource efficient\nwhen dealing with large messages.\n\nVersion 2.1.6 is for PHP 5\n\n## OO Syntax\n\n```php\n\u003c?php\n$file = \"/path/to/rfc822/compliant/message\";\n// parse the message in $file.\n// The file MUST remain in existence until you are finished using\n// the object, as mailparse does not cache the file in memory.\n// You can also use two alternative syntaxes:\n//\n// Read the message from a variable:\n//   $msg = new MimeMessage(\"var\", $message);\n//\n// Read the message from a stream (from fopen).\n// The stream MUST be seekable, or things will not work correctly.\n// Also, you MUST NOT fclose the stream until you have finished\n// using the message object (or any child objects it returns).\n//   $msg = new MimeMessage(\"stream\", $fp);\n//\n$msg = new MimeMessage(\"file\", $file);\n\n// Process the message.\ndisplay_part_info(\"message\", $msg);\n\n// Little function to display things\nfunction display_part_info($caption, \u0026$msgpart)\n{\n\techo \"Message part: $caption\\n\";\n\n\t// The data member corresponds to the information\n\t// available from the mailparse_msg_get_part_data function.\n\t// You can access a particular header like this:\n\t//   $subject = $msgpart-\u003edata[\"headers\"][\"subject\"];\n\tvar_dump($msgpart-\u003edata);\n\n\techo \"The headers are:\\n\";\n\t// Display the headers (in raw format) to the browser output.\n\t// You can also use:\n\t//   $msgpart-\u003eextract_headers(MAILPARSE_EXTRACT_STREAM, $fp);\n\t//     to write the headers to the supplied stream at it's current\n\t//     position.\n\t//\n\t//   $var = $msgpart-\u003eextract_headers(MAILPARSE_EXTRACT_RETURN);\n\t//     to return the headers in a variable.\n\t$msgpart-\u003eextract_headers(MAILPARSE_EXTRACT_OUTPUT);\n\n\t// Display the body if this part is intended to be displayed:\n\t$n = $msgpart-\u003eget_child_count();\n\n\tif ($n == 0) {\n\t\t// Return the body as a string (the MAILPARSE_EXTRACT parameter\n\t\t// acts just as it does in extract_headers method.\n\t\t$body = $msgpart-\u003eextract_body(MAILPARSE_EXTRACT_RETURN);\n\t\techo htmlentities($body);\n\n\t\t// This function tells you about any uuencoded attachments\n\t\t// that are present in this part.\n\t\t$uue = $msgpart-\u003eenum_uue();\n\t\tif ($uue !== false) {\n\t\t\tvar_dump($uue);\n\t\t\tforeach($uue as $index =\u003e $data) {\n\t\t\t\t// $data =\u003e array(\"filename\" =\u003e \"original filename\",\n\t\t\t\t//                \"filesize\" =\u003e \"size of extracted file\",\n\t\t\t\t//               );\n\n\t\t\t\tprintf(\"UUE[%d] %s (%d bytes)\\n\",\n\t\t\t\t\t$index, $data[\"filename\"],\n\t\t\t\t\t$data[\"filesize\"]);\n\n\t\t\t\t// Display the extracted part to the output.\n\t\t\t\t$msgpart-\u003eextract_uue($index, MAILPARSE_EXTRACT_OUTPUT);\n\n\t\t\t}\n\t\t}\n\n\t} else {\n\t\t// Recurse and show children of that part\n\t\tfor ($i = 0; $i \u003c $n; $i++) {\n\t\t\t$part =\u0026 $msgpart-\u003eget_child($i);\n\t\t\tdisplay_part_info(\"$caption child $i\", $part);\n\t\t}\n\t}\n}\n\n```\n\n\nThe rest of this document may be out of date! Take a look at the [mailparse section of the online manual](http://php.net/manual/en/book.mailparse.php) for more hints about this stuff.\n\n$mime = mailparse_rfc2045_parse_file($file);\n$ostruct = mailparse_rfc2045_getstructure($mime);\nforeach($ostruct as $st)\t{\n\t$section = mailparse_rfc2045_find($mime, $st);\n\t$struct[$st] = mailparse_rfc2045_getinfo($section);\n}\nvar_dump($struct);\n?\u003e\narray mailparse_rfc822_parse_addresses(string addresses)\n\tparses an rfc822 compliant recipient list, such as that found in To: From:\n\theaders.  Returns a indexed array of assoc. arrays for each recipient:\n\tarray(0 =\u003e array(\"display\" =\u003e \"Wez Furlong\", \"address\" =\u003e \"wez@php.net\"))\n\nresource mailparse_rfc2045_create()\n\tCreate a mime mail resource\n\nboolean mailparse_rfc2045_parse(resource mimemail, string data)\n\tincrementally parse data into the supplied mime mail resource.\n\tConcept: you can stream portions of a file at a time, rather than read\n\tand parse the whole thing.\n\n\nresource mailparse_rfc2045_parse_file(string $filename)\n\tParse a file and return a $mime resource.\n\tThe file is opened and streamed through the parser.\n\tThis is the optimal way of parsing a mail file that\n\tyou have on disk.\n\n\narray mailparse_rfc2045_getstructure(resource mimemail)\n\treturns an array containing a list of message parts in the form:\n\tarray(\"1\", \"1.1\", \"1.2\")\n\nresource mailparse_rfc2045_find(resource mimemail, string partname)\n\treturns an mime mail resource representing the named section\n\narray mailparse_rfc2045_getinfo(resource mimemail)\n\treturns an array containing the bounds, content type and headers of the\n  \tsection.\n\nmailparse_rfc2045_extract_file(resource mimemail, string filename[, string\n\t\tcallbackfunc])\n\tExtracts/decodes a message section from the supplied filename.\n\tIf no callback func is supplied, it outputs the results into the current\n\toutput buffer, otherwise it calls the callback with a string parameter\n\tcontaining the text.\n\tThe contents of the section will be decoded according to their transfer\n\tencoding - base64, quoted-printable and uuencoded text are supported.\n\nAll operations are done incrementally; streaming the input and output so that\nmemory usage is on the whole lower than something like procmail or doing this\nstuff in PHP space.  The aim is that it stays this way to handle large\nquantities of email.\n\n\nTODO:\n=====\n\n. Add support for binhex encoding?\n. Extracting a message part without decoding the transfer encoding so that\n\teg: pgp-signatures can be verified.\n\n. Work the other way around - build up a rfc2045 compliant message file from\n\tsimple structure information and filenames/variables.\n\nvim:tw=78\nvim600:syn=php:tw=78\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp%2Fpecl-mail-mailparse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp%2Fpecl-mail-mailparse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp%2Fpecl-mail-mailparse/lists"}