Search in sources :

Example 81 with MessagingException

use of com.fsck.k9.mail.MessagingException in project k-9 by k9mail.

the class RealImapStore method checkSettings.

public void checkSettings() throws MessagingException {
    try {
        ImapConnection connection = createImapConnection();
        connection.open();
        connection.close();
    } catch (IOException ioe) {
        throw new MessagingException("Unable to connect", ioe);
    }
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) IOException(java.io.IOException)

Example 82 with MessagingException

use of com.fsck.k9.mail.MessagingException in project k-9 by k9mail.

the class RealImapConnection method executeCommandWithIdSet.

@Override
@NotNull
public synchronized List<ImapResponse> executeCommandWithIdSet(@NotNull String commandPrefix, @NotNull String commandSuffix, @NotNull Set<Long> ids) throws IOException, MessagingException {
    GroupedIds groupedIds = IdGrouper.groupIds(ids);
    List<String> splitCommands = ImapCommandSplitter.splitCommand(commandPrefix, commandSuffix, groupedIds, getLineLengthLimit());
    List<ImapResponse> responses = new ArrayList<>();
    for (String splitCommand : splitCommands) {
        responses.addAll(executeSimpleCommand(splitCommand));
    }
    return responses;
}
Also used : GroupedIds(com.fsck.k9.mail.store.imap.IdGrouper.GroupedIds) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 83 with MessagingException

use of com.fsck.k9.mail.MessagingException in project k-9 by k9mail.

the class RealImapConnection method open.

@Override
public synchronized void open() throws IOException, MessagingException {
    if (open) {
        return;
    } else if (stacktraceForClose != null) {
        throw new IllegalStateException("open() called after close(). " + "Check wrapped exception to see where close() was called.", stacktraceForClose);
    }
    open = true;
    boolean authSuccess = false;
    nextCommandTag = 1;
    adjustDNSCacheTTL();
    try {
        socket = connect();
        configureSocket();
        setUpStreamsAndParserFromSocket();
        readInitialResponse();
        requestCapabilitiesIfNecessary();
        upgradeToTlsIfNecessary();
        List<ImapResponse> responses = authenticate();
        authSuccess = true;
        extractOrRequestCapabilities(responses);
        enableCompressionIfRequested();
        retrievePathPrefixIfNecessary();
        retrievePathDelimiterIfNecessary();
    } catch (SSLException e) {
        handleSslException(e);
    } catch (ConnectException e) {
        handleConnectException(e);
    } catch (GeneralSecurityException e) {
        throw new MessagingException("Unable to open connection to IMAP server due to security error.", e);
    } finally {
        if (!authSuccess) {
            Timber.e("Failed to login, closing connection for %s", getLogId());
            close();
        }
    }
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) GeneralSecurityException(java.security.GeneralSecurityException) SSLException(javax.net.ssl.SSLException) ConnectException(java.net.ConnectException)

Example 84 with MessagingException

use of com.fsck.k9.mail.MessagingException in project k-9 by k9mail.

the class MessageExtractorTest method getTextFromPart_withExceptionThrownGettingInputStream_shouldReturnNull.

@Test
public void getTextFromPart_withExceptionThrownGettingInputStream_shouldReturnNull() throws Exception {
    part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "text/html");
    Body body = mock(Body.class);
    when(body.getInputStream()).thenThrow(new MessagingException("Test"));
    part.setBody(body);
    String result = MessageExtractor.getTextFromPart(part);
    assertNull(result);
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) Body(com.fsck.k9.mail.Body) BinaryMemoryBody(com.fsck.k9.mailstore.BinaryMemoryBody) Test(org.junit.Test)

Example 85 with MessagingException

use of com.fsck.k9.mail.MessagingException in project k-9 by k9mail.

the class AttachmentProvider method getAttachmentDataSource.

@Nullable
private OpenPgpDataSource getAttachmentDataSource(String accountUuid, String attachmentId) throws MessagingException {
    final Account account = Preferences.getPreferences(getContext()).getAccount(accountUuid);
    LocalStore localStore = DI.get(LocalStoreProvider.class).getInstance(account);
    return localStore.getAttachmentDataSource(attachmentId);
}
Also used : Account(com.fsck.k9.Account) LocalStore(com.fsck.k9.mailstore.LocalStore) LocalStoreProvider(com.fsck.k9.mailstore.LocalStoreProvider) Nullable(androidx.annotation.Nullable)

Aggregations

MessagingException (com.fsck.k9.mail.MessagingException)159 Test (org.junit.Test)73 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)52 LocalFolder (com.fsck.k9.mailstore.LocalFolder)49 LocalStore (com.fsck.k9.mailstore.LocalStore)49 ArrayList (java.util.ArrayList)49 Message (com.fsck.k9.mail.Message)44 LocalMessage (com.fsck.k9.mailstore.LocalMessage)42 IOException (java.io.IOException)42 FetchProfile (com.fsck.k9.mail.FetchProfile)30 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)28 ByteArrayOutputStream (java.io.ByteArrayOutputStream)27 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)26 BodyPart (com.fsck.k9.mail.BodyPart)23 Part (com.fsck.k9.mail.Part)22 Account (com.fsck.k9.Account)21 Body (com.fsck.k9.mail.Body)21 TextBody (com.fsck.k9.mail.internet.TextBody)21 Date (java.util.Date)20 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)18