1 20 package org.columba.mail; 21 22 29 class HeaderTokenizer 30 { 31 32 private String input; 33 private int actPos; 34 35 public HeaderTokenizer( String input ) 36 { 37 this.input = input; 38 actPos = 0; 39 } 40 41 43 private String killComments( String commented ) 44 { 45 int end; 46 int start = commented.indexOf("("); 47 int quoted; 48 49 if( start == -1 ) return commented; 50 51 StringBuffer output = new StringBuffer ( commented ); 52 53 while( start != -1 ) 54 { 55 end = output.toString().indexOf(")",start); 56 57 if( end == -1 ) return output.toString(); 58 59 quoted = commented.indexOf( "?=", start ); 60 if( (quoted == -1) | (quoted > end) ) { 61 output = output.delete(start,end+1); 62 start = output.toString().indexOf("("); 63 } 64 else { 65 start = output.toString().indexOf("(", end); 66 } 67 } 68 69 return output.toString(); 70 } 71 72 74 public String nextLine() 75 { 76 StringBuffer output; 77 int crlfPos; 78 79 if(actPos >= input.length()) return null; 80 81 if( (input.charAt(actPos)=='\n') ) return null; 82 83 crlfPos = input.indexOf('\n',actPos); 84 if( crlfPos == -1 ) return null; 85 86 output = new StringBuffer ( killComments( input.substring(actPos,crlfPos)) ); 87 actPos = crlfPos + 1; 88 if(actPos >= input.length()) return output.toString().trim(); 89 90 while( input.charAt(actPos) == '\t' | input.charAt(actPos) == ' ' ) 91 { 92 crlfPos = input.indexOf('\n',actPos); 93 output.append( '\n' + killComments( input.substring(actPos,crlfPos)) ); actPos = crlfPos + 1; 95 if( actPos >= input.length() ) return output.toString().trim(); 96 } 97 98 return output.toString().trim(); 99 100 } 101 102 } 103 | Popular Tags |