OSDN Git Service

Fixed #12279 otsuka さんによって修正済みと思われる。念のため null のチェックとテストケースを追加。
authorIwao AVE! <harawata@gmail.com>
Tue, 22 Nov 2011 17:01:17 +0000 (02:01 +0900)
committerIwao AVE! <harawata@gmail.com>
Tue, 22 Nov 2011 17:01:17 +0000 (02:01 +0900)
src/main/java/com/ozacc/mail/fetch/ReceivedMail.java
src/test/java/com/ozacc/mail/fetch/impl/FetchMailImplTest.java [new file with mode: 0644]

index 1a6d4be..3d760cd 100644 (file)
@@ -130,7 +130,7 @@ public class ReceivedMail extends Mail {
         * @return In-Reply-Toヘッダの値
         */
        public String getInReplyTo() {
-               return (String)headers.get("In-Reply-To");
+               return headers == null ? null : (String)headers.get("In-Reply-To");
        }
 
        /**
@@ -140,7 +140,7 @@ public class ReceivedMail extends Mail {
         * @return Referencesヘッダの値
         */
        public String getRefereces() {
-               return (String)headers.get("References");
+               return headers == null ? null : (String)headers.get("References");
        }
 
        /**
diff --git a/src/test/java/com/ozacc/mail/fetch/impl/FetchMailImplTest.java b/src/test/java/com/ozacc/mail/fetch/impl/FetchMailImplTest.java
new file mode 100644 (file)
index 0000000..3288be4
--- /dev/null
@@ -0,0 +1,58 @@
+
+package com.ozacc.mail.fetch.impl;
+
+import javax.mail.Message.RecipientType;
+import javax.mail.Session;
+import javax.mail.internet.MimeMessage;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.BasicConfigurator;
+import org.jvnet.mock_javamail.Mailbox;
+
+import com.ozacc.mail.Mail;
+import com.ozacc.mail.fetch.ReceivedMail;
+
+/**
+ * FetchMailImplクラスのテストケース。
+ * 
+ * @since 1.2.3
+ * @author Iwao AVE!
+ */
+public class FetchMailImplTest extends TestCase
+{
+       protected void setUp() throws Exception
+       {
+               super.setUp();
+               BasicConfigurator.configure();
+       }
+
+       /**
+        * X-ヘッダーがない場合のテスト (#12279)
+        */
+       public void testNoXHeader() throws Exception
+       {
+               Session session = Session.getInstance(System.getProperties());
+               MimeMessage msg = new MimeMessage(session);
+               msg.setRecipients(RecipientType.TO, "info@example.com");
+               msg.setSubject("Test subject");
+               msg.setText("Test body");
+               msg.setHeader("Message-ID", "MSGID-123");
+               Mailbox inbox = Mailbox.get("info@example.com");
+               inbox.add(msg);
+
+               FetchMailImpl fetchMail = new FetchMailImpl();
+               fetchMail.setHost("example.com");
+               fetchMail.setUsername("info");
+               ReceivedMail[] mails = fetchMail.getMails();
+               assertEquals(1, mails.length);
+               Mail reply = (ReceivedMail)mails[0].reply();
+               assertEquals("Test subject", reply.getSubject());
+       }
+
+       protected void tearDown() throws Exception {
+               super.tearDown();
+               BasicConfigurator.resetConfiguration();
+               Mailbox.clearAll();
+       }
+}