mstor读取mbox文件,但返回null

时间:2012-04-21 22:44:51

标签: java mstor

使用mstor w / Windows,我可以连接到mbox商店(感谢SO)。似乎我可以读取消息指针;我知道这一点,因为无论何时我遍历商店,它都会迭代正确数量的消息。问题是没有加载标题或内容!任何的想法?

是的,我在类路径中有JavaMail的东西(最近它出现在mstor的lib中)。我甚至在mstor的一个示例文件(imagined.mbox)上使用它。

提前致谢。

我的代码:

public static void main(String[] args) throws Exception {

  Properties props = new Properties();
  props.setProperty("mstor.mbox.metadataStrategy", "xml");
  Session session1 = Session.getDefaultInstance(props);

  Session session = Session.getDefaultInstance(new Properties());

  Store store = session.getStore(new URLName("mstor:C:/tmp/imagined.mbox"));
  store.connect();

  System.out.println(store.isConnected());

  Folder inbox = store.getDefaultFolder();  // no subfolder here; even if there is an Inbox, I get the same thing...
  inbox.open(Folder.READ_ONLY);

  Message[] messages = inbox.getMessages();
  for (Message m : messages) {
    System.out.println(m.getSubject());
  }

}

我的典型结果:

true (i.e., yes, I'm connected...)
null
null
null
null

2 个答案:

答案 0 :(得分:0)

我看到这已经有一个月了,但我遇到了同样的问题。尝试添加m.saveChanges()作为for循环中的第一行。这会强制mstor创建消息标题的缓存。

从逻辑上讲,上面的代码是正确的。奇怪的是我们必须添加这一行,但它是我们问题的功能性解决方案。

如果您已找到其他解决方案,请不要忘记分享。仅仅因为没有人得到答案并不意味着没有人遇到同样的问题!

答案 1 :(得分:0)

创建名为Properties的{​​{1}}实例后,请使用以下命令禁用缓存:

properties

如果您这样做并再试一次,您应该会发现您可以调用subject,from等的访问器方法,而不必诉诸properties.setProperty("mstor.mbox.metadataStrategy", "none"); hack。