EWS: update createMessage bcc handling to match sendMessage

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1169 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-07-12 06:42:09 +00:00
parent 7a2c4d1998
commit 0d060ca1f0
2 changed files with 7 additions and 16 deletions

View File

@ -165,13 +165,15 @@ public class EwsExchangeSession extends ExchangeSession {
public void createMessage(String folderPath, String messageName, HashMap<String, String> properties, String messageBody) throws IOException {
EWSMethod.Item item = new EWSMethod.Item();
item.type = "Message";
item.mimeContent = Base64.encodeBase64(messageBody.getBytes());
String bcc = properties.get("bcc");
// Exchange 2007 is unable to handle bcc field on create
//noinspection VariableNotUsedInsideIf
if (bcc != null) {
properties.remove("bcc");
// put bcc header back into mime body, Exchange will handle it on send
item.mimeContent = Base64.encodeBase64(("bcc: "+bcc+ "\r\n" +messageBody).getBytes());
} else {
item.mimeContent = Base64.encodeBase64(messageBody.getBytes());
}
Set<FieldUpdate> fieldUpdates = buildProperties(properties);
if (!properties.containsKey("draft")) {
// need to force draft flag to false
@ -184,18 +186,6 @@ public class EwsExchangeSession extends ExchangeSession {
item.setFieldUpdates(fieldUpdates);
CreateItemMethod createItemMethod = new CreateItemMethod(MessageDisposition.SaveOnly, getFolderId(folderPath), item);
executeMethod(createItemMethod);
if (bcc != null) {
ItemId itemId = new ItemId(createItemMethod.getResponseItem());
HashMap<String, String> localProperties = new HashMap<String, String>();
localProperties.put("bcc", bcc);
UpdateItemMethod updateItemMethod = new UpdateItemMethod(MessageDisposition.SaveOnly,
ConflictResolution.AlwaysOverwrite,
SendMeetingInvitationsOrCancellations.SendToNone,
itemId, buildProperties(localProperties));
executeMethod(updateItemMethod);
}
}
@Override

View File

@ -128,7 +128,8 @@ public class TestImap extends AbstractDavMailTestCase {
public void testCreateMessage() throws IOException, MessagingException {
MimeMessage mimeMessage = new MimeMessage((Session) null);
mimeMessage.addHeader("To", "test@test.local");
mimeMessage.addHeader("to", Settings.getProperty("davmail.to"));
mimeMessage.addHeader("bcc", Settings.getProperty("davmail.bcc"));
mimeMessage.setText("Test message");
mimeMessage.setSubject("Test subject");
ByteArrayOutputStream baos = new ByteArrayOutputStream();