Package org.apache.poi.hsmf

Examples of org.apache.poi.hsmf.MAPIMessage


   }
   public OutlookTextExtactor(POIFSFileSystem fs) throws IOException {
      this(new MAPIMessage(fs));
   }
   public OutlookTextExtactor(NPOIFSFileSystem fs) throws IOException {
      this(new MAPIMessage(fs));
   }
View Full Code Here


   }
   public OutlookTextExtactor(NPOIFSFileSystem fs) throws IOException {
      this(new MAPIMessage(fs));
   }
   public OutlookTextExtactor(InputStream inp) throws IOException {
      this(new MAPIMessage(inp));
   }
View Full Code Here

     
   /**
    * Outputs something a little like a RFC822 email
    */
   public String getText() {
      MAPIMessage msg = (MAPIMessage)document;
      StringBuffer s = new StringBuffer();
     
      // 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");
         f.setTimeZone(TimeZone.getTimeZone("UTC"));
         s.append("Date: " + f.format(msg.getMessageDate().getTime()) + "\n");
      } catch(ChunkNotFoundException e) {
         try {
            // Failing that try via the raw headers
            String[] headers = msg.getHeaders();
            for(String header: headers) {
               if(header.toLowerCase().startsWith("date:")) {
                  s.append(
                        "Date:" +
                        header.substring(header.indexOf(':')+1) +
                        "\n"
                  );
                  break;
               }
            }
         } catch(ChunkNotFoundException he) {
            // We can't find the date, sorry...
         }
      }
     
      try {
         s.append("Subject: " + msg.getSubject() + "\n");
      } catch(ChunkNotFoundException e) {}
     
      // Display attachment names
      // To get the attachments, use ExtractorFactory
      for(AttachmentChunks att : msg.getAttachmentFiles()) {
         String ats = att.attachLongFileName.getValue();
         if(att.attachMimeTag != null &&
               att.attachMimeTag.getValue() != null) {
            ats = att.attachMimeTag.getValue() + " = " + ats;
         }
         s.append("Attachment: " + ats + "\n");
      }
     
      try {
         s.append("\n" + msg.getTextBody() + "\n");
      } catch(ChunkNotFoundException e) {}
     
      return s.toString();
   }
View Full Code Here

    } else if(ext instanceof PowerPointExtractor) {
      // Tricky, not stored directly in poifs
      // TODO
    } else if(ext instanceof OutlookTextExtactor) {
       // Stored in the Attachment blocks
       MAPIMessage msg = ((OutlookTextExtactor)ext).getMAPIMessage();
       for(AttachmentChunks attachment : msg.getAttachmentFiles()) {
          if(attachment.attachData != null) {
                byte[] data = attachment.attachData.getValue();
                nonPOIFS.add( new ByteArrayInputStream(data) );
          } else if(attachment.attachmentDirectory != null) {
              dirs.add(attachment.attachmentDirectory.getDirectory());
View Full Code Here

   *
   * @throws Exception
   */
  public TestFileWithAttachmentsRead() throws IOException {
        POIDataSamples samples = POIDataSamples.getHSMFInstance();
    this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("attachment_test_msg.msg"));
  }
View Full Code Here

   * Initialize this test, load up the blank.msg mapi message.
   * @throws Exception
   */
  public TestOutlook30FileRead() throws IOException {
        POIDataSamples samples = POIDataSamples.getHSMFInstance();
    this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("outlook_30_msg.msg"));
  }
View Full Code Here

   * Initialize this test, load up the blank.msg mapi message.
   * @throws Exception
   */
  public TestSimpleFileRead() throws IOException {
        POIDataSamples samples = POIDataSamples.getHSMFInstance();
    this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("simple_test_msg.msg"));
  }
View Full Code Here

  /**
   * Initialize this test, load up the blank.msg mapi message.
   */
  public TestBlankFileRead() throws IOException {
        POIDataSamples samples = POIDataSamples.getHSMFInstance();
    this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("blank.msg"));
  }
View Full Code Here

   * Initialize this test, load up the blank.msg mapi message.
   * @throws Exception
   */
  public TestSimpleFileRead() throws IOException {
    String dirname = System.getProperty("HSMF.testdata.path");
    this.mapiMessage = new MAPIMessage(dirname + "/simple_test_msg.msg");
  }
View Full Code Here

   * Initialize this test, load up the blank.msg mapi message.
   * @throws IOException
   */
  public TestBlankFileRead() throws IOException {
    String dirname = System.getProperty("HSMF.testdata.path");
    this.mapiMessage = new MAPIMessage(dirname + "/blank.msg");
  }
View Full Code Here

TOP

Related Classes of org.apache.poi.hsmf.MAPIMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.