使用协议“mapi://”从 java 打开 Outlook 中的邮件
我使用 Windows 桌面搜索开发一个 Java 应用程序,从中我可以检索有关计算机上文件的一些信息,例如 url (System.ItemUrl)。此类 url 的一个示例是
file://c:/users/ausername/documents/aninterestingfile.txt
“普通”文件。此字段还提供从 Outlook 或 Thunderbird 索引的邮件项目的 URL。 Thunderbird 的项目(仅适用于 vista 和 7)也是文件 (.wdseml)。但是 Outlook 的项目 url 以“mapi://”开头,例如:
mapi://{S-1-5-21-1626573300-1364474481-487586288-1001}/[email protected]($b423dcd5)/0/Inbox/가가가가곕갘객겒갨겑곓걌게겻겨곹곒갓곅갩갤가갠가
我遇到的问题是使用此 url 在 Outlook 中从 Java 打开真实项目。如果我将其复制/粘贴到 Windows 的运行对话框中,它就可以工作;如果我在命令行中使用“start”后跟复制/粘贴的网址,它也有效。
url 似乎是用 UTF-16 编码的。我希望能够编写这样的代码:
String url = "mapi://{S-1-5-21-1626573300-1364474481-487586288-1001}/[email protected]($b423dcd5)/0/Inbox/가가가가곕갘객겒갨겑곓걌게겻겨곹곒갓곅갩갤가갠가";
Runtime.getRuntime().exec("cmd.exe /C start " + url);
我不工作,并且我尝试了其他解决方案,例如:
String start = "start";
String url = "mapi://{S-1-5-21-1626573300-1364474481-487586288-1001}/[email protected]($b423dcd5)/0/Inbox/가가가가곕갘객겒갨겑곓걌게겻겨곹곒갓곅갩갤가갠가";
FileOutputStream fos = new FileOutputStream(new File("test.bat");
fos.write(start.getBytes("UTF16");
fos.write(url.getBytes("UTF16"));
fos.close();
Runtime.getRuntime().exec("cmd.exe /C test.bat");
但没有成功。使用上面的解决方案,文件“test.bat”包含正确的 url 和“start”命令,但运行“test.bat”会导致众所周知的错误消息:
'■' is not recognized as an internal or external command, operable program or batch file.
有任何人有想法能够打开“ mapi://”来自 Java 的项目?
I developp a Java application using Windows Desktop Search from which I can retrieve some information about files on my computer such as urls (System.ItemUrl). An example of such url is
file://c:/users/ausername/documents/aninterestingfile.txt
for "normal" files. This field give also urls of mail items indexed from Outlook or Thunderbird. Thunderbird's items (only available using vista and seven) are also files (.wdseml). But outlook's items urls start with "mapi://" like :
mapi://{S-1-5-21-1626573300-1364474481-487586288-1001}/[email protected]($b423dcd5)/0/Inbox/가가가가곕갘객겒갨겑곓걌게겻겨곹곒갓곅갩갤가갠가
The problem I have is opening the real item from Java in Outlook using this url. If I copy/paste it in the run dialog of Windows, it works ; it also works if I use "start" followed by the copied/pasted url in command line.
The url seems to be encoded in UTF-16. I want to be able to write such code :
String url = "mapi://{S-1-5-21-1626573300-1364474481-487586288-1001}/[email protected]($b423dcd5)/0/Inbox/가가가가곕갘객겒갨겑곓걌게겻겨곹곒갓곅갩갤가갠가";
Runtime.getRuntime().exec("cmd.exe /C start " + url);
I doesn't work and I've tried other solutions like :
String start = "start";
String url = "mapi://{S-1-5-21-1626573300-1364474481-487586288-1001}/[email protected]($b423dcd5)/0/Inbox/가가가가곕갘객겒갨겑곓걌게겻겨곹곒갓곅갩갤가갠가";
FileOutputStream fos = new FileOutputStream(new File("test.bat");
fos.write(start.getBytes("UTF16");
fos.write(url.getBytes("UTF16"));
fos.close();
Runtime.getRuntime().exec("cmd.exe /C test.bat");
without any success. Using the solution above, the file "test.bat" contains the correct url and the "start" command, but the run of "test.bat" results in the well known error message :
'■' is not recognized as an internal or external command, operable program or batch file.
Has anybody an idea to be able to open "mapi://" items from Java ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,我的问题有点棘手。但我终于找到了答案,并将在这里分享。
我怀疑是真的:Windows 使用 UTF-16(小端)url。当我们仅使用图像、文本等文件的路径时,在 UTF-8 中工作没有什么区别。但为了能够访问 Outlook 项目,我们必须使用 UTF-16LE。如果我用 C# 编码,就不会有任何问题。但在 Java 中,你必须更具创造力。
我从 Windows 桌面搜索中检索到以下内容:
我所做的是创建一个临时 VB 脚本并按如下方式运行它:
Well, my question was a little bit tricky. But I finally found an answer and will share it here.
What I suspected was true : Windows uses UTF-16 (little endian) urls. It makes no differences working in UTF-8 when we only use paths to files such as images, text, etc. But to be able to access Outlook items, we must use UTF-16LE. If I were coding in C#, there wouldn't have been any problem. But in Java, you have to be more inventive.
From Windows Desktop Search, I retrieve this:
And what I did is creating a temporary VB script and run it like this: