EWS: handle bcc field
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1128 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
72dff67421
commit
e2fa43e9e1
|
@ -161,6 +161,11 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||
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
|
||||
if (bcc != null) {
|
||||
properties.remove("bcc");
|
||||
}
|
||||
Set<FieldUpdate> fieldUpdates = buildProperties(properties);
|
||||
if (!properties.containsKey("draft")) {
|
||||
// need to force draft flag to false
|
||||
|
@ -173,7 +178,15 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||
item.setFieldUpdates(fieldUpdates);
|
||||
CreateItemMethod createItemMethod = new CreateItemMethod(MessageDisposition.SaveOnly, getFolderId(folderPath), item);
|
||||
executeMethod(createItemMethod);
|
||||
// TODO: do we need to update message after to force some properties ?
|
||||
|
||||
if (bcc != null) {
|
||||
ItemId itemId = new ItemId(createItemMethod.getResponseItem().get("ItemId"), createItemMethod.getResponseItem().get("ChangeKey"));
|
||||
properties.put("bcc", bcc);
|
||||
properties.remove("draft");
|
||||
UpdateItemMethod updateItemMethod = new UpdateItemMethod(MessageDisposition.SaveOnly, ConflictResolution.AlwaysOverwrite, itemId, buildProperties(properties));
|
||||
executeMethod(updateItemMethod);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -57,6 +57,7 @@ public class ExtendedFieldURI implements FieldURI {
|
|||
public ExtendedFieldURI(DistinguishedPropertySetType distinguishedPropertySetId, String propertyName) {
|
||||
this.distinguishedPropertySetId = distinguishedPropertySetId;
|
||||
this.propertyName = propertyName;
|
||||
this.propertyType = PropertyType.String;
|
||||
}
|
||||
|
||||
public String getPropertyTag() {
|
||||
|
@ -75,14 +76,15 @@ public class ExtendedFieldURI implements FieldURI {
|
|||
buffer.append("PropertySetId=\"").append(propertySetId).append("\" ");
|
||||
}
|
||||
if (propertyName != null) {
|
||||
buffer.append("propertyName=\"").append(propertyName).append("\" ");
|
||||
buffer.append("PropertyName=\"").append(propertyName).append("\" ");
|
||||
}
|
||||
if (propertyId != 0) {
|
||||
buffer.append("PropertyId=\"").append(String.valueOf(propertyId)).append("\" ");
|
||||
}
|
||||
if (propertyType != null) {
|
||||
buffer.append("PropertyType=\"").append(propertyType.toString()).append("\"/>");
|
||||
buffer.append("PropertyType=\"").append(propertyType.toString()).append("\" ");
|
||||
}
|
||||
buffer.append("/>");
|
||||
}
|
||||
|
||||
public void appendValue(StringBuilder buffer, String itemType, String value) {
|
||||
|
|
|
@ -23,6 +23,10 @@ import davmail.Settings;
|
|||
import davmail.exchange.dav.DavExchangeSession;
|
||||
import davmail.exchange.ews.EwsExchangeSession;
|
||||
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
|
@ -31,7 +35,6 @@ import java.io.IOException;
|
|||
* except if url is not null
|
||||
*/
|
||||
public class AbstractExchangeSessionTestCase extends AbstractDavMailTestCase {
|
||||
protected static ExchangeSession session;
|
||||
|
||||
@Override
|
||||
public void setUp() throws IOException {
|
||||
|
@ -48,5 +51,19 @@ public class AbstractExchangeSessionTestCase extends AbstractDavMailTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
protected MimeMessage createMimeMessage() throws MessagingException {
|
||||
MimeMessage mimeMessage = new MimeMessage((Session) null);
|
||||
mimeMessage.addHeader("To", "test@test.local");
|
||||
mimeMessage.setText("Test message");
|
||||
mimeMessage.setSubject("Test subject");
|
||||
return mimeMessage;
|
||||
}
|
||||
|
||||
protected String getMimeBody(MimeMessage mimeMessage) throws IOException, MessagingException {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
mimeMessage.writeTo(baos);
|
||||
byte[] content = baos.toByteArray();
|
||||
return new String(content);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
|
||||
* Copyright (C) 2010 Mickael Guessant
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
package davmail.exchange;
|
||||
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import javax.mail.util.SharedByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Test message handling features.
|
||||
*/
|
||||
public class TestExchangeSessionMessage extends AbstractExchangeSessionTestCase {
|
||||
static ExchangeSession.Message message;
|
||||
|
||||
public void testCreateMessage() throws IOException, MessagingException {
|
||||
session.deleteFolder("testfolder");
|
||||
session.createMessageFolder("testfolder");
|
||||
MimeMessage mimeMessage = createMimeMessage();
|
||||
String messageName = UUID.randomUUID().toString();
|
||||
HashMap<String, String> properties = new HashMap<String, String>();
|
||||
session.createMessage("testfolder", messageName, properties, getMimeBody(mimeMessage));
|
||||
}
|
||||
|
||||
public void testSearchMessage() throws IOException, MessagingException {
|
||||
ExchangeSession.MessageList messageList = session.searchMessages("testfolder");
|
||||
assertNotNull(messageList);
|
||||
assertEquals(1, messageList.size());
|
||||
message = messageList.get(0);
|
||||
assertFalse(message.answered);
|
||||
assertFalse(message.forwarded);
|
||||
assertFalse(message.flagged);
|
||||
assertFalse(message.draft);
|
||||
assertTrue(message.size > 0);
|
||||
assertFalse(message.deleted);
|
||||
// TODO
|
||||
assertFalse(message.read);
|
||||
assertNotNull(message.date);
|
||||
}
|
||||
|
||||
public void testGetContent() throws IOException, MessagingException {
|
||||
byte[] content = session.getContent(message);
|
||||
assertNotNull(content);
|
||||
MimeMessage mimeMessage = new MimeMessage(null, new SharedByteArrayInputStream(content));
|
||||
assertTrue(mimeMessage.getHeader("To")[0].indexOf("test@test.local") >= 0);
|
||||
assertEquals("Test subject", mimeMessage.getSubject());
|
||||
assertEquals("Test message", mimeMessage.getContent());
|
||||
}
|
||||
|
||||
public void testDeleteMessage() throws IOException {
|
||||
session.deleteMessage(message);
|
||||
ExchangeSession.MessageList messageList = session.searchMessages("testfolder");
|
||||
assertNotNull(messageList);
|
||||
assertEquals(0, messageList.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanup
|
||||
*/
|
||||
public void testDeleteFolder() throws IOException {
|
||||
session.deleteFolder("testfolder");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
|
||||
* Copyright (C) 2010 Mickael Guessant
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
package davmail.exchange;
|
||||
|
||||
import davmail.Settings;
|
||||
import org.apache.log4j.Level;
|
||||
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: mguessan
|
||||
* Date: 5 juil. 2010
|
||||
* Time: 16:17:45
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class TestExchangeSessionMessageFlags extends AbstractExchangeSessionTestCase {
|
||||
|
||||
@Override
|
||||
public void setUp() throws IOException {
|
||||
super.setUp();
|
||||
// recreate empty folder
|
||||
session.deleteFolder("testfolder");
|
||||
session.createMessageFolder("testfolder");
|
||||
}
|
||||
|
||||
public void testCreateDraftMessage() throws MessagingException, IOException {
|
||||
MimeMessage mimeMessage = createMimeMessage();
|
||||
String messageName = UUID.randomUUID().toString();
|
||||
HashMap<String, String> properties = new HashMap<String, String>();
|
||||
properties.put("draft", "9");
|
||||
session.createMessage("testfolder", messageName, properties, getMimeBody(mimeMessage));
|
||||
ExchangeSession.MessageList messageList = session.searchMessages("testfolder");
|
||||
assertNotNull(messageList);
|
||||
assertEquals(1, messageList.size());
|
||||
assertTrue(messageList.get(0).draft);
|
||||
}
|
||||
|
||||
public void testCreateDraftReadMessage() throws MessagingException, IOException {
|
||||
MimeMessage mimeMessage = createMimeMessage();
|
||||
String messageName = UUID.randomUUID().toString();
|
||||
HashMap<String, String> properties = new HashMap<String, String>();
|
||||
properties.put("draft", "9");
|
||||
properties.put("read", "1");
|
||||
session.createMessage("testfolder", messageName, properties, getMimeBody(mimeMessage));
|
||||
ExchangeSession.MessageList messageList = session.searchMessages("testfolder");
|
||||
assertNotNull(messageList);
|
||||
assertEquals(1, messageList.size());
|
||||
assertTrue(messageList.get(0).draft);
|
||||
assertTrue(messageList.get(0).read);
|
||||
}
|
||||
|
||||
public void testCreateReadMessage() throws MessagingException, IOException {
|
||||
MimeMessage mimeMessage = createMimeMessage();
|
||||
String messageName = UUID.randomUUID().toString();
|
||||
HashMap<String, String> properties = new HashMap<String, String>();
|
||||
properties.put("read", "1");
|
||||
session.createMessage("testfolder", messageName, properties, getMimeBody(mimeMessage));
|
||||
ExchangeSession.MessageList messageList = session.searchMessages("testfolder");
|
||||
assertNotNull(messageList);
|
||||
assertEquals(1, messageList.size());
|
||||
assertFalse(messageList.get(0).draft);
|
||||
assertTrue(messageList.get(0).read);
|
||||
}
|
||||
|
||||
public void testCreateBccMessage() throws MessagingException, IOException {
|
||||
Settings.setLoggingLevel("httpclient.wire", Level.DEBUG);
|
||||
MimeMessage mimeMessage = createMimeMessage();
|
||||
String messageName = UUID.randomUUID().toString();
|
||||
HashMap<String, String> properties = new HashMap<String, String>();
|
||||
properties.put("draft", "8");
|
||||
properties.put("bcc", "testbcc@test.local");
|
||||
session.createMessage("testfolder", messageName, properties, getMimeBody(mimeMessage));
|
||||
ExchangeSession.MessageList messageList = session.searchMessages("testfolder");
|
||||
assertNotNull(messageList);
|
||||
assertEquals(1, messageList.size());
|
||||
}
|
||||
|
||||
}
|
|
@ -21,6 +21,7 @@ package davmail.imap;
|
|||
import davmail.AbstractDavMailTestCase;
|
||||
import davmail.DavGateway;
|
||||
import davmail.Settings;
|
||||
import org.apache.log4j.Level;
|
||||
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Session;
|
||||
|
@ -126,6 +127,7 @@ public class TestImap extends AbstractDavMailTestCase {
|
|||
}
|
||||
|
||||
public void testCreateMessage() throws IOException, MessagingException {
|
||||
|
||||
MimeMessage mimeMessage = new MimeMessage((Session) null);
|
||||
mimeMessage.addHeader("To", "test@test.local");
|
||||
mimeMessage.setText("Test message");
|
||||
|
@ -133,7 +135,7 @@ public class TestImap extends AbstractDavMailTestCase {
|
|||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
mimeMessage.writeTo(baos);
|
||||
byte[] content = baos.toByteArray();
|
||||
writeLine(". APPEND testfolder (\\Draft) {" + content.length + "}");
|
||||
writeLine(". APPEND testfolder (\\Draft) {" + content.length + '}');
|
||||
assertEquals("+ send literal data", readLine());
|
||||
writeLine(new String(content));
|
||||
assertEquals(". OK APPEND completed", readFullAnswer("."));
|
||||
|
|
Loading…
Reference in New Issue