From a72a43741a4dbfb6c3b4b4fa8aca141bb427e22d Mon Sep 17 00:00:00 2001 From: mguessan Date: Wed, 8 Sep 2010 21:13:38 +0000 Subject: [PATCH] SMTP: try to force IMS encoding mode according to message contenttype git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1430 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- .../exchange/dav/DavExchangeSession.java | 25 ++++++++++++++----- src/test/davmail/smtp/TestSmtp.java | 18 +++++++++++++ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/java/davmail/exchange/dav/DavExchangeSession.java b/src/java/davmail/exchange/dav/DavExchangeSession.java index bf857909..6aea037f 100644 --- a/src/java/davmail/exchange/dav/DavExchangeSession.java +++ b/src/java/davmail/exchange/dav/DavExchangeSession.java @@ -2079,6 +2079,9 @@ public class DavExchangeSession extends ExchangeSession { // note: draft is readonly after create, create the message first with requested messageFlags davProperties.add(Field.createDavProperty("messageFlags", properties.get("draft"))); } + if (properties != null && properties.containsKey("mailOverrideFormat")) { + davProperties.add(Field.createDavProperty("mailOverrideFormat", properties.get("mailOverrideFormat"))); + } if (!davProperties.isEmpty()) { patchMethod = new PropPatchMethod(messageUrl, davProperties); try { @@ -2195,12 +2198,22 @@ public class DavExchangeSession extends ExchangeSession { @Override public void sendMessage(MimeMessage mimeMessage) throws IOException { - // need to create draft first - String itemName = UUID.randomUUID().toString() + ".EML"; - HashMap properties = new HashMap(); - properties.put("draft", "9"); - createMessage(DRAFTS, itemName, properties, mimeMessage); - moveItem(DRAFTS + '/' + itemName, SENDMSG); + try { + // need to create draft first + String itemName = UUID.randomUUID().toString() + ".EML"; + HashMap properties = new HashMap(); + properties.put("draft", "9"); + String contentType = mimeMessage.getContentType(); + if (contentType != null && contentType.startsWith("text/plain")) { + properties.put("mailOverrideFormat", "2"); + } else { + properties.put("mailOverrideFormat", "1"); + } + createMessage(DRAFTS, itemName, properties, mimeMessage); + moveItem(DRAFTS + '/' + itemName, SENDMSG); + } catch (MessagingException e) { + throw new IOException(e.getMessage()); + } } protected boolean isGzipEncoded(HttpMethod method) { diff --git a/src/test/davmail/smtp/TestSmtp.java b/src/test/davmail/smtp/TestSmtp.java index c9b525dd..2d8b1678 100644 --- a/src/test/davmail/smtp/TestSmtp.java +++ b/src/test/davmail/smtp/TestSmtp.java @@ -215,6 +215,24 @@ public class TestSmtp extends AbstractDavMailTestCase { sendAndCheckMessage(mimeMessage); } + public void testSendPlainTextMessage() throws IOException, MessagingException, InterruptedException { + String body = "Test plain text message"; + MimeMessage mimeMessage = new MimeMessage((Session) null); + mimeMessage.addHeader("To", Settings.getProperty("davmail.to")); + mimeMessage.setSubject("Test text/plain message"); + mimeMessage.setText(body); + sendAndCheckMessage(mimeMessage); + } + + public void testSendHtmlMessage() throws IOException, MessagingException, InterruptedException { + String body = "Test html message red"; + MimeMessage mimeMessage = new MimeMessage((Session) null); + mimeMessage.addHeader("To", Settings.getProperty("davmail.to")); + mimeMessage.setSubject("Test html message"); + mimeMessage.setContent(body, "text/html"); + sendAndCheckMessage(mimeMessage); + } + public void testQuit() throws IOException { writeLine("QUIT"); assertEquals("221 Closing connection", readLine());