noi/imap-idle

基于 pear/Net_IMAP 的 IMAP IDLE (RFC 2177) 实现

v1.0.1 2015-03-19 05:29 UTC

This package is not auto-updated.

Last update: 2024-09-28 15:18:18 UTC


README

扩展 pear/Net_IMAP 并提供对 IMAP IDLE 命令的支持 (RFC 2177)。

安装

将以下行添加到您的 composer.json 文件中

{
    "require": {
        "noi/imap-idle": "*"
    },
    "repositories": [
        {
            "type": "pear",
            "url": "pear.php.net"
        }
    ]
}

并运行 Composer 安装

$ php composer.phar install

(2013年9月23日) 如果您遇到以下类似的错误

[UnexpectedValueException] 无法提取 PEAR 包 /path/to/Net_IMAP/Net_IMAP-1.1.2.tgz 到 /path/to/Net_IMAP。原因:无效的 PEAR 包。package.xml 定义的文件不在 tarball 内部。

为了解决这个错误,您需要添加以下行代替

{
    "require": {
        "noi/imap-idle": "dev-master"
    },
    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "pear-pear/Net_IMAP",
                "version": "1.1.2",
                "source": {
                    "type": "git",
                    "url": "https://github.com/pear/Net_IMAP.git",
                    "reference": "1.1.2"
                },
                "require": {
                    "pear-pear/Net_Socket": ">=1.0.8"
                },
                "autoload": {
                    "classmap": ["./Net/"]
                },
                "include-path": ["./"]
            }
        },
        {
            "type": "pear",
            "url": "pear.php.net"
        }
    ]
}

这个错误似乎是由 Bug #19730 引起的。

用法

<?php
require 'vendor/autoload.php';

$imap = new \Noi\Util\Mail\ImapIdleClient('your.imap.host', 993);
$imap->login('username', 'password');
$imap->selectMailbox('INBOX');

while (!$imap->idle(300) instanceof \PEAR_Error) {
    $mails = $imap->search('UNSEEN');
    foreach ($imap->getMessages($mails) as $mail) {
        echo '==== New Message ====', "\n";
        echo $mail, "\n";
    }
}

许可

ImapIdleClient 使用 MIT 许可证 - 请参阅 LICENSE 文件以获取详细信息。