@Test public void getMessages_shouldProvideCorrectHeadersInRequest() throws MessagingException { int totalMessages = 23; int messageStart = 1; int messageEnd = 11; setupFolderWithMessages(totalMessages); String messagesXml = "<xml>MessagesXml</xml>"; buildSearchResponse(mockDataSet); when(mockStore.getMessagesXml()).thenReturn(messagesXml); when(mockStore.processRequest(eq("https: eq(messagesXml), Matchers.<Map<String, String>>any())).thenReturn(mockDataSet); folder.getMessages(messageStart, messageEnd, new Date(), listener); verify(mockStore, times(2)).processRequest(anyString(), anyString(), anyString(), headerCaptor.capture()); assertEquals(2, headerCaptor.getValue().size()); assertEquals("t", headerCaptor.getValue().get("Brief")); assertEquals("rows=" + (totalMessages - (messageEnd)) + "-" + (totalMessages - messageStart) , headerCaptor.getValue().get("Range")); }
@Override public List<WebDavMessage> getMessages(int start, int end, Date earliestDate, MessageRetrievalListener<WebDavMessage> listener) throws MessagingException { List<WebDavMessage> messages = new ArrayList<WebDavMessage>(); String[] uids; Map<String, String> headers = new HashMap<String, String>(); int uidsLength; String messageBody; int prevStart = start; start = this.messageCount - end; end = start + (end - prevStart); if (start < 0 || end < 0 || end < start) { throw new MessagingException(String.format(Locale.US, "Invalid message set %d %d", start, end)); } if (start == 0 && end < 10) { end = 10; } messageBody = store.getMessagesXml(); headers.put("Brief", "t"); headers.put("Range", "rows=" + start + "-" + end); DataSet dataset = store.processRequest(this.folderUrl, "SEARCH", messageBody, headers); uids = dataset.getUids(); Map<String, String> uidToUrl = dataset.getUidToUrl(); uidsLength = uids.length; for (int i = 0; i < uidsLength; i++) { if (listener != null) { listener.messageStarted(uids[i], i, uidsLength); } WebDavMessage message = new WebDavMessage(uids[i], this); message.setUrl(uidToUrl.get(uids[i])); messages.add(message); if (listener != null) { listener.messageFinished(message, i, uidsLength); } } return messages; }
WebDavFolder extends Folder<WebDavMessage> { @Override public List<WebDavMessage> getMessages(int start, int end, Date earliestDate, MessageRetrievalListener<WebDavMessage> listener) throws MessagingException { List<WebDavMessage> messages = new ArrayList<WebDavMessage>(); String[] uids; Map<String, String> headers = new HashMap<String, String>(); int uidsLength; String messageBody; int prevStart = start; start = this.messageCount - end; end = start + (end - prevStart); if (start < 0 || end < 0 || end < start) { throw new MessagingException(String.format(Locale.US, "Invalid message set %d %d", start, end)); } if (start == 0 && end < 10) { end = 10; } messageBody = store.getMessagesXml(); headers.put("Brief", "t"); headers.put("Range", "rows=" + start + "-" + end); DataSet dataset = store.processRequest(this.folderUrl, "SEARCH", messageBody, headers); uids = dataset.getUids(); Map<String, String> uidToUrl = dataset.getUidToUrl(); uidsLength = uids.length; for (int i = 0; i < uidsLength; i++) { if (listener != null) { listener.messageStarted(uids[i], i, uidsLength); } WebDavMessage message = new WebDavMessage(uids[i], this); message.setUrl(uidToUrl.get(uids[i])); messages.add(message); if (listener != null) { listener.messageFinished(message, i, uidsLength); } } return messages; } }
WebDavFolder extends Folder<WebDavMessage> { @Override public List<WebDavMessage> getMessages(int start, int end, Date earliestDate, MessageRetrievalListener<WebDavMessage> listener) throws MessagingException { List<WebDavMessage> messages = new ArrayList<WebDavMessage>(); String[] uids; Map<String, String> headers = new HashMap<String, String>(); int uidsLength; String messageBody; int prevStart = start; start = this.messageCount - end; end = start + (end - prevStart); if (start < 0 || end < 0 || end < start) { throw new MessagingException(String.format(Locale.US, "Invalid message set %d %d", start, end)); } if (start == 0 && end < 10) { end = 10; } messageBody = store.getMessagesXml(); headers.put("Brief", "t"); headers.put("Range", "rows=" + start + "-" + end); DataSet dataset = store.processRequest(this.folderUrl, "SEARCH", messageBody, headers); uids = dataset.getUids(); Map<String, String> uidToUrl = dataset.getUidToUrl(); uidsLength = uids.length; for (int i = 0; i < uidsLength; i++) { if (listener != null) { listener.messageStarted(uids[i], i, uidsLength); } WebDavMessage message = new WebDavMessage(uids[i], this); message.setUrl(uidToUrl.get(uids[i])); messages.add(message); if (listener != null) { listener.messageFinished(message, i, uidsLength); } } return messages; } WebDavFolder(WebDavStore nStore, String id); }
WebDavFolder extends Folder<WebDavMessage> { @Override public List<WebDavMessage> getMessages(int start, int end, Date earliestDate, MessageRetrievalListener<WebDavMessage> listener) throws MessagingException { List<WebDavMessage> messages = new ArrayList<WebDavMessage>(); String[] uids; Map<String, String> headers = new HashMap<String, String>(); int uidsLength; String messageBody; int prevStart = start; start = this.messageCount - end; end = start + (end - prevStart); if (start < 0 || end < 0 || end < start) { throw new MessagingException(String.format(Locale.US, "Invalid message set %d %d", start, end)); } if (start == 0 && end < 10) { end = 10; } messageBody = store.getMessagesXml(); headers.put("Brief", "t"); headers.put("Range", "rows=" + start + "-" + end); DataSet dataset = store.processRequest(this.folderUrl, "SEARCH", messageBody, headers); uids = dataset.getUids(); Map<String, String> uidToUrl = dataset.getUidToUrl(); uidsLength = uids.length; for (int i = 0; i < uidsLength; i++) { if (listener != null) { listener.messageStarted(uids[i], i, uidsLength); } WebDavMessage message = new WebDavMessage(uids[i], this); message.setUrl(uidToUrl.get(uids[i])); messages.add(message); if (listener != null) { listener.messageFinished(message, i, uidsLength); } } return messages; } WebDavFolder(WebDavStore nStore, String id); void setUrl(String url); @Override void open(int mode); @Override Map<String, String> copyMessages(List<? extends Message> messages, Folder folder); @Override Map<String, String> moveMessages(List<? extends Message> messages, Folder folder); @Override void delete(List<? extends Message> msgs, String trashFolderName); @Override int getMessageCount(); @Override int getUnreadMessageCount(); @Override int getFlaggedMessageCount(); @Override boolean isOpen(); @Override int getMode(); @Override String getId(); @Override String getParentId(); @Override String getName(); @Override boolean exists(); @Override boolean canHaveSubFolders(); @Override void close(); @Override boolean create(FolderType type); @Override void delete(boolean recursive); @Override WebDavMessage getMessage(String uid); @Override List<WebDavMessage> getMessages(int start, int end, Date earliestDate, MessageRetrievalListener<WebDavMessage> listener); @Override boolean areMoreMessagesAvailable(int indexOfOldestMessage, Date earliestDate); @Override void fetch(List<WebDavMessage> messages, FetchProfile fp, MessageRetrievalListener<WebDavMessage> listener); @Override void setFlags(List<? extends Message> messages, final Set<Flag> flags, boolean value); @Override Map<String, String> appendMessages(List<? extends Message> messages); List<? extends Message> appendWebDavMessages(List<? extends Message> messages); @Override boolean equals(Object o); @Override String getUidFromMessageId(Message message); @Override void setFlags(final Set<Flag> flags, boolean value); String getUrl(); }
WebDavFolder extends Folder<WebDavMessage> { @Override public List<WebDavMessage> getMessages(int start, int end, Date earliestDate, MessageRetrievalListener<WebDavMessage> listener) throws MessagingException { List<WebDavMessage> messages = new ArrayList<WebDavMessage>(); String[] uids; Map<String, String> headers = new HashMap<String, String>(); int uidsLength; String messageBody; int prevStart = start; start = this.messageCount - end; end = start + (end - prevStart); if (start < 0 || end < 0 || end < start) { throw new MessagingException(String.format(Locale.US, "Invalid message set %d %d", start, end)); } if (start == 0 && end < 10) { end = 10; } messageBody = store.getMessagesXml(); headers.put("Brief", "t"); headers.put("Range", "rows=" + start + "-" + end); DataSet dataset = store.processRequest(this.folderUrl, "SEARCH", messageBody, headers); uids = dataset.getUids(); Map<String, String> uidToUrl = dataset.getUidToUrl(); uidsLength = uids.length; for (int i = 0; i < uidsLength; i++) { if (listener != null) { listener.messageStarted(uids[i], i, uidsLength); } WebDavMessage message = new WebDavMessage(uids[i], this); message.setUrl(uidToUrl.get(uids[i])); messages.add(message); if (listener != null) { listener.messageFinished(message, i, uidsLength); } } return messages; } WebDavFolder(WebDavStore nStore, String id); void setUrl(String url); @Override void open(int mode); @Override Map<String, String> copyMessages(List<? extends Message> messages, Folder folder); @Override Map<String, String> moveMessages(List<? extends Message> messages, Folder folder); @Override void delete(List<? extends Message> msgs, String trashFolderName); @Override int getMessageCount(); @Override int getUnreadMessageCount(); @Override int getFlaggedMessageCount(); @Override boolean isOpen(); @Override int getMode(); @Override String getId(); @Override String getParentId(); @Override String getName(); @Override boolean exists(); @Override boolean canHaveSubFolders(); @Override void close(); @Override boolean create(FolderType type); @Override void delete(boolean recursive); @Override WebDavMessage getMessage(String uid); @Override List<WebDavMessage> getMessages(int start, int end, Date earliestDate, MessageRetrievalListener<WebDavMessage> listener); @Override boolean areMoreMessagesAvailable(int indexOfOldestMessage, Date earliestDate); @Override void fetch(List<WebDavMessage> messages, FetchProfile fp, MessageRetrievalListener<WebDavMessage> listener); @Override void setFlags(List<? extends Message> messages, final Set<Flag> flags, boolean value); @Override Map<String, String> appendMessages(List<? extends Message> messages); List<? extends Message> appendWebDavMessages(List<? extends Message> messages); @Override boolean equals(Object o); @Override String getUidFromMessageId(Message message); @Override void setFlags(final Set<Flag> flags, boolean value); String getUrl();  }