zbateson/mail-mime-parser
Composer 安装命令:
composer require zbateson/mail-mime-parser
包简介
MIME email message parser
README 文档
README
Testable and PSR-compliant mail mime parser alternative to PHP's imap* functions and Pear libraries for reading messages in Internet Message Format RFC 822 (and later revisions RFC 2822, RFC 5322).
The goals of this project are to be:
- Well written
- Standards-compliant but forgiving
- Tested where possible
To include it for use in your project, install it via composer:
composer require zbateson/mail-mime-parser
Sponsors
A huge thank you to all my sponsors. <3
If this project's helped you, please consider sponsoring me.
New in 4.0
Version 4.0 requires PHP 8.1+ and focuses on API cleanup and improved configurability. For details, see the 4.0 Upgrade Guide.
Requirements
MailMimeParser requires PHP 8.1 or newer. Tested on PHP 8.1, 8.2, 8.3, 8.4 and 8.5.
Usage
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); // user@example.com 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(); // user@example.com 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 HeaderConsts::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);
Encryption and Signing Plugins
Optional companion packages add S/MIME and PGP/MIME support for decrypting, encrypting, signing and verifying messages:
- zbateson/mmp-crypt-smime -- S/MIME via PHP's OpenSSL extension
- zbateson/mmp-crypt-gpg -- PGP/MIME via PEAR's Crypt_GPG
Install either package and encrypted/signed messages are automatically detected and decrypted during parsing. See the Usage Guide for examples of reading encrypted messages and composing signed/encrypted ones.
Documentation
Upgrade guides
License
BSD licensed - please see license agreement.
zbateson/mail-mime-parser 适用场景与选型建议
zbateson/mail-mime-parser 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 52.98M 次下载、GitHub Stars 达 546, 最近一次更新时间为 2015 年 11 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「mail」 「parser」 「email」 「mime」 「mailparse」 「MimeMailParser」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 zbateson/mail-mime-parser 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 zbateson/mail-mime-parser 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 zbateson/mail-mime-parser 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
An MT940 bank statement parser for PHP
Courier offers a convenient and painless solution for creating emails tailored for your Kirby website.
Laravel integration for the jsonapi.org parser
Mail libraries used by Zimbra Api
Extensible library for building notifications and sending them via different delivery channels.
统计信息
- 总下载量: 52.98M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 553
- 点击次数: 27
- 依赖项目数: 79
- 推荐数: 0
其他信息
- 授权协议: BSD-2-Clause
- 更新时间: 2015-11-23