Methods Summary |
---|
public void | append(com.sun.mail.iap.Argument arg)append the given Argument to this Argument. All items
from the source argument are copied into this destination
argument.
items.ensureCapacity(items.size() + arg.items.size());
for (int i=0; i < arg.items.size(); i++)
items.addElement(arg.items.elementAt(i));
|
private void | astring(byte[] bytes, com.sun.mail.iap.Protocol protocol)Write out given String as either an Atom, QuotedString or Literal
DataOutputStream os = (DataOutputStream)protocol.getOutputStream();
int len = bytes.length;
// If length is greater than 1024 bytes, send as literal
if (len > 1024) {
literal(bytes, protocol);
return;
}
// if 0 length, send as quoted-string
boolean quote = len == 0 ? true: false;
boolean escape = false;
byte b;
for (int i = 0; i < len; i++) {
b = bytes[i];
if (b == '\0" || b == '\r" || b == '\n" || ((b & 0xff) > 0177)) {
// NUL, CR or LF means the bytes need to be sent as literals
literal(bytes, protocol);
return;
}
if (b == '*" || b == '%" || b == '(" || b == ')" || b == '{" ||
b == '"" || b == '\\" || ((b & 0xff) <= ' ")) {
quote = true;
if (b == '"" || b == '\\") // need to escape these characters
escape = true;
}
}
if (quote) // start quote
os.write('"");
if (escape) {
// already quoted
for (int i = 0; i < len; i++) {
b = bytes[i];
if (b == '"" || b == '\\")
os.write('\\");
os.write(b);
}
} else
os.write(bytes);
if (quote) // end quote
os.write('"");
|
private void | literal(byte[] b, com.sun.mail.iap.Protocol protocol)Write out given byte[] as a literal
startLiteral(protocol, b.length).write(b);
|
private void | literal(java.io.ByteArrayOutputStream b, com.sun.mail.iap.Protocol protocol)Write out given ByteArrayOutputStream as a literal.
b.writeTo(startLiteral(protocol, b.size()));
|
private void | literal(com.sun.mail.iap.Literal b, com.sun.mail.iap.Protocol protocol)Write out given Literal as a literal.
b.writeTo(startLiteral(protocol, b.size()));
|
private java.io.OutputStream | startLiteral(com.sun.mail.iap.Protocol protocol, int size)
DataOutputStream os = (DataOutputStream)protocol.getOutputStream();
boolean nonSync = protocol.supportsNonSyncLiterals();
os.write('{");
os.writeBytes(Integer.toString(size));
if (nonSync) // server supports non-sync literals
os.writeBytes("+}\r\n");
else
os.writeBytes("}\r\n");
os.flush();
// If we are using synchronized literals, wait for the server's
// continuation signal
if (!nonSync) {
for (; ;) {
Response r = protocol.readResponse();
if (r.isContinuation())
break;
if (r.isTagged())
throw new LiteralException(r);
// XXX - throw away untagged responses;
// violates IMAP spec, hope no servers do this
}
}
return os;
|
public void | write(com.sun.mail.iap.Protocol protocol)
int size = items != null ? items.size() : 0;
DataOutputStream os = (DataOutputStream)protocol.getOutputStream();
for (int i=0; i < size; i++) {
if (i > 0) // write delimiter if not the first item
os.write(' ");
Object o = items.elementAt(i);
if (o instanceof Atom) {
os.writeBytes(((Atom)o).string);
} else if (o instanceof Number) {
os.writeBytes(((Number)o).toString());
} else if (o instanceof AString) {
astring(((AString)o).bytes, protocol);
} else if (o instanceof byte[]) {
literal((byte[])o, protocol);
} else if (o instanceof ByteArrayOutputStream) {
literal((ByteArrayOutputStream)o, protocol);
} else if (o instanceof Literal) {
literal((Literal)o, protocol);
} else if (o instanceof Argument) {
os.write('("); // open parans
((Argument)o).write(protocol);
os.write(')"); // close parans
}
}
|
public void | writeArgument(com.sun.mail.iap.Argument c)Write out as parenthesised list.
items.addElement(c);
|
public void | writeAtom(java.lang.String s)Write out given string as an Atom. Note that an Atom can contain only
certain US-ASCII characters. No validation is done on the characters
in the string.
items.addElement(new Atom(s));
|
public void | writeBytes(byte[] b)Write out given byte[] as a Literal.
items.addElement(b);
|
public void | writeBytes(java.io.ByteArrayOutputStream b)Write out given ByteArrayOutputStream as a Literal.
items.addElement(b);
|
public void | writeBytes(com.sun.mail.iap.Literal b)Write out given data as a literal.
items.addElement(b);
|
public void | writeNumber(long i)Write out number.
items.addElement(new Long(i));
|
public void | writeNumber(int i)Write out number.
items.addElement(new Integer(i));
|
public void | writeString(java.lang.String s)Write out given string as an ASTRING, depending on the type
of the characters inside the string. The string should
contain only ASCII characters.
XXX: Hmm .. this should really be called writeASCII()
items.addElement(new AString(ASCIIUtility.getBytes(s)));
|
public void | writeString(java.lang.String s, java.lang.String charset)Convert the given string into bytes in the specified
charset, and write the bytes out as an ASTRING
if (charset == null) // convenience
writeString(s);
else
items.addElement(new AString(s.getBytes(charset)));
|