Search in sources :

Example 41 with MessagingException

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

the class RemoteStore method getInstance.

/**
     * Get an instance of a remote mail store.
     */
public static synchronized Store getInstance(Context context, StoreConfig storeConfig) throws MessagingException {
    String uri = storeConfig.getStoreUri();
    if (uri.startsWith("local")) {
        throw new RuntimeException("Asked to get non-local Store object but given LocalStore URI");
    }
    Store store = sStores.get(uri);
    if (store == null) {
        if (uri.startsWith("imap")) {
            OAuth2TokenProvider oAuth2TokenProvider = null;
            store = new ImapStore(storeConfig, new DefaultTrustedSocketFactory(context), (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE), oAuth2TokenProvider);
        } else if (uri.startsWith("pop3")) {
            store = new Pop3Store(storeConfig, new DefaultTrustedSocketFactory(context));
        } else if (uri.startsWith("webdav")) {
            store = new WebDavStore(storeConfig, new WebDavHttpClient.WebDavHttpClientFactory());
        }
        if (store != null) {
            sStores.put(uri, store);
        }
    }
    if (store == null) {
        throw new MessagingException("Unable to locate an applicable Store for " + uri);
    }
    return store;
}
Also used : Pop3Store(com.fsck.k9.mail.store.pop3.Pop3Store) DefaultTrustedSocketFactory(com.fsck.k9.mail.ssl.DefaultTrustedSocketFactory) MessagingException(com.fsck.k9.mail.MessagingException) OAuth2TokenProvider(com.fsck.k9.mail.oauth.OAuth2TokenProvider) ConnectivityManager(android.net.ConnectivityManager) Pop3Store(com.fsck.k9.mail.store.pop3.Pop3Store) Store(com.fsck.k9.mail.Store) WebDavStore(com.fsck.k9.mail.store.webdav.WebDavStore) ImapStore(com.fsck.k9.mail.store.imap.ImapStore) ImapStore(com.fsck.k9.mail.store.imap.ImapStore) WebDavStore(com.fsck.k9.mail.store.webdav.WebDavStore)

Example 42 with MessagingException

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

the class ImapConnection method saslAuthExternal.

private void saslAuthExternal() throws IOException, MessagingException {
    try {
        String command = Commands.AUTHENTICATE_EXTERNAL + " " + Base64.encode(settings.getUsername());
        extractCapabilities(executeSimpleCommand(command, false));
    } catch (NegativeImapResponseException e) {
        /*
             * Provide notification to the user of a problem authenticating
             * using client certificates. We don't use an
             * AuthenticationFailedException because that would trigger a
             * "Username or password incorrect" notification in
             * AccountSetupCheckSettings.
             */
        throw new CertificateValidationException(e.getMessage());
    }
}
Also used : CertificateValidationException(com.fsck.k9.mail.CertificateValidationException)

Example 43 with MessagingException

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

the class ImapConnection method connect.

private Socket connect() throws GeneralSecurityException, MessagingException, IOException {
    Exception connectException = null;
    InetAddress[] inetAddresses = InetAddress.getAllByName(settings.getHost());
    for (InetAddress address : inetAddresses) {
        try {
            return connectToAddress(address);
        } catch (IOException e) {
            Log.w(LOG_TAG, "Could not connect to " + address, e);
            connectException = e;
        }
    }
    throw new MessagingException("Cannot connect to host", connectException);
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) IOException(java.io.IOException) InetAddress(java.net.InetAddress) CertificateValidationException(com.fsck.k9.mail.CertificateValidationException) GeneralSecurityException(java.security.GeneralSecurityException) KeyManagementException(java.security.KeyManagementException) SSLException(javax.net.ssl.SSLException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SocketException(java.net.SocketException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) MessagingException(com.fsck.k9.mail.MessagingException) AuthenticationFailedException(com.fsck.k9.mail.AuthenticationFailedException)

Example 44 with MessagingException

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

the class ImapConnection method login.

private void login() throws IOException, MessagingException {
    /*
         * Use quoted strings which permit spaces and quotes. (Using IMAP
         * string literals would be better, but some servers are broken
         * and don't parse them correctly.)
         */
    // escape double-quotes and backslash characters with a backslash
    Pattern p = Pattern.compile("[\\\\\"]");
    String replacement = "\\\\$0";
    String username = p.matcher(settings.getUsername()).replaceAll(replacement);
    String password = p.matcher(settings.getPassword()).replaceAll(replacement);
    try {
        String command = String.format(Commands.LOGIN + " \"%s\" \"%s\"", username, password);
        extractCapabilities(executeSimpleCommand(command, true));
    } catch (NegativeImapResponseException e) {
        throw new AuthenticationFailedException(e.getMessage());
    }
}
Also used : Pattern(java.util.regex.Pattern) AuthenticationFailedException(com.fsck.k9.mail.AuthenticationFailedException)

Example 45 with MessagingException

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

the class SmtpTransport method saslAuthCramMD5.

private void saslAuthCramMD5(String username, String password) throws MessagingException, AuthenticationFailedException, IOException {
    List<String> respList = executeCommand("AUTH CRAM-MD5").results;
    if (respList.size() != 1) {
        throw new MessagingException("Unable to negotiate CRAM-MD5");
    }
    String b64Nonce = respList.get(0);
    String b64CRAMString = Authentication.computeCramMd5(mUsername, mPassword, b64Nonce);
    try {
        executeSensitiveCommand(b64CRAMString);
    } catch (NegativeSmtpReplyException exception) {
        if (exception.getReplyCode() == SMTP_AUTHENTICATION_FAILURE_ERROR_CODE) {
            // Authentication credentials invalid
            throw new AuthenticationFailedException(exception.getMessage(), exception);
        } else {
            throw exception;
        }
    }
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) AuthenticationFailedException(com.fsck.k9.mail.AuthenticationFailedException)

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