2008-11-01 17:32:06 -04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-12-14 21:50:53 -05:00
|
|
|
package com.fsck.k9.mail.store;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2009-12-09 22:16:42 -05:00
|
|
|
import android.util.Log;
|
2009-12-14 21:50:53 -05:00
|
|
|
import com.fsck.k9.K9;
|
|
|
|
import com.fsck.k9.FixedLengthInputStream;
|
|
|
|
import com.fsck.k9.PeekableInputStream;
|
|
|
|
import com.fsck.k9.mail.MessagingException;
|
2009-12-09 22:16:42 -05:00
|
|
|
|
2008-11-01 17:32:06 -04:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.text.ParseException;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Date;
|
2009-03-04 14:49:39 -05:00
|
|
|
import java.util.Locale;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public class ImapResponseParser
|
|
|
|
{
|
2009-03-04 14:49:39 -05:00
|
|
|
SimpleDateFormat mDateTimeFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss Z", Locale.US);
|
2009-10-28 08:45:22 -04:00
|
|
|
|
|
|
|
SimpleDateFormat badDateTimeFormat = new SimpleDateFormat("dd MMM yyyy HH:mm:ss Z", Locale.US);
|
2010-03-25 11:21:05 -04:00
|
|
|
SimpleDateFormat badDateTimeFormat2 = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z", Locale.US);
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2008-11-01 17:32:06 -04:00
|
|
|
PeekableInputStream mIn;
|
|
|
|
InputStream mActiveLiteral;
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public ImapResponseParser(PeekableInputStream in)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
this.mIn = in;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads the next response available on the stream and returns an
|
|
|
|
* ImapResponse object that represents it.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* @throws IOException
|
|
|
|
*/
|
2009-11-24 19:40:29 -05:00
|
|
|
public ImapResponse readResponse() throws IOException
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
ImapResponse response = new ImapResponse();
|
2009-11-24 19:40:29 -05:00
|
|
|
if (mActiveLiteral != null)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
while (mActiveLiteral.read() != -1)
|
|
|
|
;
|
|
|
|
mActiveLiteral = null;
|
|
|
|
}
|
|
|
|
int ch = mIn.peek();
|
2009-11-24 19:40:29 -05:00
|
|
|
if (ch == '*')
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
parseUntaggedResponse();
|
|
|
|
readTokens(response);
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
|
|
|
else if (ch == '+')
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
response.mCommandContinuationRequested =
|
2009-11-24 19:40:29 -05:00
|
|
|
parseCommandContinuationRequest();
|
2008-11-01 17:32:06 -04:00
|
|
|
readTokens(response);
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
response.mTag = parseTaggedResponse();
|
|
|
|
readTokens(response);
|
|
|
|
}
|
2009-12-14 21:50:53 -05:00
|
|
|
if (K9.DEBUG)
|
2009-11-24 19:40:29 -05:00
|
|
|
{
|
2009-12-14 21:50:53 -05:00
|
|
|
Log.v(K9.LOG_TAG, "<<< " + response.toString());
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
private void readTokens(ImapResponse response) throws IOException
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
response.clear();
|
|
|
|
Object token;
|
2009-11-24 19:40:29 -05:00
|
|
|
while ((token = readToken()) != null)
|
|
|
|
{
|
|
|
|
if (response != null)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
response.add(token);
|
|
|
|
}
|
2009-11-24 19:40:29 -05:00
|
|
|
if (mActiveLiteral != null)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
response.mCompleted = token == null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads the next token of the response. The token can be one of: String -
|
|
|
|
* for NIL, QUOTED, NUMBER, ATOM. InputStream - for LITERAL.
|
|
|
|
* InputStream.available() returns the total length of the stream.
|
|
|
|
* ImapResponseList - for PARENTHESIZED LIST. Can contain any of the above
|
|
|
|
* elements including List.
|
|
|
|
*
|
|
|
|
* @return The next token in the response or null if there are no more
|
|
|
|
* tokens.
|
|
|
|
* @throws IOException
|
|
|
|
*/
|
2009-11-24 19:40:29 -05:00
|
|
|
public Object readToken() throws IOException
|
|
|
|
{
|
|
|
|
while (true)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
Object token = parseToken();
|
2009-11-24 19:40:29 -05:00
|
|
|
if (token == null || !token.equals(")") || !token.equals("]"))
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return token;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
private Object parseToken() throws IOException
|
|
|
|
{
|
|
|
|
if (mActiveLiteral != null)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
while (mActiveLiteral.read() != -1)
|
|
|
|
;
|
|
|
|
mActiveLiteral = null;
|
|
|
|
}
|
2009-11-24 19:40:29 -05:00
|
|
|
while (true)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
int ch = mIn.peek();
|
2009-11-24 19:40:29 -05:00
|
|
|
if (ch == '(')
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return parseList();
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
|
|
|
else if (ch == '[')
|
|
|
|
{
|
2009-10-21 20:41:06 -04:00
|
|
|
return parseSequence();
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
|
|
|
else if (ch == ')')
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
expect(')');
|
|
|
|
return ")";
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
|
|
|
else if (ch == ']')
|
|
|
|
{
|
|
|
|
expect(']');
|
|
|
|
return "]";
|
|
|
|
}
|
|
|
|
else if (ch == '"')
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return parseQuoted();
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
|
|
|
else if (ch == '{')
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
mActiveLiteral = parseLiteral();
|
|
|
|
return mActiveLiteral;
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
|
|
|
else if (ch == ' ')
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
expect(' ');
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
|
|
|
else if (ch == '\r')
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
expect('\r');
|
|
|
|
expect('\n');
|
|
|
|
return null;
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
|
|
|
else if (ch == '\n')
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
expect('\n');
|
|
|
|
return null;
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
|
|
|
else if (ch == '\t')
|
|
|
|
{
|
|
|
|
expect('\t');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return parseAtom();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
private boolean parseCommandContinuationRequest() throws IOException
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
expect('+');
|
|
|
|
expect(' ');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// * OK [UIDNEXT 175] Predicted next UID
|
2009-11-24 19:40:29 -05:00
|
|
|
private void parseUntaggedResponse() throws IOException
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
expect('*');
|
|
|
|
expect(' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
// 3 OK [READ-WRITE] Select completed.
|
2009-11-24 19:40:29 -05:00
|
|
|
private String parseTaggedResponse() throws IOException
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
String tag = readStringUntil(' ');
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
private ImapList parseList() throws IOException
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
expect('(');
|
|
|
|
ImapList list = new ImapList();
|
|
|
|
Object token;
|
2009-11-24 19:40:29 -05:00
|
|
|
while (true)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
token = parseToken();
|
2009-11-24 19:40:29 -05:00
|
|
|
if (token == null)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
break;
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
|
|
|
else if (token instanceof InputStream)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
list.add(token);
|
|
|
|
break;
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
|
|
|
else if (token.equals(")"))
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
break;
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
list.add(token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
2009-11-24 19:40:29 -05:00
|
|
|
|
|
|
|
private ImapList parseSequence() throws IOException
|
|
|
|
{
|
2009-10-21 20:41:06 -04:00
|
|
|
expect('[');
|
|
|
|
ImapList list = new ImapList();
|
|
|
|
Object token;
|
2009-11-24 19:40:29 -05:00
|
|
|
while (true)
|
|
|
|
{
|
2009-10-21 20:41:06 -04:00
|
|
|
token = parseToken();
|
2009-11-24 19:40:29 -05:00
|
|
|
if (token == null)
|
|
|
|
{
|
2009-10-21 20:41:06 -04:00
|
|
|
break;
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
|
|
|
else if (token instanceof InputStream)
|
|
|
|
{
|
2009-10-21 20:41:06 -04:00
|
|
|
list.add(token);
|
|
|
|
break;
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
|
|
|
else if (token.equals("]"))
|
|
|
|
{
|
2009-10-21 20:41:06 -04:00
|
|
|
break;
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-21 20:41:06 -04:00
|
|
|
list.add(token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
private String parseAtom() throws IOException
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
StringBuffer sb = new StringBuffer();
|
|
|
|
int ch;
|
2009-11-24 19:40:29 -05:00
|
|
|
while (true)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
ch = mIn.peek();
|
2009-11-24 19:40:29 -05:00
|
|
|
if (ch == -1)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
throw new IOException("parseAtom(): end of stream reached");
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
|
|
|
else if (ch == '(' || ch == ')' || ch == '{' || ch == ' ' ||
|
|
|
|
ch == '[' || ch == ']' ||
|
|
|
|
// docs claim that flags are \ atom but atom isn't supposed to
|
|
|
|
// contain
|
|
|
|
// * and some falgs contain *
|
|
|
|
// ch == '%' || ch == '*' ||
|
2009-10-28 08:45:22 -04:00
|
|
|
// ch == '%' ||
|
2009-11-24 19:40:29 -05:00
|
|
|
// TODO probably should not allow \ and should recognize
|
|
|
|
// it as a flag instead
|
|
|
|
// ch == '"' || ch == '\' ||
|
|
|
|
ch == '"' || (ch >= 0x00 && ch <= 0x1f) || ch == 0x7f)
|
|
|
|
{
|
|
|
|
if (sb.length() == 0)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
throw new IOException(String.format("parseAtom(): (%04x %c)", (int)ch, ch));
|
|
|
|
}
|
|
|
|
return sb.toString();
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
sb.append((char)mIn.read());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A { has been read, read the rest of the size string, the space and then
|
|
|
|
* notify the listener with an InputStream.
|
|
|
|
*
|
|
|
|
* @param mListener
|
|
|
|
* @throws IOException
|
|
|
|
*/
|
2009-11-24 19:40:29 -05:00
|
|
|
private InputStream parseLiteral() throws IOException
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
expect('{');
|
|
|
|
int size = Integer.parseInt(readStringUntil('}'));
|
|
|
|
expect('\r');
|
|
|
|
expect('\n');
|
|
|
|
FixedLengthInputStream fixed = new FixedLengthInputStream(mIn, size);
|
|
|
|
return fixed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A " has been read, read to the end of the quoted string and notify the
|
|
|
|
* listener.
|
|
|
|
*
|
|
|
|
* @param mListener
|
|
|
|
* @throws IOException
|
|
|
|
*/
|
2009-11-24 19:40:29 -05:00
|
|
|
private String parseQuoted() throws IOException
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
expect('"');
|
|
|
|
return readStringUntil('"');
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
private String readStringUntil(char end) throws IOException
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
StringBuffer sb = new StringBuffer();
|
|
|
|
int ch;
|
2009-11-24 19:40:29 -05:00
|
|
|
while ((ch = mIn.read()) != -1)
|
|
|
|
{
|
|
|
|
if (ch == end)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return sb.toString();
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
sb.append((char)ch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new IOException("readQuotedString(): end of stream reached");
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
private int expect(char ch) throws IOException
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
int d;
|
2009-11-24 19:40:29 -05:00
|
|
|
if ((d = mIn.read()) != ch)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
throw new IOException(String.format("Expected %04x (%c) but got %04x (%c)", (int)ch,
|
2009-11-24 19:40:29 -05:00
|
|
|
ch, d, (char)d));
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents an IMAP LIST response and is also the base class for the
|
|
|
|
* ImapResponse.
|
|
|
|
*/
|
2009-11-24 19:40:29 -05:00
|
|
|
public class ImapList extends ArrayList<Object>
|
|
|
|
{
|
|
|
|
public ImapList getList(int index)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return (ImapList)get(index);
|
|
|
|
}
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2009-04-21 00:22:02 -04:00
|
|
|
public Object getObject(int index)
|
|
|
|
{
|
2009-11-24 19:40:29 -05:00
|
|
|
return get(index);
|
2009-04-21 00:22:02 -04:00
|
|
|
}
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public String getString(int index)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return (String)get(index);
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public InputStream getLiteral(int index)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return (InputStream)get(index);
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public int getNumber(int index)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return Integer.parseInt(getString(index));
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public Date getDate(int index) throws MessagingException
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2009-10-28 08:45:22 -04:00
|
|
|
return parseDate(getString(index));
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
|
|
|
catch (ParseException pe)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
throw new MessagingException("Unable to parse IMAP datetime", pe);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public Object getKeyedValue(Object key)
|
|
|
|
{
|
|
|
|
for (int i = 0, count = size(); i < count; i++)
|
|
|
|
{
|
|
|
|
if (get(i).equals(key))
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return get(i + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public ImapList getKeyedList(Object key)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return (ImapList)getKeyedValue(key);
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public String getKeyedString(Object key)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return (String)getKeyedValue(key);
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public InputStream getKeyedLiteral(Object key)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return (InputStream)getKeyedValue(key);
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public int getKeyedNumber(Object key)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return Integer.parseInt(getKeyedString(key));
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public Date getKeyedDate(Object key) throws MessagingException
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
String value = getKeyedString(key);
|
2009-11-24 19:40:29 -05:00
|
|
|
if (value == null)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return null;
|
|
|
|
}
|
2009-10-28 08:45:22 -04:00
|
|
|
return parseDate(value);
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
|
|
|
catch (ParseException pe)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
throw new MessagingException("Unable to parse IMAP datetime", pe);
|
|
|
|
}
|
|
|
|
}
|
2010-02-10 08:52:25 -05:00
|
|
|
|
|
|
|
public boolean containsKey(Object key)
|
|
|
|
{
|
|
|
|
if (key == null)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0, count = size(); i < count; i++)
|
|
|
|
{
|
|
|
|
if (key.equals(get(i)))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getKeyIndex(Object key)
|
|
|
|
{
|
|
|
|
for (int i = 0, count = size(); i < count; i++)
|
|
|
|
{
|
|
|
|
if (key.equals(get(i)))
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new IllegalArgumentException("getKeyIndex() only works for keys that are in the collection.");
|
|
|
|
}
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2009-10-28 08:45:22 -04:00
|
|
|
private Date parseDate(String value) throws ParseException
|
|
|
|
{
|
2010-03-25 11:21:05 -04:00
|
|
|
//TODO: clean this up a bit
|
2009-10-28 08:45:22 -04:00
|
|
|
try
|
|
|
|
{
|
2009-11-24 19:40:29 -05:00
|
|
|
synchronized (mDateTimeFormat)
|
2009-10-28 08:45:22 -04:00
|
|
|
{
|
|
|
|
return mDateTimeFormat.parse(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2010-03-25 11:21:05 -04:00
|
|
|
try
|
2009-10-28 08:45:22 -04:00
|
|
|
{
|
2010-03-25 11:21:05 -04:00
|
|
|
synchronized (badDateTimeFormat)
|
|
|
|
{
|
|
|
|
return badDateTimeFormat.parse(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e2)
|
|
|
|
{
|
|
|
|
synchronized (badDateTimeFormat2)
|
|
|
|
{
|
|
|
|
return badDateTimeFormat2.parse(value);
|
|
|
|
}
|
2009-10-28 08:45:22 -04:00
|
|
|
}
|
|
|
|
}
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2009-10-28 08:45:22 -04:00
|
|
|
}
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents a single response from the IMAP server. Tagged responses will
|
|
|
|
* have a non-null tag. Untagged responses will have a null tag. The object
|
|
|
|
* will contain all of the available tokens at the time the response is
|
|
|
|
* received. In general, it will either contain all of the tokens of the
|
|
|
|
* response or all of the tokens up until the first LITERAL. If the object
|
|
|
|
* does not contain the entire response the caller must call more() to
|
|
|
|
* continue reading the response until more returns false.
|
|
|
|
*/
|
2009-11-24 19:40:29 -05:00
|
|
|
public class ImapResponse extends ImapList
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
private boolean mCompleted;
|
|
|
|
|
|
|
|
boolean mCommandContinuationRequested;
|
|
|
|
String mTag;
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public boolean more() throws IOException
|
|
|
|
{
|
|
|
|
if (mCompleted)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
readTokens(this);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public String getAlertText()
|
|
|
|
{
|
|
|
|
if (size() > 1 && "[ALERT]".equals(get(1)))
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
StringBuffer sb = new StringBuffer();
|
2009-11-24 19:40:29 -05:00
|
|
|
for (int i = 2, count = size(); i < count; i++)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
sb.append(get(i).toString());
|
|
|
|
sb.append(' ');
|
|
|
|
}
|
|
|
|
return sb.toString();
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public String toString()
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return "#" + mTag + "# " + super.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|