开发者

Get server output while using javax.mail

I need to implement POP3, IMAP and SMTP servers availability and identity checking by connecting to them, authorizing and comparing expected server output with received server output while doing previously mentioned operations.

I'm using Java, so not to reinvent the wheel, I'm also using javax.mail implementation. Everything works fine, except that there's no way to get recorded server output. The only available source is debug output:

Properties props = new Properties();
props.setProperty("mail.pop3.debug", "true");
Session session = Session.getInstance(props, null);
ByteArrayOutputStream out = new ByteArrayOutputStream();
session.setDebug(true);
session.setDebugOut(new PrintStream(out));
Store store = new POP3Store(session, getUrl());
store.connect();
store.close();
out.toString(); // < the only available communication output

The only way I'm able to get server output is by parsing debug output (searching for lines beginning with "S: " and reading strings until line beginning with "C: " or end of stream is found).

Sample POP3 communication debug output looks like this:

DEBUG POP3: connecting to host "pop.gmail.com", port 995, isSSL true
S: +OK Gpop ready for requests from *** ***
C: CAPA
S: +OK Capability list follows
USER
RESP-CODES
EXPIRE 0
LOGIN-DELAY 300
X-GOOGLE-VERHOEVEN
UIDL
.
C: USER ***
S: +OK send PASS
C: PASS ***
S: +OK Welcome.
C: QUIT
S: +OK Farewell.

The only other alternative I see here is to use custom SocketFactory (set "mail.*.socketFactory" property), which would produce my initially set Socket, from which I'd be able to get 开发者_StackOverflow社区server input stream.

I believe there's a better solution for this. Do you see any?

Thanks in advance.


I'd just connect via a socket and supply the exact test case. I wouldn't use javamail for this particular application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