1 36 package org.columba.ristretto.imap.parser; 37 38 import java.util.regex.Pattern ; 39 40 import org.columba.ristretto.imap.IMAPResponse; 41 import org.columba.ristretto.imap.ResponseTextCode; 42 import org.columba.ristretto.message.MailboxInfo; 43 import org.columba.ristretto.parser.ParserException; 44 45 51 public class MailboxInfoParser { 52 private static final Pattern stringListPattern = Pattern 53 .compile("(\\s|\\()?([^\\s\\)]+)"); 54 55 62 public static MailboxInfo parse(IMAPResponse in) throws ParserException { 63 return parse( in, null); 64 } 65 66 75 public static MailboxInfo parse(IMAPResponse in, MailboxInfo mailboxInfo) throws ParserException { 76 MailboxInfo result; 77 78 if( mailboxInfo != null ) { 79 result = mailboxInfo; 80 } else 81 result = new MailboxInfo(); 82 83 String type = in.getResponseSubType(); 84 if (type.equals("RECENT")) { 85 result.setRecent(in.getPreNumber()); 86 } else if (type.equals("EXISTS")) { 87 result.setExists(in.getPreNumber()); 88 } else if (type.equals("FLAGS")) { 89 result.setDefinedFlags(StringListParser.parse(in 90 .getResponseMessage())); 91 } else if (type.equals("OK")) { 92 ResponseTextCode info = in.getResponseTextCode(); 93 if (info != null) { 94 switch (info.getType()) { 95 case ResponseTextCode.UNSEEN : { 96 result.setFirstUnseen(info.getIntValue()); 97 break; 98 } 99 case ResponseTextCode.UIDVALIDITY : { 100 result.setUidValidity(info.getIntValue()); 101 break; 102 } 103 case ResponseTextCode.UIDNEXT : { 104 result.setUidNext(info.getIntValue()); 105 break; 106 } 107 case ResponseTextCode.PERMANENTFLAGS : { 108 result 109 .setPermanentFlags(info 110 .getStringArrayValue()); 111 break; 112 } 113 114 case ResponseTextCode.READ_ONLY : { 115 result.setWriteAccess(false); 116 break; 117 } 118 119 case ResponseTextCode.READ_WRITE : { 120 result.setWriteAccess(true); 121 break; 122 } 123 124 default : { 125 } 127 } 128 } 129 } 130 131 return result; 132 } 133 } | Popular Tags |