Changeset d5ff9276 in github


Ignore:
Timestamp:
Feb 12, 2008 1:44:58 PM (5 years ago)
Author:
till <till@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
a9a8ef2
Parents:
a8d23d8
Message:
  • attempted to revise the fix from #1484577 to streamline IMAP communication
  • not a 100% working, checking in for thomasb
File:
1 edited

Legend:

Unmodified
Added
Removed
  • program/lib/imap.inc

    r90180ef rd5ff9276  
    756756         
    757757        //strip off day of week 
    758         $pos=strpos($str, ' '); 
     758        $pos = strpos($str, ' '); 
    759759        if (!is_numeric(substr($str, 0, $pos))) { 
    760760            $str = substr($str, $pos+1); 
     
    916916                                $received = 0; 
    917917                                do { 
    918                                         $line = iil_ReadLine($fp, 0); 
    919                                         $received+=strlen($line); 
    920                                         $line = chop($line); 
     918                                        $line      = iil_ReadLine($fp, 0); 
     919                                        $received += strlen($line); 
     920                                        $line      = chop($line); 
    921921                                         
    922                                         if ($received>$bytes) break; 
    923                                         else if (!$line) continue; 
     922                                        if ($received>$bytes) { 
     923                        break; 
     924                                        } else if (!$line) { 
     925                        continue; 
     926                                        } 
     927 
     928                                        list($field, $string) = explode(': ', $line); 
    924929                                         
    925                                         list($field,$string)=explode(": ", $line); 
    926                                          
    927                                         if (strcasecmp($field, "date") == 0) 
     930                                        if (strcasecmp($field, 'date') == 0) { 
    928931                                                $result[$id] = iil_StrToTime($string); 
    929                                         else if ($index_field!="DATE") 
     932                                        } else if ($index_field != 'DATE') { 
    930933                                                $result[$id]=strtoupper(str_replace('"', '', $string)); 
    931                                 } while ($line[0]!=")"); 
     934                    } 
     935                                } while ($line[0] != ')'); 
    932936                        } else { 
    933937                                //one line response, not expected so ignore                              
     
    935939                        */ 
    936940                } while (!iil_StartsWith($line, $key)); 
     941 
    937942        }else if ($mode == 6) { 
     943 
    938944                $key     = 'fhi' . ($c++); 
    939945                $request = $key." FETCH $message_set (INTERNALDATE)\r\n"; 
     
    14731479} 
    14741480 
    1475 function iil_C_FetchHeaders(&$conn, $mailbox, $message_set, $uidfetch=false) { 
     1481function iil_C_FetchHeaders(&$conn, $mailbox, $message_set, $uidfetch=false) 
     1482{ 
    14761483        global $IMAP_USE_INTERNAL_DATE; 
    14771484         
     
    15211528    $request .= "(DATE FROM TO SUBJECT REPLY-TO IN-REPLY-TO CC BCC "; 
    15221529    $request .= "CONTENT-TRANSFER-ENCODING CONTENT-TYPE MESSAGE-ID "; 
    1523     $request .= "REFERENCES RECEIVED DISPOSITION-NOTIFICATION-TO X-PRIORITY)])\r\n"; 
     1530    $request .= "REFERENCES DISPOSITION-NOTIFICATION-TO X-PRIORITY)])\r\n"; 
    15241531 
    15251532        if (!fputs($fp, $request)) { 
     
    15361543                        $result[$id]->subject   = ''; 
    15371544                        $result[$id]->messageID = 'mid:' . $id; 
     1545 
    15381546                        /* 
    15391547                                Start parsing headers.  The problem is, some header "lines" take up multiple lines. 
     
    15621570                                        however, unsure how well this would work with all imap clients. 
    15631571                                */ 
    1564                                 if (preg_match("/^\s*UID [0-9]+\)$/",$line)) { 
     1572                                if (preg_match("/^\s*UID [0-9]+\)$/", $line)) { 
    15651573                                    break; 
    15661574                } 
     
    15891597                                                $result[$id]->timestamp = iil_StrToTime($string); 
    15901598                                                break; 
    1591                     case 'received': 
    1592                         if (!isset($result[$id]->date)) { 
    1593                             $_received = substr(strstr(str_replace("\n", 
    1594                                 '', $string), '; '), 2); 
    1595      
    1596                             $result[$id]->date      = str_replace("\n", '', $_received); 
    1597                             $result[$id]->timestamp = iil_StrToTime($_received); 
    1598                         } 
    1599                         break; 
    16001599                                        case 'from': 
    16011600                                                $result[$id]->from = $string; 
     
    16501649                        } // end while () 
    16511650                    } else { 
    1652                             $a=explode(' ', $line); 
     1651                            $a = explode(' ', $line); 
    16531652                    } 
    1654                 } 
    1655         } while (strcmp($a[0], $key)!=0); 
    1656                  
     1653 
     1654            if (!isset($result[$id]->date)) { 
     1655                $result[$id]->date = ''; 
     1656            } 
     1657            $result[$id]->date = trim($result[$id]->date); 
     1658 
     1659            $before = true; 
     1660 
     1661            if ($result[$id]->date == '') { 
     1662 
     1663                $before = false; 
     1664 
     1665                /* FETCH RECEIVED header */ 
     1666                $key      = 'fh' . ($c++); 
     1667                $request  = $key; 
     1668                $request .= " UID FETCH $id (BODY.PEEK[HEADER.FIELDS "; 
     1669                $request .= "(RECEIVED)])\r\n"; 
     1670 
     1671                if (fputs($fp, $request)) { 
     1672                    $_received = ''; 
     1673                    while ($line = chop(iil_ReadLine($fp, 200))) { 
     1674                        $line = trim($line); 
     1675                        if (preg_match('/for <(.*)>;(.*)/', $line)) { 
     1676                            $_received .= trim($line); 
     1677                            break; 
     1678                        } 
     1679                    } 
     1680                    if ($_received != '') { 
     1681                        $_received = trim(str_replace(';', '', 
     1682                            substr($_received, strpos($_received, ';')) )); 
     1683 
     1684                        if ($_received != '') { 
     1685                            $result[$id]->date      = $_received; 
     1686                            $result[$id]->timestamp = iil_StrToTime($_received); 
     1687                            //trigger_error("Date: {$result[$id]->timestamp}", E_USER_WARNING); 
     1688                        } 
     1689                    } 
     1690                    $result[$id]->date = trim($result[$id]->date); 
     1691                } 
     1692                /** 
     1693                 * This is  hack to display something. 
     1694                 */ 
     1695                if ($result[$id]->date == '') { 
     1696                    $result[$id]->date      = date('r'); 
     1697                    $result[$id]->timestamp = time(); 
     1698                } 
     1699            } 
     1700            trigger_error("set before? {$before}, ID {$id}: {$result[$id]->date} / {$result[$id]->timestamp}", E_USER_WARNING); 
     1701                } 
     1702        } while (strcmp($a[0], $key) != 0); 
     1703 
    16571704        /*  
    16581705                FETCH uid, size, flags 
     
    16701717                //$a = explode(' ', $line); 
    16711718                //if (($line[0]=="*") && ($a[2]=="FETCH")) { 
    1672                 if ($line[0]=="*") { 
     1719                if ($line[0] == '*') { 
    16731720                        //echo "<!-- $line //-->\n"; 
    16741721                        //get outter most parens 
     
    17631810} 
    17641811 
    1765  
    17661812function iil_C_FetchHeader(&$conn, $mailbox, $id, $uidfetch=false) { 
    17671813        $fp = $conn->fp; 
     
    18181864                 
    18191865                // sort index 
    1820                 $i=0; 
     1866                $i = 0; 
    18211867                if ($flag == 'ASC') { 
    18221868                    asort($index); 
     
    18441890                do { 
    18451891                        $line=chop(iil_ReadLine($fp, 100)); 
    1846                         if ($line[0]=="*") $c++; 
     1892                        if ($line[0] == '*') { 
     1893                $c++; 
     1894            } 
    18471895                } while (!iil_StartsWith($line, 'exp1')); 
    18481896                 
     
    19401988        $month  = (int) $month; 
    19411989    $months = $GLOBALS['IMAP_MONTHS']; 
    1942         /* $months=array( 
    1943                         1=>"Jan", 2=>"Feb", 3=>"Mar", 4=>"Apr",  
    1944                         5=>"May", 6=>"Jun", 7=>"Jul", 8=>"Aug",  
    1945                         9=>"Sep", 10=>"Oct", 11=>"Nov", 12=>"Dec" 
    1946                         ); 
    1947     */ 
    19481990        return $day . '-' . $months[$month] . '-' . $year; 
    19491991} 
Note: See TracChangeset for help on using the changeset viewer.