You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2019/12/26 06:12:56 UTC

svn commit: r1871986 - in /poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor: OutlookTextExtactor.java OutlookTextExtractor.java

Author: fanningpj
Date: Thu Dec 26 06:12:56 2019
New Revision: 1871986

URL: http://svn.apache.org/viewvc?rev=1871986&view=rev
Log:
fix spelling of OutlookTextExtractor class name

Added:
    poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtractor.java
      - copied, changed from r1871985, poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtactor.java
Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtactor.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtactor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtactor.java?rev=1871986&r1=1871985&r2=1871986&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtactor.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtactor.java Thu Dec 26 06:12:56 2019
@@ -16,174 +16,46 @@
 ==================================================================== */
 package org.apache.poi.hsmf.extractor;
 
-import static org.apache.poi.util.StringUtil.startsWithIgnoreCase;
+import org.apache.poi.hsmf.MAPIMessage;
+import org.apache.poi.poifs.filesystem.DirectoryNode;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.util.Removal;
 
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
-import java.text.SimpleDateFormat;
-import java.util.Locale;
-
-import org.apache.poi.extractor.POIOLE2TextExtractor;
-import org.apache.poi.hsmf.MAPIMessage;
-import org.apache.poi.hsmf.datatypes.AttachmentChunks;
-import org.apache.poi.hsmf.datatypes.StringChunk;
-import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
-import org.apache.poi.poifs.filesystem.DirectoryNode;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.apache.poi.util.LocaleUtil;
-import org.apache.poi.util.StringUtil.StringsIterator;
 
 /**
  * A text extractor for HSMF (Outlook) .msg files.
  * Outputs in a format somewhat like a plain text email.
+ *
+ * @deprecated use @{link OutlookTextExtractor} instead
  */
