1 36 package org.columba.ristretto.pop3.parser; 37 38 import java.util.regex.Matcher ; 39 import java.util.regex.Pattern ; 40 41 import org.columba.ristretto.parser.ParserException; 42 import org.columba.ristretto.pop3.POP3Response; 43 44 49 public class POP3ResponseParser { 50 51 private static final Pattern responsePattern = Pattern.compile("(\\+|\\-)(OK|ERR)? ?([^\r\n]*)\r?\n?"); 52 53 60 public static POP3Response parse( CharSequence line ) throws ParserException { 61 Matcher matcher = responsePattern.matcher(line); 62 63 if( matcher.find() ) { 64 POP3Response response = new POP3Response(line); 65 response.setType(matcher.group(1).equals("+") ? POP3Response.OK : POP3Response.ERR); 67 68 response.setMessage(matcher.group(3)); 70 71 return response; 72 } else { 73 throw new ParserException( "Malformed POP3 response : "+line ); 74 } 75 76 } 77 78 } 79 | Popular Tags |