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;
}
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());
}
}
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);
}
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());
}
}
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;
}
}
}
Aggregations