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

Fetching flags causes permanent hang #407

Open
InterLinked1 opened this issue May 23, 2023 · 2 comments
Open

Fetching flags causes permanent hang #407

InterLinked1 opened this issue May 23, 2023 · 2 comments
Labels
bug Something isn't working validated

Comments

@InterLinked1
Copy link
Contributor

Describe the bug
Trying to fetch the flags for a message causes the library to hang forever.

Used config

$cm = new ClientManager($options = []);
$client = $cm->make([
	'host'          => $w['server'],
	'port'          => $w['port'],
	'encryption'    => $w['secure'] ? 'ssl' : 'none',
	'validate_cert' => true,
	'username'      => $w['username'],
	'password'      => $w['password'],
	'protocol'      => 'imap'
]);

Code to Reproduce
The troubling code section which produces the reported bug.

printf("Fetching flags\n");
$flags = $client->getConnection()->flags((int) $f['uid'], 1)->validatedData();
printf("Done fetching flags\n");

It never gets to "Done fetching flags". This happens every single time.

I'm fetching the flags per message manually since $overview = $client->getConnection()->overview($sequence, 3)->validatedData(); omits a lot of mandatory message info, e.g. the UID, INTERNALDATE, flags, size, etc. Not very efficient, but that's another issue to deal with separately.

Expected behavior
Given the FETCH call is issued and successful, the function should return immediately.

Desktop / Server (please complete the following information):

  • OS: Debian 11
  • PHP: 8.2
  • Version: GIT (master) from yesterday

Seems to be a bug with the reading/parsing, as it did issue a FETCH to the IMAP server, but the function call above never returns. IMAP logs for the above function call:

[2023-05-23 12:46:38.578]   DEBUG[922738]: net_imap.c:9096 handle_client: 0x7f26577fb5d0 => TAG35 UID FETCH 2154 (FLAGS)
[2023-05-23 12:46:38.578]   DEBUG[922738]: net_imap.c:4643 process_fetch: 0x7f26577fb5d0 <= * 59 FETCH (FLAGS (\Seen) UID 2154)
[2023-05-23 12:46:38.578]   DEBUG[922738]: net_imap.c:4676 process_fetch: 0x7f26577fb5d0 <= TAG35 OK UID FETCH Completed
@InterLinked1
Copy link
Contributor Author

The bug appears to be here:

if ($to === null && !is_array($from) && ($uid === IMAP::ST_UID ? $tokens[2][$uidKey] == $from : $tokens[0] == $from)) {

Rewriting the code using an array, with a single element, it works properly:
$flags = $client->getConnection()->flags(array((int) $f['uid']), 1)->validatedData();

However, if a number is provided directly, the logic is incorrect. It continues iterating the outer loop, but it shouldn't be. I confirmed this by tracking what it was doing in the fetch function.

@Webklex
Copy link
Owner

Webklex commented Jun 23, 2023

Hi @InterLinked1,

Thanks a lot for reporting this issue. I really appreciate it! I was able to reproduce the issue and just pushed a fix.

Once again, thanks for taking the time and effort to make this library better! If you have any more questions or need further assistance, feel free to let me know.

Best regards and happy coding!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working validated
Projects
None yet
Development

No branches or pull requests

2 participants