Fields Summary |
---|
public static final int | CONNECTION_SECURITY_NONE |
public static final int | CONNECTION_SECURITY_TLS_OPTIONAL |
public static final int | CONNECTION_SECURITY_TLS_REQUIRED |
public static final int | CONNECTION_SECURITY_SSL_REQUIRED |
public static final int | CONNECTION_SECURITY_SSL_OPTIONAL |
private static final com.android.email.mail.Flag[] | PERMANENT_FLAGS |
private com.android.email.mail.Transport | mRootTransport |
private String | mUsername |
private String | mPassword |
private String | mLoginPhrase |
private String | mPathPrefix |
private LinkedList | mConnections |
private Charset | mModifiedUtf7CharsetCharset used for converting folder names to and from UTF-7 as defined by RFC 3501. |
private HashMap | mFolderCacheCache of ImapFolder objects. ImapFolders are attached to a given folder on the server
and as long as their associated connection remains open they are reusable between
requests. This cache lets us make sure we always reuse, if possible, for a given
folder name. |
Methods Summary |
---|
public void | checkSettings()
try {
ImapConnection connection = new ImapConnection();
connection.open();
connection.close();
}
catch (IOException ioe) {
throw new MessagingException(MessagingException.IOERROR, ioe.toString());
}
|
private java.lang.String | decodeFolderName(java.lang.String name)
/*
* Convert the encoded name to US-ASCII, then pass it through the modified UTF-7
* decoder and return the Unicode String.
*/
try {
byte[] encoded = name.getBytes("US-ASCII");
CharBuffer cb = mModifiedUtf7Charset.decode(ByteBuffer.wrap(encoded));
return cb.toString();
}
catch (UnsupportedEncodingException uee) {
/*
* The only thing that can throw this is getBytes("US-ASCII") and if US-ASCII doesn't
* exist we're totally screwed.
*/
throw new RuntimeException("Unable to decode folder name: " + name, uee);
}
|
private java.lang.String | encodeFolderName(java.lang.String name)
try {
ByteBuffer bb = mModifiedUtf7Charset.encode(name);
byte[] b = new byte[bb.limit()];
bb.get(b);
return new String(b, "US-ASCII");
}
catch (UnsupportedEncodingException uee) {
/*
* The only thing that can throw this is getBytes("US-ASCII") and if US-ASCII doesn't
* exist we're totally screwed.
*/
throw new RuntimeException("Unabel to encode folder name: " + name, uee);
}
|
private com.android.email.mail.store.ImapStore$ImapConnection | getConnection()Gets a connection if one is available for reuse, or creates a new one if not.
synchronized (mConnections) {
ImapConnection connection = null;
while ((connection = mConnections.poll()) != null) {
try {
connection.executeSimpleCommand("NOOP");
break;
}
catch (IOException ioe) {
connection.close();
}
}
if (connection == null) {
connection = new ImapConnection();
}
return connection;
}
|
public com.android.email.mail.Folder | getFolder(java.lang.String name)
ImapFolder folder;
synchronized (mFolderCache) {
folder = mFolderCache.get(name);
if (folder == null) {
folder = new ImapFolder(name);
mFolderCache.put(name, folder);
}
}
return folder;
|
public com.android.email.mail.Folder[] | getPersonalNamespaces()
ImapConnection connection = getConnection();
try {
ArrayList<Folder> folders = new ArrayList<Folder>();
List<ImapResponse> responses =
connection.executeSimpleCommand(String.format("LIST \"\" \"%s*\"",
mPathPrefix == null ? "" : mPathPrefix));
for (ImapResponse response : responses) {
if (response.get(0).equals("LIST")) {
boolean includeFolder = true;
String folder = decodeFolderName(response.getString(3));
if (folder.equalsIgnoreCase("INBOX")) {
continue;
}
ImapList attributes = response.getList(1);
for (int i = 0, count = attributes.size(); i < count; i++) {
String attribute = attributes.getString(i);
if (attribute.equalsIgnoreCase("\\NoSelect")) {
includeFolder = false;
}
}
if (includeFolder) {
folders.add(getFolder(folder));
}
}
}
folders.add(getFolder("INBOX"));
return folders.toArray(new Folder[] {});
} catch (IOException ioe) {
connection.close();
throw new MessagingException("Unable to get folder list.", ioe);
} finally {
releaseConnection(connection);
}
|
private void | releaseConnection(com.android.email.mail.store.ImapStore$ImapConnection connection)
mConnections.offer(connection);
|
void | setTransport(com.android.email.mail.Transport testTransport)For testing only. Injects a different root transport (it will be copied using
newInstanceWithConfiguration() each time IMAP sets up a new channel). The transport
should already be set up and ready to use. Do not use for real code.
mRootTransport = testTransport;
|