javanile / php-imap2

PHP IMAP with OAUTH2
https://php-imap2.javanile.org/
GNU General Public License v3.0
54 stars 31 forks source link

*_UID flags not implemented #15

Open bago opened 2 years ago

bago commented 2 years ago

My code uses SE_UID, FT_UID, ST_UID, CP_UID flags in order to use uids instead of message numbers, because some IMAP server have issues dealing with message numbers and works better with uids.

When I moved to imap2_ functions I found nothing worked anymore and looking at the source code I guess $flags parameter is ignored in php-imap2 code.

I suggest to raise an error if people tries to use an unsupported feature instead of ignoring it silently and also to document the unsupported features, if you don't plan to support them.

PS: thank you for the project

nettunodev commented 2 years ago

Hi there @bago, were you able to make it work? I think we may have the same issue. We can retrieve the headers but the body is always empty. Thanks

bago commented 2 years ago

I confirm that the first effect I detected about this bug was that the "body" was empty.

Well, my solution has been to rewrite my code to use message numbers instead of message uids (so I don't use that unimplemtented flags).

Unfortunately some server have issues working with message numbers, so I changed my code to be able to work in both ways and I use uids by default (with imap*) and msgno by default with imap2 (that I currently use only with exchange 365).

nettunodev commented 2 years ago

@bago thanks for your answer. We also experienced a lot of issues when using message numbers but also when using message uids (especially with POP but also IMAP). We can't use message numbers, it wouldn't work in our software.

Anyway, I'm trying to brutally solve it, by hardcoding $is_uid = true in the Roundcube/ImapClient.php library. It works but it's still not enough.

I also sent an email, before I read your thread, to @francescobianco but he didn't reply yet, nor replied to any of the most recents issues / threads. Maybe he is busy, but I hope he will fix some of this issues, because this library is really useful.

nettunodev commented 2 years ago

I got it to work. Again I had to modify the Roundcube library. It seems that the fetch function always replies with an array with the message number as key. Therefore if you try to force the use of message uids the php-imap2 library will call the Roundcube function with the wrong message number and of course you will get a bunch of errors.

In a very unorthodox way, I modified the fetch function to always return an array whose key is the message number that it receives as parameter.

I'm aware that that's not the right way to do it, but I need this to work just for my very specific use case. I really hope that @francescobianco will modify the library to officially support UIDs.

francescobianco commented 2 years ago

Hi @bago @nettunodev please, I need your help to point me on problematic functions.

List here all functions you use on your project, I'll check it one-by-one to found any missing

Thanks!

nettunodev commented 2 years ago

Hi,

1st Issue every time that you call the roundcube function

public function fetch($mailbox, $message_set, $is_uid = false, $query_items = array(),$mod_seq = null, $vanished = false)

you often set the third parameter to false. Like for example in the message.php file, the headerInfo function call the fetch function:

$messages = $client->fetch($imap->getMailboxName(), $messageNum, false, [

while in the same file the body function set the $isUid variable and then call the function:

$isUid = boolval($flags & FT_UID);

$messages = $client->fetch($imap->getMailboxName(), $messageNum, $isUid, ['BODY[TEXT]']);

Maybe you have a reason for that or maybe you just forgot.

2nd Issue Also, using UIDs leads to another error. The roundcube fetch function always replies with an array and the key is always the message number, even when using UIDs. Therefore when I call one of your functions, let's say the headers function in the message.php file, and I'm using UIDs, I pass the UID as messageNum parameter.

public static function headers($imap,$messageNum,$fromLength = 0, $subjectLength = 0, $defaultHost = null)

you then call the fetch() function and it replies with an array and you try to get the body section looking up the UID as the array key, but the fetch() function replies with the message number as key, therefore this will never work this way.

return $messages[$messageNum]->body;

I had to purposely modify the roundcube fetch function to always reply with the UID as key, but that's just because I don't use message numbers in my software.

nettunodev commented 2 years ago

It turned out that the modify that I made to the fetch() function of roundcube does work but it also seems to fail when trying to retrieve more and a thousand messages (ie. message_set is a string with more than a thousand uids).

I don't know if that's related to my modification or if it's a limitation of the roundcube library.

IZSkiSurfer commented 2 years ago

Also check #32 This is a design flaw by roundcubes library. Check my ticket for how to handle it the "roundcube way"