OSDN Git Service

fixes #32920 SendMailImpl#send() の引数に MimeMessage を渡すと NullPointerException が発生する不具合を修正。
authorIwao AVE! <harawata@gmail.com>
Wed, 22 Jan 2014 10:22:56 +0000 (19:22 +0900)
committerIwao AVE! <harawata@gmail.com>
Wed, 22 Jan 2014 10:22:56 +0000 (19:22 +0900)
src/main/java/com/ozacc/mail/impl/SendMailImpl.java
src/test/java/com/ozacc/mail/impl/SendMailImplTest.java

index 18184c5..a00e4e9 100644 (file)
@@ -475,7 +475,7 @@ public class SendMailImpl implements SendMail {
                }
 
                public boolean hasEnvelopeTo() {
-                       return envelopeTo.length > 0;
+                       return envelopeTo != null && envelopeTo.length > 0;
                }
 
                public InternetAddress[] getEnvelopeTo() {
index 28249fb..afd2e6c 100644 (file)
@@ -1,7 +1,12 @@
 package com.ozacc.mail.impl;
 
+import java.util.Properties;
+
 import javax.mail.Message;
+import javax.mail.Message.RecipientType;
+import javax.mail.Session;
 import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
 
 import junit.framework.TestCase;
 
@@ -237,4 +242,23 @@ public class SendMailImplTest extends TestCase {
                Message email = inbox.get(0);
                assertEquals("text/plain; charset=UTF-8", email.getContentType());
        }
+
+       public void testSendMimeMessage() throws Exception {
+               Session session = Session.getInstance(new Properties());
+               MimeMessage message = new MimeMessage(session);
+               message.setFrom(new InternetAddress("from@example.com"));
+               message.addRecipient(RecipientType.TO, new InternetAddress(
+                               "info@example.com"));
+               message.setSubject("subject");
+               message.setText("メッセージ", "utf-8");
+               message.setHeader("Content-Transfer-Encoding", "base64");
+               sendMail.send(message);
+
+               Mailbox inbox = Mailbox.get("info@example.com");
+               assertEquals("1", 1, inbox.size());
+
+               Message email = inbox.get(0);
+               assertEquals("text/plain; charset=utf-8", email.getContentType());
+               assertEquals("info@example.com", email.getRecipients(RecipientType.TO)[0].toString());
+       }
 }