Hi,
Here's a bug fix for Courier-IMAP 4.x and reading unread mail.
[Background] New mails need to be flagged as Seen after it's opened. The IMAP command STORE $UID +Flags ($flag) is issued for this.
[Problem] New mail cannot opened when using Courier-IMAP. No page is rendered.
[Solution] Tcpdump reveals the following:
Client -> Server: flg STORE 139 +Flags (\Seen) Server -> Client: * 139 FETCH (FLAGS (\Seen)) Server -> Client: flg OK STORE completed.
However, the 'flg' part is not stripped when the input is sent to ParseResult to valid the server's response code (OK, BAD etc).
If we strip 'flg' before validating the response, we get the proper input.
File: program/lib/imap.inc:1455 Old code:
}while (!iil_StartsWith($line, "flg")); if (iil_ParseResult($line) == 0){
File: program/lib/imap.inc:1455 New code:
}while (!iil_StartsWith($line, "flg")); $line = str_replace('flg','',$line); if (iil_ParseResult($line) == 0){
This patch shouldn't affect other IMAP-servers.
Core problem is that errors in imap.inc need to be logged using error_log for example or a custom error handler. Otherwise a function returns -1 and the exception is handled.
Best regards,
Jasper
Kennedy, Richard (Aventure Media) wrote:
*cut*
Now the onlist reply ->
Uhm, I also modified iil_Readline a bit as I suspected the problem was there ->
function iil_ReadLine($fp, $size){ $line=""; if ($fp){ do{ $buffer = fgets($fp, 1024); $endID = strlen($buffer) - 1; $end = ($buffer[$endID] == "\n"); $line.=$buffer; }while(!$end); } return $line; }
It seems to be older version of iil_Readline but it has the same functionality. Can you give that a try?
Jasper
Hi Jasper
I was also working on this issue and tried out your solution. Unfortunately the request still hangs... I did not yet find the reason for this problem but please note the following:
(iil_ModFlag) is called as when opening the message. The only difference when opening the message is, that RoundCube loaded the message from the server before marking it as read (with the same socket connection). 2) The app does not hang when marking the message as read but when trying to reload the message headers afterwards (iil_C_FetchHeaders).
To avoid this problem, I close the connection to the server, after setting the flag and re-open it for loading the message headers. If doing this, RoundCube won't hang anymore when opening unread messages but the problem is not solved completely.
Just unpack the attached archive and replace the rcube_imap.inc. Please post your experience with this patch back to the list.
Thomas
2005/10/11, Jasper Slits jasper@insiders.nl:
Hi Thomas,
I'm glad to say it works! Perfect! Things are running now, like they were prior to the fatal cPanel update.
What can I say! Ben
Hi Jasper
I was also working on this issue and tried out your solution. Unfortunately the request still hangs... I did not yet find the reason for this problem but please note the following:
(iil_ModFlag) is called as when opening the message. The only difference when opening the message is, that RoundCube loaded the message from the server before marking it as read (with the same socket connection). 2) The app does not hang when marking the message as read but when trying to reload the message headers afterwards (iil_C_FetchHeaders).
To avoid this problem, I close the connection to the server, after setting the flag and re-open it for loading the message headers. If doing this, RoundCube won't hang anymore when opening unread messages but the problem is not solved completely.
Just unpack the attached archive and replace the rcube_imap.inc. Please post your experience with this patch back to the list.
Thomas
Hello everyone. I fixed this problem after 3 hours of diging the code :). Basically, the problem is in "fetchheaders" function. At some point script queries IMAP and looks for result like "* blah FETCH blah blah". And after it automatically assumes that server will send headers back. It's true. BUT for unseen message server sends back ONE more reposnse "* blah FETCH (FLAGS (\Seen))" which is NOT followed by any other data related to this FETCH. if everything's ok, server sends "blah OK FETCH completed".
Quick trace: C -> S "blah FETCH blah (BODY.PEEK[HEADER.FIELDS (DATE FROM TO SUBJECT REPLY-TO IN-REPLY-TO CC CONTENT-TRANSFER-ENCODING CONTENT-TYPE MESSAGE-ID)]) S -> C "* blah FETCH blah blah" // first message S -> C "date: blah" -- " -- " -- S -> C "from: blah" S -> C ")" //<- end of headers
C -> S "blah FETCH blah (BODY.PEEK[HEADER.FIELDS (DATE FROM TO SUBJECT REPLY-TO IN-REPLY-TO CC CONTENT-TRANSFER-ENCODING CONTENT-TYPE MESSAGE-ID)]) S -> C "* blah FETCH blah blah" // second message (unseen) S -> C "date: blah" -- " -- " -- S -> C "from: blah" S -> C ")" //<- end of headers S -> C "* blah FETCH (FLAGS (\Seen))"
// At this point if($a[0] == "*" && $a[2] == "FETCH") IS true. Script goes inside the ifbody and attempes to read headers with are supposed to end with ")", HOWEVER it gets "fh0 OK FETCH completed" which means FETCH was successful, MOVE ON :). BUT no this time, we are waiting and waiting and ... waiting for ")", which never comes :).
Did anyone understand what I wrote here ?
And here quick fix (I think in the release it should be done a little different):
do{ $line=chop(iil_ReadLine($fp, 200)); $a=explode(" ", $line); if (($line[0]=="*") && ($a[2]=="FETCH")){
<<<!!! SKIP !!!>>>
do{
$line = chop(iil_ReadLine($fp, 300),"\r\n");
if (ord($line[0])<=32)
$lines[$i].=(empty($lines[$i])?"":"\n").trim(chop($line)); else{ $i++; $lines[$i] = trim(chop($line)); } ! }while($line[0]!=")" && strncmp($line, $key, strlen($key)));
if(strncmp($line, $key, strlen($key)))
{
//process header, fill iilBasicHeader obj.
// initialize
if (is_array($headers)){
reset($headers);
while ( list($k, $bar) = each($headers) ) $headers[$k] = "";
}
<<<!!! SKIP !!!>>>
$result[$id]->messageID = $messageID;
}
else
{
$a=explode(" ", $line);
}
}
}while(strcmp($a[0], $key)!=0);Right now, everything works fine. Good luck.
P.S. is there an archive of this mailing list ? Thanks !
Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
Hi Maksim,
Hello everyone. I fixed this problem after 3 hours of diging the code :).
can you send the changed source code files to the list as well? I have applied the fixes provided here but none of them did work out so far :-( I will your one a try and otherwise I will dig into the code myself tonight...
All the best & cheers, Sebastian
Do you have the line numbers for these changes? It'd be slick if you were able to submit them. The problem still exists in 20051021, and your patch fixed it for me earlier. But, I can't use your complete imap.inc as now I have it patched for sorting.
Oddly enough, I only have the "unread mail bug" if I am opening the first message in my inbox and it happens to be unread. I am able to open every other unread message in by box... just not if the message I am opening is the first in the list. Strange, eh?
Dave
On Wed, 12 Oct 2005 02:38:09 -0400, "Maksim Rubis" siburny@hotmail.com wrote:
Hi David.
Line 1217:
change from:
}while($line[0]!=")");
to:
}while($line[0]!=")" && strncmp($line, $key, strlen($key))); if(strncmp($line, $key, strlen($key))) {
Line 1250:
After:
$result[$id]->messageID = $messageID;
add:
} else { $a=explode(" ", $line); }
That's it :) Let me know if it solves your problem.
Maksim
FREE pop-up blocking with the new MSN Toolbar get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/
Great, thanks.
Actually, I'm running the latest CVS and the problem seems to have disappeared. Can anyone else verify?
Dave
On Tue, 25 Oct 2005 12:16:24 -0400, "Maksim Rubis" siburny@hotmail.com wrote: