Changeset 2331 in subversion


Ignore:
Timestamp:
Mar 6, 2009 4:12:41 AM (4 years ago)
Author:
alec
Message:
  • Fix FETCH result parsing for servers returning flags at the end of result (#1485763)
Location:
trunk/roundcubemail
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/CHANGELOG

    r2330 r2331  
    55---------- 
    66- Fix errors handling in IMAP command continuations (#1485762) 
     7- Fix FETCH result parsing for servers returning flags at the end of result (#1485763) 
    78 
    892009/03/04 (alec) 
  • trunk/roundcubemail/program/lib/imap.inc

    r2330 r2331  
    16911691                $line = iil_ReadLine($fp, 1024); 
    16921692                $line = iil_MultLine($fp, $line); 
    1693                  
     1693 
    16941694                $a    = explode(' ', $line); 
    16951695                if (($line[0] == '*') && ($a[2] == 'FETCH')) { 
     
    17191719                                // did we get the right number of replies? 
    17201720                                $parts_count = count($a); 
    1721                                 if ($parts_count>=8) { 
     1721                                if ($parts_count>=6) { 
    17221722                                        for ($i=0; $i<$parts_count; $i=$i+2) { 
    17231723                                                if (strcasecmp($a[$i],'UID') == 0) 
     
    17291729                                                else if (strcasecmp($a[$i],'FLAGS') == 0) 
    17301730                                                        $flags_str = $a[$i+1]; 
    1731                                         } 
    1732  
    1733                                         // process flags 
    1734                                         $flags_str = eregi_replace('[\\\"]', '', $flags_str); 
    1735                                         $flags_a   = explode(' ', $flags_str); 
    1736                                          
    1737                                         if (is_array($flags_a)) { 
    1738                                                 reset($flags_a); 
    1739                                                 while (list(,$val)=each($flags_a)) { 
    1740                                                         if (strcasecmp($val,'Seen') == 0) { 
    1741                                                             $result[$id]->seen = true; 
    1742                                                         } else if (strcasecmp($val, 'Deleted') == 0) { 
    1743                                                             $result[$id]->deleted=true; 
    1744                                                         } else if (strcasecmp($val, 'Recent') == 0) { 
    1745                                                             $result[$id]->recent = true; 
    1746                                                         } else if (strcasecmp($val, 'Answered') == 0) { 
    1747                                                             $result[$id]->answered = true; 
    1748                                                         } else if (strcasecmp($val, '$Forwarded') == 0) { 
    1749                                                             $result[$id]->forwarded = true; 
    1750                                                         } else if (strcasecmp($val, 'Draft') == 0) { 
    1751                                                             $result[$id]->is_draft = true; 
    1752                                                         } else if (strcasecmp($val, '$MDNSent') == 0) { 
    1753                                                             $result[$id]->mdn_sent = true; 
    1754                                                         } else if (strcasecmp($val, 'Flagged') == 0) { 
    1755                                                              $result[$id]->flagged = true; 
    1756                                                         } 
    1757                                                 } 
    1758                                                 $result[$id]->flags = $flags_a; 
    17591731                                        } 
    17601732 
     
    18011773                                foreach ($reslines as $line) { 
    18021774                                        if (ord($line[0])<=32) { 
    1803                                             $lines[$ln] .= (empty($lines[$ln])?'':"\n").trim($line); 
     1775                                                $lines[$ln] .= (empty($lines[$ln])?'':"\n").trim($line); 
    18041776                                        } else { 
    18051777                                                $lines[++$ln] = trim($line); 
     
    18181790                                $line = chop(iil_ReadLine($fp, 300), "\r\n"); 
    18191791 
     1792                                // The preg_match below works around communigate imap, which outputs " UID <number>)". 
     1793                                // Without this, the while statement continues on and gets the "FH0 OK completed" message. 
     1794                                // If this loop gets the ending message, then the outer loop does not receive it from radline on line 1249.   
     1795                                // This in causes the if statement on line 1278 to never be true, which causes the headers to end up missing 
     1796                                // If the if statement was changed to pick up the fh0 from this loop, then it causes the outer loop to spin 
     1797                                // An alternative might be: 
     1798                                // if (!preg_match("/:/",$line) && preg_match("/\)$/",$line)) break; 
     1799                                // however, unsure how well this would work with all imap clients. 
     1800                                if (preg_match("/^\s*UID [0-9]+\)$/", $line)) { 
     1801                                    break; 
     1802                                } 
     1803 
     1804                                // handle FLAGS reply after headers (AOL, Zimbra?) 
     1805                                if (preg_match('/\s+FLAGS \((.*)\)\)$/', $line, $matches)) { 
     1806                                        $flags_str = $matches[1]; 
     1807                                        break; 
     1808                                } 
     1809 
    18201810                                if (ord($line[0])<=32) { 
    1821                                     $lines[$ln] .= (empty($lines[$ln])?'':"\n").trim($line); 
     1811                                        $lines[$ln] .= (empty($lines[$ln])?'':"\n").trim($line); 
    18221812                                } else { 
    18231813                                        $lines[++$ln] = trim($line); 
    1824                                 } 
    1825                                 /*  
    1826                                         The preg_match below works around communigate imap, which outputs " UID <number>)". 
    1827                                         Without this, the while statement continues on and gets the "FH0 OK completed" message. 
    1828                                         If this loop gets the ending message, then the outer loop does not receive it from radline on line 1249.   
    1829                                         This in causes the if statement on line 1278 to never be true, which causes the headers to end up missing 
    1830                                         If the if statement was changed to pick up the fh0 from this loop, then it causes the outer loop to spin 
    1831                                         An alternative might be: 
    1832                                         if (!preg_match("/:/",$line) && preg_match("/\)$/",$line)) break; 
    1833                                         however, unsure how well this would work with all imap clients. 
    1834                                 */ 
    1835                                 if (preg_match("/^\s*UID [0-9]+\)$/", $line)) { 
    1836                                     break; 
    18371814                                } 
    18381815                        // patch from "Maksim Rubis" <siburny@hotmail.com> 
     
    19231900                                $a = explode(' ', $line); 
    19241901                        } 
     1902 
     1903                        // process flags 
     1904                        if (!empty($flags_str)) { 
     1905                                $flags_str = eregi_replace('[\\\"]', '', $flags_str); 
     1906                                $flags_a   = explode(' ', $flags_str); 
     1907                                         
     1908                                if (is_array($flags_a)) { 
     1909                                        reset($flags_a); 
     1910                                        while (list(,$val)=each($flags_a)) { 
     1911                                                if (strcasecmp($val,'Seen') == 0) { 
     1912                                                    $result[$id]->seen = true; 
     1913                                                } else if (strcasecmp($val, 'Deleted') == 0) { 
     1914                                                    $result[$id]->deleted=true; 
     1915                                                } else if (strcasecmp($val, 'Recent') == 0) { 
     1916                                                    $result[$id]->recent = true; 
     1917                                                } else if (strcasecmp($val, 'Answered') == 0) { 
     1918                                                        $result[$id]->answered = true; 
     1919                                                } else if (strcasecmp($val, '$Forwarded') == 0) { 
     1920                                                        $result[$id]->forwarded = true; 
     1921                                                } else if (strcasecmp($val, 'Draft') == 0) { 
     1922                                                        $result[$id]->is_draft = true; 
     1923                                                } else if (strcasecmp($val, '$MDNSent') == 0) { 
     1924                                                        $result[$id]->mdn_sent = true; 
     1925                                                } else if (strcasecmp($val, 'Flagged') == 0) { 
     1926                                                         $result[$id]->flagged = true; 
     1927                                                } 
     1928                                        } 
     1929                                        $result[$id]->flags = $flags_a; 
     1930                                } 
     1931                        } 
    19251932                } 
    19261933        } while (strcmp($a[0], $key) != 0); 
Note: See TracChangeset for help on using the changeset viewer.