@Override public String getUidFromMessageId(String messageId) throws MessagingException { throw new MessagingException("Cannot call getUidFromMessageId on LocalFolder"); }
Timber.v("Skipping sending message " + message.getUid()); notificationController.showSendFailedNotification(account, new MessagingException(message.getSubject())); continue; } catch (MessagingException e) { lastFailure = e; wasPermanentFailure = e.isPermanentFailure(); String errorMessage = e.getMessage(); outboxStateRepository.setSendAttemptError(messageId, errorMessage); } else if (outboxState.getNumberOfSendAttempts() + 1 >= MAX_SEND_ATTEMPTS) {
private void assertCheckOpenErrorMessage(String folderName, MessagingException e) { assertEquals("Folder " + folderName + " is not open.", e.getMessage()); }
@Test public void sendMessage_withMessageTooLarge_shouldThrow() throws Exception { Message message = getDefaultMessageBuilder() .setHasAttachments(true) .messageSize(1234L) .build(); MockSmtpServer server = createServerAndSetupForPlainAuthentication("SIZE 1000"); SmtpTransport transport = startServerAndCreateSmtpTransport(server); try { transport.sendMessage(message); fail("Expected message too large error"); } catch (MessagingException e) { assertTrue(e.isPermanentFailure()); assertEquals("Message too large for server", e.getMessage()); } //FIXME: Make sure connection was closed //server.verifyConnectionClosed(); }
@Test public void checkSettings_withOpenThrowing_shouldThrowMessagingException() throws Exception { ImapConnection imapConnection = mock(ImapConnection.class); doThrow(IOException.class).when(imapConnection).open(); imapStore.enqueueImapConnection(imapConnection); try { imapStore.checkSettings(); fail("Expected exception"); } catch (MessagingException e) { assertEquals("Unable to connect", e.getMessage()); assertNotNull(e.getCause()); assertEquals(IOException.class, e.getCause().getClass()); } }
if (me.isPermanentFailure()) { Timber.e("Failure of command '%s' was permanent, removing command from queue", command); localStore.removePendingCommand(processingCommand);
@Test public void open_withIoException_shouldThrowMessagingException() throws Exception { ImapFolder imapFolder = createFolder("Folder"); when(imapStore.getConnection()).thenReturn(imapConnection); doThrow(IOException.class).when(imapConnection).executeSimpleCommand("SELECT \"Folder\""); try { imapFolder.open(OPEN_MODE_RW); fail("Expected exception"); } catch (MessagingException e) { assertNotNull(e.getCause()); assertEquals(IOException.class, e.getCause().getClass()); } }
@Test public void copyMessages_withoutDestinationFolderOfWrongType_shouldThrow() throws Exception { ImapFolder sourceFolder = createFolder("Source"); Folder destinationFolder = mock(Folder.class); List<ImapMessage> messages = singletonList(mock(ImapMessage.class)); try { sourceFolder.copyMessages(messages, destinationFolder); fail("Expected exception"); } catch (MessagingException e) { assertEquals("ImapFolder.copyMessages passed non-ImapFolder", e.getMessage()); } }
@Test public void open_withConnectionError_shouldThrow() throws Exception { settings.setHost("127.1.2.3"); settings.setPort(143); ImapConnection imapConnection = createImapConnection( settings, socketFactory, connectivityManager, oAuth2TokenProvider); try { imapConnection.open(); fail("Expected exception"); } catch (MessagingException e) { assertEquals("Cannot connect to host", e.getMessage()); assertTrue(e.getCause() instanceof IOException); } }
public List<T> search(String queryString, final Set<Flag> requiredFlags, final Set<Flag> forbiddenFlags) throws MessagingException { throw new MessagingException("K-9 does not support searches on this folder type"); }
@Test public void search_withRemoteSearchDisabled_shouldThrow() throws Exception { ImapFolder folder = createFolder("Folder"); when(storeConfig.isAllowRemoteSearch()).thenReturn(false); try { folder.search("query", Collections.<Flag>emptySet(), Collections.<Flag>emptySet()); fail("Expected exception"); } catch (MessagingException e) { assertEquals("Your settings do not allow remote searching of this account", e.getMessage()); } }
@Override public InputStream getInputStream() throws MessagingException { try { return new FileInputStream(file); } catch (FileNotFoundException e) { throw new MessagingException("File not found", e); } }
@Test public void copyMessages_withClosedFolder_shouldThrow() throws Exception { ImapFolder sourceFolder = createFolder("Source"); ImapFolder destinationFolder = createFolder("Destination"); when(imapStore.getConnection()).thenReturn(imapConnection); when(imapStore.getCombinedPrefix()).thenReturn(""); List<ImapMessage> messages = singletonList(mock(ImapMessage.class)); try { sourceFolder.copyMessages(messages, destinationFolder); fail("Expected exception"); } catch (MessagingException e) { assertEquals("Folder Source is not open.", e.getMessage()); } }
@Override public void setEncoding(String encoding) throws MessagingException { if (!MimeUtil.ENC_7BIT.equalsIgnoreCase(encoding) && !MimeUtil.ENC_8BIT.equalsIgnoreCase(encoding)) { throw new MessagingException("Incompatible content-transfer-encoding for a multipart/* body"); } /* Nothing else to do. Each subpart has its own separate encoding */ }
@Test public void open_withoutExistsResponse_shouldThrowMessagingException() throws Exception { ImapFolder imapFolder = createFolder("Folder"); when(imapStore.getConnection()).thenReturn(imapConnection); List<ImapResponse> selectResponses = asList( createImapResponse("* OK [UIDNEXT 57576] Predicted next UID"), createImapResponse("2 OK [READ-WRITE] Select completed.") ); when(imapConnection.executeSimpleCommand("SELECT \"Folder\"")).thenReturn(selectResponses); try { imapFolder.open(OPEN_MODE_RW); fail("Expected exception"); } catch (MessagingException e) { assertEquals("Did not find message count during open", e.getMessage()); } }
@Override public void setEncoding(String encoding) throws MessagingException { if (!MimeUtil.ENC_7BIT.equalsIgnoreCase(encoding) && !MimeUtil.ENC_8BIT.equalsIgnoreCase(encoding)) { throw new MessagingException("Incompatible content-transfer-encoding for a message/rfc822 body"); } mEncoding = encoding; } }
@Test public void getUnreadMessageCount_connectionThrowsIOException_shouldThrowMessagingException() throws Exception { ImapFolder folder = createFolder("Folder"); prepareImapFolderForOpen(OPEN_MODE_RW); when(imapConnection.executeSimpleCommand("SEARCH 1:* UNSEEN NOT DELETED")).thenThrow(new IOException()); folder.open(OPEN_MODE_RW); try { folder.getUnreadMessageCount(); fail("Expected exception"); } catch (MessagingException e) { assertEquals("IO Error", e.getMessage()); } }
@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); }
@Test public void getHighestUid_imapConnectionThrowsIOException_shouldThrowMessagingException() throws Exception { ImapFolder folder = createFolder("Folder"); prepareImapFolderForOpen(OPEN_MODE_RW); doThrow(IOException.class).when(imapConnection).executeSimpleCommand("UID SEARCH *:*"); folder.open(OPEN_MODE_RW); try { folder.getHighestUid(); fail("Expected MessagingException"); } catch (MessagingException e) { assertEquals("IO Error", e.getMessage()); } }
/** * 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); } }