-
Notifications
You must be signed in to change notification settings - Fork 457
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 throws \ErrorException and masks real error #571
Comments
PR are very welcome! Let us see, which change you expect. Please also provide a current and after example, that we can see from which behaviour it would change to which new one. |
I wan to know if there is any progress on this issue? |
I get warnings from imap_open() from time to time, I assume something is temporarly out of service while it tries to connect.
I wonder if imap_open() should just return false like said before. Since it doesn't, wouldn't
help here, too? |
Does this issue still exist in the latest release 4.3.0? |
Yes, it's still there. I'm sorry I don't have much time for this. I did a little tinkering with 4.3.0 today, simply trying to connect to a gmail account with invalid credentials. On
Debuggin a little more, I think the issue relies in the imap errors management on function array:4 [
0 => "[ALERT] Application-specific password required: https://support.google.com/accounts/answer/185833 (Failure)"
1 => "[ALERT] Application-specific password required: https://support.google.com/accounts/answer/185833 (Failure)"
2 => "[ALERT] Application-specific password required: https://support.google.com/accounts/answer/185833 (Failure)"
3 => "Too many login failures"
] But then on line 710 we first check the last error (which we throw) and there's another check that throws all errors but we never got to it: public static function open(
string $mailbox,
string $username,
string $password,
int $options = 0,
int $n_retries = 0,
array $params = []
) {
if (\preg_match("/^\{.*\}(.*)$/", $mailbox, $matches)) {
$mailbox_name = $matches[1] ?? '';
if (!\mb_detect_encoding($mailbox_name, 'ASCII', true)) {
$mailbox = static::encodeStringToUtf7Imap($mailbox);
}
}
\imap_errors(); // flush errors
$result = @\imap_open($mailbox, $username, $password, $options, $n_retries, $params);
if (!$result) {
$lastError = \imap_last_error();
if ((\is_string($lastError)) && ('' !== \trim($lastError))) {
throw new UnexpectedValueException('IMAP error:'.$lastError);
}
throw new UnexpectedValueException('Could not open mailbox!', 0, self::HandleErrors(\imap_errors(), 'imap_open'));
}
return $result;
} Given that before trying to connect we cleared all the imap_errors, then all errors should be related to the ongoing connection so shouldn't it just output all the errors. That would be as easy as removing lines 710 to 715: public static function open(
string $mailbox,
string $username,
string $password,
int $options = 0,
int $n_retries = 0,
array $params = []
) {
if (\preg_match("/^\{.*\}(.*)$/", $mailbox, $matches)) {
$mailbox_name = $matches[1] ?? '';
if (!\mb_detect_encoding($mailbox_name, 'ASCII', true)) {
$mailbox = static::encodeStringToUtf7Imap($mailbox);
}
}
\imap_errors(); // flush errors
$result = @\imap_open($mailbox, $username, $password, $options, $n_retries, $params);
if (!$result) {
throw new UnexpectedValueException('Could not open mailbox!', 0, self::HandleErrors(\imap_errors(), 'imap_open'));
}
return $result;
} |
You don't have that much time, but provide that much and useful information. Thank you! :D I'll re-check, investigate, test and fix this as soon as possible. |
…-and-masks-real-error #571: Improve ConnectionException handling
I've changed the behaviour. Please take a look at the respective merge request #652 for further information. The change is on the You can check test it by using the current composer require php-imap/php-imap:dev-master I hope, this solves your issue here. :) |
Changes have been released in version 4.4.0. |
Environment (please complete the following information):
Your Text
A little context: I'm woking with Laravel, and am facing this issue when debuggin connection to Gmail accounts.
Whenever there's a credentials error, I get the next error:
imap_open(): Couldn't open stream {imap.gmail.com:993/ssl/novalidate-cert}
Trying to debug this, if catch that error and run
imap_last_error()
:[AUTHENTICATIONFAILED] Invalid credentials (Failure)
It seems that
imap_open()
is throwing an\ErrorException
that is undocumented (it should simply return false) and this exception is masking the real error.I think we could catch
\ErrorException
onPhpImap:702
and add the exception message as additional info to$lastError
as a workaround. I can submit a PR if that seems ok.The text was updated successfully, but these errors were encountered: