Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 75868b5a authored by Daniel Applebaum's avatar Daniel Applebaum
Browse files

Enhancements to WebDAV (Exchange) capabilities:

1) Automatically add / separators if not supplied by user.  Fixes
   Issue 290

2) Enable Move and Copy.

3) Enable setting a message to unread state.

4) Set authentication header for downloading and sending messages, so
   that those functions work with sites using Basic authentication.

5) Don't swallow log Exceptions.  Instead, allow Exceptions to
   percolate up to higher levels so that they can be logged into
   K9mail-errors.

6) Provide appendMessages function, so that Drafts get stored on the
   server.

7) Enable server-side message deletion, using user-selected Trash
   folder.

parent ec25d145
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -89,6 +89,14 @@ public abstract class Store {
    public boolean isPushCapable() {
        return false;
    }
    public boolean isSendCapable()
    {
        return false;
    }
    
    public void sendMessages(Message[] messages) throws MessagingException
    {
    }

    public Pusher getPusher(PushReceiver receiver, List<String> names)
    {
+382 −176

File changed.

Preview size limit exceeded, changes collapsed.

+3 −77
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.util.Log;

import com.android.email.Email;
import com.android.email.PeekableInputStream;
import com.android.email.Utility;
import com.android.email.codec.binary.Base64;
import com.android.email.mail.Address;
import com.android.email.mail.AuthenticationFailedException;
@@ -95,89 +96,14 @@ public class WebDavTransport extends Transport {
        store.getHttpClient();
    }
    
//    public void sendMessage(Message message) throws MessagingException {
//        Address[] from = message.getFrom();
//        
//    }
    
    public void close() {
    }
    
    public String generateTempURI(String subject) {
    	String encodedSubject = URLEncoder.encode(subject);
    	return store.getUrl()  + "/drafts/" + encodedSubject + ".eml";
    }
    public String generateSendURI() {
    	return store.getUrl() +  "/##DavMailSubmissionURI##/";
    }
    
    public void sendMessage(Message message) throws MessagingException {
        Log.d(Email.LOG_TAG, ">>> sendMessage called.");

        DefaultHttpClient httpclient;
        httpclient = store.getHttpClient();
        HttpGeneric httpmethod;
        HttpResponse response;
        StringEntity bodyEntity;
        int statusCode;
        String subject;
        ByteArrayOutputStream out;
        try {
        	try {
        		subject = message.getSubject();
        	} catch (MessagingException e) {
        		Log.e(Email.LOG_TAG, "MessagingException while retrieving Subject: " + e);
        		subject = "";
        	}
        	try {
        		out = new ByteArrayOutputStream(message.getSize());
        	} catch (MessagingException e) {
        		Log.e(Email.LOG_TAG, "MessagingException while getting size of message: " + e);
        		out = new ByteArrayOutputStream();
        	}
        	open();
        	message.writeTo(
        			new EOLConvertingOutputStream(
        					new BufferedOutputStream(out, 1024)));

        	bodyEntity = new StringEntity(out.toString(), "UTF-8");
        	bodyEntity.setContentType("message/rfc822");

        	httpmethod = store.new HttpGeneric(generateTempURI(subject));
        	httpmethod.setMethod("PUT");
        	httpmethod.setEntity(bodyEntity);

        	response = httpclient.execute(httpmethod);
        	statusCode = response.getStatusLine().getStatusCode();

        	if (statusCode < 200 ||
        			statusCode > 300) {
    			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));
        	httpmethod.setMethod("MOVE");
        	httpmethod.setHeader("Destination", generateSendURI());
        store.sendMessages(new Message[] { message });

        	response = httpclient.execute(httpmethod);
        	statusCode = response.getStatusLine().getStatusCode();
        	
        	if (statusCode < 200 ||
        			statusCode > 300) {
    			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 sendMessage() " + uee);
        } catch (IOException 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");
    }

}