1 21 22 27 28 package com.sun.mail.imap.protocol; 29 30 import java.util.*; 31 import com.sun.mail.iap.*; 32 33 40 41 public class Namespaces { 42 43 46 public static class Namespace { 47 50 public String prefix; 51 52 55 public char delimiter; 56 57 60 public Namespace(Response r) throws ProtocolException { 61 if (r.readByte() != '(') 64 throw new ProtocolException( 65 "Missing '(' at start of Namespace"); 66 prefix = BASE64MailboxDecoder.decode(r.readString()); 68 r.skipSpaces(); 69 if (r.peekByte() == '"') { 71 r.readByte(); 72 delimiter = (char)r.readByte(); 73 if (delimiter == '\\') 74 delimiter = (char)r.readByte(); 75 if (r.readByte() != '"') 76 throw new ProtocolException( 77 "Missing '\"' at end of QUOTED_CHAR"); 78 } else { 79 String s = r.readAtom(); 80 if (s == null) 81 throw new ProtocolException("Expected NIL, got null"); 82 if (!s.equalsIgnoreCase("NIL")) 83 throw new ProtocolException("Expected NIL, got " + s); 84 delimiter = 0; 85 } 86 if (r.peekByte() != ')') { 88 r.skipSpaces(); 92 r.readString(); 93 r.skipSpaces(); 94 r.readStringList(); 95 } 96 if (r.readByte() != ')') 97 throw new ProtocolException("Missing ')' at end of Namespace"); 98 } 99 }; 100 101 105 public Namespace[] personal; 106 107 111 public Namespace[] otherUsers; 112 113 117 public Namespace[] shared; 118 119 122 public Namespaces(Response r) throws ProtocolException { 123 personal = getNamespaces(r); 124 otherUsers = getNamespaces(r); 125 shared = getNamespaces(r); 126 } 127 128 131 private Namespace[] getNamespaces(Response r) throws ProtocolException { 132 r.skipSpaces(); 133 if (r.peekByte() == '(') { 135 Vector v = new Vector(); 136 r.readByte(); 137 do { 138 Namespace ns = new Namespace(r); 139 v.addElement(ns); 140 } while (r.peekByte() != ')'); 141 r.readByte(); 142 Namespace[] nsa = new Namespace[v.size()]; 143 v.copyInto(nsa); 144 return nsa; 145 } else { 146 String s = r.readAtom(); 147 if (s == null) 148 throw new ProtocolException("Expected NIL, got null"); 149 if (!s.equalsIgnoreCase("NIL")) 150 throw new ProtocolException("Expected NIL, got " + s); 151 return null; 152 } 153 } 154 } 155 | Popular Tags |