-public class OutlookTextExtactor extends POIOLE2TextExtractor {
-   public OutlookTextExtactor(MAPIMessage msg) {
-      super(msg);
-   }
-   public OutlookTextExtactor(DirectoryNode poifsDir) throws IOException {
-      this(new MAPIMessage(poifsDir));
-   }
-   public OutlookTextExtactor(POIFSFileSystem fs) throws IOException {
-      this(new MAPIMessage(fs));
-   }
-   public OutlookTextExtactor(InputStream inp) throws IOException {
-      this(new MAPIMessage(inp));
-   }
-   
-   public static void main(String[] args) throws Exception {
-      for(String filename : args) {
-         try (POIFSFileSystem poifs = new POIFSFileSystem(new File(filename));
-              OutlookTextExtactor extractor = new OutlookTextExtactor(poifs)) {
-            System.out.println(extractor.getText());
-         }
-      }
-   }
-
-   /**
-    * Returns the underlying MAPI message
-    */
-   public MAPIMessage getMAPIMessage() {
-      return (MAPIMessage)document;
-   }
-      
-   /**
-    * Outputs something a little like a RFC822 email
-    */
-   public String getText() {
-      MAPIMessage msg = (MAPIMessage)document;
-      StringBuilder s = new StringBuilder();
-      
-      // See if we can get a suitable encoding for any
-      //  non unicode text in the file
-      msg.guess7BitEncoding();
-      
-      // Off we go
-      StringsIterator emails;
-      try {
-         emails = new StringsIterator(
-               msg.getRecipientEmailAddressList()
-         );
-      } catch(ChunkNotFoundException e) {
-         emails = new StringsIterator(new String[0]);
-      }
-      
-      try {
-         s.append("From: " + msg.getDisplayFrom() + "\n");
-      } catch(ChunkNotFoundException e) {}
-      
-      // For To, CC and BCC, try to match the names
-      //  up with their email addresses. Relies on the
-      //  Recipient Chunks being in the same order as
-      //  people in To + CC + BCC.
-      try {
-         handleEmails(s, "To", msg.getDisplayTo(), emails);
-      } catch(ChunkNotFoundException e) {}
-      try {
-         handleEmails(s, "CC", msg.getDisplayCC(), emails);
-      } catch(ChunkNotFoundException e) {}
-      try {
-         handleEmails(s, "BCC", msg.getDisplayBCC(), emails);
-      } catch(ChunkNotFoundException e) {}
-      
-      // Date - try two ways to find it
-      try {
-         // First try via the proper chunk
-         SimpleDateFormat f = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss Z", Locale.ROOT);
-         f.setTimeZone(LocaleUtil.getUserTimeZone());
-         s.append("Date: ").append(f.format(msg.getMessageDate().getTime())).append("\n");
-      } catch(ChunkNotFoundException e) {
-         try {
-            // Failing that try via the raw headers 
-            String[] headers = msg.getHeaders();
-            for(String header: headers) {
-               if(startsWithIgnoreCase(header, "date:")) {
-                  s.append("Date:").append(header, header.indexOf(':')+1, header.length()).append("\n");
-                  break;
-               }
-            }
-         } catch(ChunkNotFoundException he) {
-            // We can't find the date, sorry...
-         }
-      }
-      
-      try {
-         s.append("Subject: ").append(msg.getSubject()).append("\n");
-      } catch(ChunkNotFoundException e) {}
-      
-      // Display attachment names
-      // To get the attachments, use ExtractorFactory
-      for(AttachmentChunks att : msg.getAttachmentFiles()) {
-         StringChunk name = att.getAttachLongFileName();
-         if (name == null) name = att.getAttachFileName();
-         String attName = name == null ? null : name.getValue();
-          
-         if(att.getAttachMimeTag() != null && 
-               att.getAttachMimeTag().getValue() != null) {
-             attName = att.getAttachMimeTag().getValue() + " = " + attName; 
-         }
-         s.append("Attachment: ").append(attName).append("\n");
-      }
-      
-      try {
-         s.append("\n").append(msg.getTextBody()).append("\n");
-      } catch(ChunkNotFoundException e) {}
-      
-      return s.toString();
-   }
-   
-   /**
-    * Takes a Display focused string, eg "Nick; Jim" and an iterator
-    *  of emails, and does its best to return something like
-    *  "Nick <ni...@example.com>; Jim <ji...@example.com>"
-    */
-   protected void handleEmails(StringBuilder s, String type, String displayText, StringsIterator emails) {
-      if(displayText == null || displayText.length() == 0) {
-         return;
-      }
-      
-      String[] names = displayText.split(";\\s*");
-      boolean first = true;
-      
-      s.append(type).append(": ");
-      for(String name : names) {
-         if(first) {
-            first = false;
-         } else {
-            s.append("; ");
-         }
-         
-         s.append(name);
-         if(emails.hasNext()) {
-            String email = emails.next();
-            // Append the email address in <>, assuming
-            //  the name wasn't already the email address
-            if(! email.equals(name)) {
-               s.append(" <").append(email).append(">");
+@Deprecated
+@Removal(version = "5.0.0")
+public class OutlookTextExtactor extends OutlookTextExtractor {
+    public OutlookTextExtactor(MAPIMessage msg) {
+        super(msg);
+    }
+
+    public OutlookTextExtactor(DirectoryNode poifsDir) throws IOException {
+        super(new MAPIMessage(poifsDir));
+    }
+
+    public OutlookTextExtactor(POIFSFileSystem fs) throws IOException {
+        super(new MAPIMessage(fs));
+    }
+
+    public OutlookTextExtactor(InputStream inp) throws IOException {
+        super(new MAPIMessage(inp));
+    }
+
+    public static void main(String[] args) throws Exception {
+        for (String filename : args) {
+            try (POIFSFileSystem poifs = new POIFSFileSystem(new File(filename));
+                 OutlookTextExtractor extractor = new OutlookTextExtractor(poifs)) {
+                System.out.println(extractor.getText());
             }
-         }
-      }
-      s.append("\n");
-   }
+        }
+    }
 }

Copied: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtractor.java (from r1871985, poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtactor.java)
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtractor.java?p2=poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtractor.java&p1=poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtactor.java&r1=1871985&r2=1871986&rev=1871986&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtactor.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtractor.java Thu Dec 26 06:12:56 2019
@@ -16,14 +16,6 @@
 ==================================================================== */
 package org.apache.poi.hsmf.extractor;
 
-import static org.apache.poi.util.StringUtil.startsWithIgnoreCase;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.text.SimpleDateFormat;
-import java.util.Locale;
-
 import org.apache.poi.extractor.POIOLE2TextExtractor;
 import org.apache.poi.hsmf.MAPIMessage;
 import org.apache.poi.hsmf.datatypes.AttachmentChunks;
@@ -32,158 +24,178 @@ import org.apache.poi.hsmf.exceptions.Ch
 import org.apache.poi.poifs.filesystem.DirectoryNode;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.util.LocaleUtil;
+import org.apache.poi.util.Removal;
 import org.apache.poi.util.StringUtil.StringsIterator;
 
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.SimpleDateFormat;
+import java.util.Locale;
+
+import static org.apache.poi.util.StringUtil.startsWithIgnoreCase;
+
 /**
  * A text extractor for HSMF (Outlook) .msg files.
  * Outputs in a format somewhat like a plain text email.
+ *
+ * @since 4.1.2
  */
-public class OutlookTextExtactor extends POIOLE2TextExtractor {
-   public OutlookTextExtactor(MAPIMessage msg) {
-      super(msg);
-   }
-   public OutlookTextExtactor(DirectoryNode poifsDir) throws IOException {
-      this(new MAPIMessage(poifsDir));
-   }
-   public OutlookTextExtactor(POIFSFileSystem fs) throws IOException {
-      this(new MAPIMessage(fs));
-   }
-   public OutlookTextExtactor(InputStream inp) throws IOException {
-      this(new MAPIMessage(inp));
-   }
-   
-   public static void main(String[] args) throws Exception {
-      for(String filename : args) {
-         try (POIFSFileSystem poifs = new POIFSFileSystem(new File(filename));
-              OutlookTextExtactor extractor = new OutlookTextExtactor(poifs)) {
-            System.out.println(extractor.getText());
-         }
-      }
-   }
-
-   /**
-    * Returns the underlying MAPI message
-    */
-   public MAPIMessage getMAPIMessage() {
-      return (MAPIMessage)document;
-   }
-      
-   /**
-    * Outputs something a little like a RFC822 email
-    */
-   public String getText() {
-      MAPIMessage msg = (MAPIMessage)document;
-      StringBuilder s = new StringBuilder();
-      
-      // See if we can get a suitable encoding for any
-      //  non unicode text in the file
-      msg.guess7BitEncoding();
-      
-      // Off we go
-      StringsIterator emails;
-      try {
-         emails = new StringsIterator(
-               msg.getRecipientEmailAddressList()
-         );
-      } catch(ChunkNotFoundException e) {
-         emails = new StringsIterator(new String[0]);
-      }
-      
-      try {
-         s.append("From: " + msg.getDisplayFrom() + "\n");
-      } catch(ChunkNotFoundException e) {}
-      
-      // For To, CC and BCC, try to match the names
-      //  up with their email addresses. Relies on the
-      //  Recipient Chunks being in the same order as
-      //  people in To + CC + BCC.
-      try {
-         handleEmails(s, "To", msg.getDisplayTo(), emails);
-      } catch(ChunkNotFoundException e) {}
-      try {
-         handleEmails(s, "CC", msg.getDisplayCC(), emails);
-      } catch(ChunkNotFoundException e) {}
-      try {
-         handleEmails(s, "BCC", msg.getDisplayBCC(), emails);
-      } catch(ChunkNotFoundException e) {}
-      
-      // Date - try two ways to find it
-      try {
-         // First try via the proper chunk
-         SimpleDateFormat f = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss Z", Locale.ROOT);
-         f.setTimeZone(LocaleUtil.getUserTimeZone());
-         s.append("Date: ").append(f.format(msg.getMessageDate().getTime())).append("\n");
-      } catch(ChunkNotFoundException e) {
-         try {
-            // Failing that try via the raw headers 
-            String[] headers = msg.getHeaders();
-            for(String header: headers) {
-               if(startsWithIgnoreCase(header, "date:")) {
-                  s.append("Date:").append(header, header.indexOf(':')+1, header.length()).append("\n");
-                  break;
-               }
+public class OutlookTextExtractor extends POIOLE2TextExtractor {
+    public OutlookTextExtractor(MAPIMessage msg) {
+        super(msg);
+    }
+
+    public OutlookTextExtractor(DirectoryNode poifsDir) throws IOException {
+        this(new MAPIMessage(poifsDir));
+    }
+
+    public OutlookTextExtractor(POIFSFileSystem fs) throws IOException {
+        this(new MAPIMessage(fs));
+    }
+
+    public OutlookTextExtractor(InputStream inp) throws IOException {
+        this(new MAPIMessage(inp));
+    }
+
+    public static void main(String[] args) throws Exception {
+        for (String filename : args) {
+            try (POIFSFileSystem poifs = new POIFSFileSystem(new File(filename));
+                 OutlookTextExtractor extractor = new OutlookTextExtractor(poifs)) {
+                System.out.println(extractor.getText());
             }
-         } catch(ChunkNotFoundException he) {
-            // We can't find the date, sorry...
-         }
-      }
-      
-      try {
-         s.append("Subject: ").append(msg.getSubject()).append("\n");
-      } catch(ChunkNotFoundException e) {}
-      
-      // Display attachment names
-      // To get the attachments, use ExtractorFactory
-      for(AttachmentChunks att : msg.getAttachmentFiles()) {
-         StringChunk name = att.getAttachLongFileName();
-         if (name == null) name = att.getAttachFileName();
-         String attName = name == null ? null : name.getValue();
-          
-         if(att.getAttachMimeTag() != null && 
-               att.getAttachMimeTag().getValue() != null) {
-             attName = att.getAttachMimeTag().getValue() + " = " + attName; 
-         }
-         s.append("Attachment: ").append(attName).append("\n");
-      }
-      
-      try {
-         s.append("\n").append(msg.getTextBody()).append("\n");
-      } catch(ChunkNotFoundException e) {}
-      
-      return s.toString();
-   }
-   
-   /**
-    * Takes a Display focused string, eg "Nick; Jim" and an iterator
-    *  of emails, and does its best to return something like
-    *  "Nick <ni...@example.com>; Jim <ji...@example.com>"
-    */
-   protected void handleEmails(StringBuilder s, String type, String displayText, StringsIterator emails) {
-      if(displayText == null || displayText.length() == 0) {
-         return;
-      }
-      
-      String[] names = displayText.split(";\\s*");
-      boolean first = true;
-      
-      s.append(type).append(": ");
-      for(String name : names) {
-         if(first) {
-            first = false;
-         } else {
-            s.append("; ");
-         }
-         
-         s.append(name);
-         if(emails.hasNext()) {
-            String email = emails.next();
-            // Append the email address in <>, assuming
-            //  the name wasn't already the email address
-            if(! email.equals(name)) {
-               s.append(" <").append(email).append(">");
+        }
+    }
+
+    /**
+     * Returns the underlying MAPI message
+     */
+    public MAPIMessage getMAPIMessage() {
+        return (MAPIMessage) document;
+    }
+
+    /**
+     * Outputs something a little like a RFC822 email
+     */
+    public String getText() {
+        MAPIMessage msg = (MAPIMessage) document;
+        StringBuilder s = new StringBuilder();
+
+        // See if we can get a suitable encoding for any
+        //  non unicode text in the file
+        msg.guess7BitEncoding();
+
+        // Off we go
+        StringsIterator emails;
+        try {
+            emails = new StringsIterator(
+                    msg.getRecipientEmailAddressList()
+            );
+        } catch (ChunkNotFoundException e) {
+            emails = new StringsIterator(new String[0]);
+        }
+
+        try {
+            s.append("From: " + msg.getDisplayFrom() + "\n");
+        } catch (ChunkNotFoundException e) {
+        }
+
+        // For To, CC and BCC, try to match the names
+        //  up with their email addresses. Relies on the
+        //  Recipient Chunks being in the same order as
+        //  people in To + CC + BCC.
+        try {
+            handleEmails(s, "To", msg.getDisplayTo(), emails);
+        } catch (ChunkNotFoundException e) {
+        }
+        try {
+            handleEmails(s, "CC", msg.getDisplayCC(), emails);
+        } catch (ChunkNotFoundException e) {
+        }
+        try {
+            handleEmails(s, "BCC", msg.getDisplayBCC(), emails);
+        } catch (ChunkNotFoundException e) {
+        }
+
+        // Date - try two ways to find it
+        try {
+            // First try via the proper chunk
+            SimpleDateFormat f = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss Z", Locale.ROOT);
+            f.setTimeZone(LocaleUtil.getUserTimeZone());
+            s.append("Date: ").append(f.format(msg.getMessageDate().getTime())).append("\n");
+        } catch (ChunkNotFoundException e) {
+            try {
+                // Failing that try via the raw headers
+                String[] headers = msg.getHeaders();
+                for (String header : headers) {
+                    if (startsWithIgnoreCase(header, "date:")) {
+                        s.append("Date:").append(header, header.indexOf(':') + 1, header.length()).append("\n");
+                        break;
+                    }
+                }
+            } catch (ChunkNotFoundException he) {
+                // We can't find the date, sorry...
+            }
+        }
+
+        try {
+            s.append("Subject: ").append(msg.getSubject()).append("\n");
+        } catch (ChunkNotFoundException e) {
+        }
+
+        // Display attachment names
+        // To get the attachments, use ExtractorFactory
+        for (AttachmentChunks att : msg.getAttachmentFiles()) {
+            StringChunk name = att.getAttachLongFileName();
+            if (name == null) name = att.getAttachFileName();
+            String attName = name == null ? null : name.getValue();
+
+            if (att.getAttachMimeTag() != null &&
+                    att.getAttachMimeTag().getValue() != null) {
+                attName = att.getAttachMimeTag().getValue() + " = " + attName;
+            }
+            s.append("Attachment: ").append(attName).append("\n");
+        }
+
+        try {
+            s.append("\n").append(msg.getTextBody()).append("\n");
+        } catch (ChunkNotFoundException e) {
+        }
+
+        return s.toString();
+    }
+
+    /**
+     * Takes a Display focused string, eg "Nick; Jim" and an iterator
+     * of emails, and does its best to return something like
+     * "Nick <ni...@example.com>; Jim <ji...@example.com>"
+     */
+    protected void handleEmails(StringBuilder s, String type, String displayText, StringsIterator emails) {
+        if (displayText == null || displayText.length() == 0) {
+            return;
+        }
+
+        String[] names = displayText.split(";\\s*");
+        boolean first = true;
+
+        s.append(type).append(": ");
+        for (String name : names) {
+            if (first) {
+                first = false;
+            } else {
+                s.append("; ");
+            }
+
+            s.append(name);
+            if (emails.hasNext()) {
+                String email = emails.next();
+                // Append the email address in <>, assuming
+                //  the name wasn't already the email address
+                if (!email.equals(name)) {
+                    s.append(" <").append(email).append(">");
+                }
             }
-         }
-      }
-      s.append("\n");
-   }
+        }
+        s.append("\n");
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org