diff options
Diffstat (limited to 'java/com/android/voicemail/impl/mail/store')
12 files changed, 257 insertions, 257 deletions
diff --git a/java/com/android/voicemail/impl/mail/store/ImapConnection.java b/java/com/android/voicemail/impl/mail/store/ImapConnection.java index 0a48dfc69..ac43f8d72 100644 --- a/java/com/android/voicemail/impl/mail/store/ImapConnection.java +++ b/java/com/android/voicemail/impl/mail/store/ImapConnection.java @@ -42,11 +42,11 @@ import javax.net.ssl.SSLException; public class ImapConnection { private final String TAG = "ImapConnection"; - private String mLoginPhrase; - private ImapStore mImapStore; - private MailTransport mTransport; - private ImapResponseParser mParser; - private Set<String> mCapabilities = new ArraySet<>(); + private String loginPhrase; + private ImapStore imapStore; + private MailTransport transport; + private ImapResponseParser parser; + private Set<String> capabilities = new ArraySet<>(); static final String IMAP_REDACTED_LOG = "[IMAP command redacted]"; @@ -55,7 +55,7 @@ public class ImapConnection { * counter to make tests simpler. (Some of the tests involve multiple connections but only have a * single counter to track the tag.) */ - private final AtomicInteger mNextCommandTag = new AtomicInteger(0); + private final AtomicInteger nextCommandTag = new AtomicInteger(0); ImapConnection(ImapStore store) { setStore(store); @@ -65,8 +65,8 @@ public class ImapConnection { // TODO: maybe we should throw an exception if the connection is not closed here, // if it's not currently closed, then we won't reopen it, so if the credentials have // changed, the connection will not be reestablished. - mImapStore = store; - mLoginPhrase = null; + imapStore = store; + loginPhrase = null; } /** @@ -76,42 +76,42 @@ public class ImapConnection { * @return the login command string to sent to the IMAP server */ String getLoginPhrase() { - if (mLoginPhrase == null) { - if (mImapStore.getUsername() != null && mImapStore.getPassword() != null) { + if (loginPhrase == null) { + if (imapStore.getUsername() != null && imapStore.getPassword() != null) { // build the LOGIN string once (instead of over-and-over again.) // apply the quoting here around the built-up password - mLoginPhrase = + loginPhrase = ImapConstants.LOGIN + " " - + mImapStore.getUsername() + + imapStore.getUsername() + " " - + ImapUtility.imapQuoted(mImapStore.getPassword()); + + ImapUtility.imapQuoted(imapStore.getPassword()); } } - return mLoginPhrase; + return loginPhrase; } public void open() throws IOException, MessagingException { - if (mTransport != null && mTransport.isOpen()) { + if (transport != null && transport.isOpen()) { return; } try { // copy configuration into a clean transport, if necessary - if (mTransport == null) { - mTransport = mImapStore.cloneTransport(); + if (transport == null) { + transport = imapStore.cloneTransport(); } - mTransport.open(); + transport.open(); createParser(); // The server should greet us with something like // * OK IMAP4rev1 Server // consume the response before doing anything else. - ImapResponse response = mParser.readResponse(false); + ImapResponse response = parser.readResponse(false); if (!response.isOk()) { - mImapStore.getImapHelper().handleEvent(OmtpEvents.DATA_INVALID_INITIAL_SERVER_RESPONSE); + imapStore.getImapHelper().handleEvent(OmtpEvents.DATA_INVALID_INITIAL_SERVER_RESPONSE); throw new MessagingException( MessagingException.AUTHENTICATION_FAILED_OR_SERVER_ERROR, "Invalid server initial response"); @@ -125,11 +125,11 @@ public class ImapConnection { doLogin(); } catch (SSLException e) { LogUtils.d(TAG, "SSLException ", e); - mImapStore.getImapHelper().handleEvent(OmtpEvents.DATA_SSL_EXCEPTION); + imapStore.getImapHelper().handleEvent(OmtpEvents.DATA_SSL_EXCEPTION); throw new CertificateValidationException(e.getMessage(), e); } catch (IOException ioe) { LogUtils.d(TAG, "IOException", ioe); - mImapStore.getImapHelper().handleEvent(OmtpEvents.DATA_IOE_ON_OPEN); + imapStore.getImapHelper().handleEvent(OmtpEvents.DATA_IOE_ON_OPEN); throw ioe; } finally { destroyResponses(); @@ -139,10 +139,10 @@ public class ImapConnection { void logout() { try { sendCommand(ImapConstants.LOGOUT, false); - if (!mParser.readResponse(true).is(0, ImapConstants.BYE)) { + if (!parser.readResponse(true).is(0, ImapConstants.BYE)) { VvmLog.e(TAG, "Server did not respond LOGOUT with BYE"); } - if (!mParser.readResponse(false).isOk()) { + if (!parser.readResponse(false).isOk()) { VvmLog.e(TAG, "Server did not respond OK after LOGOUT"); } } catch (IOException | MessagingException e) { @@ -155,14 +155,14 @@ public class ImapConnection { * {@link #setStore(ImapStore)} is called. */ void close() { - if (mTransport != null) { + if (transport != null) { logout(); - mTransport.close(); - mTransport = null; + transport.close(); + transport = null; } destroyResponses(); - mParser = null; - mImapStore = null; + parser = null; + imapStore = null; } /** Attempts to convert the connection into secure connection. */ @@ -171,7 +171,7 @@ public class ImapConnection { // Make sure the server does have this capability if (hasCapability(ImapConstants.CAPABILITY_STARTTLS)) { executeSimpleCommand(ImapConstants.STARTTLS); - mTransport.reopenTls(); + transport.reopenTls(); createParser(); // The cached capabilities should be refreshed after TLS is established. queryCapability(); @@ -181,7 +181,7 @@ public class ImapConnection { /** Logs into the IMAP server */ private void doLogin() throws IOException, MessagingException, AuthenticationFailedException { try { - if (mCapabilities.contains(ImapConstants.CAPABILITY_AUTH_DIGEST_MD5)) { + if (capabilities.contains(ImapConstants.CAPABILITY_AUTH_DIGEST_MD5)) { doDigestMd5Auth(); } else { executeSimpleCommand(getLoginPhrase(), true); @@ -195,36 +195,36 @@ public class ImapConnection { if (ImapConstants.NO.equals(status)) { switch (statusMessage) { case ImapConstants.NO_UNKNOWN_USER: - mImapStore.getImapHelper().handleEvent(OmtpEvents.DATA_AUTH_UNKNOWN_USER); + imapStore.getImapHelper().handleEvent(OmtpEvents.DATA_AUTH_UNKNOWN_USER); break; case ImapConstants.NO_UNKNOWN_CLIENT: - mImapStore.getImapHelper().handleEvent(OmtpEvents.DATA_AUTH_UNKNOWN_DEVICE); + imapStore.getImapHelper().handleEvent(OmtpEvents.DATA_AUTH_UNKNOWN_DEVICE); break; case ImapConstants.NO_INVALID_PASSWORD: - mImapStore.getImapHelper().handleEvent(OmtpEvents.DATA_AUTH_INVALID_PASSWORD); + imapStore.getImapHelper().handleEvent(OmtpEvents.DATA_AUTH_INVALID_PASSWORD); break; case ImapConstants.NO_MAILBOX_NOT_INITIALIZED: - mImapStore.getImapHelper().handleEvent(OmtpEvents.DATA_AUTH_MAILBOX_NOT_INITIALIZED); + imapStore.getImapHelper().handleEvent(OmtpEvents.DATA_AUTH_MAILBOX_NOT_INITIALIZED); break; case ImapConstants.NO_SERVICE_IS_NOT_PROVISIONED: - mImapStore.getImapHelper().handleEvent(OmtpEvents.DATA_AUTH_SERVICE_NOT_PROVISIONED); + imapStore.getImapHelper().handleEvent(OmtpEvents.DATA_AUTH_SERVICE_NOT_PROVISIONED); break; case ImapConstants.NO_SERVICE_IS_NOT_ACTIVATED: - mImapStore.getImapHelper().handleEvent(OmtpEvents.DATA_AUTH_SERVICE_NOT_ACTIVATED); + imapStore.getImapHelper().handleEvent(OmtpEvents.DATA_AUTH_SERVICE_NOT_ACTIVATED); break; case ImapConstants.NO_USER_IS_BLOCKED: - mImapStore.getImapHelper().handleEvent(OmtpEvents.DATA_AUTH_USER_IS_BLOCKED); + imapStore.getImapHelper().handleEvent(OmtpEvents.DATA_AUTH_USER_IS_BLOCKED); break; case ImapConstants.NO_APPLICATION_ERROR: - mImapStore.getImapHelper().handleEvent(OmtpEvents.DATA_REJECTED_SERVER_RESPONSE); + imapStore.getImapHelper().handleEvent(OmtpEvents.DATA_REJECTED_SERVER_RESPONSE); break; default: - mImapStore.getImapHelper().handleEvent(OmtpEvents.DATA_BAD_IMAP_CREDENTIAL); + imapStore.getImapHelper().handleEvent(OmtpEvents.DATA_BAD_IMAP_CREDENTIAL); } throw new AuthenticationFailedException(alertText, ie); } - mImapStore.getImapHelper().handleEvent(OmtpEvents.DATA_REJECTED_SERVER_RESPONSE); + imapStore.getImapHelper().handleEvent(OmtpEvents.DATA_REJECTED_SERVER_RESPONSE); throw new MessagingException(alertText, ie); } } @@ -243,7 +243,7 @@ public class ImapConnection { String decodedChallenge = decodeBase64(responses.get(0).getStringOrEmpty(0).getString()); Map<String, String> challenge = DigestMd5Utils.parseDigestMessage(decodedChallenge); - DigestMd5Utils.Data data = new DigestMd5Utils.Data(mImapStore, mTransport, challenge); + DigestMd5Utils.Data data = new DigestMd5Utils.Data(imapStore, transport, challenge); String response = data.createResponse(); // Respond to the challenge. If the server accepts it, it will reply a response-auth which @@ -281,9 +281,9 @@ public class ImapConnection { private void queryCapability() throws IOException, MessagingException { List<ImapResponse> responses = executeSimpleCommand(ImapConstants.CAPABILITY); - mCapabilities.clear(); + capabilities.clear(); Set<String> disabledCapabilities = - mImapStore.getImapHelper().getConfig().getDisabledCapabilities(); + imapStore.getImapHelper().getConfig().getDisabledCapabilities(); for (ImapResponse response : responses) { if (response.isTagged()) { continue; @@ -292,40 +292,40 @@ public class ImapConnection { String capability = response.getStringOrEmpty(i).getString(); if (disabledCapabilities != null) { if (!disabledCapabilities.contains(capability)) { - mCapabilities.add(capability); + capabilities.add(capability); } } else { - mCapabilities.add(capability); + capabilities.add(capability); } } } - LogUtils.d(TAG, "Capabilities: " + mCapabilities.toString()); + LogUtils.d(TAG, "Capabilities: " + capabilities.toString()); } private boolean hasCapability(String capability) { - return mCapabilities.contains(capability); + return capabilities.contains(capability); } /** * Create an {@link ImapResponseParser} from {@code mTransport.getInputStream()} and set it to - * {@link #mParser}. + * {@link #parser}. * * <p>If we already have an {@link ImapResponseParser}, we {@link #destroyResponses()} and throw * it away. */ private void createParser() { destroyResponses(); - mParser = new ImapResponseParser(mTransport.getInputStream()); + parser = new ImapResponseParser(transport.getInputStream()); } public void destroyResponses() { - if (mParser != null) { - mParser.destroyResponses(); + if (parser != null) { + parser.destroyResponses(); } } public ImapResponse readResponse() throws IOException, MessagingException { - return mParser.readResponse(false); + return parser.readResponse(false); } public List<ImapResponse> executeSimpleCommand(String command) @@ -356,18 +356,18 @@ public class ImapConnection { throws IOException, MessagingException { open(); - if (mTransport == null) { + if (transport == null) { throw new IOException("Null transport"); } - String tag = Integer.toString(mNextCommandTag.incrementAndGet()); + String tag = Integer.toString(nextCommandTag.incrementAndGet()); String commandToSend = tag + " " + command; - mTransport.writeLine(commandToSend, (sensitive ? IMAP_REDACTED_LOG : command)); + transport.writeLine(commandToSend, (sensitive ? IMAP_REDACTED_LOG : command)); return tag; } List<ImapResponse> executeContinuationResponse(String response, boolean sensitive) throws IOException, MessagingException { - mTransport.writeLine(response, (sensitive ? IMAP_REDACTED_LOG : response)); + transport.writeLine(response, (sensitive ? IMAP_REDACTED_LOG : response)); return getCommandResponses(); } @@ -382,7 +382,7 @@ public class ImapConnection { final List<ImapResponse> responses = new ArrayList<ImapResponse>(); ImapResponse response; do { - response = mParser.readResponse(false); + response = parser.readResponse(false); responses.add(response); } while (!(response.isTagged() || response.isContinuationRequest())); diff --git a/java/com/android/voicemail/impl/mail/store/ImapFolder.java b/java/com/android/voicemail/impl/mail/store/ImapFolder.java index 5760ee216..3c76ec33d 100644 --- a/java/com/android/voicemail/impl/mail/store/ImapFolder.java +++ b/java/com/android/voicemail/impl/mail/store/ImapFolder.java @@ -59,21 +59,21 @@ public class ImapFolder { }; private static final int COPY_BUFFER_SIZE = 16 * 1024; - private final ImapStore mStore; - private final String mName; - private int mMessageCount = -1; - private ImapConnection mConnection; - private String mMode; - private boolean mExists; + private final ImapStore store; + private final String name; + private int messageCount = -1; + private ImapConnection connection; + private String mode; + private boolean exists; /** A set of hashes that can be used to track dirtiness */ - Object[] mHash; + Object[] hash; public static final String MODE_READ_ONLY = "mode_read_only"; public static final String MODE_READ_WRITE = "mode_read_write"; public ImapFolder(ImapStore store, String name) { - mStore = store; - mName = name; + this.store = store; + this.name = name; } /** Callback for each message retrieval. */ @@ -82,8 +82,8 @@ public class ImapFolder { } private void destroyResponses() { - if (mConnection != null) { - mConnection.destroyResponses(); + if (connection != null) { + connection.destroyResponses(); } } @@ -93,7 +93,7 @@ public class ImapFolder { throw new AssertionError("Duplicated open on ImapFolder"); } synchronized (this) { - mConnection = mStore.getConnection(); + connection = store.getConnection(); } // * FLAGS (\Answered \Flagged \Deleted \Seen \Draft NonJunk // $MDNSent) @@ -107,28 +107,28 @@ public class ImapFolder { try { doSelect(); } catch (IOException ioe) { - throw ioExceptionHandler(mConnection, ioe); + throw ioExceptionHandler(connection, ioe); } finally { destroyResponses(); } } catch (AuthenticationFailedException e) { // Don't cache this connection, so we're forced to try connecting/login again - mConnection = null; + connection = null; close(false); throw e; } catch (MessagingException e) { - mExists = false; + exists = false; close(false); throw e; } } public boolean isOpen() { - return mExists && mConnection != null; + return exists && connection != null; } public String getMode() { - return mMode; + return mode; } public void close(boolean expunge) { @@ -139,14 +139,14 @@ public class ImapFolder { VvmLog.e(TAG, "Messaging Exception", e); } } - mMessageCount = -1; + messageCount = -1; synchronized (this) { - mConnection = null; + connection = null; } } public int getMessageCount() { - return mMessageCount; + return messageCount; } String[] getSearchUids(List<ImapResponse> responses) { @@ -173,7 +173,7 @@ public class ImapFolder { try { try { final String command = ImapConstants.UID_SEARCH + " " + searchCriteria; - final String[] result = getSearchUids(mConnection.executeSimpleCommand(command)); + final String[] result = getSearchUids(connection.executeSimpleCommand(command)); VvmLog.d(TAG, "searchForUids '" + searchCriteria + "' results: " + result.length); return result; } catch (ImapException me) { @@ -181,8 +181,8 @@ public class ImapFolder { return Utility.EMPTY_STRINGS; // Not found } catch (IOException ioe) { VvmLog.d(TAG, "IOException in search: " + searchCriteria, ioe); - mStore.getImapHelper().handleEvent(OmtpEvents.DATA_GENERIC_IMAP_IOE); - throw ioExceptionHandler(mConnection, ioe); + store.getImapHelper().handleEvent(OmtpEvents.DATA_GENERIC_IMAP_IOE); + throw ioExceptionHandler(connection, ioe); } } finally { destroyResponses(); @@ -296,7 +296,7 @@ public class ImapFolder { } try { - mConnection.sendCommand( + connection.sendCommand( String.format( Locale.US, ImapConstants.UID_FETCH + " %s (%s)", @@ -307,7 +307,7 @@ public class ImapFolder { do { response = null; try { - response = mConnection.readResponse(); + response = connection.readResponse(); if (!response.isDataResponse(1, ImapConstants.FETCH)) { continue; // Ignore @@ -395,7 +395,7 @@ public class ImapFolder { // (We'll need to share a temp file. Protect it with a ref-count.) message.setBody( decodeBody( - mStore.getContext(), + store.getContext(), bodyStream, contentTransferEncoding, fetchPart.getSize(), @@ -417,8 +417,8 @@ public class ImapFolder { } } while (!response.isTagged()); } catch (IOException ioe) { - mStore.getImapHelper().handleEvent(OmtpEvents.DATA_GENERIC_IMAP_IOE); - throw ioExceptionHandler(mConnection, ioe); + store.getImapHelper().handleEvent(OmtpEvents.DATA_GENERIC_IMAP_IOE); + throw ioExceptionHandler(connection, ioe); } } @@ -476,7 +476,7 @@ public class ImapFolder { */ private void handleUntaggedResponse(ImapResponse response) { if (response.isDataResponse(1, ImapConstants.EXISTS)) { - mMessageCount = response.getStringOrEmpty(0).getNumberOrZero(); + messageCount = response.getStringOrEmpty(0).getNumberOrZero(); } } @@ -660,10 +660,10 @@ public class ImapFolder { public Message[] expunge() throws MessagingException { checkOpen(); try { - handleUntaggedResponses(mConnection.executeSimpleCommand(ImapConstants.EXPUNGE)); + handleUntaggedResponses(connection.executeSimpleCommand(ImapConstants.EXPUNGE)); } catch (IOException ioe) { - mStore.getImapHelper().handleEvent(OmtpEvents.DATA_GENERIC_IMAP_IOE); - throw ioExceptionHandler(mConnection, ioe); + store.getImapHelper().handleEvent(OmtpEvents.DATA_GENERIC_IMAP_IOE); + throw ioExceptionHandler(connection, ioe); } finally { destroyResponses(); } @@ -692,7 +692,7 @@ public class ImapFolder { allFlags = flagList.substring(1); } try { - mConnection.executeSimpleCommand( + connection.executeSimpleCommand( String.format( Locale.US, ImapConstants.UID_STORE + " %s %s" + ImapConstants.FLAGS_SILENT + " (%s)", @@ -701,8 +701,8 @@ public class ImapFolder { allFlags)); } catch (IOException ioe) { - mStore.getImapHelper().handleEvent(OmtpEvents.DATA_GENERIC_IMAP_IOE); - throw ioExceptionHandler(mConnection, ioe); + store.getImapHelper().handleEvent(OmtpEvents.DATA_GENERIC_IMAP_IOE); + throw ioExceptionHandler(connection, ioe); } finally { destroyResponses(); } @@ -714,11 +714,11 @@ public class ImapFolder { */ private void doSelect() throws IOException, MessagingException { final List<ImapResponse> responses = - mConnection.executeSimpleCommand( - String.format(Locale.US, ImapConstants.SELECT + " \"%s\"", mName)); + connection.executeSimpleCommand( + String.format(Locale.US, ImapConstants.SELECT + " \"%s\"", name)); // Assume the folder is opened read-write; unless we are notified otherwise - mMode = MODE_READ_WRITE; + mode = MODE_READ_WRITE; int messageCount = -1; for (ImapResponse response : responses) { if (response.isDataResponse(1, ImapConstants.EXISTS)) { @@ -726,12 +726,12 @@ public class ImapFolder { } else if (response.isOk()) { final ImapString responseCode = response.getResponseCodeOrEmpty(); if (responseCode.is(ImapConstants.READ_ONLY)) { - mMode = MODE_READ_ONLY; + mode = MODE_READ_ONLY; } else if (responseCode.is(ImapConstants.READ_WRITE)) { - mMode = MODE_READ_WRITE; + mode = MODE_READ_WRITE; } } else if (response.isTagged()) { // Not OK - mStore.getImapHelper().handleEvent(OmtpEvents.DATA_MAILBOX_OPEN_FAILED); + store.getImapHelper().handleEvent(OmtpEvents.DATA_MAILBOX_OPEN_FAILED); throw new MessagingException( "Can't open mailbox: " + response.getStatusResponseTextOrEmpty()); } @@ -739,8 +739,8 @@ public class ImapFolder { if (messageCount == -1) { throw new MessagingException("Did not find message count during select"); } - mMessageCount = messageCount; - mExists = true; + this.messageCount = messageCount; + exists = true; } public class Quota { @@ -757,8 +757,8 @@ public class ImapFolder { public Quota getQuota() throws MessagingException { try { final List<ImapResponse> responses = - mConnection.executeSimpleCommand( - String.format(Locale.US, ImapConstants.GETQUOTAROOT + " \"%s\"", mName)); + connection.executeSimpleCommand( + String.format(Locale.US, ImapConstants.GETQUOTAROOT + " \"%s\"", name)); for (ImapResponse response : responses) { if (!response.isDataResponse(0, ImapConstants.QUOTA)) { @@ -775,8 +775,8 @@ public class ImapFolder { } } } catch (IOException ioe) { - mStore.getImapHelper().handleEvent(OmtpEvents.DATA_GENERIC_IMAP_IOE); - throw ioExceptionHandler(mConnection, ioe); + store.getImapHelper().handleEvent(OmtpEvents.DATA_GENERIC_IMAP_IOE); + throw ioExceptionHandler(connection, ioe); } finally { destroyResponses(); } @@ -785,15 +785,15 @@ public class ImapFolder { private void checkOpen() throws MessagingException { if (!isOpen()) { - throw new MessagingException("Folder " + mName + " is not open."); + throw new MessagingException("Folder " + name + " is not open."); } } private MessagingException ioExceptionHandler(ImapConnection connection, IOException ioe) { VvmLog.d(TAG, "IO Exception detected: ", ioe); connection.close(); - if (connection == mConnection) { - mConnection = null; // To prevent close() from returning the connection to the pool. + if (connection == this.connection) { + this.connection = null; // To prevent close() from returning the connection to the pool. close(false); } return new MessagingException(MessagingException.IOERROR, "IO Error", ioe); diff --git a/java/com/android/voicemail/impl/mail/store/ImapStore.java b/java/com/android/voicemail/impl/mail/store/ImapStore.java index 838bae257..6b88080fe 100644 --- a/java/com/android/voicemail/impl/mail/store/ImapStore.java +++ b/java/com/android/voicemail/impl/mail/store/ImapStore.java @@ -34,12 +34,12 @@ public class ImapStore { */ public static final int FETCH_BODY_SANE_SUGGESTED_SIZE = (125 * 1024); - private final Context mContext; - private final ImapHelper mHelper; - private final String mUsername; - private final String mPassword; - private final MailTransport mTransport; - private ImapConnection mConnection; + private final Context context; + private final ImapHelper helper; + private final String username; + private final String password; + private final MailTransport transport; + private ImapConnection connection; public static final int FLAG_NONE = 0x00; // No flags public static final int FLAG_SSL = 0x01; // Use SSL @@ -58,32 +58,32 @@ public class ImapStore { String serverName, int flags, Network network) { - mContext = context; - mHelper = helper; - mUsername = username; - mPassword = password; - mTransport = new MailTransport(context, this.getImapHelper(), network, serverName, port, flags); + this.context = context; + this.helper = helper; + this.username = username; + this.password = password; + transport = new MailTransport(context, this.getImapHelper(), network, serverName, port, flags); } public Context getContext() { - return mContext; + return context; } public ImapHelper getImapHelper() { - return mHelper; + return helper; } public String getUsername() { - return mUsername; + return username; } public String getPassword() { - return mPassword; + return password; } /** Returns a clone of the transport associated with this store. */ MailTransport cloneTransport() { - return mTransport.clone(); + return transport.clone(); } /** Returns UIDs of Messages joined with "," as the separator. */ @@ -101,15 +101,15 @@ public class ImapStore { } static class ImapMessage extends MimeMessage { - private ImapFolder mFolder; + private ImapFolder folder; ImapMessage(String uid, ImapFolder folder) { - mUid = uid; - mFolder = folder; + this.uid = uid; + this.folder = folder; } public void setSize(int size) { - mSize = size; + this.size = size; } @Override @@ -124,17 +124,17 @@ public class ImapStore { @Override public void setFlag(String flag, boolean set) throws MessagingException { super.setFlag(flag, set); - mFolder.setFlags(new Message[] {this}, new String[] {flag}, set); + folder.setFlags(new Message[] {this}, new String[] {flag}, set); } } static class ImapException extends MessagingException { private static final long serialVersionUID = 1L; - private final String mStatus; - private final String mStatusMessage; - private final String mAlertText; - private final String mResponseCode; + private final String status; + private final String statusMessage; + private final String alertText; + private final String responseCode; public ImapException( String message, @@ -143,40 +143,40 @@ public class ImapStore { String alertText, String responseCode) { super(message); - mStatus = status; - mStatusMessage = statusMessage; - mAlertText = alertText; - mResponseCode = responseCode; + this.status = status; + this.statusMessage = statusMessage; + this.alertText = alertText; + this.responseCode = responseCode; } public String getStatus() { - return mStatus; + return status; } public String getStatusMessage() { - return mStatusMessage; + return statusMessage; } public String getAlertText() { - return mAlertText; + return alertText; } public String getResponseCode() { - return mResponseCode; + return responseCode; } } public void closeConnection() { - if (mConnection != null) { - mConnection.close(); - mConnection = null; + if (connection != null) { + connection.close(); + connection = null; } } public ImapConnection getConnection() { - if (mConnection == null) { - mConnection = new ImapConnection(this); + if (connection == null) { + connection = new ImapConnection(this); } - return mConnection; + return connection; } } diff --git a/java/com/android/voicemail/impl/mail/store/imap/DigestMd5Utils.java b/java/com/android/voicemail/impl/mail/store/imap/DigestMd5Utils.java index f156f67c1..aa2886812 100644 --- a/java/com/android/voicemail/impl/mail/store/imap/DigestMd5Utils.java +++ b/java/com/android/voicemail/impl/mail/store/imap/DigestMd5Utils.java @@ -121,27 +121,27 @@ public class DigestMd5Utils { private static class ResponseBuilder { - private StringBuilder mBuilder = new StringBuilder(); + private StringBuilder builder = new StringBuilder(); public ResponseBuilder appendQuoted(String key, String value) { - if (mBuilder.length() != 0) { - mBuilder.append(","); + if (builder.length() != 0) { + builder.append(","); } - mBuilder.append(key).append("=\"").append(value).append("\""); + builder.append(key).append("=\"").append(value).append("\""); return this; } public ResponseBuilder append(String key, String value) { - if (mBuilder.length() != 0) { - mBuilder.append(","); + if (builder.length() != 0) { + builder.append(","); } - mBuilder.append(key).append("=").append(value); + builder.append(key).append("=").append(value); return this; } @Override public String toString() { - return mBuilder.toString(); + return builder.toString(); } } } @@ -229,20 +229,20 @@ public class DigestMd5Utils { /** Parse the key-value pair returned by the server. */ private static class DigestMessageParser { - private final String mMessage; - private int mPosition = 0; - private Map<String, String> mResult = new ArrayMap<>(); + private final String message; + private int position = 0; + private Map<String, String> result = new ArrayMap<>(); public DigestMessageParser(String message) { - mMessage = message; + this.message = message; } @Nullable public Map<String, String> parse() { try { - while (mPosition < mMessage.length()) { + while (position < message.length()) { parsePair(); - if (mPosition != mMessage.length()) { + if (position != message.length()) { expect(','); } } @@ -250,42 +250,42 @@ public class DigestMd5Utils { VvmLog.e(TAG, e.toString()); return null; } - return mResult; + return result; } private void parsePair() { String key = parseKey(); expect('='); String value = parseValue(); - mResult.put(key, value); + result.put(key, value); } private void expect(char c) { if (pop() != c) { - throw new IllegalStateException("unexpected character " + mMessage.charAt(mPosition)); + throw new IllegalStateException("unexpected character " + message.charAt(position)); } } private char pop() { char result = peek(); - mPosition++; + position++; return result; } private char peek() { - return mMessage.charAt(mPosition); + return message.charAt(position); } private void goToNext(char c) { while (peek() != c) { - mPosition++; + position++; } } private String parseKey() { - int start = mPosition; + int start = position; goToNext('='); - return mMessage.substring(start, mPosition); + return message.substring(start, position); } private String parseValue() { @@ -319,13 +319,13 @@ public class DigestMd5Utils { if (c == '\\') { result.append(pop()); } else if (c == ',') { - mPosition--; + position--; break; } else { result.append(c); } - if (mPosition == mMessage.length()) { + if (position == message.length()) { break; } } diff --git a/java/com/android/voicemail/impl/mail/store/imap/ImapElement.java b/java/com/android/voicemail/impl/mail/store/imap/ImapElement.java index ee255d1eb..c2571f3d9 100644 --- a/java/com/android/voicemail/impl/mail/store/imap/ImapElement.java +++ b/java/com/android/voicemail/impl/mail/store/imap/ImapElement.java @@ -77,14 +77,14 @@ public abstract class ImapElement { } }; - private boolean mDestroyed = false; + private boolean destroyed = false; public abstract boolean isList(); public abstract boolean isString(); protected boolean isDestroyed() { - return mDestroyed; + return destroyed; } /** @@ -92,12 +92,12 @@ public abstract class ImapElement { * ImapTempFileLiteral}. */ public void destroy() { - mDestroyed = true; + destroyed = true; } /** Throws {@link RuntimeException} if it's already destroyed. */ protected final void checkNotDestroyed() { - if (mDestroyed) { + if (destroyed) { throw new RuntimeException("Already destroyed"); } } diff --git a/java/com/android/voicemail/impl/mail/store/imap/ImapList.java b/java/com/android/voicemail/impl/mail/store/imap/ImapList.java index e4a6ec0ac..a72883fa6 100644 --- a/java/com/android/voicemail/impl/mail/store/imap/ImapList.java +++ b/java/com/android/voicemail/impl/mail/store/imap/ImapList.java @@ -35,13 +35,13 @@ public class ImapList extends ImapElement { } }; - private ArrayList<ImapElement> mList = new ArrayList<ImapElement>(); + private ArrayList<ImapElement> list = new ArrayList<ImapElement>(); /* package */ void add(ImapElement e) { if (e == null) { throw new RuntimeException("Can't add null"); } - mList.add(e); + list.add(e); } @Override @@ -55,7 +55,7 @@ public class ImapList extends ImapElement { } public final int size() { - return mList.size(); + return list.size(); } public final boolean isEmpty() { @@ -84,7 +84,7 @@ public class ImapList extends ImapElement { * ImapElement#NONE}. */ public final ImapElement getElementOrNone(int index) { - return (index >= mList.size()) ? ImapElement.NONE : mList.get(index); + return (index >= list.size()) ? ImapElement.NONE : list.get(index); } /** @@ -112,7 +112,7 @@ public class ImapList extends ImapElement { /* package */ final ImapElement getKeyedElementOrNull(String key, boolean prefixMatch) { for (int i = 1; i < size(); i += 2) { if (is(i - 1, key, prefixMatch)) { - return mList.get(i); + return list.get(i); } } return null; @@ -162,18 +162,18 @@ public class ImapList extends ImapElement { @Override public void destroy() { - if (mList != null) { - for (ImapElement e : mList) { + if (list != null) { + for (ImapElement e : list) { e.destroy(); } - mList = null; + list = null; } super.destroy(); } @Override public String toString() { - return mList.toString(); + return list.toString(); } /** Return the text representations of the contents concatenated with ",". */ @@ -192,7 +192,7 @@ public class ImapList extends ImapElement { */ private final StringBuilder flatten(StringBuilder sb) { sb.append('['); - for (int i = 0; i < mList.size(); i++) { + for (int i = 0; i < list.size(); i++) { if (i > 0) { sb.append(','); } @@ -217,7 +217,7 @@ public class ImapList extends ImapElement { return false; } for (int i = 0; i < size(); i++) { - if (!mList.get(i).equalsForTest(thatList.getElementOrNone(i))) { + if (!list.get(i).equalsForTest(thatList.getElementOrNone(i))) { return false; } } diff --git a/java/com/android/voicemail/impl/mail/store/imap/ImapMemoryLiteral.java b/java/com/android/voicemail/impl/mail/store/imap/ImapMemoryLiteral.java index 96a8c4ae5..46f3fc5ed 100644 --- a/java/com/android/voicemail/impl/mail/store/imap/ImapMemoryLiteral.java +++ b/java/com/android/voicemail/impl/mail/store/imap/ImapMemoryLiteral.java @@ -26,35 +26,35 @@ import java.io.UnsupportedEncodingException; /** Subclass of {@link ImapString} used for literals backed by an in-memory byte array. */ public class ImapMemoryLiteral extends ImapString { private final String TAG = "ImapMemoryLiteral"; - private byte[] mData; + private byte[] data; /* package */ ImapMemoryLiteral(FixedLengthInputStream in) throws IOException { // We could use ByteArrayOutputStream and IOUtils.copy, but it'd perform an unnecessary // copy.... - mData = new byte[in.getLength()]; + data = new byte[in.getLength()]; int pos = 0; - while (pos < mData.length) { - int read = in.read(mData, pos, mData.length - pos); + while (pos < data.length) { + int read = in.read(data, pos, data.length - pos); if (read < 0) { break; } pos += read; } - if (pos != mData.length) { + if (pos != data.length) { VvmLog.w(TAG, "length mismatch"); } } @Override public void destroy() { - mData = null; + data = null; super.destroy(); } @Override public String getString() { try { - return new String(mData, "US-ASCII"); + return new String(data, "US-ASCII"); } catch (UnsupportedEncodingException e) { VvmLog.e(TAG, "Unsupported encoding: ", e); } @@ -63,11 +63,11 @@ public class ImapMemoryLiteral extends ImapString { @Override public InputStream getAsStream() { - return new ByteArrayInputStream(mData); + return new ByteArrayInputStream(data); } @Override public String toString() { - return String.format("{%d byte literal(memory)}", mData.length); + return String.format("{%d byte literal(memory)}", data.length); } } diff --git a/java/com/android/voicemail/impl/mail/store/imap/ImapResponse.java b/java/com/android/voicemail/impl/mail/store/imap/ImapResponse.java index d53d458da..48eb39d2d 100644 --- a/java/com/android/voicemail/impl/mail/store/imap/ImapResponse.java +++ b/java/com/android/voicemail/impl/mail/store/imap/ImapResponse.java @@ -18,12 +18,12 @@ package com.android.voicemail.impl.mail.store.imap; /** Class represents an IMAP response. */ public class ImapResponse extends ImapList { - private final String mTag; - private final boolean mIsContinuationRequest; + private final String tag; + private final boolean isContinuationRequest; /* package */ ImapResponse(String tag, boolean isContinuationRequest) { - mTag = tag; - mIsContinuationRequest = isContinuationRequest; + this.tag = tag; + this.isContinuationRequest = isContinuationRequest; } /* package */ static boolean isStatusResponse(String symbol) { @@ -36,12 +36,12 @@ public class ImapResponse extends ImapList { /** @return whether it's a tagged response. */ public boolean isTagged() { - return mTag != null; + return tag != null; } /** @return whether it's a continuation request. */ public boolean isContinuationRequest() { - return mIsContinuationRequest; + return isContinuationRequest; } public boolean isStatusResponse() { @@ -112,7 +112,7 @@ public class ImapResponse extends ImapList { @Override public String toString() { - String tag = mTag; + String tag = this.tag; if (isContinuationRequest()) { tag = "+"; } @@ -125,16 +125,16 @@ public class ImapResponse extends ImapList { return false; } final ImapResponse thatResponse = (ImapResponse) that; - if (mTag == null) { - if (thatResponse.mTag != null) { + if (tag == null) { + if (thatResponse.tag != null) { return false; } } else { - if (!mTag.equals(thatResponse.mTag)) { + if (!tag.equals(thatResponse.tag)) { return false; } } - if (mIsContinuationRequest != thatResponse.mIsContinuationRequest) { + if (isContinuationRequest != thatResponse.isContinuationRequest) { return false; } return true; diff --git a/java/com/android/voicemail/impl/mail/store/imap/ImapResponseParser.java b/java/com/android/voicemail/impl/mail/store/imap/ImapResponseParser.java index e37106a69..68d6babbd 100644 --- a/java/com/android/voicemail/impl/mail/store/imap/ImapResponseParser.java +++ b/java/com/android/voicemail/impl/mail/store/imap/ImapResponseParser.java @@ -33,21 +33,21 @@ public class ImapResponseParser { public static final int LITERAL_KEEP_IN_MEMORY_THRESHOLD = 2 * 1024 * 1024; /** Input stream */ - private final PeekableInputStream mIn; + private final PeekableInputStream in; - private final int mLiteralKeepInMemoryThreshold; + private final int literalKeepInMemoryThreshold; /** StringBuilder used by readUntil() */ - private final StringBuilder mBufferReadUntil = new StringBuilder(); + private final StringBuilder bufferReadUntil = new StringBuilder(); /** StringBuilder used by parseBareString() */ - private final StringBuilder mParseBareString = new StringBuilder(); + private final StringBuilder parseBareString = new StringBuilder(); /** * We store all {@link ImapResponse} in it. {@link #destroyResponses()} must be called from time * to time to destroy them and clear it. */ - private final ArrayList<ImapResponse> mResponsesToDestroy = new ArrayList<ImapResponse>(); + private final ArrayList<ImapResponse> responsesToDestroy = new ArrayList<ImapResponse>(); /** * Exception thrown when we receive BYE. It derives from IOException, so it'll be treated in the @@ -68,8 +68,8 @@ public class ImapResponseParser { /** Constructor for testing to override the literal size threshold. */ /* package for test */ ImapResponseParser(InputStream in, int literalKeepInMemoryThreshold) { - mIn = new PeekableInputStream(in); - mLiteralKeepInMemoryThreshold = literalKeepInMemoryThreshold; + this.in = new PeekableInputStream(in); + this.literalKeepInMemoryThreshold = literalKeepInMemoryThreshold; } private static IOException newEOSException() { @@ -85,7 +85,7 @@ public class ImapResponseParser { * shouldn't see EOF during parsing. */ private int peek() throws IOException { - final int next = mIn.peek(); + final int next = in.peek(); if (next == -1) { throw newEOSException(); } @@ -93,13 +93,13 @@ public class ImapResponseParser { } /** - * Read and return one byte from {@link #mIn}, and put it in {@link #mDiscourseLogger}. + * Read and return one byte from {@link #in}, and put it in {@link #mDiscourseLogger}. * * <p>Throws IOException() if reaches EOF. As long as logical response lines end with \r\n, we * shouldn't see EOF during parsing. */ private int readByte() throws IOException { - int next = mIn.read(); + int next = in.read(); if (next == -1) { throw newEOSException(); } @@ -112,10 +112,10 @@ public class ImapResponseParser { * @see #readResponse() */ public void destroyResponses() { - for (ImapResponse r : mResponsesToDestroy) { + for (ImapResponse r : responsesToDestroy) { r.destroy(); } - mResponsesToDestroy.clear(); + responsesToDestroy.clear(); } /** @@ -151,7 +151,7 @@ public class ImapResponseParser { response.destroy(); throw new ByeException(); } - mResponsesToDestroy.add(response); + responsesToDestroy.add(response); return response; } @@ -192,13 +192,13 @@ public class ImapResponseParser { * (rather than peeked) and won't be included in the result. */ /* package for test */ String readUntil(char end) throws IOException { - mBufferReadUntil.setLength(0); + bufferReadUntil.setLength(0); for (; ; ) { final int ch = readByte(); if (ch != end) { - mBufferReadUntil.append((char) ch); + bufferReadUntil.append((char) ch); } else { - return mBufferReadUntil.toString(); + return bufferReadUntil.toString(); } } } @@ -326,7 +326,7 @@ public class ImapResponseParser { * <p>If the value is "NIL", returns an empty string. */ private ImapString parseBareString() throws IOException, MessagingException { - mParseBareString.setLength(0); + parseBareString.setLength(0); for (; ; ) { final int ch = peek(); @@ -351,10 +351,10 @@ public class ImapResponseParser { ch == '"' || (0x00 <= ch && ch <= 0x1f) || ch == 0x7f) { - if (mParseBareString.length() == 0) { + if (parseBareString.length() == 0) { throw new MessagingException("Expected string, none found."); } - String s = mParseBareString.toString(); + String s = parseBareString.toString(); // NIL will be always converted into the empty string. if (ImapConstants.NIL.equalsIgnoreCase(s)) { @@ -363,11 +363,11 @@ public class ImapResponseParser { return new ImapSimpleString(s); } else if (ch == '[') { // Eat all until next ']' - mParseBareString.append((char) readByte()); - mParseBareString.append(readUntil(']')); - mParseBareString.append(']'); // readUntil won't include the end char. + parseBareString.append((char) readByte()); + parseBareString.append(readUntil(']')); + parseBareString.append(']'); // readUntil won't include the end char. } else { - mParseBareString.append((char) readByte()); + parseBareString.append((char) readByte()); } } } @@ -414,8 +414,8 @@ public class ImapResponseParser { } expect('\r'); expect('\n'); - FixedLengthInputStream in = new FixedLengthInputStream(mIn, size); - if (size > mLiteralKeepInMemoryThreshold) { + FixedLengthInputStream in = new FixedLengthInputStream(this.in, size); + if (size > literalKeepInMemoryThreshold) { return new ImapTempFileLiteral(in); } else { return new ImapMemoryLiteral(in); diff --git a/java/com/android/voicemail/impl/mail/store/imap/ImapSimpleString.java b/java/com/android/voicemail/impl/mail/store/imap/ImapSimpleString.java index 7cc866b74..76d3c6e91 100644 --- a/java/com/android/voicemail/impl/mail/store/imap/ImapSimpleString.java +++ b/java/com/android/voicemail/impl/mail/store/imap/ImapSimpleString.java @@ -24,27 +24,27 @@ import java.io.UnsupportedEncodingException; /** Subclass of {@link ImapString} used for non literals. */ public class ImapSimpleString extends ImapString { private final String TAG = "ImapSimpleString"; - private String mString; + private String string; /* package */ ImapSimpleString(String string) { - mString = (string != null) ? string : ""; + this.string = (string != null) ? string : ""; } @Override public void destroy() { - mString = null; + string = null; super.destroy(); } @Override public String getString() { - return mString; + return string; } @Override public InputStream getAsStream() { try { - return new ByteArrayInputStream(mString.getBytes("US-ASCII")); + return new ByteArrayInputStream(string.getBytes("US-ASCII")); } catch (UnsupportedEncodingException e) { VvmLog.e(TAG, "Unsupported encoding: ", e); } @@ -54,6 +54,6 @@ public class ImapSimpleString extends ImapString { @Override public String toString() { // Purposefully not return just mString, in order to prevent using it instead of getString. - return "\"" + mString + "\""; + return "\"" + string + "\""; } } diff --git a/java/com/android/voicemail/impl/mail/store/imap/ImapString.java b/java/com/android/voicemail/impl/mail/store/imap/ImapString.java index d5c555126..099e569a8 100644 --- a/java/com/android/voicemail/impl/mail/store/imap/ImapString.java +++ b/java/com/android/voicemail/impl/mail/store/imap/ImapString.java @@ -64,9 +64,9 @@ public abstract class ImapString extends ImapElement { private static final SimpleDateFormat DATE_TIME_FORMAT = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss Z", Locale.US); - private boolean mIsInteger; - private int mParsedInteger; - private Date mParsedDate; + private boolean isInteger; + private int parsedInteger; + private Date parsedDate; @Override public final boolean isList() { @@ -94,12 +94,12 @@ public abstract class ImapString extends ImapElement { /** @return whether it can be parsed as a number. */ public final boolean isNumber() { - if (mIsInteger) { + if (isInteger) { return true; } try { - mParsedInteger = Integer.parseInt(getString()); - mIsInteger = true; + parsedInteger = Integer.parseInt(getString()); + isInteger = true; return true; } catch (NumberFormatException e) { return false; @@ -116,19 +116,19 @@ public abstract class ImapString extends ImapElement { if (!isNumber()) { return defaultValue; } - return mParsedInteger; + return parsedInteger; } /** @return whether it can be parsed as a date using {@link #DATE_TIME_FORMAT}. */ public final boolean isDate() { - if (mParsedDate != null) { + if (parsedDate != null) { return true; } if (isEmpty()) { return false; } try { - mParsedDate = DATE_TIME_FORMAT.parse(getString()); + parsedDate = DATE_TIME_FORMAT.parse(getString()); return true; } catch (ParseException e) { VvmLog.w("ImapString", getString() + " can't be parsed as a date."); @@ -141,7 +141,7 @@ public abstract class ImapString extends ImapElement { if (!isDate()) { return null; } - return mParsedDate; + return parsedDate; } /** @return whether the value case-insensitively equals to {@code s}. */ diff --git a/java/com/android/voicemail/impl/mail/store/imap/ImapTempFileLiteral.java b/java/com/android/voicemail/impl/mail/store/imap/ImapTempFileLiteral.java index ab64d8537..417adcc02 100644 --- a/java/com/android/voicemail/impl/mail/store/imap/ImapTempFileLiteral.java +++ b/java/com/android/voicemail/impl/mail/store/imap/ImapTempFileLiteral.java @@ -33,20 +33,20 @@ import org.apache.commons.io.IOUtils; public class ImapTempFileLiteral extends ImapString { private final String TAG = "ImapTempFileLiteral"; - /* package for test */ final File mFile; + /* package for test */ final File file; /** Size is purely for toString() */ - private final int mSize; + private final int size; /* package */ ImapTempFileLiteral(FixedLengthInputStream stream) throws IOException { - mSize = stream.getLength(); - mFile = File.createTempFile("imap", ".tmp", TempDirectory.getTempDirectory()); + size = stream.getLength(); + file = File.createTempFile("imap", ".tmp", TempDirectory.getTempDirectory()); // Unfortunately, we can't really use deleteOnExit(), because temp filenames are random // so it'd simply cause a memory leak. // deleteOnExit() simply adds filenames to a static list and the list will never shrink. // mFile.deleteOnExit(); - OutputStream out = new FileOutputStream(mFile); + OutputStream out = new FileOutputStream(file); IOUtils.copy(stream, out); out.close(); } @@ -69,7 +69,7 @@ public class ImapTempFileLiteral extends ImapString { public InputStream getAsStream() { checkNotDestroyed(); try { - return new FileInputStream(mFile); + return new FileInputStream(file); } catch (FileNotFoundException e) { // It's probably possible if we're low on storage and the system clears the cache dir. LogUtils.w(TAG, "ImapTempFileLiteral: Temp file not found"); @@ -98,8 +98,8 @@ public class ImapTempFileLiteral extends ImapString { @Override public void destroy() { try { - if (!isDestroyed() && mFile.exists()) { - mFile.delete(); + if (!isDestroyed() && file.exists()) { + file.delete(); } } catch (RuntimeException re) { // Just log and ignore. @@ -110,10 +110,10 @@ public class ImapTempFileLiteral extends ImapString { @Override public String toString() { - return String.format("{%d byte literal(file)}", mSize); + return String.format("{%d byte literal(file)}", size); } public boolean tempFileExistsForTest() { - return mFile.exists(); + return file.exists(); } } |