mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-23 18:02:15 -05:00
Fix for sending mail; additional logging when there is an invalid (non-http-2xx) response.
This commit is contained in:
parent
37e6d0c949
commit
2e4ee5b59f
@ -403,6 +403,31 @@ public class WebDavStore extends Store {
|
||||
return status;
|
||||
}
|
||||
|
||||
public static String getHttpRequestResponse(HttpEntity request, HttpEntity response) throws IllegalStateException, IOException{
|
||||
String responseText = "";
|
||||
String requestText = "";
|
||||
if (response != null) {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getContent()), 8192);
|
||||
String tempText = "";
|
||||
|
||||
while ((tempText = reader.readLine()) != null) {
|
||||
responseText += tempText;
|
||||
}
|
||||
}
|
||||
if (request != null) {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(request.getContent()), 8192);
|
||||
String tempText = "";
|
||||
|
||||
while ((tempText = reader.readLine()) != null) {
|
||||
requestText += tempText;
|
||||
}
|
||||
requestText = requestText.replaceAll("password=.*?&", "password=(omitted)&");
|
||||
}
|
||||
return "Request: " + requestText +
|
||||
"\n\nResponse: " + responseText;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the Form Based Authentication
|
||||
* Returns the CookieStore object for later use or null
|
||||
@ -450,33 +475,11 @@ public class WebDavStore extends Store {
|
||||
int status_code = response.getStatusLine().getStatusCode();
|
||||
|
||||
/** Verify success */
|
||||
if (status_code < 500 &&
|
||||
status_code >= 400) {
|
||||
String errorText = "";
|
||||
String requestText = "";
|
||||
if (entity != null) {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent()), 8192);
|
||||
String tempText = "";
|
||||
|
||||
while ((tempText = reader.readLine()) != null) {
|
||||
errorText += tempText;
|
||||
}
|
||||
}
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(formEntity.getContent()), 8192);
|
||||
String tempText = "";
|
||||
|
||||
while ((tempText = reader.readLine()) != null) {
|
||||
requestText += tempText;
|
||||
}
|
||||
requestText = requestText.replaceAll("password=.*?&", "password=(omitted)&");
|
||||
throw new MessagingException("Error during authentication: "+
|
||||
response.getStatusLine().toString()+ "\n\nRequest: "+
|
||||
requestText + "\n\nResponse: " +
|
||||
errorText);
|
||||
}
|
||||
if (status_code > 300 ||
|
||||
status_code < 200) {
|
||||
throw new IOException("Error during authentication: "+status_code);
|
||||
throw new MessagingException("Error during authentication: "+
|
||||
response.getStatusLine().toString()+ "\n\n"+
|
||||
getHttpRequestResponse(formEntity, entity));
|
||||
}
|
||||
|
||||
cookies = httpclient.getCookieStore();
|
||||
@ -588,7 +591,7 @@ public class WebDavStore extends Store {
|
||||
httpclient.setCookieStore(this.mAuthCookies);
|
||||
try {
|
||||
int statusCode = -1;
|
||||
StringEntity messageEntity;
|
||||
StringEntity messageEntity = null;
|
||||
HttpGeneric httpmethod = new HttpGeneric(url);
|
||||
HttpResponse response;
|
||||
HttpEntity entity;
|
||||
@ -610,25 +613,11 @@ public class WebDavStore extends Store {
|
||||
|
||||
entity = response.getEntity();
|
||||
|
||||
if (statusCode < 500 &&
|
||||
statusCode >= 400) {
|
||||
String errorText = "";
|
||||
if (entity != null) {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent()), 8192);
|
||||
String tempText = "";
|
||||
|
||||
while ((tempText = reader.readLine()) != null) {
|
||||
errorText += tempText;
|
||||
}
|
||||
}
|
||||
throw new IOException("Error during authentication: "+
|
||||
response.getStatusLine().toString()+ "\n\nRequest: "+
|
||||
messageBody + "\n\nResponse: " +
|
||||
errorText);
|
||||
}
|
||||
if (statusCode < 200 ||
|
||||
statusCode > 300) {
|
||||
throw new IOException("Error processing request, returned HTTP Response Code was " + statusCode);
|
||||
throw new IOException("Error during request processing: "+
|
||||
response.getStatusLine().toString()+ "\n\n"+
|
||||
getHttpRequestResponse(messageEntity, entity));
|
||||
}
|
||||
|
||||
if (entity != null &&
|
||||
@ -1053,13 +1042,15 @@ public class WebDavStore extends Store {
|
||||
|
||||
statusCode = response.getStatusLine().getStatusCode();
|
||||
|
||||
entity = response.getEntity();
|
||||
|
||||
if (statusCode < 200 ||
|
||||
statusCode > 300) {
|
||||
throw new IOException("Status Code in invalid range, URL: "+wdMessage.getUrl());
|
||||
throw new IOException("Error during fetch: "+
|
||||
response.getStatusLine().toString()+ "\n\n"+
|
||||
getHttpRequestResponse(null, entity));
|
||||
}
|
||||
|
||||
entity = response.getEntity();
|
||||
|
||||
if (entity != null) {
|
||||
InputStream istream = null;
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
@ -111,10 +111,10 @@ public class WebDavTransport extends Transport {
|
||||
|
||||
public String generateTempURI(String subject) {
|
||||
String encodedSubject = URLEncoder.encode(subject);
|
||||
return store.getUrl() + "/Exchange/" + store.getAlias() + "/drafts/" + encodedSubject + ".eml";
|
||||
return store.getUrl() + "/drafts/" + encodedSubject + ".eml";
|
||||
}
|
||||
public String generateSendURI() {
|
||||
return store.getUrl() + "/Exchange/" + store.getAlias() + "/##DavMailSubmissionURI##/";
|
||||
return store.getUrl() + "/##DavMailSubmissionURI##/";
|
||||
}
|
||||
|
||||
public void sendMessage(Message message) throws MessagingException {
|
||||
@ -132,7 +132,6 @@ public class WebDavTransport extends Transport {
|
||||
}
|
||||
HttpGeneric httpmethod;
|
||||
HttpResponse response;
|
||||
HttpEntity responseEntity;
|
||||
StringEntity bodyEntity;
|
||||
int statusCode;
|
||||
String subject;
|
||||
@ -168,7 +167,9 @@ public class WebDavTransport extends Transport {
|
||||
|
||||
if (statusCode < 200 ||
|
||||
statusCode > 300) {
|
||||
throw new IOException("Error sending message, status code was " + statusCode);
|
||||
throw new IOException("Sending Message: Error while trying to upload to drafts folder: "+
|
||||
response.getStatusLine().toString()+ "\n\n"+
|
||||
WebDavStore.getHttpRequestResponse(bodyEntity, response.getEntity()));
|
||||
}
|
||||
|
||||
httpmethod = store.new HttpGeneric(generateTempURI(subject));
|
||||
@ -180,14 +181,16 @@ public class WebDavTransport extends Transport {
|
||||
|
||||
if (statusCode < 200 ||
|
||||
statusCode > 300) {
|
||||
throw new IOException("Error sending message, status code was " + statusCode);
|
||||
throw new IOException("Sending Message: Error while trying to move finished draft to Outbox: "+
|
||||
response.getStatusLine().toString()+ "\n\n"+
|
||||
WebDavStore.getHttpRequestResponse(null, response.getEntity()));
|
||||
}
|
||||
|
||||
} catch (UnsupportedEncodingException uee) {
|
||||
Log.e(Email.LOG_TAG, "UnsupportedEncodingException in getMessageCount() " + uee);
|
||||
Log.e(Email.LOG_TAG, "UnsupportedEncodingException in sendMessage() " + uee);
|
||||
} catch (IOException ioe) {
|
||||
Log.e(Email.LOG_TAG, "IOException in getMessageCount() " + ioe);
|
||||
throw new MessagingException("Unable to send message", ioe);
|
||||
Log.e(Email.LOG_TAG, "IOException in sendMessage() " + ioe);
|
||||
throw new MessagingException("Unable to send message"+ioe.getMessage(), ioe);
|
||||
}
|
||||
Log.d(Email.LOG_TAG, ">>> getMessageCount finished");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user