Closed cxc222 closed 2 years ago
The readme has an example. I didn't understand what you are looking for.
sorry,I didn't understand the readme.md. I have imap address and account password,how to get the content ?
how to execute the command ? Thanks ~
First, read this RFC3501 to know how each IMAP protocol works and how each command is used. https://datatracker.ietf.org/doc/html/rfc3501
Second, as explained in readme, following example command can be used to fetch CAPABILITY for example. For FETCH command the UidFetchCommand is one example to use.
final Future<ImapAsyncResponse> capaCmdFuture = session.execute(new CapaCommand());
First, read this RFC3501 to know how each IMAP protocol works and how each command is used. https://datatracker.ietf.org/doc/html/rfc3501
Second, as explained in readme, following example command can be used to fetch CAPABILITY for example. For FETCH command the UidFetchCommand is one example to use.
final Future<ImapAsyncResponse> capaCmdFuture = session.execute(new CapaCommand());
thanks, I see ~
after I execute fetchCommand
getting the response,
how to convert to MimeMessage
or how to get the subject ?
Thanks~
Following is just an example, values need to be adjusted. Learn something about how com.sun.mail.imap.protocol.FetchResponse works, it will be helpful.
final Future<ImapAsyncResponse> cmdFuture = session.execute(new UidFetchCommand(....));
final ImapAsyncResponse resp = cmdFuture.get(30 * 1000, TimeUnit.MILLISECONDS);
final IMAPResponse[] imapResp = resp.getResponseLines().toArray(new IMAPResponse[0]);
final int len = imapResp.length;
for (int i = 0; i < len; i++) {
IMAPResponse response = imapResp[i];
if (response.keyEquals("FETCH")) {
final FetchResponse r = new FetchResponse(response, new FetchItem[0]);
// Now you get FetchResponse, and you can do operation with it, notes following import is needed
// com.sun.mail.imap.protocol.FetchResponse
// com.sun.mail.imap.protocol.IMAPResponse
final BODY body = r.getItem(BODY.class);
InternetHeaders headers = new InternetHeaders(body.getByteArrayInputStream());
String subject = headers.getHeader("Subject")[0]; // now you are able to get subject
}
}
Following is just an example, values need to be adjusted. Learn something about how com.sun.mail.imap.protocol.FetchResponse works, it will be helpful.
final Future<ImapAsyncResponse> cmdFuture = session.execute(new UidFetchCommand(....)); final ImapAsyncResponse resp = cmdFuture.get(30 * 1000, TimeUnit.MILLISECONDS); final IMAPResponse[] imapResp = resp.getResponseLines().toArray(new IMAPResponse[0]); final int len = imapResp.length; for (int i = 0; i < len; i++) { IMAPResponse response = imapResp[i]; if (response.keyEquals("FETCH")) { final FetchResponse r = new FetchResponse(response, new FetchItem[0]); // Now you get FetchResponse, and you can do operation with it, notes following import is needed // com.sun.mail.imap.protocol.FetchResponse // com.sun.mail.imap.protocol.IMAPResponse final BODY body = r.getItem(BODY.class); InternetHeaders headers = new InternetHeaders(body.getByteArrayInputStream()); String subject = headers.getHeader("Subject")[0]; // now you are able to get subject } }
Thanks, I see ~
This library is for accessing messages through IMAP server and client using mime libraries like apache or sun to read the message content. Reading mime message content is outside of this library.
As the title
Can you provide a complete example
Thanks ~