deblan/clivern-imap 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

deblan/clivern-imap

Composer 安装命令:

composer require deblan/clivern-imap

包简介

Access Mailbox Using PHP IMAP

关键字:

README 文档

README

:mailbox_with_mail: Access Mailbox Using PHP IMAP.

Current Version: 1.0.6

Build Status

Installation

To install the package via composer, use the following:

composer require clivern/imap

This command requires you to have Composer installed globally.

Usage

After adding the package as a dependency, Please read the following steps:

Connect and Authenticate

include_once dirname(__FILE__) . '/vendor/autoload.php';

use Clivern\Imap\Core\Connection;

$connection = new Connection(
    "imap.gmail.com",
    "993",
    "test@clivern.com",
    "my_password",
    "/ssl",
    "INBOX"
);
$connection->connect();

After end of everything, you should close connection

$connection->disconnect();

Connection Options

$folder = "INBOX";

// Reconnect & Update Mailbox Folder
$connection->reconnect($folder);
// Reopen Connection
$connection->survive($folder);
// Get Connection Stream
$connection->getStream();
// Get Server String
$connection->getServer();
// Check Connection
$connection->checkConnection();
// Get Quota Array
$connection->getQuota($folder);
// Get Status Array
$connection->getStatus($folder);
// Check MailBox Data
$connection->check();
// Ping Connection
$connection->ping();
// Get Errors
$connection->getErrors();
// Get Alerts
$connection->getAlerts();
// Get Last Error
$connection->getLastError();
// Disconnect
$connection->disconnect();

Mailboxes

Retrieve mailboxes (also known as mail folders) from the mail server and iterate over them:

use Clivern\Imap\MailBox;

$mailbox = new MailBox($connection);

$messages = $mailbox->getMessages();

foreach ($messages as $message) {
    echo "Subject: " . $message->header()->get('subject');
    echo "<br/>";
    echo $message->body()->getMessage();
}

Searching

To add custom search

use Clivern\Imap\Core\Search;
use Clivern\Imap\Core\Search\Condition\All;
use Clivern\Imap\Core\Search\Condition\Answered;
use Clivern\Imap\Core\Search\Condition\BCC;
use Clivern\Imap\Core\Search\Condition\Before;
use Clivern\Imap\Core\Search\Condition\Body;
use Clivern\Imap\Core\Search\Condition\CC;
use Clivern\Imap\Core\Search\Condition\Deleted;
use Clivern\Imap\Core\Search\Condition\Flagged;
use Clivern\Imap\Core\Search\Condition\From;
use Clivern\Imap\Core\Search\Condition\Keyword;
use Clivern\Imap\Core\Search\Condition\NewFlag;
use Clivern\Imap\Core\Search\Condition\Old;
use Clivern\Imap\Core\Search\Condition\On;
use Clivern\Imap\Core\Search\Condition\Recent;
use Clivern\Imap\Core\Search\Condition\Seen;
use Clivern\Imap\Core\Search\Condition\Since;
use Clivern\Imap\Core\Search\Condition\Subject;
use Clivern\Imap\Core\Search\Condition\Text;
use Clivern\Imap\Core\Search\Condition\To;
use Clivern\Imap\Core\Search\Condition\UnAnswered;
use Clivern\Imap\Core\Search\Condition\UnDeleted;
use Clivern\Imap\Core\Search\Condition\UnFlagged;
use Clivern\Imap\Core\Search\Condition\UnKeyword;
use Clivern\Imap\Core\Search\Condition\UnSeen;

$search = new Search();
$search->addCondition(new All());
// $search->addCondition(new Answered());
// $search->addCondition(new BCC("filter@gmail.com"));
// $search->addCondition(new Before(date("j F Y")));
// $search->addCondition(new Body("search text"));
// $search->addCondition(new CC("filter@gmail.com"));
// $search->addCondition(new Deleted());
// $search->addCondition(new Flagged());
// $search->addCondition(new From("filter@gmail.com"));
// $search->addCondition(new Keyword("test"));
// $search->addCondition(new NewFlag());
// $search->addCondition(new Old());
// $search->addCondition(new On(date("j F Y")));
// $search->addCondition(new Recent());
// $search->addCondition(new Seen());
// $search->addCondition(new Since(date("j F Y")));
// $search->addCondition(new Subject("search text"));
// $search->addCondition(new Text("search text"));
// $search->addCondition(new To("filter@gmail.com"));
// $search->addCondition(new UnAnswered());
// $search->addCondition(new UnDeleted());
// $search->addCondition(new UnFlagged());
// $search->addCondition(new UnKeyword("test"));
// $search->addCondition(new UnSeen());

// For more info, please check http://php.net/manual/en/function.imap-search.php

Then configure mailbox:

use Clivern\Imap\MailBox;

$mailbox = new MailBox($connection);

$messages = $mailbox->getMessages($search);

foreach ($messages as $message) {
    echo "Subject: " . $message->header()->get('subject');
    echo "<br/>";
    echo $message->body()->getMessage();
}

Mailbox Option

Some good methods in mailbox

use Clivern\Imap\MailBox;

$mailbox = new MailBox($connection);
// Get Folders
$mailbox->getFolders();
// Update Folder
$mailbox->setFolder("[Gmail]/All Mail");
// Count Messages in Current Folder
$mailbox->count();

$messages = $mailbox->getMessages();

foreach ($messages as $message) {
    echo "Subject: " . $message->header()->get('subject');
    echo "<br/>";
    echo $message->body()->getMessage();
}

Messages

To get message header data:

$message->header()->get('subject');
$message->header()->get('from');
$message->header()->get('to');
$message->header()->get('date');
$message->header()->get('message_id');
$message->header()->get('in_reply_to');
$message->header()->get('references');
$message->header()->get('size');
$message->header()->get('uid');
$message->header()->get('msgno');
$message->header()->get('recent');
$message->header()->get('flagged');
$message->header()->get('answered');
$message->header()->get('deleted');
$message->header()->get('seen');
$message->header()->get('draft');
$message->header()->get('udate');

To get message body

$message->body()->getMessage();
$message->body()->getEncoding();

To get message attachments

$attachments = $message->attachments();
foreach ($attachments as $attachment) {
    $attachment->getFilename();
    $attachment->getExtension();
    $attachment->getSize();
    $attachment->getEncoding();
    $attachment->getBytes();
    // get attachment content
    $attachment->getPlainBody();
    // get decoded attachment content
    $attachment->getBody();
    // Store attachment in provided path
    $attachment->store(__DIR__ . '/');
}

To do actions on message like delete or undelete

$message->action()->delete();
$message->action()->undelete();
// and don't forget to run the following to delete all messages marked for deletion
$mailbox->expunge();

Misc

Changelog

Version 1.0.6:

Fix Class Name.

Version 1.0.5:

Enhance code style.
Automate code fixes and linting.

Version 1.0.4:

Fix for plain text messages.

Version 1.0.3:

Fix Attachment Object.

Version 1.0.2:

Message delete & undelete actions added.

Version 1.0.1:

Debug data removed.

Version 1.0.0:

Initial Release.

Acknowledgements

© 2019, Clivern. Released under the MIT License.

Imap is authored and maintained by @clivern.

deblan/clivern-imap 适用场景与选型建议

deblan/clivern-imap 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 04 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「imap」 「clivern」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 deblan/clivern-imap 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 deblan/clivern-imap 我们能提供哪些服务?
定制开发 / 二次开发

基于 deblan/clivern-imap 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-04-04