Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imap_open warning results in exception #186

Open
OskarStark opened this issue Jan 15, 2020 · 2 comments
Open

imap_open warning results in exception #186

OskarStark opened this issue Jan 15, 2020 · 2 comments

Comments

@OskarStark
Copy link
Collaborator

OskarStark commented Jan 15, 2020

ErrorException/src/Mail/ImapManager.php in App\Mail\ImapManager::connect
Warning: imap_open(): Couldn't open stream {mail.foo-bar.de:993/ssl/novalidate-cert}

Hi,. the following code results in a warning before using \Safe\imap_open:

$stream = imap_open(
    sprintf('{%s:%d/ssl/novalidate-cert}', $this->host, $this->port),
    $this->username,
    $this->password,
    0,
    1,
    ['DISABLE_AUTHENTICATOR' => 'GSSAPI']
);

now the reworked code with using \Safe\imap_open:

try {
    $stream = imap_open(
        sprintf('{%s:%d/ssl/novalidate-cert}', $this->host, $this->port),
        $this->username,
        $this->password,
        0,
        1,
        ['DISABLE_AUTHENTICATOR' => 'GSSAPI']
    );
} catch (Exceptions\ImapException $exception) {
    throw new \Exception(
        sprintf('Cannot connect to %s on port %d with username %s: %s',
            $this->host,
            $this->port,
            $this->username,
            imap_last_error()
        )
    );
}

results with the error above where its only a warning.
Is there a best pracitse on how to handle such warnings, which are now exceptions? 🤔

cc @localheinz

@moufmouf
Copy link
Member

Hey @OskarStark ,

I'm sorry, I don't understand your issue.
Is it that Safe does not print the correct error message (because the correct error message should be fetched using imap_last_error and we are not using that in Safe?)

Could you be a bit more specific? (maybe by showing the warning you are getting and we you expect from Safe?)

@OskarStark
Copy link
Collaborator Author

Hi @moufmouf 👋

first of all thanks for your time and your answer.
Ofc let me explain:
Before a warning was raised: Warning: imap_open(): Couldn't open stream {mail.foo-bar.de:993/ssl/novalidate-cert}. Now this warning is wrapped in an Exception, and because of this, the code stopped here.

Is the best practice here to catch the ErrorException or does it make sense for the Safe lib to wrap all warnings in a special "WarningException" to stay BC and handle them like before? in this case swallow it and go further?

I hope it makes it a bit more clear? If not maybe @localheinz can help me to mention the problem with other words?

Cheers Oskar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants