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");
         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

   * 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

  public Msg2txt(String fileName) throws IOException {
    fileNameStem = fileName;
    if(fileNameStem.endsWith(".msg") || fileNameStem.endsWith(".MSG")) {
      fileNameStem = fileNameStem.substring(0, fileNameStem.length() - 4);
    }
    msg = new MAPIMessage(fileName);
  }
View Full Code Here

         if (is.available() == 0)
         {
            return "";
         }
        
         MAPIMessage message;
         try
         {
            message = new MAPIMessage(is);
         }
         catch (IOException e)
         {
            throw new DocumentReadException("Can't open message.", e);
         }
         StringBuilder builder = new StringBuilder();
         try
         {
            builder.append(message.getDisplayFrom()).append('\n');
         }
         catch (ChunkNotFoundException e)
         {
            // "from" is empty
         }
         try
         {
            builder.append(message.getDisplayTo()).append('\n');
         }
         catch (ChunkNotFoundException e)
         {
            // "to" is empty
         }
         try
         {
            builder.append(message.getSubject()).append('\n');
         }
         catch (ChunkNotFoundException e)
         {
            // "subject" is empty
         }
         try
         {
            builder.append(message.getTextBody());
         }
         catch (ChunkNotFoundException e)
         {
            // "textBody" is empty
         }
View Full Code Here

         if (is.available() == 0)
         {
            return "";
         }
        
         MAPIMessage message;
         try
         {
            message = new MAPIMessage(is);
         }
         catch (IOException e)
         {
            throw new DocumentReadException("Can't open message.", e);
         }
         StringBuilder builder = new StringBuilder();
         try
         {
            builder.append(message.getDisplayFrom()).append('\n');
         }
         catch (ChunkNotFoundException e)
         {
            // "from" is empty
            if (LOG.isTraceEnabled())
            {
               LOG.trace("An exception occurred: " + e.getMessage());
            }
         }
         try
         {
            builder.append(message.getDisplayTo()).append('\n');
         }
         catch (ChunkNotFoundException e)
         {
            // "to" is empty
            if (LOG.isTraceEnabled())
            {
               LOG.trace("An exception occurred: " + e.getMessage());
            }
         }
         try
         {
            builder.append(message.getSubject()).append('\n');
         }
         catch (ChunkNotFoundException e)
         {
            // "subject" is empty
            if (LOG.isTraceEnabled())
            {
               LOG.trace("An exception occurred: " + e.getMessage());
            }
         }
         try
         {
            builder.append(message.getTextBody());
         }
         catch (ChunkNotFoundException e)
         {
            // "textBody" is empty
            if (LOG.isTraceEnabled())
View Full Code Here

      {
         throw new NullPointerException("InputStream is null.");
      }
      try
      {
         MAPIMessage message;
         try
         {
            message = new MAPIMessage(is);
         }
         catch (IOException e)
         {
            return "";
         }
         StringBuffer buffer = new StringBuffer();
         try
         {
            buffer.append(message.getDisplayFrom()).append('\n');
         }
         catch (ChunkNotFoundException e)
         {
            // "from" is empty
         }
         try
         {
            buffer.append(message.getDisplayTo()).append('\n');
         }
         catch (ChunkNotFoundException e)
         {
            // "to" is empty
         }
         try
         {
            buffer.append(message.getSubject()).append('\n');
         }
         catch (ChunkNotFoundException e)
         {
            // "subject" is empty
         }
         try
         {
            buffer.append(message.getTextBody());
         }
         catch (ChunkNotFoundException e)
         {
            // "textBody" is empty
         }
View Full Code Here

   *
   * @throws Exception
   */
  public TestFileWithAttachmentsRead() throws IOException {
    String dirname = System.getProperty("HSMF.testdata.path");
    this.mapiMessage = new MAPIMessage(dirname + "/attachment_test_msg.msg");
  }
View Full Code Here

   * Initialize this test, load up the blank.msg mapi message.
   * @throws Exception
   */
  public TestOutlook30FileRead() throws IOException {
    String dirname = System.getProperty("HSMF.testdata.path");
    this.mapiMessage = new MAPIMessage(dirname + "/outlook_30_msg.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.