mirror of
https://github.com/moparisthebest/k-9
synced 2024-12-24 08:38:51 -05:00
Fix issue 6269: IMAP LOGIN failure
Some IMAP servers are broken and don't correctly handle string literals with the LOGIN command. This switches to using quoted strings instead. This is what Thunderbird does.
This commit is contained in:
parent
18da76f4aa
commit
a7898fa2eb
@ -46,6 +46,7 @@ import java.util.StringTokenizer;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
import java.util.zip.Inflater;
|
import java.util.zip.Inflater;
|
||||||
import java.util.zip.InflaterInputStream;
|
import java.util.zip.InflaterInputStream;
|
||||||
|
|
||||||
@ -127,7 +128,6 @@ public class ImapStore extends Store {
|
|||||||
private static final String CAPABILITY_AUTH_CRAM_MD5 = "AUTH=CRAM-MD5";
|
private static final String CAPABILITY_AUTH_CRAM_MD5 = "AUTH=CRAM-MD5";
|
||||||
private static final String CAPABILITY_AUTH_PLAIN = "AUTH=PLAIN";
|
private static final String CAPABILITY_AUTH_PLAIN = "AUTH=PLAIN";
|
||||||
private static final String CAPABILITY_LOGINDISABLED = "LOGINDISABLED";
|
private static final String CAPABILITY_LOGINDISABLED = "LOGINDISABLED";
|
||||||
private static final String CAPABILITY_LITERAL_PLUS = "LITERAL+";
|
|
||||||
private static final String COMMAND_IDLE = "IDLE";
|
private static final String COMMAND_IDLE = "IDLE";
|
||||||
private static final String CAPABILITY_NAMESPACE = "NAMESPACE";
|
private static final String CAPABILITY_NAMESPACE = "NAMESPACE";
|
||||||
private static final String COMMAND_NAMESPACE = "NAMESPACE";
|
private static final String COMMAND_NAMESPACE = "NAMESPACE";
|
||||||
@ -2655,29 +2655,23 @@ public class ImapStore extends Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void login() throws IOException, MessagingException {
|
protected void login() throws IOException, MessagingException {
|
||||||
boolean hasLiteralPlus = hasCapability(CAPABILITY_LITERAL_PLUS);
|
/*
|
||||||
String tag;
|
* Use quoted strings which permit spaces and quotes. (Using IMAP
|
||||||
byte[] username = mSettings.getUsername().getBytes();
|
* string literals would be better, but some servers are broken
|
||||||
byte[] password = mSettings.getPassword().getBytes();
|
* and don't parse them correctly.)
|
||||||
tag = sendCommand(String.format(Locale.US, "LOGIN {%d%s}",
|
*/
|
||||||
username.length, hasLiteralPlus ? "+" : ""), true);
|
|
||||||
if (!hasLiteralPlus) {
|
// escape double-quotes and backslash characters with a backslash
|
||||||
readContinuationResponse(tag);
|
Pattern p = Pattern.compile("[\\\\\"]");
|
||||||
}
|
String replacement = "\\\\$0";
|
||||||
mOut.write(username);
|
String username = p.matcher(mSettings.getUsername()).replaceAll(
|
||||||
mOut.write(String.format(Locale.US, " {%d%s}\r\n", password.length,
|
replacement);
|
||||||
hasLiteralPlus ? "+" : "").getBytes());
|
String password = p.matcher(mSettings.getPassword()).replaceAll(
|
||||||
if (!hasLiteralPlus) {
|
replacement);
|
||||||
mOut.flush();
|
|
||||||
readContinuationResponse(tag);
|
|
||||||
}
|
|
||||||
mOut.write(password);
|
|
||||||
mOut.write('\r');
|
|
||||||
mOut.write('\n');
|
|
||||||
mOut.flush();
|
|
||||||
try {
|
try {
|
||||||
receiveCapabilities(readStatusResponse(tag, "LOGIN", null));
|
receiveCapabilities(executeSimpleCommand(
|
||||||
} catch (MessagingException e) {
|
String.format("LOGIN \"%s\" \"%s\"", username, password), true));
|
||||||
|
} catch (ImapException e) {
|
||||||
throw new AuthenticationFailedException(e.getMessage());
|
throw new AuthenticationFailedException(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user