Author: tallison
Date: Wed Mar  1 15:47:47 2017
New Revision: 1784978

URL: http://svn.apache.org/viewvc?rev=1784978&view=rev
Log:
Bug 60795 -- add enum for message class in MAPIMessage; deprecate 
getMessageClass()

Added:
    poi/trunk/test-data/hsmf/msgClassAppointment.msg   (with props)
    poi/trunk/test-data/hsmf/msgClassContact.msg   (with props)
    poi/trunk/test-data/hsmf/msgClassPost.msg   (with props)
    poi/trunk/test-data/hsmf/msgClassStickyNote.msg   (with props)
    poi/trunk/test-data/hsmf/msgClassTask.msg   (with props)
Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java
    
poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestSimpleFileRead.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java?rev=1784978&r1=1784977&r2=1784978&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java Wed Mar  
1 15:47:47 2017
@@ -49,7 +49,6 @@ import org.apache.poi.hsmf.exceptions.Ch
 import org.apache.poi.hsmf.parsers.POIFSChunkParser;
 import org.apache.poi.poifs.filesystem.DirectoryNode;
 import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.util.CodePageUtil;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
@@ -63,6 +62,21 @@ import org.apache.poi.util.POILogger;
  * [MS-OXCMSG]: Message and Attachment Object Protocol Specification
  */
 public class MAPIMessage extends POIReadOnlyDocument {
+
+   /**
+    * A MAPI file can be an email (NOTE) or a number of other types
+    */
+   public enum MESSAGE_CLASS {
+      APPOINTMENT,
+      CONTACT,
+      NOTE,
+      POST,
+      STICKY_NOTE,
+      TASK,
+      UNKNOWN,
+      UNSPECIFIED
+   }
+
    /** For logging problems we spot with the file */
    private POILogger logger = POILogFactory.getLogger(MAPIMessage.class);
    
@@ -528,12 +542,43 @@ public class MAPIMessage extends POIRead
     * For emails the class will be IPM.Note
     *
     * @throws ChunkNotFoundException
+    * @deprecated use {@link #getMessageClassEnum()}
     */
    public String getMessageClass() throws ChunkNotFoundException {
       return getStringFromChunk(mainChunks.getMessageClass());
    }
 
    /**
+    * Gets the message class of the parsed Outlook Message.
+    * (Yes, you can use this to determine if a message is a calendar
+    *  item, note, or actual outlook Message)
+    * For emails the class will be IPM.Note
+    *
+    * @throws ChunkNotFoundException
+    */
+   public MESSAGE_CLASS getMessageClassEnum() throws ChunkNotFoundException {
+      String mc = getMessageClass();
+      if (mc == null || mc.trim().length() == 0) {
+         return MESSAGE_CLASS.UNSPECIFIED;
+      } else if (mc.equalsIgnoreCase("IPM.Note")) {
+         return MESSAGE_CLASS.NOTE;
+      } else if (mc.equalsIgnoreCase("IPM.Contact")) {
+         return MESSAGE_CLASS.CONTACT;
+      } else if (mc.equalsIgnoreCase("IPM.Appointment")) {
+         return MESSAGE_CLASS.APPOINTMENT;
+      } else if (mc.equalsIgnoreCase("IPM.StickyNote")) {
+         return MESSAGE_CLASS.STICKY_NOTE;
+      } else if (mc.equalsIgnoreCase("IPM.Task")) {
+         return MESSAGE_CLASS.TASK;
+      } else if (mc.equalsIgnoreCase("IPM.Post")) {
+         return MESSAGE_CLASS.POST;
+      } else {
+         logger.log(POILogger.WARN, "I don't recognize message class '"+mc+"'. 
" +
+                 "Please open an issue on POI's bugzilla");
+         return MESSAGE_CLASS.UNKNOWN;
+      }
+   }
+   /**
     * Gets the date that the message was accepted by the
     *  server on.
     */

Modified: 
poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestSimpleFileRead.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestSimpleFileRead.java?rev=1784978&r1=1784977&r2=1784978&view=diff
==============================================================================
--- 
poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestSimpleFileRead.java 
(original)
+++ 
poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestSimpleFileRead.java 
Wed Mar  1 15:47:47 2017
@@ -19,11 +19,10 @@ package org.apache.poi.hsmf;
 
 import java.io.IOException;
 
-import org.apache.poi.hsmf.MAPIMessage;
-import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
-import org.apache.poi.POIDataSamples;
-
 import junit.framework.TestCase;
+import org.apache.poi.POIDataSamples;
+import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
+import org.junit.Test;
 
 /**
  * Tests to verify that we can read a simple msg file, that is in plain/text
@@ -134,4 +133,25 @@ public final class TestSimpleFileRead ex
         String obtained = mapiMessage.getMessageClass();
         TestCase.assertEquals("IPM.Note", obtained);
     }
+
+    /**
+     * Check the various message classes
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testReadMessageClass2() throws Exception {
+        TestCase.assertEquals(
+                MAPIMessage.MESSAGE_CLASS.NOTE, 
mapiMessage.getMessageClassEnum());
+
+        for (String messageClass : new String[]{
+                "Appointment", "Contact", "Post", "StickyNote", "Task"
+        }) {
+            MAPIMessage.MESSAGE_CLASS mc = new MAPIMessage(
+                    
POIDataSamples.getHSMFInstance().getFile("msgClass"+messageClass+".msg")
+            ).getMessageClassEnum();
+            assertTrue( mc + " but expected " + messageClass,
+                    
messageClass.equalsIgnoreCase(mc.toString().replaceAll("_", "")));
+        }
+    }
 }

Added: poi/trunk/test-data/hsmf/msgClassAppointment.msg
URL: 
http://svn.apache.org/viewvc/poi/trunk/test-data/hsmf/msgClassAppointment.msg?rev=1784978&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/hsmf/msgClassAppointment.msg
------------------------------------------------------------------------------
    svn:mime-type = application/vnd.ms-outlook

Added: poi/trunk/test-data/hsmf/msgClassContact.msg
URL: 
http://svn.apache.org/viewvc/poi/trunk/test-data/hsmf/msgClassContact.msg?rev=1784978&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/hsmf/msgClassContact.msg
------------------------------------------------------------------------------
    svn:mime-type = application/vnd.ms-outlook

Added: poi/trunk/test-data/hsmf/msgClassPost.msg
URL: 
http://svn.apache.org/viewvc/poi/trunk/test-data/hsmf/msgClassPost.msg?rev=1784978&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/hsmf/msgClassPost.msg
------------------------------------------------------------------------------
    svn:mime-type = application/vnd.ms-outlook

Added: poi/trunk/test-data/hsmf/msgClassStickyNote.msg
URL: 
http://svn.apache.org/viewvc/poi/trunk/test-data/hsmf/msgClassStickyNote.msg?rev=1784978&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/hsmf/msgClassStickyNote.msg
------------------------------------------------------------------------------
    svn:mime-type = application/vnd.ms-outlook

Added: poi/trunk/test-data/hsmf/msgClassTask.msg
URL: 
http://svn.apache.org/viewvc/poi/trunk/test-data/hsmf/msgClassTask.msg?rev=1784978&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/hsmf/msgClassTask.msg
------------------------------------------------------------------------------
    svn:mime-type = application/vnd.ms-outlook



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to