@Override public InputStream getInputStream() throws MessagingException { try { return new FileInputStream(file); } catch (FileNotFoundException e) { throw new MessagingException("File not found", e); } }
@Override public Map<String, String> copyMessages(List<? extends Message> msgs, Folder folder) throws MessagingException { if (!(folder instanceof LocalFolder)) { throw new MessagingException("copyMessages called with incorrect Folder"); } return ((LocalFolder) folder).appendMessages(msgs, true); }
/** * Collect the viewable textual parts of a message. * @return A set of viewable parts of the message. * @throws MessagingException In case of an error. */ public static Set<Part> collectTextParts(Message message) throws MessagingException { try { return getTextParts(message); } catch (Exception e) { throw new MessagingException("Couldn't extract viewable parts", e); } }
@Override public List<LocalMessage> getMessages(int start, int end, Date earliestDate, MessageRetrievalListener<LocalMessage> listener) throws MessagingException { open(OPEN_MODE_RW); throw new MessagingException( "LocalStore.getMessages(int, int, MessageRetrievalListener) not yet implemented"); }
private void checkConnectionNotNull(ImapConnection conn) throws MessagingException { if (conn == null) { String message = "Could not establish connection for IDLE"; pushReceiver.pushError(message, null); throw new MessagingException(message); } }
private Date getDate(String value) throws MessagingException { try { if (value == null || "NIL".equals(value)) { return null; } return parseDate(value); } catch (ParseException pe) { throw new MessagingException("Unable to parse IMAP datetime '" + value + "' ", pe); } }
@Override public void open(int mode) throws MessagingException { internalOpen(mode); if (messageCount == -1) { throw new MessagingException("Did not find message count during open"); } }
private void checkConnectionIdleCapable(ImapConnection conn) throws MessagingException { if (!conn.isIdleCapable()) { stop = true; String message = "IMAP server is not IDLE capable: " + conn.toString(); pushReceiver.pushError(message, null); throw new MessagingException(message); } }
private void syncFolderOnConnect() throws MessagingException { processStoredUntaggedResponses(); if (messageCount == -1) { throw new MessagingException("Message count = -1 for idling"); } pushReceiver.syncFolder(ImapFolderPusher.this); }
public static void parse(final Part part, InputStream headerInputStream) throws MessagingException { MimeStreamParser parser = getMimeStreamParser(); parser.setContentHandler(new MessageHeaderParserContentHandler(part)); try { parser.parse(headerInputStream); } catch (MimeException me) { throw new MessagingException("Error parsing headers", me); } catch (IOException e) { throw new MessagingException("I/O error parsing headers", e); } }
@Override protected void buildMessageInternal() { queueMessageBuildException(new MessagingException("expected error")); } };
@Override public void checkSettings() throws MessagingException { try { ImapConnection connection = createImapConnection(); connection.open(); connection.close(); } catch (IOException ioe) { throw new MessagingException("Unable to connect", ioe); } }
@Override protected void buildMessageInternal() { queueMessageBuildException(new MessagingException("expected error")); } };
private MessagingException ioExceptionHandler(ImapConnection connection, IOException ioe) { Timber.e(ioe, "IOException for %s", getLogId()); if (connection != null) { connection.close(); } close(); return new MessagingException("IO Error", ioe); }
@Test(expected = MessagingException.class) public void open_withInboxFolderWithExceptionCreatingConnection_shouldThrow() throws MessagingException { when(mockStore.createConnection()).thenThrow(new MessagingException("Test")); folder.open(Folder.OPEN_MODE_RW); }
@Test(expected = MessagingException.class) public void open_withInboxFolder_whenStatCommandFails_shouldThrow() throws MessagingException { when(mockConnection.executeSimpleCommand(Pop3Commands.STAT_COMMAND)) .thenThrow(new MessagingException("Test")); folder.open(Folder.OPEN_MODE_RW); }
@Test public void listFoldersSynchronous_shouldNotNotifyFinishedAfterFailure() throws MessagingException { when(localStore.getPersonalNamespaces(false)).thenThrow(new MessagingException("Test")); controller.listFoldersSynchronous(account, true, listener); verify(listener, never()).listFoldersFinished(account); }
@Test public void listFoldersSynchronous_shouldNotifyFailureOnException() throws MessagingException { when(localStore.getPersonalNamespaces(false)).thenThrow(new MessagingException("Test")); controller.listFoldersSynchronous(account, true, listener); verify(listener).listFoldersFailed(account, "Test"); }
@Test public void searchRemoteMessagesSynchronous_shouldNotifyOnFailure() throws Exception { setupRemoteSearch(); when(backend.search(anyString(), anyString(), nullable(Set.class), nullable(Set.class))) .thenThrow(new MessagingException("Test")); controller.searchRemoteMessagesSynchronous(ACCOUNT_UUID, FOLDER_NAME, "query", reqFlags, forbiddenFlags, listener); verify(listener).remoteSearchFailed(null, "Test"); }
@Test public void searchRemoteMessagesSynchronous_shouldNotifyOnFinish() throws Exception { setupRemoteSearch(); when(backend.search(anyString(), nullable(String.class), nullable(Set.class), nullable(Set.class))) .thenThrow(new MessagingException("Test")); controller.searchRemoteMessagesSynchronous(ACCOUNT_UUID, FOLDER_NAME, "query", reqFlags, forbiddenFlags, listener); verify(listener).remoteSearchFinished(FOLDER_NAME, 0, 50, Collections.<String>emptyList()); }