SSilence / php-imap-client

a easy solution for simple IMAP email access in php
MIT License
268 stars 136 forks source link

Advanced Connect Issues / Redundant Inputs Required / Unused member variables #194

Closed Xavious closed 6 years ago

Xavious commented 6 years ago

Feature request or bug

Bug

If a bug, what did you expect to happen?

To connect using the parameters provided.

If a bug, what happened?

Using advanced connection parameters is misleading because it throws errors for missing array keys, but it never uses those keys when actually utilizing the connect() method. In fact, I do not see anywhere that the ImapConnect class uses its member variables in conjunction with the methods associated with connecting to the remote server.

If a bug, list steps to reproduce bugs.

Line 180-183 of ImapClient.php:

        $connect = new ImapConnect();
        $connect->prepareFlags($config['flags']);
        $connect->prepareMailbox($config['mailbox']);
        $connect->connect($config['connect']);

The methods prepareFlags and prepareMailbox set the ImapConnect class member variables, but those member variables are never actually utilized and not setting them will cause errors to be thrown. Once the method connect() is invoked, it only uses the connection parameters provided in the 'connect' array. So basically the two methods are required, but serve no function in actually connecting to the server.

If a bug, did you do these steps?

[X] Download and use the lastest stable version [X] See if the issue has already been reported [X] Debug

If a feature request, what do you want to be added or changed?

Either use the methods that set the member variables, and actually utilize those member variables, or remove them and allow the connectAdvanced() method to simply use the attributes provided by the 'connect' array.

If a feature request, is this feature already in a pull request?

I don't know

If a feature request, do you know anyone who can help?

Maybe me if I find some time. I just started tinkering with this library.

Side notes(Read then del this chunk)

Example configuration (Note this works, but requires redundant inputs):

$params = array('DISABLE_AUTHENTICATOR' => 'GSSAPI');
$mailbox = '192.168.1.1';
$username = 'user';
$password = 'pass';
$encryption = Imap::ENCRYPT_TLS;
$service = ImapConnect::SERVICE_IMAP;
$certificate = ImapConnect::NOVALIDATE_CERT;

$config = array(
    'mailbox' => $mailbox,
    'username' => $username,
    'password' => $password,
    'params' => $params,
    'flags' => array(
        'encrypt' => $encryption,
        'service' =>  $service,
        'validateCertificates' => $certificate
    ),
    'connect' => array(
        'mailbox' => '{192.168.1.1/imap/novalidate-cert}INBOX',
        'username' => $username,
        'password' => $password,
        'params' => $params
    )
);
// Open connection
try{
    //$imap = new Imap($mailbox, $username, $password, $encryption);
    $imap = new Imap($config);
    // You can also check out example-connect.php for more connection options

}catch (ImapClientException $error){
    echo $error->getMessage().PHP_EOL;
    die(); // Oh no :( we failed
}
mattparksjr commented 6 years ago

I see. I can't get Sergey to ping. We may have to do a re write

Xavious commented 6 years ago

This may be a misunderstanding on my part. Since the advanced configuration isn't really documented, I've been trying to piece it together from the code and it's been a bit of a process.

mattparksjr commented 6 years ago

Yea very sorry. I don't know how it works as he never wrong any in code comments on it.

Xavious commented 6 years ago

I think it was probably a misunderstanding on my part. Here's a sample advanced configuration for anyone wanting to use DISABLE_AUTHENTICATOR.

$mailbox = '1.1.1.1';
$username = 'myusername';
$password = 'mypassword';
$params = array('DISABLE_AUTHENTICATOR' => 'GSSAPI');
$encrypt = Imap::ENCRYPT_TLS;
$service = ImapConnect::SERVICE_IMAP;
$certificate = ImapConnect::NOVALIDATE_CERT;

$config = array(
    'mailbox' => $mailbox,
    'flags' => array(
        'encrypt' => $encrypt,
        'service' =>  $service,
        'validateCertificates' => $certificate
    ),
    'connect' => array(
        'username' => $username,
        'password' => $password,
        'params' => $params
    )
);

try{
    //$imap = new Imap($mailbox, $username, $password, $encryption);
    $imap = new Imap($config);
    // You can also check out example-connect.php for more connection options

}catch (ImapClientException $error){
    echo $error->getMessage().PHP_EOL;
    die(); // Oh no :( we failed
}