Package org.apache.poi.hsmf

Examples of org.apache.poi.hsmf.MAPIMessage


   * 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


    } 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

public class OutlookTextExtactor extends POIOLE2TextExtractor {
   public OutlookTextExtactor(MAPIMessage msg) {
      super(msg);
   }
   public OutlookTextExtactor(DirectoryNode poifsDir, POIFSFileSystem fs) throws IOException {
      this(new MAPIMessage(poifsDir, fs));
   }
View Full Code Here

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

   }
   public OutlookTextExtactor(POIFSFileSystem 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();
     
      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

      simple.getRoot().getEntry(
            (new StringChunk(Chunks.DISPLAY_FROM, Types.ASCII_STRING)).getEntryName()
      );
     
      // Now load the file
      MAPIMessage msg = new MAPIMessage(simple);
      try {
         assertEquals("Kevin Roast", msg.getDisplayTo());
         assertEquals("Kevin Roast", msg.getDisplayFrom());
         assertEquals("Test the content transformer", msg.getSubject());
      } catch(ChunkNotFoundException e) {
         fail();
      }
     
      // Check date too
      try {
         SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        
         Calendar c = msg.getMessageDate();
         assertEquals( "2007-06-14 09:42:55", f.format(c.getTime()) );
      } catch(ChunkNotFoundException e) {
         fail();
      }
   }
View Full Code Here

     
      String search = new String(recips.recipientSearchChunk.getValue(), "ASCII");
      assertEquals("CN=KEVIN.ROAST@BEN\0", search.substring(search.length()-19));
     
      // Now via MAPIMessage
      MAPIMessage msg = new MAPIMessage(simple);
      assertNotNull(msg.getRecipientDetailsChunks());
      assertEquals(1, msg.getRecipientDetailsChunks().length);
     
      assertEquals("kevin.roast@alfresco.org", msg.getRecipientDetailsChunks()[0].recipientSMTPChunk.getValue());
      assertEquals("kevin.roast@alfresco.org", msg.getRecipientDetailsChunks()[0].getRecipientEmailAddress());
      assertEquals("Kevin Roast", msg.getRecipientDetailsChunks()[0].getRecipientName());
      assertEquals("kevin.roast@alfresco.org", msg.getRecipientEmailAddress());
     
     
      // Try both SMTP and EX files for recipient
      assertEquals("EX", msg.getRecipientDetailsChunks()[0].deliveryTypeChunk.getValue());
      assertEquals("kevin.roast@alfresco.org", msg.getRecipientDetailsChunks()[0].recipientSMTPChunk.getValue());
      assertEquals("/O=HOSTEDSERVICE2/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=Kevin.roast@ben",
            msg.getRecipientDetailsChunks()[0].recipientEmailChunk.getValue());
     
      // Now look at another message
      msg = new MAPIMessage(new POIFSFileSystem(
            new FileInputStream(samples.getFile("simple_test_msg.msg"))
      ));
      assertNotNull(msg.getRecipientDetailsChunks());
      assertEquals(1, msg.getRecipientDetailsChunks().length);
     
      assertEquals("SMTP", msg.getRecipientDetailsChunks()[0].deliveryTypeChunk.getValue());
      assertEquals(null, msg.getRecipientDetailsChunks()[0].recipientSMTPChunk);
      assertEquals(null, msg.getRecipientDetailsChunks()[0].recipientNameChunk);
      assertEquals("travis@overwrittenstack.com", msg.getRecipientDetailsChunks()[0].recipientEmailChunk.getValue());
      assertEquals("travis@overwrittenstack.com", msg.getRecipientEmailAddress());
   }
View Full Code Here

      assertEquals("nick.burch@alfresco.com", chunks[4].getRecipientEmailAddress());
      assertEquals("'Roy Wetherall'", chunks[5].getRecipientName());
      assertEquals("roy.wetherall@alfresco.com", chunks[5].getRecipientEmailAddress());
     
      // Finally check on message
      MAPIMessage msg = new MAPIMessage(multiple);
      assertEquals(6, msg.getRecipientEmailAddressList().length);
      assertEquals(6, msg.getRecipientNamesList().length);
     
      assertEquals("'Ashutosh Dandavate'", msg.getRecipientNamesList()[0]);
      assertEquals("'Paul Holmes-Higgin'", msg.getRecipientNamesList()[1]);
      assertEquals("'Mike Farman'",        msg.getRecipientNamesList()[2]);
      assertEquals("nickb@alfresco.com",   msg.getRecipientNamesList()[3]);
      assertEquals("nick.burch@alfresco.com", msg.getRecipientNamesList()[4]);
      assertEquals("'Roy Wetherall'",      msg.getRecipientNamesList()[5]);
     
      assertEquals("ashutosh.dandavate@alfresco.com", msg.getRecipientEmailAddressList()[0]);
      assertEquals("paul.hh@alfresco.com",            msg.getRecipientEmailAddressList()[1]);
      assertEquals("mikef@alfresco.com",              msg.getRecipientEmailAddressList()[2]);
      assertEquals("nickb@alfresco.com",              msg.getRecipientEmailAddressList()[3]);
      assertEquals("nick.burch@alfresco.com",         msg.getRecipientEmailAddressList()[4]);
      assertEquals("roy.wetherall@alfresco.com",      msg.getRecipientEmailAddressList()[5]);
   }
View Full Code Here

     
      NameIdChunks nameId = (NameIdChunks)groups[2];
      assertEquals(10, nameId.getAll().length);
     
      // Now via MAPIMessage
      MAPIMessage msg = new MAPIMessage(simple);
      assertNotNull(msg.getNameIdChunks());
      assertEquals(10, msg.getNameIdChunks().getAll().length);
   }
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.