2012-02-23 88 views
0

我想从Outlook .msg文件使用POI hsmf提取字段BillingInformation,但每次我得到一个ChunkNotFoundException。我已在Outlook中验证了该字段中有内容。如何阅读与Apache POI HSMF共同财产

public class MessageReader { 
    private static final int SUBJECT_CHUNK = 0x0037; 
    private static final int BILLING_INFORMATION_CHUNK = 0x00008535; 
    public static void main(String[] argv) { 
     try { 
      MAPIMessage mapiMessage = new MAPIMessage("MessageWithBillingInformation.msg"); 
      System.out.println(mapiMessage.getStringFromChunk(new StringChunk(SUBJECT_CHUNK, true))); 
      System.out.println(mapiMessage.getStringFromChunk(new StringChunk(BILLING_INFORMATION_CHUNK, true))); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } catch (ChunkNotFoundException e) { 
      e.printStackTrace(); 
     } 
    } 
} 

所有的文档,我发现名单0x00008535作为计费信息的权限ID: http://msdn.microsoft.com/en-us/library/cc765867.aspx

谢谢

+0

你确定该块位于根目录吗?它可以存储在其他部分的下面,这可以解释为什么找不到该块。我建议你尝试使用org.apache.poi.poifs.dev.POIFSLister和org.apache.poi.hsmf.dev.HSMFDump来检查它的确切位置 – Gagravarr 2012-02-25 10:38:48

+0

HSMFDump在“Chunks”部分下列出它,没有任何其他的名称。但是,idName会根据等于MAPIProperty.UNKNOWN而列为“(未知)”。 – 2012-02-27 16:34:26

+0

你可以在POIFSLister中看到它吗? (块名和类型应该包含在名称中) – Gagravarr 2012-02-28 03:33:03

回答

1

使用0x800A的作品块ID读取结算信息领域,使代码如下所示:

public class MessageReader { 
private static final int SUBJECT_CHUNK = 0x0037; 
private static final int BILLING_INFORMATION_CHUNK = 0x800A; 
public static void main(String[] argv) { 
    try { 
     MAPIMessage mapiMessage = new MAPIMessage("MessageWithBillingInformation.msg"); 
     System.out.println(mapiMessage.getStringFromChunk(new StringChunk(SUBJECT_CHUNK, true))); 
     System.out.println(mapiMessage.getStringFromChunk(new StringChunk(BILLING_INFORMATION_CHUNK, true))); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } catch (ChunkNotFoundException e) { 
     e.printStackTrace(); 
    } 
} 

}