1 21 22 27 28 package com.sun.mail.imap.protocol; 29 30 import java.io.*; 31 import java.util.*; 32 import com.sun.mail.util.*; 33 import com.sun.mail.iap.*; 34 35 42 43 public class IMAPResponse extends Response { 44 private String key; 45 private int number; 46 47 public IMAPResponse(Protocol c) throws IOException, ProtocolException { 48 super(c); 49 50 if (isUnTagged() && !isOK() && !isNO() && !isBAD() && !isBYE()) { 52 key = readAtom(); 53 54 try { 56 number = Integer.parseInt(key); 57 key = readAtom(); 58 } catch (NumberFormatException ne) { } 59 } 60 } 61 62 65 public IMAPResponse(IMAPResponse r) { 66 super((Response)r); 67 key = r.key; 68 number = r.number; 69 } 70 71 77 public String [] readSimpleList() { 78 skipSpaces(); 79 80 if (buffer[index] != '(') return null; 82 index++; 84 Vector v = new Vector(); 85 int start; 86 for (start = index; buffer[index] != ')'; index++) { 87 if (buffer[index] == ' ') { v.addElement(ASCIIUtility.toString(buffer, start, index)); 89 start = index+1; } 91 } 92 if (index > start) v.addElement(ASCIIUtility.toString(buffer, start, index)); 94 index++; 96 int size = v.size(); 97 if (size > 0) { 98 String [] s = new String [size]; 99 v.copyInto(s); 100 return s; 101 } else return null; 103 } 104 105 public String getKey() { 106 return key; 107 } 108 109 public boolean keyEquals(String k) { 110 if (key != null && key.equalsIgnoreCase(k)) 111 return true; 112 else 113 return false; 114 } 115 116 public int getNumber() { 117 return number; 118 } 119 120 public static IMAPResponse readResponse(Protocol p) 121 throws IOException, ProtocolException { 122 IMAPResponse r = new IMAPResponse(p); 123 if (r.keyEquals("FETCH")) 124 r = new FetchResponse(r); 125 return r; 126 } 127 } 128 | Popular Tags |