@Override public List<MessageMetaData> getMessages() throws IOException { try { mailboxManager.startProcessingRequest(session); Iterator<MessageResult> results = manager.getMessages(MessageRange.all(), METADATA_GROUP, session); List<MessageMetaData> mList = new ArrayList<>(); while (results.hasNext()) { MessageResult result = results.next(); MessageMetaData metaData = new MessageMetaData(String.valueOf(result.getUid().asLong()), result.getSize()); mList.add(metaData); } return ImmutableList.copyOf(mList); } catch (MailboxException e) { throw new IOException("Unable to retrieve messages", e); } finally { mailboxManager.endProcessingRequest(session); } }
public static Builder builderFromMessageResult(MessageResult messageResult) throws MailboxException { Builder builder = builder() .uid(messageResult.getUid()) .modSeq(messageResult.getModSeq()) .size(messageResult.getSize()) .internalDate(messageResult.getInternalDate().toInstant()) .attachments(messageResult.getAttachments()) .mailboxId(messageResult.getMailboxId()); try { return builder.content(messageResult.getFullContent().getInputStream()); } catch (IOException e) { throw new MailboxException("Can't get message full content: " + e.getMessage(), e); } }
private FetchResponse.BodyElement headers(MessageResult messageResult, String name, int[] path, boolean isBase) throws MailboxException { if (isBase) { // if its base we can just return the raw headers without parsing // them. See MAILBOX-311 and IMAP-? HeadersBodyElement element = new HeadersBodyElement(name, messageResult.getHeaders()); try { if (messageResult.getSize() - element.size() <= 0) { // Seems like this mail has no body element.noBody(); } } catch (IOException e) { throw new MailboxException("Unable to get size of header body element", e); } return element; } else { final Iterator<MessageResult.Header> headers = getHeaders(messageResult, path, isBase); List<MessageResult.Header> lines = MessageResultUtils.getAll(headers); return headerBodyElement(messageResult, name, lines, path, isBase); } }
private FetchResponse.BodyElement headers(final MessageResult messageResult, String name, final int[] path, final boolean isBase) throws MailboxException { if (isBase) { // if its base we can just return the raw headers without parsing // them. See MAILBOX-311 and IMAP-? HeadersBodyElement element = new HeadersBodyElement(name, messageResult.getHeaders()); try { if (messageResult.getSize() - element.size() <= 0) { // Seems like this mail has no body element.noBody(); } } catch (IOException e) { throw new MailboxException("Unable to get size of header body element", e); } return element; } else { final Iterator<MessageResult.Header> headers = getHeaders(messageResult, path, isBase); List<MessageResult.Header> lines = MessageResultUtils.getAll(headers); return headerBodyElement(messageResult, name, lines, path, isBase); } }
private HeaderBodyElement headerBodyElement(MessageResult messageResult, String name, List<MessageResult.Header> lines, int[] path, boolean isBase) throws MailboxException { final HeaderBodyElement result = new HeaderBodyElement(name, lines); // if the size is 2 we had found not header and just want to write the empty line with CLRF terminated // so check if there is a content for it. If not we MUST NOT write the empty line in any case // as stated in rfc3501 if (result.size() == 2) { // Check if its base as this can give use a more correctly working check // to see if we need to write the newline out to the client. // This is related to IMAP-298 if (isBase) { if (messageResult.getSize() - result.size() <= 0) { // Seems like this mail has no body result.noBody(); } } else { try { if (content(messageResult, name, path, isBase).size() <= 0) { // Seems like this mail has no body result.noBody(); } } catch (IOException e) { throw new MailboxException("Unable to get size of header body element", e); } } } return result; }
private HeaderBodyElement headerBodyElement(final MessageResult messageResult, String name, List<MessageResult.Header> lines, final int[] path, final boolean isBase) throws MailboxException { final HeaderBodyElement result = new HeaderBodyElement(name, lines); // if the size is 2 we had found not header and just want to write the empty line with CLRF terminated // so check if there is a content for it. If not we MUST NOT write the empty line in any case // as stated in rfc3501 if (result.size() == 2) { // Check if its base as this can give use a more correctly working check // to see if we need to write the newline out to the client. // This is related to IMAP-298 if (isBase) { if (messageResult.getSize() - result.size() <= 0) { // Seems like this mail has no body result.noBody(); } } else try { if (content(messageResult, name, path, isBase).size() <= 0) { // Seems like this mail has no body result.noBody(); } } catch (IOException e) { throw new MailboxException("Unable to get size of header body element", e); } } return result; } private FetchResponse.BodyElement headers(final MessageResult messageResult, String name, final int[] path, final boolean isBase) throws MailboxException {
session); while (results.hasNext()) { size += results.next().getSize();
setSize(result.getSize());
setSize(result.getSize());