mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-16 06:25:06 -05:00
Finished initial refactoring of fetch(). Some slight formatting and cleanup changes as well.
This commit is contained in:
parent
34be0269f8
commit
72c4095ceb
@ -2,12 +2,14 @@ package com.android.email.mail.store;
|
|||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
@ -34,6 +36,7 @@ import com.android.email.mail.Store;
|
|||||||
import com.android.email.mail.internet.MimeBodyPart;
|
import com.android.email.mail.internet.MimeBodyPart;
|
||||||
import com.android.email.mail.internet.MimeMessage;
|
import com.android.email.mail.internet.MimeMessage;
|
||||||
import com.android.email.mail.internet.TextBody;
|
import com.android.email.mail.internet.TextBody;
|
||||||
|
import com.android.email.mail.transport.EOLConvertingOutputStream;
|
||||||
|
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
@ -230,13 +233,10 @@ public class WebDavStore extends Store {
|
|||||||
buffer.append("<?xml version='1.0' ?>");
|
buffer.append("<?xml version='1.0' ?>");
|
||||||
buffer.append("<a:searchrequest xmlns:a='DAV:'><a:sql>\r\n");
|
buffer.append("<a:searchrequest xmlns:a='DAV:'><a:sql>\r\n");
|
||||||
buffer.append("SELECT \"DAV:ishidden\"\r\n");
|
buffer.append("SELECT \"DAV:ishidden\"\r\n");
|
||||||
// buffer.append(" FROM \"\"\r\n");
|
|
||||||
buffer.append(" FROM SCOPE('deep traversal of \""+this.mUrl+"\"')\r\n");
|
buffer.append(" FROM SCOPE('deep traversal of \""+this.mUrl+"\"')\r\n");
|
||||||
buffer.append(" WHERE \"DAV:ishidden\"=False AND \"DAV:isfolder\"=True\r\n");
|
buffer.append(" WHERE \"DAV:ishidden\"=False AND \"DAV:isfolder\"=True\r\n");
|
||||||
buffer.append("</a:sql></a:searchrequest>\r\n");
|
buffer.append("</a:sql></a:searchrequest>\r\n");
|
||||||
|
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getMessageCountXml(String messageState) {
|
private String getMessageCountXml(String messageState) {
|
||||||
@ -869,6 +869,15 @@ public class WebDavStore extends Store {
|
|||||||
fetchEnvelope(messages, listener);
|
fetchEnvelope(messages, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fp.contains(FetchProfile.Item.BODY_SANE)) {
|
||||||
|
fetchMessages(messages, listener, FETCH_BODY_SANE_SUGGESTED_SIZE / 76);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fp.contains(FetchProfile.Item.BODY)) {
|
||||||
|
fetchMessages(messages, listener, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fp.contains(FetchProfile.Item.STRUCTURE)) {
|
||||||
for (int i = 0, count = messages.length; i < count; i++) {
|
for (int i = 0, count = messages.length; i < count; i++) {
|
||||||
if (!(messages[i] instanceof WebDavMessage)) {
|
if (!(messages[i] instanceof WebDavMessage)) {
|
||||||
throw new MessagingException("WebDavStore fetch called with non-WebDavMessage");
|
throw new MessagingException("WebDavStore fetch called with non-WebDavMessage");
|
||||||
@ -879,30 +888,48 @@ public class WebDavStore extends Store {
|
|||||||
listener.messageStarted(wdMessage.getUid(), i, count);
|
listener.messageStarted(wdMessage.getUid(), i, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the body to null if it's asking for the structure because
|
|
||||||
* we don't support it yet.
|
|
||||||
*/
|
|
||||||
if (fp.contains(FetchProfile.Item.STRUCTURE)) {
|
|
||||||
wdMessage.setBody(null);
|
wdMessage.setBody(null);
|
||||||
|
|
||||||
|
if (listener != null) {
|
||||||
|
listener.messageFinished(wdMessage, i, count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Message fetching that we can pull as a stream
|
* Fetches the full messages or up to lines lines and passes them to the message parser.
|
||||||
*/
|
*/
|
||||||
if (fp.contains(FetchProfile.Item.BODY) ||
|
private void fetchMessages(Message[] messages, MessageRetrievalListener listener, int lines) throws MessagingException {
|
||||||
fp.contains(FetchProfile.Item.BODY_SANE)) {
|
|
||||||
|
|
||||||
DefaultHttpClient httpclient = new DefaultHttpClient();
|
DefaultHttpClient httpclient = new DefaultHttpClient();
|
||||||
InputStream istream = null;
|
|
||||||
InputStream resultStream = null;
|
/**
|
||||||
HttpGet httpget;
|
* We can't hand off to processRequest() since we need the stream to parse.
|
||||||
HttpEntity entity;
|
*/
|
||||||
HttpResponse response;
|
if (needAuth()) {
|
||||||
|
authenticate();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (WebDavStore.this.mAuthenticated == false ||
|
||||||
|
WebDavStore.this.mAuthCookies == null) {
|
||||||
|
throw new MessagingException("Error during authentication in fetchMessages().");
|
||||||
|
}
|
||||||
|
|
||||||
|
httpclient.setCookieStore(WebDavStore.this.mAuthCookies);
|
||||||
|
|
||||||
|
for (int i = 0, count = messages.length; i < count; i++) {
|
||||||
|
WebDavMessage wdMessage;
|
||||||
int statusCode = 0;
|
int statusCode = 0;
|
||||||
|
|
||||||
try {
|
if (!(messages[i] instanceof WebDavMessage)) {
|
||||||
httpclient.setCookieStore(WebDavStore.this.mAuthCookies);
|
throw new MessagingException("WebDavStore fetch called with non-WebDavMessage");
|
||||||
|
}
|
||||||
|
|
||||||
|
wdMessage = (WebDavMessage) messages[i];
|
||||||
|
|
||||||
|
if (listener != null) {
|
||||||
|
listener.messageStarted(wdMessage.getUid(), i, count);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If fetch is called outside of the initial list (ie, a locally stored
|
* If fetch is called outside of the initial list (ie, a locally stored
|
||||||
@ -915,7 +942,11 @@ public class WebDavStore extends Store {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
httpget = new HttpGet(new URI(wdMessage.getUrl()));
|
try {
|
||||||
|
HttpGet httpget = new HttpGet(new URI(wdMessage.getUrl()));
|
||||||
|
HttpResponse response;
|
||||||
|
HttpEntity entity;
|
||||||
|
|
||||||
httpget.setHeader("translate", "f");
|
httpget.setHeader("translate", "f");
|
||||||
|
|
||||||
response = httpclient.execute(httpget);
|
response = httpclient.execute(httpget);
|
||||||
@ -928,24 +959,25 @@ public class WebDavStore extends Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
entity = response.getEntity();
|
entity = response.getEntity();
|
||||||
|
|
||||||
if (entity != null) {
|
if (entity != null) {
|
||||||
|
InputStream istream = null;
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
String tempText = new String();
|
String tempText = new String();
|
||||||
String resultText = new String();
|
String resultText = new String();
|
||||||
String bodyBoundary = "";
|
String bodyBoundary = "";
|
||||||
BufferedReader reader;
|
BufferedReader reader;
|
||||||
int totalLines = FETCH_BODY_SANE_SUGGESTED_SIZE / 76;
|
int currentLines = 0;
|
||||||
int lines = 0;
|
|
||||||
|
|
||||||
istream = entity.getContent();
|
istream = entity.getContent();
|
||||||
|
|
||||||
if (fp.contains(FetchProfile.Item.BODY_SANE)) {
|
if (lines != -1) {
|
||||||
reader = new BufferedReader(new InputStreamReader(istream), 8192);
|
reader = new BufferedReader(new InputStreamReader(istream), 8192);
|
||||||
|
|
||||||
while ((tempText = reader.readLine()) != null &&
|
while ((tempText = reader.readLine()) != null &&
|
||||||
(lines < totalLines)) {
|
(currentLines < lines)) {
|
||||||
buffer.append(tempText+"\r\n");
|
buffer.append(tempText+"\r\n");
|
||||||
lines++;
|
currentLines++;
|
||||||
}
|
}
|
||||||
|
|
||||||
istream.close();
|
istream.close();
|
||||||
@ -954,7 +986,6 @@ public class WebDavStore extends Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wdMessage.parse(istream);
|
wdMessage.parse(istream);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IllegalArgumentException iae) {
|
} catch (IllegalArgumentException iae) {
|
||||||
@ -964,7 +995,6 @@ public class WebDavStore extends Store {
|
|||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
Log.e(Email.LOG_TAG, "Non-success response code loading message, response code was " + statusCode);
|
Log.e(Email.LOG_TAG, "Non-success response code loading message, response code was " + statusCode);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
listener.messageFinished(wdMessage, i, count);
|
listener.messageFinished(wdMessage, i, count);
|
||||||
@ -1189,20 +1219,18 @@ public class WebDavStore extends Store {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void appendMessages(Message[] messages) throws MessagingException {
|
public void appendMessages(Message[] messages) throws MessagingException {
|
||||||
appendMessages(messages, false);
|
Log.e(Email.LOG_TAG, "appendMessages() not implmented");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void appendMessages(Message[] messages, boolean copy) throws MessagingException {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void copyMessages(Message[] msgs, Folder folder) throws MessagingException {
|
public void copyMessages(Message[] msgs, Folder folder) throws MessagingException {
|
||||||
|
Log.e(Email.LOG_TAG, "copyMessages() not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Message[] expunge() throws MessagingException {
|
public Message[] expunge() throws MessagingException {
|
||||||
|
/** Do nothing, deletes occur as soon as the call is made rather than flags on the message */
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user