如何捕获从com.sun.mail.iap.Argument生成的String?

时间:2022-09-02 18:09:42

I'm trying to debug my custom javamail IMAPCommands.

我正在尝试调试我的自定义javamail IMAPCommands。

In the process of constructing the command to send to the IMAP server, I do something like this:

在构造发送到IMAP服务器的命令的过程中,我做了这样的事情:

public Object doCommand(IMAPProtocol p) throws ProtocolException {
Argument args = new Argument();

Argument sortCrit = new Argument();
sortCrit.writeString("REVERSE");
sortCrit.writeString("DATE");
args.writeArgument(sortCrit);

args.writeString("UTF-8");

Argument from1 = new Argument();
from1.writeString("FROM");
from1.writeString(searchFrom.get(0));

Argument from2 = new Argument();
from2.writeString("FROM");
from2.writeString(searchFrom.get(1));

fromArg.writeString("OR");
fromArg.writeArgument(from1);
fromArg.writeArgument(from2);

args.writeArgument(fromArg);

Response[] r = p.command("UID SORT", args);
Response response = r[r.length - 1];
[...]
}

I want to log (say, to stderr) what will be sent to the server with p.command. How do I do that?

我想记录(比如说stderr)用p.command发送到服务器的内容。我怎么做?

2 个解决方案

#1


0  

Call session.setDebug(true) and you'll get an entire protocol trace on System.out. That will show you what you're actually sending.

调用session.setDebug(true),您将在System.out上获得整个协议跟踪。这将显示您实际发送的内容。

#2


0  

From a quick glance it looks like the Protocol implementation has some debugging capabilities. Create a Protocol with streams and pass true for the debug argument.

从快速浏览一下,看起来协议实现具有一些调试功能。使用流创建协议,并为调试参数传递true。

Then you should see the input and output for this command dumped to System.out.

然后,您应该看到此命令的输入和输出转储到System.out。

#1


0  

Call session.setDebug(true) and you'll get an entire protocol trace on System.out. That will show you what you're actually sending.

调用session.setDebug(true),您将在System.out上获得整个协议跟踪。这将显示您实际发送的内容。

#2


0  

From a quick glance it looks like the Protocol implementation has some debugging capabilities. Create a Protocol with streams and pass true for the debug argument.

从快速浏览一下,看起来协议实现具有一些调试功能。使用流创建协议,并为调试参数传递true。

Then you should see the input and output for this command dumped to System.out.

然后,您应该看到此命令的输入和输出转储到System.out。