mvnaz/imapconnector

该包的最新版本(1.0)没有可用的许可证信息。

1.0 2018-09-12 18:48 UTC

This package is auto-updated.

Last update: 2024-09-25 22:10:11 UTC


README

此包允许您通过代理连接到IMAP协议。

优点

  • 包非常灵活,您可以替换任何元素为您的自定义版本(ResponseContainer、Parser、Commander、实现自己的代理类型)
  • 已实现Socks5和Https代理

限制

  • 代理授权需要实现
  • Parser、Commander - 我不建议在真实项目中使用此包中的这些对象。我包括它们是为了举例说明如何使用流。

要在您的项目中使用它,请在composer.json中添加以下代码

    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/mvnaz/ImapConnector.git"
        }
    ],
    "require": {
        "mvnaz/imapconnector": "dev-master"
    }

用法

// This object contains all success and errors (You can use your own)
$responseContainer = \Mvnaz\ImapConnector\Containers\ResponseContainer::getInstance();

$connector = new \Mvnaz\ImapConnector\Connector($responseContainer);

// This object is for imap response parsing (You can use your own)
$parser = new \Mvnaz\ImapConnector\Parsers\Parser();

// Socks 5 proxy instance (You can also use HTTP proxy or your own implementation)
$socks5Proxy = new \Mvnaz\ImapConnector\Proxies\Socks5Proxy($responseContainer, "ip", 'port');

// Connecting to the proxy (if you skip this line script will connect to imap directly, without proxy)
$connector->connectToProxy($socks5Proxy);

// Here we get the stream which is via proxy (You can use this stream in your own order, i.e with your own commander)
$stream = $connector->connectToImap("imap_host", 'imap_port');

// Here we check if we was successfully connected to imap
if(is_resource($stream)) {

    // Here we create the commander and pass the stream
    $commander = new \Mvnaz\ImapConnector\Commander($stream, $parser, $responseContainer);

    // Lets login to imap
    if($commander->login("login", "password")){
        echo "Success!";
    }

}