Webklex / php-imap

PHP-IMAP is a wrapper for common IMAP communication without the need to have the php-imap module installed / enabled. The protocol is completely integrated and therefore supports IMAP IDLE operation and the "new" oAuth authentication process as well.
https://www.php-imap.com
MIT License
302 stars 144 forks source link

Needed custom options on ssl params #238

Open mdemori opened 2 years ago

mdemori commented 2 years ago

Hi,

there is a way to use custom option to the defaultSocketOptions() function? i need some special settings on context creation, i just tried with below code but seem that doesn't work:

        $settings =
            [
                'host' => 'xxx',
                'port' => '143',
                'encryption' => 'tls',
                'validate_cert' => false,
                'username' => 'xxxx',
                'password' => 'xxxx',
                'protocol' => 'imap',
                'ssl' => [
                    'verify_peer_name' => false,
                    'verify_peer'      => false,
                    'ciphers' => 'DEFAULT:!DH',
                ],
            ];
        //Connect to the IMAP Server
        try {
            $cm = new ClientManager();
        } catch (MaskNotFoundException $e) {
            dd($e->getMessage());
        }
        // or create a new instance manually
        $client = $cm->make($settings);

        $client->connect();
        // or create a new instance manually
Webklex commented 2 years ago

Hi @mdemori , many thanks for the suggestion. I guess you're talking about this method right? https://github.com/Webklex/php-imap/blob/6e76b3552491e437f37721ae113129682489c141/src/Connection/Protocols/Protocol.php#L165 ..and: https://github.com/Webklex/php-imap/blob/6e76b3552491e437f37721ae113129682489c141/src/Connection/Protocols/Protocol.php#L200

..and you would like to extend the array which gets parsed to stream_context_create in: https://github.com/Webklex/php-imap/blob/6e76b3552491e437f37721ae113129682489c141/src/Connection/Protocols/Protocol.php#L204

..or am I off?

In theory those could be many options, besides ssl.ciphers. I would suggest a new custom or advanced option like this:

$settings = [
    'host' => 'xxx',
    'port' => '143',
    'encryption' => 'tls',
    'validate_cert' => false,
    'username' => 'xxxx',
    'password' => 'xxxx',
    'protocol' => 'imap',
    'ssl' => [
        'verify_peer_name' => false,
        'verify_peer'      => false,
    ],
    'custom' => [
        'ciphers' => 'DEFAULT:!DH',
        'foo' => 'bar',
    ],
];

..by which the custom settings attribute gets merged with the parameters for stream_context_create.

Best regards,