Ignore:
Timestamp:
09/05/10 20:46:53 (21 months ago)
Author:
octorian
Message:

Separation, unit test, and minor bugfix for IMAP line response tester

Location:
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/imap
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LogicMail/src/org/logicprobe/LogicMail/mail/imap/ImapProtocol.java

    r698 r699  
    5555    private Connection connection; 
    5656    private String idleCommandTag; 
     57    private static final ConnectionResponseTester executeResponseTester = new ImapResponseLineTester();     
    5758 
    5859    /** 
     
    17441745        public String name; 
    17451746    } 
    1746      
    1747     private static ConnectionResponseTester executeResponseTester = new ConnectionResponseTester() { 
    1748         private static final byte CR = (byte) 0x0D; 
    1749         private static final byte LF = (byte) 0x0A; 
    1750         private int trimCount; 
    1751         private int lastLength = 0; 
    1752         private int literalLength = 0; 
    1753  
    1754         public int checkForCompleteResponse(byte[] buf, int len) { 
    1755             trimCount = 0; 
    1756  
    1757             if (literalLength > 0) { 
    1758                 if ((lastLength + literalLength) < len) { 
    1759                     lastLength += literalLength; 
    1760                     literalLength = 0; 
    1761                 } else { 
    1762                     literalLength -= (len - lastLength); 
    1763                     lastLength = len; 
    1764  
    1765                     return -1; 
    1766                 } 
    1767             } 
    1768  
    1769             int p = StringArrays.indexOf(buf, LF, lastLength); 
    1770  
    1771             while ((p != -1) && (p < len)) { 
    1772                 if ((p > 0) && (buf[p - 1] == CR)) { 
    1773                     if ((p > 3) && (buf[p - 2] == '}')) { 
    1774                         int i = p - 3; 
    1775  
    1776                         while (i >= 0) { 
    1777                             if ((buf[i] >= '0') && (buf[i] <= '9')) { 
    1778                                 i--; 
    1779                             } else if (buf[i] == '{') { 
    1780                                 try { 
    1781                                     literalLength = StringArrays.parseInt(buf, i + 1, p - i - 3); 
    1782                                     break; 
    1783                                 } catch (NumberFormatException e) { } 
    1784                             } 
    1785                         } 
    1786                     } 
    1787  
    1788                     trimCount = 2; 
    1789                 } else { 
    1790                     trimCount = 1; 
    1791                 } 
    1792  
    1793                 p++; 
    1794  
    1795                 if (literalLength > 0) { 
    1796                     if ((len - p) >= literalLength) { 
    1797                         p += literalLength; 
    1798                         literalLength = 0; 
    1799                     } else { 
    1800                         literalLength -= (len - p); 
    1801                         lastLength = len; 
    1802  
    1803                         return -1; 
    1804                     } 
    1805                 } else { 
    1806                     lastLength = 0; 
    1807                     literalLength = 0; 
    1808  
    1809                     return p; 
    1810                 } 
    1811  
    1812                 p = StringArrays.indexOf(buf, LF, p); 
    1813             } 
    1814  
    1815             lastLength = len; 
    1816  
    1817             return -1; 
    1818         } 
    1819  
    1820         public int trimCount() { 
    1821             return trimCount; 
    1822         } 
    1823  
    1824         public String logString(byte[] result) { 
    1825             return new String(result); 
    1826         } 
    1827     }; 
    18281747     
    18291748    // String constants 
Note: See TracChangeset for help on using the changeset viewer.