From 6ed52ac5512eabbf3d9e00826e4d380f069e5c81 Mon Sep 17 00:00:00 2001 From: Jan Berkel Date: Fri, 19 Dec 2014 10:01:34 +0100 Subject: [PATCH] Fix some warnings in ImapStore / Pop3Store / WebDavStore --- .../fsck/k9/mail/store/imap/ImapStore.java | 35 ++--- .../fsck/k9/mail/store/pop3/Pop3Store.java | 4 +- .../k9/mail/store/webdav/WebDavStore.java | 130 +++++++++--------- 3 files changed, 79 insertions(+), 90 deletions(-) diff --git a/src/com/fsck/k9/mail/store/imap/ImapStore.java b/src/com/fsck/k9/mail/store/imap/ImapStore.java index e5e0998b3..20450b6e0 100644 --- a/src/com/fsck/k9/mail/store/imap/ImapStore.java +++ b/src/com/fsck/k9/mail/store/imap/ImapStore.java @@ -506,7 +506,7 @@ public class ImapStore extends RemoteStore { * @throws MessagingException uh oh! */ private void autoconfigureFolders(final ImapConnection connection) throws IOException, MessagingException { - String commandResponse = null; + String commandResponse; String commandOptions = ""; if (connection.getCapabilities().contains("XLIST")) { @@ -581,10 +581,6 @@ public class ImapStore extends RemoteStore { } } - /** - * Gets a connection if one is available for reuse, or creates a new one if not. - * @return - */ private ImapConnection getConnection() throws MessagingException { synchronized (mConnections) { ImapConnection connection; @@ -669,7 +665,7 @@ public class ImapStore extends RemoteStore { } - class ImapFolder extends Folder { + protected class ImapFolder extends Folder { private String mName; protected volatile int mMessageCount = -1; protected volatile long uidNext = -1L; @@ -689,7 +685,7 @@ public class ImapStore extends RemoteStore { public String getPrefixedName() throws MessagingException { String prefixedName = ""; if (!mStoreConfig.getInboxFolderName().equalsIgnoreCase(mName)) { - ImapConnection connection = null; + ImapConnection connection; synchronized (this) { if (mConnection == null) { connection = getConnection(); @@ -737,10 +733,9 @@ public class ImapStore extends RemoteStore { // Make sure the connection is valid. If it's not we'll close it down and continue // on to get a new one. try { - List responses = executeSimpleCommand("NOOP"); - return responses; + return executeSimpleCommand("NOOP"); } catch (IOException ioe) { - ioExceptionHandler(mConnection, ioe); + /* don't throw */ ioExceptionHandler(mConnection, ioe); } } releaseConnection(mConnection); @@ -909,7 +904,7 @@ public class ImapStore extends RemoteStore { * so we must get the connection ourselves if it's not there. We are specifically * not calling checkOpen() since we don't care if the folder is open. */ - ImapConnection connection = null; + ImapConnection connection; synchronized (this) { if (mConnection == null) { connection = getConnection(); @@ -941,7 +936,7 @@ public class ImapStore extends RemoteStore { * so we must get the connection ourselves if it's not there. We are specifically * not calling checkOpen() since we don't care if the folder is open. */ - ImapConnection connection = null; + ImapConnection connection; synchronized (this) { if (mConnection == null) { connection = getConnection(); @@ -1191,12 +1186,12 @@ public class ImapStore extends RemoteStore { @Override - public List getMessages(int start, int end, Date earliestDate, MessageRetrievalListener listener) + public List getMessages(int start, int end, Date earliestDate, MessageRetrievalListener listener) throws MessagingException { return getMessages(start, end, earliestDate, false, listener); } - protected List getMessages(final int start, final int end, Date earliestDate, final boolean includeDeleted, final MessageRetrievalListener listener) + protected List getMessages(final int start, final int end, Date earliestDate, final boolean includeDeleted, final MessageRetrievalListener listener) throws MessagingException { if (start < 1 || end < 1 || end < start) { throw new MessagingException( @@ -1223,7 +1218,7 @@ public class ImapStore extends RemoteStore { } protected List getMessages(final List mesgSeqs, final boolean includeDeleted, - final MessageRetrievalListener listener) + final MessageRetrievalListener listener) throws MessagingException { ImapSearcher searcher = new ImapSearcher() { @Override @@ -1236,7 +1231,7 @@ public class ImapStore extends RemoteStore { protected List getMessagesFromUids(final List mesgUids, final boolean includeDeleted, - final MessageRetrievalListener listener) throws MessagingException { + final MessageRetrievalListener listener) throws MessagingException { ImapSearcher searcher = new ImapSearcher() { @Override public List search() throws IOException, MessagingException { @@ -1606,7 +1601,6 @@ public class ImapStore extends RemoteStore { /** * Handle any untagged responses that the caller doesn't care to handle themselves. - * @param responses */ protected List handleUntaggedResponses(List responses) { for (ImapResponse response : responses) { @@ -1640,7 +1634,6 @@ public class ImapStore extends RemoteStore { /** * Handle an untagged response that the caller doesn't care to handle themselves. - * @param response */ protected void handleUntaggedResponse(ImapResponse response) { if (response.getTag() == null && response.size() > 1) { @@ -2205,7 +2198,7 @@ public class ImapStore extends RemoteStore { } } - static class ImapMessage extends MimeMessage { + protected static class ImapMessage extends MimeMessage { ImapMessage(String uid, Folder folder) { this.mUid = uid; this.mFolder = folder; @@ -2232,7 +2225,7 @@ public class ImapStore extends RemoteStore { } } - public class ImapFolderPusher extends ImapFolder implements UntaggedHandler { + protected class ImapFolderPusher extends ImapFolder implements UntaggedHandler { private final PushReceiver receiver; private Thread listeningThread = null; private final AtomicBoolean stop = new AtomicBoolean(false); @@ -2395,7 +2388,7 @@ public class ImapStore extends RemoteStore { doneSent.set(false); conn.setReadTimeout((mStoreConfig.getIdleRefreshMinutes() * 60 * 1000) + IDLE_READ_TIMEOUT_INCREMENT); - untaggedResponses = executeSimpleCommand(ImapCommands.COMMAND_IDLE, false, ImapFolderPusher.this); + executeSimpleCommand(ImapCommands.COMMAND_IDLE, false, ImapFolderPusher.this); idling.set(false); delayTime.set(NORMAL_DELAY_TIME); idleFailureCount.set(0); diff --git a/src/com/fsck/k9/mail/store/pop3/Pop3Store.java b/src/com/fsck/k9/mail/store/pop3/Pop3Store.java index 7856b4a38..d1d096427 100644 --- a/src/com/fsck/k9/mail/store/pop3/Pop3Store.java +++ b/src/com/fsck/k9/mail/store/pop3/Pop3Store.java @@ -747,12 +747,12 @@ public class Pop3Store extends RemoteStore { } @Override - public List getMessages(MessageRetrievalListener listener) throws MessagingException { + public List getMessages(MessageRetrievalListener listener) throws MessagingException { throw new UnsupportedOperationException("Pop3: No getMessages"); } @Override - public List getMessages(String[] uids, MessageRetrievalListener listener) + public List getMessages(String[] uids, MessageRetrievalListener listener) throws MessagingException { throw new UnsupportedOperationException("Pop3: No getMessages by uids"); } diff --git a/src/com/fsck/k9/mail/store/webdav/WebDavStore.java b/src/com/fsck/k9/mail/store/webdav/WebDavStore.java index 4c8ac495f..1709207ba 100644 --- a/src/com/fsck/k9/mail/store/webdav/WebDavStore.java +++ b/src/com/fsck/k9/mail/store/webdav/WebDavStore.java @@ -185,7 +185,7 @@ public class WebDavStore extends RemoteStore { * * @return A WebDavStore URI that holds the same information as the {@code server} parameter. * - * @see Account#getStoreUri() + * @see StoreConfig#getStoreUri() * @see WebDavStore#decodeUri(String) */ public static String createUri(ServerSettings server) { @@ -374,10 +374,9 @@ public class WebDavStore extends RemoteStore { * and setup the account accordingly */ Map headers = new HashMap(); - DataSet dataset = new DataSet(); headers.put("Depth", "0"); headers.put("Brief", "t"); - dataset = processRequest(this.mUrl, "PROPFIND", getSpecialFoldersList(), headers); + DataSet dataset = processRequest(this.mUrl, "PROPFIND", getSpecialFoldersList(), headers); Map specialFoldersMap = dataset.getSpecialFolderToUrl(); String folderName = getFolderName(specialFoldersMap.get(DAV_MAIL_INBOX_FOLDER)); @@ -413,7 +412,6 @@ public class WebDavStore extends RemoteStore { * Next we get all the folders (including "special" ones) */ headers = new HashMap(); - dataset = new DataSet(); headers.put("Brief", "t"); dataset = processRequest(this.mUrl, "SEARCH", getFolderListXml(), headers); String[] folderUrls = dataset.getHrefs(); @@ -512,50 +510,50 @@ public class WebDavStore extends RemoteStore { } private String getSpecialFoldersList() { - StringBuilder buffer = new StringBuilder(200); - buffer.append(""); - buffer.append(""); - buffer.append(""); - buffer.append("<").append(DAV_MAIL_INBOX_FOLDER).append(" xmlns=\"urn:schemas:httpmail:\"/>"); - buffer.append("<").append(DAV_MAIL_DRAFTS_FOLDER).append(" xmlns=\"urn:schemas:httpmail:\"/>"); - buffer.append("<").append(DAV_MAIL_OUTBOX_FOLDER).append(" xmlns=\"urn:schemas:httpmail:\"/>"); - buffer.append("<").append(DAV_MAIL_SENT_FOLDER).append(" xmlns=\"urn:schemas:httpmail:\"/>"); - buffer.append("<").append(DAV_MAIL_TRASH_FOLDER).append(" xmlns=\"urn:schemas:httpmail:\"/>"); + StringBuilder builder = new StringBuilder(200); + builder.append(""); + builder.append(""); + builder.append(""); + builder.append("<").append(DAV_MAIL_INBOX_FOLDER).append(" xmlns=\"urn:schemas:httpmail:\"/>"); + builder.append("<").append(DAV_MAIL_DRAFTS_FOLDER).append(" xmlns=\"urn:schemas:httpmail:\"/>"); + builder.append("<").append(DAV_MAIL_OUTBOX_FOLDER).append(" xmlns=\"urn:schemas:httpmail:\"/>"); + builder.append("<").append(DAV_MAIL_SENT_FOLDER).append(" xmlns=\"urn:schemas:httpmail:\"/>"); + builder.append("<").append(DAV_MAIL_TRASH_FOLDER).append(" xmlns=\"urn:schemas:httpmail:\"/>"); // This should always be ##DavMailSubmissionURI## for which we already have a constant // buffer.append(""); - buffer.append("<").append(DAV_MAIL_SPAM_FOLDER).append(" xmlns=\"urn:schemas:httpmail:\"/>"); + builder.append("<").append(DAV_MAIL_SPAM_FOLDER).append(" xmlns=\"urn:schemas:httpmail:\"/>"); - buffer.append(""); - buffer.append(""); - return buffer.toString(); + builder.append(""); + builder.append(""); + return builder.toString(); } /*************************************************************** * WebDAV XML Request body retrieval functions */ private String getFolderListXml() { - StringBuilder buffer = new StringBuilder(200); - buffer.append(""); - buffer.append("\r\n"); - buffer.append("SELECT \"DAV:uid\", \"DAV:ishidden\"\r\n"); - buffer.append(" FROM SCOPE('hierarchical traversal of \"").append(this.mUrl).append("\"')\r\n"); - buffer.append(" WHERE \"DAV:ishidden\"=False AND \"DAV:isfolder\"=True\r\n"); - buffer.append("\r\n"); - return buffer.toString(); + StringBuilder builder = new StringBuilder(200); + builder.append(""); + builder.append("\r\n"); + builder.append("SELECT \"DAV:uid\", \"DAV:ishidden\"\r\n"); + builder.append(" FROM SCOPE('hierarchical traversal of \"").append(this.mUrl).append("\"')\r\n"); + builder.append(" WHERE \"DAV:ishidden\"=False AND \"DAV:isfolder\"=True\r\n"); + builder.append("\r\n"); + return builder.toString(); } private String getMessageCountXml(String messageState) { - StringBuilder buffer = new StringBuilder(200); - buffer.append(""); - buffer.append("\r\n"); - buffer.append("SELECT \"DAV:visiblecount\"\r\n"); - buffer.append(" FROM \"\"\r\n"); - buffer.append(" WHERE \"DAV:ishidden\"=False AND \"DAV:isfolder\"=False AND \"urn:schemas:httpmail:read\"=") + StringBuilder builder = new StringBuilder(200); + builder.append(""); + builder.append("\r\n"); + builder.append("SELECT \"DAV:visiblecount\"\r\n"); + builder.append(" FROM \"\"\r\n"); + builder.append(" WHERE \"DAV:ishidden\"=False AND \"DAV:isfolder\"=False AND \"urn:schemas:httpmail:read\"=") .append(messageState).append("\r\n"); - buffer.append(" GROUP BY \"DAV:ishidden\"\r\n"); - buffer.append("\r\n"); - return buffer.toString(); + builder.append(" GROUP BY \"DAV:ishidden\"\r\n"); + builder.append("\r\n"); + return builder.toString(); } private String getMessageEnvelopeXml(String[] uids) { @@ -589,14 +587,14 @@ public class WebDavStore extends RemoteStore { } private String getMessagesXml() { - StringBuilder buffer = new StringBuilder(200); - buffer.append(""); - buffer.append("\r\n"); - buffer.append("SELECT \"DAV:uid\"\r\n"); - buffer.append(" FROM \"\"\r\n"); - buffer.append(" WHERE \"DAV:ishidden\"=False AND \"DAV:isfolder\"=False\r\n"); - buffer.append("\r\n"); - return buffer.toString(); + StringBuilder builder = new StringBuilder(200); + builder.append(""); + builder.append("\r\n"); + builder.append("SELECT \"DAV:uid\"\r\n"); + builder.append(" FROM \"\"\r\n"); + builder.append(" WHERE \"DAV:ishidden\"=False AND \"DAV:isfolder\"=False\r\n"); + builder.append("\r\n"); + return builder.toString(); } private String getMessageUrlsXml(String[] uids) { @@ -926,7 +924,7 @@ public class WebDavStore extends RemoteStore { // Read line by line until we find something like:
. while ((tempText = reader.readLine()) != null && formAction == null) { - if (tempText.indexOf(" action=") > -1) { + if (tempText.contains(" action=")) { String[] actionParts = tempText.split(" action="); if (actionParts.length > 1 && actionParts[1].length() > 1) { char openQuote = actionParts[1].charAt(0); @@ -1039,27 +1037,25 @@ public class WebDavStore extends RemoteStore { private InputStream sendRequest(String url, String method, StringEntity messageBody, Map headers, boolean tryAuth) throws MessagingException { - InputStream istream = null; - if (url == null || method == null) { - return istream; + return null; } - WebDavHttpClient httpclient = getHttpClient(); + WebDavHttpClient httpClient = getHttpClient(); try { - int statusCode = -1; - HttpGeneric httpmethod = new HttpGeneric(url); + int statusCode; + HttpGeneric httpMethod = new HttpGeneric(url); HttpResponse response; HttpEntity entity; if (messageBody != null) { - httpmethod.setEntity(messageBody); + httpMethod.setEntity(messageBody); } if (headers != null) { for (Map.Entry entry : headers.entrySet()) { - httpmethod.setHeader(entry.getKey(), entry.getValue()); + httpMethod.setHeader(entry.getKey(), entry.getValue()); } } @@ -1068,11 +1064,11 @@ public class WebDavStore extends RemoteStore { throw new MessagingException("Unable to authenticate in sendRequest()."); } } else if (mAuthentication == AUTH_TYPE_BASIC) { - httpmethod.setHeader("Authorization", mAuthString); + httpMethod.setHeader("Authorization", mAuthString); } - httpmethod.setMethod(method); - response = httpclient.executeOverride(httpmethod, mContext); + httpMethod.setMethod(method); + response = httpClient.executeOverride(httpMethod, mContext); statusCode = response.getStatusLine().getStatusCode(); entity = response.getEntity(); @@ -1093,7 +1089,7 @@ public class WebDavStore extends RemoteStore { } if (entity != null) { - istream = WebDavHttpClient.getUngzippedContent(entity); + return WebDavHttpClient.getUngzippedContent(entity); } } catch (UnsupportedEncodingException uee) { Log.e(LOG_TAG, "UnsupportedEncodingException: " + uee + "\nTrace: " + processException(uee)); @@ -1103,7 +1099,7 @@ public class WebDavStore extends RemoteStore { throw new MessagingException("IOException", ioe); } - return istream; + return null; } public String getAuthString() { @@ -1235,7 +1231,7 @@ public class WebDavStore extends RemoteStore { store = nStore; this.mName = name; - String encodedName = ""; + String encodedName; String[] urlParts = name.split("/"); String url = ""; for (int i = 0, count = urlParts.length; i < count; i++) { @@ -1293,7 +1289,7 @@ public class WebDavStore extends RemoteStore { for (int i = 0, count = messages.size(); i < count; i++) { uids[i] = messages.get(i).getUid(); } - String messageBody = ""; + String messageBody; Map headers = new HashMap(); Map uidToUrl = getMessageUrls(uids); String[] urls = new String[uids.length]; @@ -1404,12 +1400,12 @@ public class WebDavStore extends RemoteStore { } @Override - public List getMessages(int start, int end, Date earliestDate, MessageRetrievalListener listener) + public List getMessages(int start, int end, Date earliestDate, MessageRetrievalListener listener) throws MessagingException { - List messages = new ArrayList(); + List messages = new ArrayList(); String[] uids; Map headers = new HashMap(); - int uidsLength = -1; + int uidsLength; String messageBody; int prevStart = start; @@ -1454,7 +1450,7 @@ public class WebDavStore extends RemoteStore { } @Override - public List getMessages(MessageRetrievalListener listener) throws MessagingException { + public List getMessages(MessageRetrievalListener listener) throws MessagingException { return getMessages(null, listener); } @@ -1645,9 +1641,9 @@ public class WebDavStore extends RemoteStore { * Fetches and sets the message flags for the supplied messages. The idea is to have this be recursive so that * we do a series of medium calls instead of one large massive call or a large number of smaller calls. */ - private void fetchFlags(List startMessages, MessageRetrievalListener listener) throws MessagingException { + private void fetchFlags(List startMessages, MessageRetrievalListener listener) throws MessagingException { HashMap headers = new HashMap(); - String messageBody = ""; + String messageBody; List messages = new ArrayList(20); String[] uids; @@ -1657,7 +1653,7 @@ public class WebDavStore extends RemoteStore { } if (startMessages.size() > 20) { - List newMessages = new ArrayList(startMessages.size() - 20); + List newMessages = new ArrayList(startMessages.size() - 20); for (int i = 0, count = startMessages.size(); i < count; i++) { if (i < 20) { messages.set(i, startMessages.get(i)); @@ -1717,7 +1713,7 @@ public class WebDavStore extends RemoteStore { private void fetchEnvelope(List startMessages, MessageRetrievalListener listener) throws MessagingException { Map headers = new HashMap(); - String messageBody = ""; + String messageBody; String[] uids; List messages = new ArrayList(10); @@ -2426,7 +2422,7 @@ public class WebDavStore extends RemoteStore { throws IOException { InputStream responseStream = entity.getContent(); if (responseStream == null) - return responseStream; + return null; Header header = entity.getContentEncoding(); if (header == null) return responseStream;