zbateson / mail-mime-parser
MIME电子邮件消息解析器
3.0.3
2024-08-10 18:44 UTC
Requires
- php: >=8.0
- guzzlehttp/psr7: ^2.5
- php-di/php-di: ^6.0|^7.0
- psr/log: ^1|^2|^3
- zbateson/mb-wrapper: ^2.0
- zbateson/stream-decorators: ^2.1
Requires (Dev)
- friendsofphp/php-cs-fixer: *
- monolog/monolog: ^2|^3
- phpstan/phpstan: *
- phpunit/phpunit: ^9.6
Suggests
- ext-iconv: For best support/performance
- ext-mbstring: For best support/performance
- dev-master
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 3.0.0-beta.2
- 3.0.0-beta
- 2.4.1
- 2.4.0
- 2.3.0
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.1
- 2.1.0
- 2.0.x-dev
- 2.0.1
- 2.0.0
- 2.0.0-beta.1
- 2.0.0-beta
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.8
- 1.1.7
- 1.1.6
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.x-dev
- 1.0.0
- 1.0-beta
- 1.0-alpha.2
- 1.0-alpha
- 0.4.13
- 0.4.12
- 0.4.11
- 0.4.10
- 0.4.9
- 0.4.8
- 0.4.7
- 0.4.6
- 0.4.5
- 0.4.4
- 0.4.3
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.3
- 0.3.2
- 0.3.1
- 0.3.0
- 0.2.5
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.1
- 0.1.0
This package is auto-updated.
Last update: 2024-09-10 19:32:09 UTC
README
可测试且符合PSR规范的mail mime解析器,是PHP的imap*函数和Pear库的替代品,用于读取以Internet Message Format(RFC 822)格式编写的消息(以及后续修订RFC 2822、RFC 5322)。
本项目目标是
- 编写良好
- 符合标准但具有容错性
- 尽可能进行测试
要将其包含到项目中使用,请通过composer安装
composer require zbateson/mail-mime-parser
赞助商
向所有赞助商表示衷心的感谢。<3
如果本项目对您有所帮助,请考虑赞助我。
PHP 7支持已弃用
从mail-mime-parser 3.0版本开始,已弃用对PHP 7的支持。
3.0版本新增功能
3.0版本中的大多数更改是'后端'更改,例如切换到PHP-DI进行依赖注入,基本使用不应受到影响。
在3.0版本中,'getAllParts'类方法包含注释部分。
增加了错误、验证和日志支持。
要求
MailMimeParser需要PHP 8.0或更高版本。已在PHP 8.0、8.1、8.2和8.3上进行了测试。
使用方法
use ZBateson\MailMimeParser\MailMimeParser; use ZBateson\MailMimeParser\Message; use ZBateson\MailMimeParser\Header\HeaderConsts; // use an instance of MailMimeParser as a class dependency $mailParser = new MailMimeParser(); // parse() accepts a string, resource or Psr7 StreamInterface // pass `true` as the second argument to attach the passed $handle and close // it when the returned IMessage is destroyed. $handle = fopen('file.mime', 'r'); $message = $mailParser->parse($handle, false); // returns `IMessage` // OR: use this procedurally (Message::from also accepts a string, // resource or Psr7 StreamInterface // true or false as second parameter doesn't matter if passing a string. $string = "Content-Type: text/plain\r\nSubject: Test\r\n\r\nMessage"; $message = Message::from($string, false); echo $message->getHeaderValue(HeaderConsts::FROM); // [email protected] echo $message ->getHeader(HeaderConsts::FROM) // AddressHeader ->getPersonName(); // Person Name echo $message->getSubject(); // The email's subject echo $message ->getHeader(HeaderConsts::TO) // also AddressHeader ->getAddresses()[0] // AddressPart ->getPersonName(); // Person Name echo $message ->getHeader(HeaderConsts::CC) // also AddressHeader ->getAddresses()[0] // AddressPart ->getEmail(); // [email protected] echo $message->getTextContent(); // or getHtmlContent() echo $message->getHeader('X-Foo'); // for custom or undocumented headers $att = $message->getAttachmentPart(0); // first attachment echo $att->getHeaderValue(HeaderConsts::CONTENT_TYPE); // e.g. "text/plain" echo $att->getHeaderParameter( // value of "charset" part 'content-type', 'charset' ); echo $att->getContent(); // get the attached file's contents $stream = $att->getContentStream(); // the file is decoded automatically $dest = \GuzzleHttp\Psr7\stream_for( fopen('my-file.ext') ); \GuzzleHttp\Psr7\copy_to_stream( $stream, $dest ); // OR: more simply if saving or copying to another stream $att->saveContent('my-file.ext'); // writes to my-file.ext $att->saveContent($stream); // copies to the stream // close only when $message is no longer being used. fclose($handle);
文档
升级指南
许可证
BSD许可证 - 请参阅许可协议。