Hello,
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 server input stream.
I believe there's a better solution for this. Do you see any?
Thanks in advance.