int sendMessage(File cacheDir, long msgId) throws IOException, MessagingException {
// We always return SUCCESS unless the sending error is account-specific (security or
// authentication) rather than message-specific; returning anything else will terminate
// the Outbox sync! Message-specific errors are marked in the messages themselves.
int result = EmailServiceStatus.SUCCESS;
// Say we're starting to send this message
sendCallback(msgId, null, EmailServiceStatus.IN_PROGRESS);
// Create a temporary file (this will hold the outgoing message in RFC822 (MIME) format)
File tmpFile = File.createTempFile("eas_", "tmp", cacheDir);
try {
// Get the message and fail quickly if not found
Message msg = Message.restoreMessageWithId(mContext, msgId);
if (msg == null) return EmailServiceStatus.MESSAGE_NOT_FOUND;
// See what kind of outgoing messge this is
int flags = msg.mFlags;
boolean reply = (flags & Message.FLAG_TYPE_REPLY) != 0;
boolean forward = (flags & Message.FLAG_TYPE_FORWARD) != 0;
boolean includeQuotedText = (flags & Message.FLAG_NOT_INCLUDE_QUOTED_TEXT) == 0;
// The reference message and mailbox are called item and collection in EAS
OriginalMessageInfo referenceInfo = null;
// Respect the sense of the include quoted text flag
if (includeQuotedText && (reply || forward)) {
referenceInfo = getOriginalMessageInfo(mContext, msgId);
}
// Generally, we use SmartReply/SmartForward if we've got a good reference
[color=red]boolean smartSend = referenceInfo != null;[/color]
// But we won't use SmartForward if the account isn't set up for it (currently, we only
// use SmartForward for EAS 12.0 or later to avoid creating eml files that are
// potentially difficult for the recipient to handle)
if (forward && ((mAccount.mFlags & Account.FLAGS_SUPPORTS_SMART_FORWARD) == 0)) {
smartSend = false;
}
// Write the message to the temporary file
FileOutputStream fileOutputStream = new FileOutputStream(tmpFile);
Rfc822Output.writeTo(mContext, msgId, fileOutputStream, [color=red]smartSend[/color], true);