mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 03:02:22 -05:00
SMTP: send message directly without creating a Draft message to preserve Message-id
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1245 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
af54daf497
commit
10db0a079a
@ -452,7 +452,7 @@ public class DavExchangeSession extends ExchangeSession {
|
||||
|
||||
@Override
|
||||
public void appendTo(StringBuilder buffer) {
|
||||
buffer.append('"').append(Field.getHeader(attributeName)).append('"');
|
||||
buffer.append('"').append(Field.getHeader(attributeName).getUri()).append('"');
|
||||
buffer.append(operatorMap.get(operator));
|
||||
buffer.append('\'');
|
||||
if (Operator.Like == operator) {
|
||||
@ -1488,7 +1488,7 @@ public class DavExchangeSession extends ExchangeSession {
|
||||
PropPatchMethod patchMethod;
|
||||
List<DavConstants> davProperties = buildProperties(properties);
|
||||
|
||||
if (properties.containsKey("draft")) {
|
||||
if (properties != null && properties.containsKey("draft")) {
|
||||
// note: draft is readonly after create, create the message first with requested messageFlags
|
||||
davProperties.add(Field.createDavProperty("messageFlags", properties.get("draft")));
|
||||
}
|
||||
@ -1509,6 +1509,8 @@ public class DavExchangeSession extends ExchangeSession {
|
||||
// update message body
|
||||
PutMethod putmethod = new PutMethod(messageUrl);
|
||||
putmethod.setRequestHeader("Translate", "f");
|
||||
putmethod.setRequestHeader("Content-Type", "message/rfc822");
|
||||
|
||||
try {
|
||||
// use same encoding as client socket reader
|
||||
putmethod.setRequestEntity(new ByteArrayRequestEntity(messageBody));
|
||||
@ -1560,14 +1562,7 @@ public class DavExchangeSession extends ExchangeSession {
|
||||
public void sendMessage(byte[] messageBody) throws IOException {
|
||||
String messageName = UUID.randomUUID().toString() + ".EML";
|
||||
|
||||
createMessage(DRAFTS, messageName, null, messageBody);
|
||||
|
||||
String tempUrl = draftsUrl + '/' + messageName + ".EML";
|
||||
MoveMethod method = new MoveMethod(URIUtil.encodePath(tempUrl), URIUtil.encodePath(sendmsgUrl), true);
|
||||
int status = DavGatewayHttpClientFacade.executeHttpMethod(httpClient, method);
|
||||
if (status != HttpStatus.SC_OK) {
|
||||
throw DavGatewayHttpClientFacade.buildHttpException(method);
|
||||
}
|
||||
createMessage(sendmsgUrl, messageName, null, messageBody);
|
||||
}
|
||||
|
||||
protected boolean isGzipEncoded(HttpMethod method) {
|
||||
|
@ -139,6 +139,9 @@ public class Field {
|
||||
createField(URN_SCHEMAS_MAILHEADER, "bcc");//PS_INTERNET_HEADERS/bcc
|
||||
createField(URN_SCHEMAS_HTTPMAIL, "datereceived");//PR_MESSAGE_DELIVERY_TIME, 0x0E06
|
||||
|
||||
// unused: force message encoding
|
||||
createField("messageFormat", 0x5909, PropertyType.Long);//PR_MSG_EDITOR_FORMAT EDITOR_FORMAT_PLAINTEXT = 1 EDITOR_FORMAT_HTML = 2
|
||||
createField("mailOverrideFormat", 0x5909, PropertyType.Long);//PR_INETMAIL_OVERRIDE_FORMAT ENCODING_PREFERENCE = 2 BODY_ENCODING_TEXT_AND_HTML = 1 ENCODING_MIME = 4
|
||||
|
||||
// IMAP search
|
||||
|
||||
|
@ -66,7 +66,7 @@ public class AbstractDavMailTestCase extends TestCase {
|
||||
// enable WIRE debug log
|
||||
//Settings.setLoggingLevel("httpclient.wire", Level.DEBUG);
|
||||
// enable EWS support
|
||||
Settings.setProperty("davmail.enableEws", "false");
|
||||
//Settings.setProperty("davmail.enableEws", "false");
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -112,14 +112,29 @@ public class TestSmtp extends AbstractDavMailTestCase {
|
||||
writeLine(".");
|
||||
assertEquals("250 Queued mail for delivery", readLine());
|
||||
// wait for asynchronous message send
|
||||
Thread.sleep(1000);
|
||||
ExchangeSession.MessageList messages = session.searchMessages("Sent", session.headerEquals("message-id", mimeMessage.getMessageID()));
|
||||
ExchangeSession.MessageList messages = null;
|
||||
for (int i=0;i<5;i++) {
|
||||
messages = session.searchMessages("Sent", session.headerEquals("message-id", mimeMessage.getMessageID()));
|
||||
if (messages.size() > 0) {
|
||||
break;
|
||||
}
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
assertEquals(1, messages.size());
|
||||
ExchangeSession.Message message = messages.get(0);
|
||||
message.getMimeMessage().writeTo(System.out);
|
||||
assertEquals(mimeMessage.getDataHandler().getContent(), (String) message.getMimeMessage().getDataHandler().getContent());
|
||||
}
|
||||
|
||||
public void testSendSimpleMessage() throws IOException, MessagingException, InterruptedException {
|
||||
String body = "Test message";
|
||||
MimeMessage mimeMessage = new MimeMessage((Session) null);
|
||||
mimeMessage.addHeader("To", Settings.getProperty("davmail.to"));
|
||||
mimeMessage.setSubject("Test subject");
|
||||
mimeMessage.setText(body);
|
||||
sendAndCheckMessage(mimeMessage);
|
||||
}
|
||||
|
||||
public void testSendMessage() throws IOException, MessagingException, InterruptedException {
|
||||
String body = "Test message\r\n" +
|
||||
"Special characters: éèçà\r\n" +
|
||||
|
Loading…
Reference in New Issue
Block a user