Changeset a9a8ef2 in github


Ignore:
Timestamp:
Feb 12, 2008 2:20:14 PM (5 years ago)
Author:
thomascube <thomas@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
a0ce2f0
Parents:
d5ff9276
Message:

Use INTERNALDATE if Date: header is missing; convert some spaces back to tabs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • program/lib/imap.inc

    rd5ff9276 ra9a8ef2  
    792792    } 
    793793        $fields = array('ARRIVAL'=>1,'CC'=>1,'DATE'=>1,'FROM'=>1,'SIZE'=>1, 
    794         'SUBJECT'=>1,'TO'=>1); 
     794 'SUBJECT'=>1,'TO'=>1); 
    795795         
    796796        if (!$fields[$field]) { 
     
    14891489        list($from_idx, $to_idx) = explode(':', $message_set); 
    14901490        if (empty($message_set) || (isset($to_idx) 
    1491         && (int)$from_idx > (int)$to_idx)) { 
     1491                && (int)$from_idx > (int)$to_idx)) { 
    14921492                return false; 
    1493     } 
     1493        } 
    14941494                 
    14951495        /*  Do "SELECT" command */ 
     
    15101510                                } else { 
    15111511                                    $needed_set.=($needed_set ? ',': '') . $id; 
    1512                 } 
     1512                                } 
    15131513                        } 
    15141514                        //echo "<!-- iil_C_FetchHeader\nMessage Set: $message_set\nNeeded Set:$needed_set\n//-->\n"; 
    15151515                        if ($needed_set) { 
    1516                             $message_set = iil_CompressMessageSet($needed_set); 
    1517             } else { 
    1518                 return $result; 
    1519             } 
     1516                                $message_set = iil_CompressMessageSet($needed_set); 
     1517                        } else { 
     1518                                return $result; 
     1519                        } 
    15201520                } 
    15211521        } 
    15221522 
    15231523        /* FETCH date,from,subject headers */ 
    1524         $key      = 'fh' . ($c++); 
    1525         $prefix   = $uidfetch?' UID':''; 
     1524        $key      = 'fh' . ($c++); 
     1525        $prefix   = $uidfetch?' UID':''; 
    15261526        $request  = $key . $prefix; 
    1527     $request .= " FETCH $message_set (BODY.PEEK[HEADER.FIELDS "; 
    1528     $request .= "(DATE FROM TO SUBJECT REPLY-TO IN-REPLY-TO CC BCC "; 
    1529     $request .= "CONTENT-TRANSFER-ENCODING CONTENT-TYPE MESSAGE-ID "; 
    1530     $request .= "REFERENCES DISPOSITION-NOTIFICATION-TO X-PRIORITY)])\r\n"; 
     1527        $request .= " FETCH $message_set (BODY.PEEK[HEADER.FIELDS "; 
     1528        $request .= "(DATE FROM TO SUBJECT REPLY-TO IN-REPLY-TO CC BCC "; 
     1529        $request .= "CONTENT-TRANSFER-ENCODING CONTENT-TYPE MESSAGE-ID "; 
     1530        $request .= "REFERENCES DISPOSITION-NOTIFICATION-TO X-PRIORITY)])\r\n"; 
    15311531 
    15321532        if (!fputs($fp, $request)) { 
    1533             return false; 
    1534     } 
     1533                return false; 
     1534        } 
    15351535        do { 
    15361536                $line = chop(iil_ReadLine($fp, 200)); 
     
    15721572                                if (preg_match("/^\s*UID [0-9]+\)$/", $line)) { 
    15731573                                    break; 
    1574                 } 
    1575             // patch from "Maksim Rubis" <siburny@hotmail.com> 
     1574                                } 
     1575                        // patch from "Maksim Rubis" <siburny@hotmail.com> 
    15761576                        } while (trim($line[0]) != ')' && strncmp($line, $key, strlen($key))); 
    15771577                         
    1578             if (strncmp($line, $key, strlen($key))) {  
    1579                         //process header, fill iilBasicHeader obj. 
    1580                         //      initialize 
    1581                         if (is_array($headers)) { 
    1582                                 reset($headers); 
    1583                                 while (list($k, $bar) = each($headers)) { 
    1584                         $headers[$k] = ''; 
    1585                     } 
    1586                         } 
    1587      
    1588                         //      create array with header field:data 
    1589                         while ( list($lines_key, $str) = each($lines) ) { 
    1590                                 list($field, $string) = iil_SplitHeaderLine($str); 
    1591                      
    1592                                 $field = strtolower($field); 
    1593                                  
    1594                                 switch ($field) { 
     1578                        if (strncmp($line, $key, strlen($key))) {  
     1579                                //process header, fill iilBasicHeader obj. 
     1580                                //      initialize 
     1581                                if (is_array($headers)) { 
     1582                                        reset($headers); 
     1583                                        while (list($k, $bar) = each($headers)) { 
     1584                                                $headers[$k] = ''; 
     1585                                        } 
     1586                                } 
     1587         
     1588                                //      create array with header field:data 
     1589                                while ( list($lines_key, $str) = each($lines) ) { 
     1590                                        list($field, $string) = iil_SplitHeaderLine($str); 
     1591                                         
     1592                                        $field = strtolower($field); 
     1593                                         
     1594                                        switch ($field) { 
    15951595                                        case 'date'; 
    1596                                                 $result[$id]->date      = $string; 
     1596                                                $result[$id]->date = $string; 
    15971597                                                $result[$id]->timestamp = iil_StrToTime($string); 
    15981598                                                break; 
     
    16191619                                                break; 
    16201620                                        case 'content-type': 
    1621                                                 $ctype_parts = explode(";", $string); 
     1621                                                $ctype_parts = explode(";", $string); 
    16221622                                                $result[$id]->ctype = array_shift($ctype_parts); 
    16231623                                                foreach ($ctype_parts as $ctype_add) { 
    1624                             if (preg_match('/charset="?([a-z0-9\-\.\_]+)"?/i', 
    1625                                 $ctype_add, $regs)) { 
    1626                                 $result[$id]->charset = $regs[1]; 
     1624                                                        if (preg_match('/charset="?([a-z0-9\-\.\_]+)"?/i', 
     1625                                                                $ctype_add, $regs)) { 
     1626                                                                $result[$id]->charset = $regs[1]; 
    16271627                                                        } 
    1628                         } 
    1629                         break; 
     1628                                                } 
     1629                                                break; 
    16301630                                        case 'in-reply-to': 
    16311631                                                $result[$id]->in_reply_to = ereg_replace("[\n<>]", '', $string); 
     
    16461646                                                        $result[$id]->priority = intval($matches[1]); 
    16471647                                                break; 
    1648                                 } // end switch () 
    1649                         } // end while () 
    1650                     } else { 
    1651                             $a = explode(' ', $line); 
    1652                     } 
    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); 
     1648                                        } // end switch () 
     1649                                } // end while () 
     1650                        } else { 
     1651                                $a = explode(' ', $line); 
     1652                        } 
    17011653                } 
    17021654        } while (strcmp($a[0], $key) != 0); 
     
    17071659        */ 
    17081660        $command_key = 'fh' . ($c++); 
    1709      
    17101661        $request  = $command_key . $prefix; 
    1711     $request .= " FETCH $message_set (UID RFC822.SIZE FLAGS INTERNALDATE)\r\n"; 
     1662        $request .= " FETCH $message_set (UID RFC822.SIZE FLAGS INTERNALDATE)\r\n"; 
     1663         
    17121664        if (!fputs($fp, $request)) { 
    17131665            return false; 
    17141666        } 
    17151667    do { 
    1716                 $line=chop(iil_ReadLine($fp, 200)); 
     1668                $line = chop(iil_ReadLine($fp, 200)); 
    17171669                //$a = explode(' ', $line); 
    17181670                //if (($line[0]=="*") && ($a[2]=="FETCH")) { 
     
    17801732                                            $time_zone += 0.5;  //handle half hour offset 
    17811733                                        } 
    1782                     if ($time_zone_str[0] == '-') { 
    1783                         $time_zone = $time_zone * -1.0; //minus? 
     1734                                        if ($time_zone_str[0] == '-') { 
     1735                                                $time_zone = $time_zone * -1.0; //minus? 
    17841736                                        } 
    1785                     $result[$id]->internaldate = $time_str; 
     1737                                        $result[$id]->internaldate = $time_str; 
    17861738                                         
    1787                                         if ($IMAP_USE_INTERNAL_DATE) { 
     1739                                        if ($IMAP_USE_INTERNAL_DATE || empty($result[$id]->date)) { 
    17881740                                                //calculate timestamp 
    17891741                                                $timestamp     = strtotime($time_str); //return's server's time 
     
    17921744                                                 
    17931745                                                $result[$id]->timestamp = $timestamp; 
     1746                                                $result[$id]->date = $time_str; 
    17941747                                        } 
    17951748                                                 
     
    18141767        $a  = iil_C_FetchHeaders($conn, $mailbox, $id, $uidfetch); 
    18151768        if (is_array($a)) { 
    1816             return array_shift($a); 
    1817     } 
     1769                return array_shift($a); 
     1770        } 
    18181771        return false; 
    18191772} 
Note: See TracChangeset for help on using the changeset viewer.