Fix some warnings in ImapStore / Pop3Store / WebDavStore

This commit is contained in:
Jan Berkel 2014-12-19 10:01:34 +01:00
parent e214dbbd99
commit 6ed52ac551
3 changed files with 79 additions and 90 deletions

View File

@ -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<ImapMessage> {
protected class ImapFolder extends Folder<ImapMessage> {
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<ImapResponse> 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<ImapMessage> getMessages(int start, int end, Date earliestDate, MessageRetrievalListener listener)
public List<ImapMessage> getMessages(int start, int end, Date earliestDate, MessageRetrievalListener<ImapMessage> listener)
throws MessagingException {
return getMessages(start, end, earliestDate, false, listener);
}
protected List<ImapMessage> getMessages(final int start, final int end, Date earliestDate, final boolean includeDeleted, final MessageRetrievalListener listener)
protected List<ImapMessage> getMessages(final int start, final int end, Date earliestDate, final boolean includeDeleted, final MessageRetrievalListener<ImapMessage> listener)
throws MessagingException {
if (start < 1 || end < 1 || end < start) {
throw new MessagingException(
@ -1223,7 +1218,7 @@ public class ImapStore extends RemoteStore {
}
protected List<ImapMessage> getMessages(final List<Long> mesgSeqs,
final boolean includeDeleted,
final MessageRetrievalListener listener)
final MessageRetrievalListener<ImapMessage> listener)
throws MessagingException {
ImapSearcher searcher = new ImapSearcher() {
@Override
@ -1236,7 +1231,7 @@ public class ImapStore extends RemoteStore {
protected List<? extends Message> getMessagesFromUids(final List<String> mesgUids,
final boolean includeDeleted,
final MessageRetrievalListener listener) throws MessagingException {
final MessageRetrievalListener<ImapMessage> listener) throws MessagingException {
ImapSearcher searcher = new ImapSearcher() {
@Override
public List<ImapResponse> 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<ImapResponse> handleUntaggedResponses(List<ImapResponse> 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);

View File

@ -747,12 +747,12 @@ public class Pop3Store extends RemoteStore {
}
@Override
public List<? extends Message> getMessages(MessageRetrievalListener listener) throws MessagingException {
public List<Pop3Message> getMessages(MessageRetrievalListener listener) throws MessagingException {
throw new UnsupportedOperationException("Pop3: No getMessages");
}
@Override
public List<? extends Message> getMessages(String[] uids, MessageRetrievalListener listener)
public List<Pop3Message> getMessages(String[] uids, MessageRetrievalListener listener)
throws MessagingException {
throw new UnsupportedOperationException("Pop3: No getMessages by uids");
}

View File

@ -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<String, String> headers = new HashMap<String, String>();
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<String, String> 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<String, String>();
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("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>");
buffer.append("<propfind xmlns=\"DAV:\">");
buffer.append("<prop>");
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("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>");
builder.append("<propfind xmlns=\"DAV:\">");
builder.append("<prop>");
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("<sendmsg xmlns=\"urn:schemas:httpmail:\"/>");
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("</prop>");
buffer.append("</propfind>");
return buffer.toString();
builder.append("</prop>");
builder.append("</propfind>");
return builder.toString();
}
/***************************************************************
* WebDAV XML Request body retrieval functions
*/
private String getFolderListXml() {
StringBuilder buffer = new StringBuilder(200);
buffer.append("<?xml version='1.0' ?>");
buffer.append("<a:searchrequest xmlns:a='DAV:'><a:sql>\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("</a:sql></a:searchrequest>\r\n");
return buffer.toString();
StringBuilder builder = new StringBuilder(200);
builder.append("<?xml version='1.0' ?>");
builder.append("<a:searchrequest xmlns:a='DAV:'><a:sql>\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("</a:sql></a:searchrequest>\r\n");
return builder.toString();
}
private String getMessageCountXml(String messageState) {
StringBuilder buffer = new StringBuilder(200);
buffer.append("<?xml version='1.0' ?>");
buffer.append("<a:searchrequest xmlns:a='DAV:'><a:sql>\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("<?xml version='1.0' ?>");
builder.append("<a:searchrequest xmlns:a='DAV:'><a:sql>\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("</a:sql></a:searchrequest>\r\n");
return buffer.toString();
builder.append(" GROUP BY \"DAV:ishidden\"\r\n");
builder.append("</a:sql></a:searchrequest>\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("<?xml version='1.0' ?>");
buffer.append("<a:searchrequest xmlns:a='DAV:'><a:sql>\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("</a:sql></a:searchrequest>\r\n");
return buffer.toString();
StringBuilder builder = new StringBuilder(200);
builder.append("<?xml version='1.0' ?>");
builder.append("<a:searchrequest xmlns:a='DAV:'><a:sql>\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("</a:sql></a:searchrequest>\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: <form action="owaauth.dll"...>.
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<String, String> 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<String, String> 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<String, String> headers = new HashMap<String, String>();
Map<String, String> uidToUrl = getMessageUrls(uids);
String[] urls = new String[uids.length];
@ -1404,12 +1400,12 @@ public class WebDavStore extends RemoteStore {
}
@Override
public List<? extends Message> getMessages(int start, int end, Date earliestDate, MessageRetrievalListener listener)
public List<WebDavMessage> getMessages(int start, int end, Date earliestDate, MessageRetrievalListener<WebDavMessage> listener)
throws MessagingException {
List<Message> messages = new ArrayList<Message>();
List<WebDavMessage> messages = new ArrayList<WebDavMessage>();
String[] uids;
Map<String, String> headers = new HashMap<String, String>();
int uidsLength = -1;
int uidsLength;
String messageBody;
int prevStart = start;
@ -1454,7 +1450,7 @@ public class WebDavStore extends RemoteStore {
}
@Override
public List<? extends Message> getMessages(MessageRetrievalListener listener) throws MessagingException {
public List<WebDavMessage> getMessages(MessageRetrievalListener<WebDavMessage> 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<? extends Message> startMessages, MessageRetrievalListener listener) throws MessagingException {
private void fetchFlags(List<WebDavMessage> startMessages, MessageRetrievalListener<WebDavMessage> listener) throws MessagingException {
HashMap<String, String> headers = new HashMap<String, String>();
String messageBody = "";
String messageBody;
List<Message> messages = new ArrayList<Message>(20);
String[] uids;
@ -1657,7 +1653,7 @@ public class WebDavStore extends RemoteStore {
}
if (startMessages.size() > 20) {
List<Message> newMessages = new ArrayList<Message>(startMessages.size() - 20);
List<WebDavMessage> newMessages = new ArrayList<WebDavMessage>(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<WebDavMessage> startMessages, MessageRetrievalListener<WebDavMessage> listener)
throws MessagingException {
Map<String, String> headers = new HashMap<String, String>();
String messageBody = "";
String messageBody;
String[] uids;
List<WebDavMessage> messages = new ArrayList<WebDavMessage>(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;