1 36 package org.columba.ristretto.imap.parser; 37 38 import java.util.regex.Matcher ; 39 import java.util.regex.Pattern ; 40 41 import org.columba.ristretto.message.Attributes; 42 43 49 public class MessageAttributeParser { 50 51 52 private static final Pattern msg_att_key = Pattern.compile(" ?(ENVELOPE|INTERNALDATE|RFC822.(HEADER|TEXT|SIZE)|UID|FLAGS|BODYSTRUCTURE|BODY(\\[[^\\]]*\\])?) "); 53 54 60 public static Attributes parse( String input ) { 61 String strippedParentheses = input.substring(1,input.length()-1); 63 64 Matcher matcher = msg_att_key.matcher(strippedParentheses); 65 Attributes result = new Attributes(); 66 String lastKey = null; 67 int lastEnd = 0; 68 69 while(matcher.find()) { 71 if( lastKey != null ) { 72 result.put(lastKey,strippedParentheses.substring(lastEnd,matcher.start())); 73 } 74 lastKey = matcher.group(1); 75 if( lastKey.startsWith("BODY") && !lastKey.equals("BODYSTRUCTURE") ) { 77 lastKey = "BODY"; 78 } 79 lastEnd = matcher.end(); 80 } 81 82 if( lastKey != null ) { 83 result.put(lastKey,strippedParentheses.substring(lastEnd,strippedParentheses.length())); 84 } 85 86 return result; 87 } 88 89 } 90 | Popular Tags |