mirror of
https://github.com/moparisthebest/davmail
synced 2025-01-07 11:48:02 -05:00
EWS: implement bcc support in sendMessage
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1168 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
d9ecb65c0d
commit
7a2c4d1998
@ -149,8 +149,6 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
if ("104".equals(entry.getValue())) {
|
if ("104".equals(entry.getValue())) {
|
||||||
list.add(Field.createFieldUpdate("iconIndex", "262"));
|
list.add(Field.createFieldUpdate("iconIndex", "262"));
|
||||||
}
|
}
|
||||||
} else if ("bcc".equals(entry.getKey())) {
|
|
||||||
list.add(Field.createFieldUpdate("bcc", entry.getValue()));
|
|
||||||
} else if ("draft".equals(entry.getKey())) {
|
} else if ("draft".equals(entry.getKey())) {
|
||||||
// note: draft is readonly after create
|
// note: draft is readonly after create
|
||||||
list.add(Field.createFieldUpdate("messageFlags", entry.getValue()));
|
list.add(Field.createFieldUpdate("messageFlags", entry.getValue()));
|
||||||
@ -219,11 +217,18 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
public void sendMessage(HashMap<String, String> properties, String messageBody) throws IOException {
|
public void sendMessage(HashMap<String, String> properties, String messageBody) throws IOException {
|
||||||
EWSMethod.Item item = new EWSMethod.Item();
|
EWSMethod.Item item = new EWSMethod.Item();
|
||||||
item.type = "Message";
|
item.type = "Message";
|
||||||
item.mimeContent = Base64.encodeBase64(messageBody.getBytes());
|
String bcc = properties.get("bcc");
|
||||||
// TODO: handle bcc
|
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);
|
Set<FieldUpdate> fieldUpdates = buildProperties(properties);
|
||||||
item.setFieldUpdates(fieldUpdates);
|
item.setFieldUpdates(fieldUpdates);
|
||||||
CreateItemMethod createItemMethod = new CreateItemMethod(MessageDisposition.SendAndSaveCopy, getFolderId("Drafts"), item);
|
CreateItemMethod createItemMethod = new CreateItemMethod(MessageDisposition.SendAndSaveCopy, getFolderId(SENT), item);
|
||||||
executeMethod(createItemMethod);
|
executeMethod(createItemMethod);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -539,7 +544,7 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
if (baseFolderPath.startsWith("/users/")) {
|
if (baseFolderPath.startsWith("/users/")) {
|
||||||
int index = baseFolderPath.indexOf('/', "/users/".length());
|
int index = baseFolderPath.indexOf('/', "/users/".length());
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
baseFolderPath = baseFolderPath.substring(index+1);
|
baseFolderPath = baseFolderPath.substring(index + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<ExchangeSession.Folder> folders = new ArrayList<ExchangeSession.Folder>();
|
List<ExchangeSession.Folder> folders = new ArrayList<ExchangeSession.Folder>();
|
||||||
|
@ -88,8 +88,7 @@ public class TestSmtp extends AbstractDavMailTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testCreateMessage() throws IOException, MessagingException {
|
public void testSendMessage() throws IOException, MessagingException {
|
||||||
|
|
||||||
MimeMessage mimeMessage = new MimeMessage((Session) null);
|
MimeMessage mimeMessage = new MimeMessage((Session) null);
|
||||||
mimeMessage.addHeader("To", Settings.getProperty("davmail.to"));
|
mimeMessage.addHeader("To", Settings.getProperty("davmail.to"));
|
||||||
mimeMessage.setText("Test message");
|
mimeMessage.setText("Test message");
|
||||||
@ -108,6 +107,27 @@ public class TestSmtp extends AbstractDavMailTestCase {
|
|||||||
assertEquals("250 Queued mail for delivery", readLine());
|
assertEquals("250 Queued mail for delivery", readLine());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBccMessage() throws IOException, MessagingException {
|
||||||
|
MimeMessage mimeMessage = new MimeMessage((Session) null);
|
||||||
|
mimeMessage.addHeader("to", Settings.getProperty("davmail.to"));
|
||||||
|
mimeMessage.setText("Test message");
|
||||||
|
mimeMessage.setSubject("Test subject");
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
mimeMessage.writeTo(baos);
|
||||||
|
byte[] content = baos.toByteArray();
|
||||||
|
writeLine("MAIL FROM:"+session.getEmail());
|
||||||
|
readLine();
|
||||||
|
writeLine("RCPT TO:"+Settings.getProperty("davmail.to"));
|
||||||
|
readLine();
|
||||||
|
writeLine("RCPT TO:"+Settings.getProperty("davmail.bcc"));
|
||||||
|
readLine();
|
||||||
|
writeLine("DATA");
|
||||||
|
assertEquals("354 Start mail input; end with <CRLF>.<CRLF>", readLine());
|
||||||
|
writeLine(new String(content));
|
||||||
|
writeLine(".");
|
||||||
|
assertEquals("250 Queued mail for delivery", readLine());
|
||||||
|
}
|
||||||
|
|
||||||
public void testQuit() throws IOException {
|
public void testQuit() throws IOException {
|
||||||
writeLine("QUIT");
|
writeLine("QUIT");
|
||||||
assertEquals("221 Closing connection", readLine());
|
assertEquals("221 Closing connection", readLine());
|
||||||
|
Loading…
Reference in New Issue
Block a user