Support bcc in Exchange (Fixes #2117849)

* Must send the bcc header for EAS

Change-Id: I38d119beed334c6bb23a09b87375804f8c03ea76
This commit is contained in:
Marc Blank 2009-09-15 14:03:14 -07:00
parent ffc681a4da
commit 2d5691cac1
4 changed files with 23 additions and 16 deletions

View File

@ -110,7 +110,7 @@ public class Rfc822Output {
* TODO alternative parts (e.g. text+html) are not supported here.
*/
public static void writeTo(Context context, long messageId, OutputStream out,
boolean appendQuotedText) throws IOException, MessagingException {
boolean appendQuotedText, boolean sendBcc) throws IOException, MessagingException {
Message message = Message.restoreMessageWithId(context, messageId);
if (message == null) {
// throw something?
@ -130,10 +130,14 @@ public class Rfc822Output {
writeHeader(writer, "Message-ID", message.mMessageId);
// Address fields. Note, obviously, we skip bcc here
writeAddressHeader(writer, "From", message.mFrom);
writeAddressHeader(writer, "To", message.mTo);
writeAddressHeader(writer, "Cc", message.mCc);
// Address fields. Note that we skip bcc unless the sendBcc argument is true
// SMTP should NOT send bcc headers, but EAS must send it!
if (sendBcc) {
writeAddressHeader(writer, "Bcc", message.mBcc);
}
writeAddressHeader(writer, "Reply-To", message.mReplyTo);
// Analyze message and determine if we have multiparts

View File

@ -41,7 +41,7 @@ import javax.net.ssl.SSLException;
* This class handles all of the protocol-level aspects of sending messages via SMTP.
*/
public class SmtpSender extends Sender {
public static final int CONNECTION_SECURITY_NONE = 0;
public static final int CONNECTION_SECURITY_TLS_OPTIONAL = 1;
public static final int CONNECTION_SECURITY_TLS_REQUIRED = 2;
@ -160,7 +160,7 @@ public class SmtpSender extends Sender {
* Exim.
*/
result = executeSimpleCommand("EHLO " + localHost);
} else if (mTransport.getSecurity() ==
} else if (mTransport.getSecurity() ==
Transport.CONNECTION_SECURITY_TLS_REQUIRED) {
if (Config.LOGD && Email.DEBUG) {
Log.d(Email.LOG_TAG, "TLS not supported but required");
@ -232,7 +232,7 @@ public class SmtpSender extends Sender {
executeSimpleCommand("DATA");
// TODO byte stuffing
Rfc822Output.writeTo(mContext, messageId,
new EOLConvertingOutputStream(mTransport.getOutputStream()), true);
new EOLConvertingOutputStream(mTransport.getOutputStream()), true, false);
executeSimpleCommand("\r\n.");
} catch (IOException ioe) {
throw new MessagingException("Unable to send message", ioe);
@ -240,8 +240,8 @@ public class SmtpSender extends Sender {
}
/**
* Close the protocol (and the transport below it).
*
* Close the protocol (and the transport below it).
*
* MUST NOT return any exceptions.
*/
@Override
@ -253,24 +253,24 @@ public class SmtpSender extends Sender {
* Send a single command and wait for a single response. Handles responses that continue
* onto multiple lines. Throws MessagingException if response code is 4xx or 5xx. All traffic
* is logged (if debug logging is enabled) so do not use this function for user ID or password.
*
*
* @param command The command string to send to the server.
* @return Returns the response string from the server.
*/
private String executeSimpleCommand(String command) throws IOException, MessagingException {
return executeSensitiveCommand(command, null);
}
/**
* Send a single command and wait for a single response. Handles responses that continue
* onto multiple lines. Throws MessagingException if response code is 4xx or 5xx.
*
*
* @param command The command string to send to the server.
* @param sensitiveReplacement If the command includes sensitive data (e.g. authentication)
* please pass a replacement string here (for logging).
* @return Returns the response string from the server.
*/
private String executeSensitiveCommand(String command, String sensitiveReplacement)
private String executeSensitiveCommand(String command, String sensitiveReplacement)
throws IOException, MessagingException {
if (command != null) {
mTransport.writeLine(command, sensitiveReplacement);
@ -317,9 +317,9 @@ public class SmtpSender extends Sender {
AuthenticationFailedException, IOException {
try {
executeSimpleCommand("AUTH LOGIN");
executeSensitiveCommand(new String(Base64.encodeBase64(username.getBytes())),
executeSensitiveCommand(new String(Base64.encodeBase64(username.getBytes())),
"/username redacted/");
executeSensitiveCommand(new String(Base64.encodeBase64(password.getBytes())),
executeSensitiveCommand(new String(Base64.encodeBase64(password.getBytes())),
"/password redacted/");
}
catch (MessagingException me) {

View File

@ -114,7 +114,7 @@ public class EasOutboxService extends EasSyncService {
// Write the message in rfc822 format to the temporary file
FileOutputStream fileStream = new FileOutputStream(tmpFile);
Rfc822Output.writeTo(mContext, msgId, fileStream, !smartSend);
Rfc822Output.writeTo(mContext, msgId, fileStream, !smartSend, true);
fileStream.close();
// Now, get an input stream to our temporary file and create an entity with it
@ -126,7 +126,7 @@ public class EasOutboxService extends EasSyncService {
String cmd = "SendMail&SaveInSent=T";
if (smartSend) {
cmd = reply ? "SmartReply" : "SmartForward";
cmd += "&ItemId=" + URLEncoder.encode(itemId, "UTF-8") + "&CollectionId="
cmd += "&ItemId=" + URLEncoder.encode(itemId, "UTF-8") + "&CollectionId="
+ URLEncoder.encode(collectionId, "UTF-8") + "&SaveInSent=T";
}
HttpResponse resp = sendHttpClientPost(cmd, inputEntity);

View File

@ -41,9 +41,12 @@ public class Rfc822OutputTests extends AndroidTestCase {
// TODO Create more tests here. Specifically, we should test to make sure that forward works
// properly instead of just reply
// TODO Write test that ensures that bcc is handled properly (i.e. sent/not send depending
// on the flag passed to writeTo
// TODO Localize the following test, which will not work properly in other than English
// speaking locales!
/**
* Test for buildBodyText().
* Compare with expected values.