@Test public void appendWebDavMessages_sendsRequestUsingStore() throws MessagingException, IOException { List<Message> existingMessages = new ArrayList<>(); Message existingMessage = mock(Message.class); existingMessages.add(existingMessage); String messageUid = "testMessageUid"; when(existingMessage.getUid()).thenReturn(messageUid); folder.appendWebDavMessages(existingMessages); verify(mockStore).sendRequest(urlCaptor.capture(), eq("PUT"), entityCaptor.capture(), Matchers.<Map<String, String>>eq(null), eq(true)); assertTrue(urlCaptor.getValue().startsWith(storeUrl + "/" + folderName + "/" + messageUid)); assertTrue(urlCaptor.getValue().endsWith(".eml")); }
public List<? extends Message> appendWebDavMessages(List<? extends Message> messages) throws MessagingException { List<Message> retMessages = new ArrayList<Message>(messages.size()); QMailHttpClient httpclient = store.getHttpClient(); for (Message message : messages) { HttpGeneric httpmethod; HttpResponse response; StringEntity bodyEntity; int statusCode; try { ByteArrayOutputStream out; long size = message.getSize(); if (size > Integer.MAX_VALUE) { throw new MessagingException("message size > Integer.MAX_VALUE!"); } out = new ByteArrayOutputStream((int) size); open(Folder.OPEN_MODE_RW); EOLConvertingOutputStream msgOut = new EOLConvertingOutputStream( new BufferedOutputStream(out, 1024)); message.writeTo(msgOut); msgOut.flush(); bodyEntity = new StringEntity(out.toString(), "UTF-8"); bodyEntity.setContentType("message/rfc822"); String messageURL = folderUrl; if (!messageURL.endsWith("/")) { messageURL += "/"; } messageURL += encodeUtf8(message.getUid() + ":" + System.currentTimeMillis() + ".eml"); Timber.i("Uploading message as %s", messageURL); store.sendRequest(messageURL, "PUT", bodyEntity, null, true); WebDavMessage retMessage = new WebDavMessage(message.getUid(), this); retMessage.setUrl(messageURL); retMessages.add(retMessage); } catch (Exception e) { throw new MessagingException("Unable to append", e); } } return retMessages; }
WebDavFolder extends Folder<WebDavMessage> { public List<? extends Message> appendWebDavMessages(List<? extends Message> messages) throws MessagingException { List<Message> retMessages = new ArrayList<Message>(messages.size()); QMailHttpClient httpclient = store.getHttpClient(); for (Message message : messages) { HttpGeneric httpmethod; HttpResponse response; StringEntity bodyEntity; int statusCode; try { ByteArrayOutputStream out; long size = message.getSize(); if (size > Integer.MAX_VALUE) { throw new MessagingException("message size > Integer.MAX_VALUE!"); } out = new ByteArrayOutputStream((int) size); open(Folder.OPEN_MODE_RW); EOLConvertingOutputStream msgOut = new EOLConvertingOutputStream( new BufferedOutputStream(out, 1024)); message.writeTo(msgOut); msgOut.flush(); bodyEntity = new StringEntity(out.toString(), "UTF-8"); bodyEntity.setContentType("message/rfc822"); String messageURL = folderUrl; if (!messageURL.endsWith("/")) { messageURL += "/"; } messageURL += encodeUtf8(message.getUid() + ":" + System.currentTimeMillis() + ".eml"); Timber.i("Uploading message as %s", messageURL); store.sendRequest(messageURL, "PUT", bodyEntity, null, true); WebDavMessage retMessage = new WebDavMessage(message.getUid(), this); retMessage.setUrl(messageURL); retMessages.add(retMessage); } catch (Exception e) { throw new MessagingException("Unable to append", e); } } return retMessages; } }
WebDavFolder extends Folder<WebDavMessage> { public List<? extends Message> appendWebDavMessages(List<? extends Message> messages) throws MessagingException { List<Message> retMessages = new ArrayList<Message>(messages.size()); QMailHttpClient httpclient = store.getHttpClient(); for (Message message : messages) { HttpGeneric httpmethod; HttpResponse response; StringEntity bodyEntity; int statusCode; try { ByteArrayOutputStream out; long size = message.getSize(); if (size > Integer.MAX_VALUE) { throw new MessagingException("message size > Integer.MAX_VALUE!"); } out = new ByteArrayOutputStream((int) size); open(Folder.OPEN_MODE_RW); EOLConvertingOutputStream msgOut = new EOLConvertingOutputStream( new BufferedOutputStream(out, 1024)); message.writeTo(msgOut); msgOut.flush(); bodyEntity = new StringEntity(out.toString(), "UTF-8"); bodyEntity.setContentType("message/rfc822"); String messageURL = folderUrl; if (!messageURL.endsWith("/")) { messageURL += "/"; } messageURL += encodeUtf8(message.getUid() + ":" + System.currentTimeMillis() + ".eml"); Timber.i("Uploading message as %s", messageURL); store.sendRequest(messageURL, "PUT", bodyEntity, null, true); WebDavMessage retMessage = new WebDavMessage(message.getUid(), this); retMessage.setUrl(messageURL); retMessages.add(retMessage); } catch (Exception e) { throw new MessagingException("Unable to append", e); } } return retMessages; } WebDavFolder(WebDavStore nStore, String id); }
WebDavFolder extends Folder<WebDavMessage> { public List<? extends Message> appendWebDavMessages(List<? extends Message> messages) throws MessagingException { List<Message> retMessages = new ArrayList<Message>(messages.size()); QMailHttpClient httpclient = store.getHttpClient(); for (Message message : messages) { HttpGeneric httpmethod; HttpResponse response; StringEntity bodyEntity; int statusCode; try { ByteArrayOutputStream out; long size = message.getSize(); if (size > Integer.MAX_VALUE) { throw new MessagingException("message size > Integer.MAX_VALUE!"); } out = new ByteArrayOutputStream((int) size); open(Folder.OPEN_MODE_RW); EOLConvertingOutputStream msgOut = new EOLConvertingOutputStream( new BufferedOutputStream(out, 1024)); message.writeTo(msgOut); msgOut.flush(); bodyEntity = new StringEntity(out.toString(), "UTF-8"); bodyEntity.setContentType("message/rfc822"); String messageURL = folderUrl; if (!messageURL.endsWith("/")) { messageURL += "/"; } messageURL += encodeUtf8(message.getUid() + ":" + System.currentTimeMillis() + ".eml"); Timber.i("Uploading message as %s", messageURL); store.sendRequest(messageURL, "PUT", bodyEntity, null, true); WebDavMessage retMessage = new WebDavMessage(message.getUid(), this); retMessage.setUrl(messageURL); retMessages.add(retMessage); } catch (Exception e) { throw new MessagingException("Unable to append", e); } } return retMessages; } 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> { public List<? extends Message> appendWebDavMessages(List<? extends Message> messages) throws MessagingException { List<Message> retMessages = new ArrayList<Message>(messages.size()); QMailHttpClient httpclient = store.getHttpClient(); for (Message message : messages) { HttpGeneric httpmethod; HttpResponse response; StringEntity bodyEntity; int statusCode; try { ByteArrayOutputStream out; long size = message.getSize(); if (size > Integer.MAX_VALUE) { throw new MessagingException("message size > Integer.MAX_VALUE!"); } out = new ByteArrayOutputStream((int) size); open(Folder.OPEN_MODE_RW); EOLConvertingOutputStream msgOut = new EOLConvertingOutputStream( new BufferedOutputStream(out, 1024)); message.writeTo(msgOut); msgOut.flush(); bodyEntity = new StringEntity(out.toString(), "UTF-8"); bodyEntity.setContentType("message/rfc822"); String messageURL = folderUrl; if (!messageURL.endsWith("/")) { messageURL += "/"; } messageURL += encodeUtf8(message.getUid() + ":" + System.currentTimeMillis() + ".eml"); Timber.i("Uploading message as %s", messageURL); store.sendRequest(messageURL, "PUT", bodyEntity, null, true); WebDavMessage retMessage = new WebDavMessage(message.getUid(), this); retMessage.setUrl(messageURL); retMessages.add(retMessage); } catch (Exception e) { throw new MessagingException("Unable to append", e); } } return retMessages; } 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();  }