- }
- // If we know the size, no need to look at the end parameters
- if ($size > 0) {
- if ($total_size == $size) {
- // We've reached the end of this 'message', switch to the next one.
- $data[] = $read;
- break;
- } else if ($total_size > $size) {
- $difference = $total_size - $size;
- $total_size = $total_size - strlen($read);
- $data[] = substr ($read, 0, strlen($read)-$difference);
- $read = substr ($read, strlen($read)-$difference, strlen($read));
- break;
- } else {
- $data[] = $read;
- $read = fgets($imap_stream, $bufsize);
- while (strpos($read, "\n") === false) {
- $read .= fgets($imap_stream, $bufsize);
- }
- }
- $total_size += strlen($read);
- } else {
- if (preg_match("/^$pre (OK|BAD|NO)(.*)/", $read, $regs) ||
- // if (ereg("^$pre (OK|BAD|NO)(.*)", $read, $regs) ||
- (($size == -1) && ereg("^\\* [0-9]+ FETCH.*", $read, $regs))) {
- break;
- } else if ( preg_match("/^\* OK \[PARSE.*/", $read, $regs ) ) {
- /*
- This block has been added in order to avoid the problem
- caused by the * OK [PARSE] Missing parameter answer
- Please, replace it with a better parsing if you know how.
- */
- $read = fgets ($imap_stream, $bufsize);
- $data[] = $read;
- $read = fgets ($imap_stream, $bufsize);
- } else if (preg_match("/^\* BYE \[ALERT\](.*)/", $read, $regs)) {
- /*
- It seems that the IMAP server has coughed a lung up
- and hung up the connection. Print any info we have
- and abort.
- */
- echo _("Please contact your system administrator and report the following error:") . "<br>\n";
- echo "$regs[1]";
- exit(0);
- } else {
- $data[] = $read;
- $read = fgets ($imap_stream, $bufsize);