sazanof / php-imap-sockets
基于套接字的 PHP IMAP 库
1.1.2
2023-08-16 07:04 UTC
Requires
- ext-iconv: *
- ext-imap: *
- phpunit/phpunit: ^10.2
- symfony/var-dumper: ^6.3
README
PHP IMAP SOCKETS
用于处理电子邮件的新库,使用套接字。
特性
- 无依赖
- 通过[BODYSTRUCTURE]命令分析邮件体结构
- 灵活的搜索和检索
- 支持附件(包括内联附件)
- 标志管理
- 分页
待办事项
- 排序
通过 composer 安装
要安装此项目,请运行
composer require sazanof/php-imap-sockets
网站(即将推出)
基本用法
连接
use \Sazanof\PhpImapSockets\Models\Connection; // create new connection $connection = new Connection('imap.example.com'); // open connection and enable debug $connection->open()->enableDebug(); // login $connection->login('USERNAME', 'PASSWORD');
查询
use \Sazanof\PhpImapSockets\Models\SearchQuery; $query = new SearchQuery(); $query->all(); // OR $query->subject('Test'); // OR $query->new(); // OR $query->or([ 'subject'=>[ 'One', 'Two' ], 'since'=>'01-Jan-2023' ]); // Use clear() method to clear query string $query->clear();
邮箱
$path = 'INBOX'; $mailbox = $connection->getMailboxByPath($path)->setConnection($connection)->select(); // array of messages NUMBERS (not UIDS) $uids = $mailbox->search($query)->msgNums(); // or $mailbox->search($query)->setOrderDirection('DESC')->msgNums() // or ASC
邮件
use \Sazanof\PhpImapSockets\Models\MessageCollection; $collection = new MessageCollection($uids, $mailbox); // array of "Message" $items = $collection->items();
分页
use \Sazanof\PhpImapSockets\Models\Paginator; $paginator = new \Sazanof\PhpImapSockets\Models\Paginator($uids, $mailbox, 1, 6); $messagesPaginated = $p->messages();
附件
/** @var \Sazanof\PhpImapSockets\Models\Message $message **/ $attachmentsParts = $message->getBodyStructure()->getAttachmentParts(); foreach ($attachmentsParts as $attachmentsPart) { if (!$attachmentsPart->isInline()) { // set attachment content to $attachmentsPart $attachmentsPart->setContent( $message->getAttachment($attachmentsPart->getSection()) // or save locally ); } }
邮件文本内容
/** @var \Sazanof\PhpImapSockets\Models\Message $message **/ //get text parts (plain,html) with inline images $message->getBodyStructure()->getTextParts();
标志管理
use \Sazanof\PhpImapSockets\Models\Message; //$message $message->setImportant()->markAsDeleted(); //or $message->addFlags(['one','two']) //or $message->replaceFlags(['one','two']) //or $message->clearFlags() //or $message->deleteFlags('one'); //trigger save $message->saveFlags();
作者
许可证
反馈
如果您发现任何安全漏洞,请通过 m@sazanof.ru 联系我们