Changes to support cleaving sync out of ExchangeService.

Change-Id: Idbfff4ddc8fca4829228d04816d40a4ab9639382
This commit is contained in:
Yu Ping Hu 2013-05-08 17:34:58 -07:00
parent b8d7d8d31d
commit 7c3f85885c
3 changed files with 19 additions and 21 deletions

View File

@ -35,7 +35,6 @@ import org.apache.commons.io.IOUtils;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@ -64,7 +63,7 @@ public class Rfc822Output {
private static final Pattern BODY_PATTERN = Pattern.compile(
"(?:<\\s*body[^>]*>)(.*)(?:<\\s*/\\s*body\\s*>)",
Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
/** Match group in {@code BODDY_PATTERN} for the body HTML */
/** Match group in {@code BODY_PATTERN} for the body HTML */
private static final int BODY_PATTERN_GROUP = 1;
/** Index of the plain text version of the message body */
private final static int INDEX_BODY_TEXT = 0;
@ -110,20 +109,15 @@ public class Rfc822Output {
* not necessary to pass in a buffered output stream here.
*
* @param context system context for accessing the provider
* @param messageId the message to write out
* @param message the message to write out
* @param out the output stream to write the message to
* @param useSmartReply whether or not quoted text is appended to a reply/forward
* @param a list of attachments to send (or null if retrieved from the message itself)
* @param sendBcc Whether to add the bcc header
* @param attachments list of attachments to send (or null if retrieved from the message itself)
*/
public static void writeTo(Context context, long messageId, OutputStream out,
boolean useSmartReply, boolean sendBcc) throws IOException, MessagingException {
writeTo(context, messageId, out, useSmartReply, sendBcc, null);
}
public static void writeTo(Context context, long messageId, OutputStream out,
public static void writeTo(Context context, Message message, OutputStream out,
boolean useSmartReply, boolean sendBcc, List<Attachment> attachments)
throws IOException, MessagingException {
Message message = Message.restoreMessageWithId(context, messageId);
if (message == null) {
// throw something?
return;
@ -160,7 +154,7 @@ public class Rfc822Output {
// If a list of attachments hasn't been passed in, build one from the message
if (attachments == null) {
attachments =
Arrays.asList(Attachment.restoreAttachmentsWithMessageId(context, messageId));
Arrays.asList(Attachment.restoreAttachmentsWithMessageId(context, message.mId));
}
boolean multipart = attachments.size() > 0;

View File

@ -190,10 +190,11 @@ public class SmtpSender extends Sender {
}
executeSimpleCommand("DATA");
// TODO byte stuffing
Rfc822Output.writeTo(mContext, messageId,
Rfc822Output.writeTo(mContext, message,
new EOLConvertingOutputStream(mTransport.getOutputStream()),
false /* do not use smart reply */,
false /* do not send BCC */);
false /* do not send BCC */,
null /* attachments are in the message itself */);
executeSimpleCommand("\r\n.");
} catch (IOException ioe) {
throw new MessagingException("Unable to send message", ioe);

View File

@ -3140,18 +3140,21 @@ public class EmailProvider extends ContentProvider {
final Uri uri = EmailContent.Message.CONTENT_URI;
resolver.update(uri, contentValues, MessageColumns.MAILBOX_KEY + " = ?",
new String[] {String.valueOf(mailbox.mId)});
// If it's been long enough, force sync this mailbox.
// For non-push mailboxes, if it's stale (i.e. last sync was a while
// ago), force a sync.
if (mailbox.mSyncInterval > Mailbox.CHECK_INTERVAL_PUSH) {
final long timeSinceLastSync =
System.currentTimeMillis() - mailbox.mSyncTime;
if (timeSinceLastSync > AUTO_REFRESH_INTERVAL_MS) {
final Uri refreshUri = Uri.parse(EmailContent.CONTENT_URI + "/" +
QUERY_UIREFRESH + "/" + mailbox.mId);
final Uri refreshUri = Uri.parse(EmailContent.CONTENT_URI +
"/" + QUERY_UIREFRESH + "/" + mailbox.mId);
resolver.query(refreshUri, null, null, null, null);
}
}
}
}
}
}
// Return success
Bundle response = new Bundle();
response.putString(setVisibilityKey,