mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-24 02:12:15 -05:00
Remove URLEncodingHelper dependency
This commit is contained in:
parent
8ef9eae0d6
commit
238c1650c5
@ -1,6 +1,9 @@
|
|||||||
|
|
||||||
package com.fsck.k9.mail;
|
package com.fsck.k9.mail;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLDecoder;
|
||||||
|
import java.net.URLEncoder;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,4 +50,20 @@ public abstract class Store {
|
|||||||
public Pusher getPusher(PushReceiver receiver) {
|
public Pusher getPusher(PushReceiver receiver) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static String decodeUtf8(String s) {
|
||||||
|
try {
|
||||||
|
return URLDecoder.decode(s, "UTF-8");
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw new RuntimeException("UTF-8 not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static String encodeUtf8(String s) {
|
||||||
|
try {
|
||||||
|
return URLEncoder.encode(s, "UTF-8");
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw new RuntimeException("UTF-8 not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,10 @@ import com.fsck.k9.mail.store.StoreConfig;
|
|||||||
import com.fsck.k9.mail.transport.SmtpTransport;
|
import com.fsck.k9.mail.transport.SmtpTransport;
|
||||||
import com.fsck.k9.mail.transport.WebDavTransport;
|
import com.fsck.k9.mail.transport.WebDavTransport;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLDecoder;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
|
||||||
public abstract class Transport {
|
public abstract class Transport {
|
||||||
protected static final int SOCKET_CONNECT_TIMEOUT = 10000;
|
protected static final int SOCKET_CONNECT_TIMEOUT = 10000;
|
||||||
|
|
||||||
@ -71,4 +75,19 @@ public abstract class Transport {
|
|||||||
public abstract void sendMessage(Message message) throws MessagingException;
|
public abstract void sendMessage(Message message) throws MessagingException;
|
||||||
|
|
||||||
public abstract void close();
|
public abstract void close();
|
||||||
|
|
||||||
|
protected static String encodeUtf8(String s) {
|
||||||
|
try {
|
||||||
|
return URLEncoder.encode(s, "UTF-8");
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw new RuntimeException("UTF-8 not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected static String decodeUtf8(String s) {
|
||||||
|
try {
|
||||||
|
return URLDecoder.decode(s, "UTF-8");
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw new RuntimeException("UTF-8 not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,6 @@ import android.util.Log;
|
|||||||
|
|
||||||
import com.fsck.k9.K9;
|
import com.fsck.k9.K9;
|
||||||
import com.fsck.k9.R;
|
import com.fsck.k9.R;
|
||||||
import com.fsck.k9.helper.UrlEncodingHelper;
|
|
||||||
import com.fsck.k9.helper.power.TracingPowerManager;
|
import com.fsck.k9.helper.power.TracingPowerManager;
|
||||||
import com.fsck.k9.helper.power.TracingPowerManager.TracingWakeLock;
|
import com.fsck.k9.helper.power.TracingPowerManager.TracingWakeLock;
|
||||||
import com.fsck.k9.mail.AuthType;
|
import com.fsck.k9.mail.AuthType;
|
||||||
@ -197,19 +196,19 @@ public class ImapStore extends RemoteStore {
|
|||||||
if (userinfo.endsWith(":")) {
|
if (userinfo.endsWith(":")) {
|
||||||
// Password is empty. This can only happen after an account was imported.
|
// Password is empty. This can only happen after an account was imported.
|
||||||
authenticationType = AuthType.valueOf(userInfoParts[0]);
|
authenticationType = AuthType.valueOf(userInfoParts[0]);
|
||||||
username = UrlEncodingHelper.decodeUtf8(userInfoParts[1]);
|
username = decodeUtf8(userInfoParts[1]);
|
||||||
} else if (userInfoParts.length == 2) {
|
} else if (userInfoParts.length == 2) {
|
||||||
authenticationType = AuthType.PLAIN;
|
authenticationType = AuthType.PLAIN;
|
||||||
username = UrlEncodingHelper.decodeUtf8(userInfoParts[0]);
|
username = decodeUtf8(userInfoParts[0]);
|
||||||
password = UrlEncodingHelper.decodeUtf8(userInfoParts[1]);
|
password = decodeUtf8(userInfoParts[1]);
|
||||||
} else if (userInfoParts.length == 3) {
|
} else if (userInfoParts.length == 3) {
|
||||||
authenticationType = AuthType.valueOf(userInfoParts[0]);
|
authenticationType = AuthType.valueOf(userInfoParts[0]);
|
||||||
username = UrlEncodingHelper.decodeUtf8(userInfoParts[1]);
|
username = decodeUtf8(userInfoParts[1]);
|
||||||
|
|
||||||
if (AuthType.EXTERNAL == authenticationType) {
|
if (AuthType.EXTERNAL == authenticationType) {
|
||||||
clientCertificateAlias = UrlEncodingHelper.decodeUtf8(userInfoParts[2]);
|
clientCertificateAlias = decodeUtf8(userInfoParts[2]);
|
||||||
} else {
|
} else {
|
||||||
password = UrlEncodingHelper.decodeUtf8(userInfoParts[2]);
|
password = decodeUtf8(userInfoParts[2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -248,11 +247,11 @@ public class ImapStore extends RemoteStore {
|
|||||||
* @see ImapStore#decodeUri(String)
|
* @see ImapStore#decodeUri(String)
|
||||||
*/
|
*/
|
||||||
public static String createUri(ServerSettings server) {
|
public static String createUri(ServerSettings server) {
|
||||||
String userEnc = UrlEncodingHelper.encodeUtf8(server.username);
|
String userEnc = encodeUtf8(server.username);
|
||||||
String passwordEnc = (server.password != null) ?
|
String passwordEnc = (server.password != null) ?
|
||||||
UrlEncodingHelper.encodeUtf8(server.password) : "";
|
encodeUtf8(server.password) : "";
|
||||||
String clientCertificateAliasEnc = (server.clientCertificateAlias != null) ?
|
String clientCertificateAliasEnc = (server.clientCertificateAlias != null) ?
|
||||||
UrlEncodingHelper.encodeUtf8(server.clientCertificateAlias) : "";
|
encodeUtf8(server.clientCertificateAlias) : "";
|
||||||
|
|
||||||
String scheme;
|
String scheme;
|
||||||
switch (server.connectionSecurity) {
|
switch (server.connectionSecurity) {
|
||||||
|
@ -5,7 +5,6 @@ import android.util.Log;
|
|||||||
|
|
||||||
import com.fsck.k9.K9;
|
import com.fsck.k9.K9;
|
||||||
import com.fsck.k9.R;
|
import com.fsck.k9.R;
|
||||||
import com.fsck.k9.helper.UrlEncodingHelper;
|
|
||||||
import com.fsck.k9.mail.*;
|
import com.fsck.k9.mail.*;
|
||||||
import com.fsck.k9.mail.filter.Base64;
|
import com.fsck.k9.mail.filter.Base64;
|
||||||
import com.fsck.k9.mail.filter.Hex;
|
import com.fsck.k9.mail.filter.Hex;
|
||||||
@ -125,12 +124,12 @@ public class Pop3Store extends RemoteStore {
|
|||||||
passwordIndex++;
|
passwordIndex++;
|
||||||
authType = AuthType.valueOf(userInfoParts[0]);
|
authType = AuthType.valueOf(userInfoParts[0]);
|
||||||
}
|
}
|
||||||
username = UrlEncodingHelper.decodeUtf8(userInfoParts[userIndex]);
|
username = decodeUtf8(userInfoParts[userIndex]);
|
||||||
if (userInfoParts.length > passwordIndex) {
|
if (userInfoParts.length > passwordIndex) {
|
||||||
if (authType == AuthType.EXTERNAL) {
|
if (authType == AuthType.EXTERNAL) {
|
||||||
clientCertificateAlias = UrlEncodingHelper.decodeUtf8(userInfoParts[passwordIndex]);
|
clientCertificateAlias = decodeUtf8(userInfoParts[passwordIndex]);
|
||||||
} else {
|
} else {
|
||||||
password = UrlEncodingHelper.decodeUtf8(userInfoParts[passwordIndex]);
|
password = decodeUtf8(userInfoParts[passwordIndex]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -151,11 +150,11 @@ public class Pop3Store extends RemoteStore {
|
|||||||
* @see Pop3Store#decodeUri(String)
|
* @see Pop3Store#decodeUri(String)
|
||||||
*/
|
*/
|
||||||
public static String createUri(ServerSettings server) {
|
public static String createUri(ServerSettings server) {
|
||||||
String userEnc = UrlEncodingHelper.encodeUtf8(server.username);
|
String userEnc = encodeUtf8(server.username);
|
||||||
String passwordEnc = (server.password != null) ?
|
String passwordEnc = (server.password != null) ?
|
||||||
UrlEncodingHelper.encodeUtf8(server.password) : "";
|
encodeUtf8(server.password) : "";
|
||||||
String clientCertificateAliasEnc = (server.clientCertificateAlias != null) ?
|
String clientCertificateAliasEnc = (server.clientCertificateAlias != null) ?
|
||||||
UrlEncodingHelper.encodeUtf8(server.clientCertificateAlias) : "";
|
encodeUtf8(server.clientCertificateAlias) : "";
|
||||||
|
|
||||||
String scheme;
|
String scheme;
|
||||||
switch (server.connectionSecurity) {
|
switch (server.connectionSecurity) {
|
||||||
|
@ -4,7 +4,6 @@ import android.util.Log;
|
|||||||
|
|
||||||
import com.fsck.k9.K9;
|
import com.fsck.k9.K9;
|
||||||
|
|
||||||
import com.fsck.k9.helper.UrlEncodingHelper;
|
|
||||||
import com.fsck.k9.mail.*;
|
import com.fsck.k9.mail.*;
|
||||||
import com.fsck.k9.mail.filter.Base64;
|
import com.fsck.k9.mail.filter.Base64;
|
||||||
import com.fsck.k9.mail.filter.EOLConvertingOutputStream;
|
import com.fsck.k9.mail.filter.EOLConvertingOutputStream;
|
||||||
@ -137,7 +136,7 @@ public class WebDavStore extends RemoteStore {
|
|||||||
String userInfo = webDavUri.getUserInfo();
|
String userInfo = webDavUri.getUserInfo();
|
||||||
if (userInfo != null) {
|
if (userInfo != null) {
|
||||||
String[] userInfoParts = userInfo.split(":");
|
String[] userInfoParts = userInfo.split(":");
|
||||||
username = UrlEncodingHelper.decodeUtf8(userInfoParts[0]);
|
username = decodeUtf8(userInfoParts[0]);
|
||||||
String userParts[] = username.split("\\\\", 2);
|
String userParts[] = username.split("\\\\", 2);
|
||||||
|
|
||||||
if (userParts.length > 1) {
|
if (userParts.length > 1) {
|
||||||
@ -146,7 +145,7 @@ public class WebDavStore extends RemoteStore {
|
|||||||
alias = username;
|
alias = username;
|
||||||
}
|
}
|
||||||
if (userInfoParts.length > 1) {
|
if (userInfoParts.length > 1) {
|
||||||
password = UrlEncodingHelper.decodeUtf8(userInfoParts[1]);
|
password = decodeUtf8(userInfoParts[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,9 +185,9 @@ public class WebDavStore extends RemoteStore {
|
|||||||
* @see WebDavStore#decodeUri(String)
|
* @see WebDavStore#decodeUri(String)
|
||||||
*/
|
*/
|
||||||
public static String createUri(ServerSettings server) {
|
public static String createUri(ServerSettings server) {
|
||||||
String userEnc = UrlEncodingHelper.encodeUtf8(server.username);
|
String userEnc = encodeUtf8(server.username);
|
||||||
String passwordEnc = (server.password != null) ?
|
String passwordEnc = (server.password != null) ?
|
||||||
UrlEncodingHelper.encodeUtf8(server.password) : "";
|
encodeUtf8(server.password) : "";
|
||||||
|
|
||||||
String scheme;
|
String scheme;
|
||||||
switch (server.connectionSecurity) {
|
switch (server.connectionSecurity) {
|
||||||
@ -474,7 +473,7 @@ public class WebDavStore extends RemoteStore {
|
|||||||
|
|
||||||
// Decodes the url-encoded folder name (i.e. "My%20folder" => "My Folder"
|
// Decodes the url-encoded folder name (i.e. "My%20folder" => "My Folder"
|
||||||
|
|
||||||
return UrlEncodingHelper.decodeUtf8(fullPathName);
|
return decodeUtf8(fullPathName);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -1237,9 +1236,9 @@ public class WebDavStore extends RemoteStore {
|
|||||||
String url = "";
|
String url = "";
|
||||||
for (int i = 0, count = urlParts.length; i < count; i++) {
|
for (int i = 0, count = urlParts.length; i < count; i++) {
|
||||||
if (i != 0) {
|
if (i != 0) {
|
||||||
url = url + "/" + UrlEncodingHelper.encodeUtf8(urlParts[i]);
|
url = url + "/" + encodeUtf8(urlParts[i]);
|
||||||
} else {
|
} else {
|
||||||
url = UrlEncodingHelper.encodeUtf8(urlParts[i]);
|
url = encodeUtf8(urlParts[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
encodedName = url;
|
encodedName = url;
|
||||||
@ -1880,7 +1879,7 @@ public class WebDavStore extends RemoteStore {
|
|||||||
if (!messageURL.endsWith("/")) {
|
if (!messageURL.endsWith("/")) {
|
||||||
messageURL += "/";
|
messageURL += "/";
|
||||||
}
|
}
|
||||||
messageURL += UrlEncodingHelper.encodeUtf8(message.getUid() + ":" + System.currentTimeMillis() + ".eml");
|
messageURL += encodeUtf8(message.getUid() + ":" + System.currentTimeMillis() + ".eml");
|
||||||
|
|
||||||
Log.i(K9.LOG_TAG, "Uploading message as " + messageURL);
|
Log.i(K9.LOG_TAG, "Uploading message as " + messageURL);
|
||||||
|
|
||||||
@ -1967,8 +1966,8 @@ public class WebDavStore extends RemoteStore {
|
|||||||
* We have to decode, then encode the URL because Exchange likes to not properly encode all characters
|
* We have to decode, then encode the URL because Exchange likes to not properly encode all characters
|
||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
end = UrlEncodingHelper.decodeUtf8(end);
|
end = decodeUtf8(end);
|
||||||
end = UrlEncodingHelper.encodeUtf8(end);
|
end = encodeUtf8(end);
|
||||||
end = end.replaceAll("\\+", "%20");
|
end = end.replaceAll("\\+", "%20");
|
||||||
} catch (IllegalArgumentException iae) {
|
} catch (IllegalArgumentException iae) {
|
||||||
Log.e(K9.LOG_TAG, "IllegalArgumentException caught in setUrl: " + iae + "\nTrace: "
|
Log.e(K9.LOG_TAG, "IllegalArgumentException caught in setUrl: " + iae + "\nTrace: "
|
||||||
@ -2372,8 +2371,8 @@ public class WebDavStore extends RemoteStore {
|
|||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
if (length > 3) {
|
if (length > 3) {
|
||||||
end = UrlEncodingHelper.decodeUtf8(end);
|
end = decodeUtf8(end);
|
||||||
end = UrlEncodingHelper.encodeUtf8(end);
|
end = encodeUtf8(end);
|
||||||
end = end.replaceAll("\\+", "%20");
|
end = end.replaceAll("\\+", "%20");
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException iae) {
|
} catch (IllegalArgumentException iae) {
|
||||||
|
@ -5,7 +5,6 @@ import android.util.Log;
|
|||||||
|
|
||||||
import com.fsck.k9.K9;
|
import com.fsck.k9.K9;
|
||||||
import com.fsck.k9.R;
|
import com.fsck.k9.R;
|
||||||
import com.fsck.k9.helper.UrlEncodingHelper;
|
|
||||||
import com.fsck.k9.mail.*;
|
import com.fsck.k9.mail.*;
|
||||||
import com.fsck.k9.mail.Message.RecipientType;
|
import com.fsck.k9.mail.Message.RecipientType;
|
||||||
import com.fsck.k9.mail.filter.Base64;
|
import com.fsck.k9.mail.filter.Base64;
|
||||||
@ -94,19 +93,19 @@ public class SmtpTransport extends Transport {
|
|||||||
String[] userInfoParts = smtpUri.getUserInfo().split(":");
|
String[] userInfoParts = smtpUri.getUserInfo().split(":");
|
||||||
if (userInfoParts.length == 1) {
|
if (userInfoParts.length == 1) {
|
||||||
authType = AuthType.PLAIN;
|
authType = AuthType.PLAIN;
|
||||||
username = UrlEncodingHelper.decodeUtf8(userInfoParts[0]);
|
username = decodeUtf8(userInfoParts[0]);
|
||||||
} else if (userInfoParts.length == 2) {
|
} else if (userInfoParts.length == 2) {
|
||||||
authType = AuthType.PLAIN;
|
authType = AuthType.PLAIN;
|
||||||
username = UrlEncodingHelper.decodeUtf8(userInfoParts[0]);
|
username = decodeUtf8(userInfoParts[0]);
|
||||||
password = UrlEncodingHelper.decodeUtf8(userInfoParts[1]);
|
password = decodeUtf8(userInfoParts[1]);
|
||||||
} else if (userInfoParts.length == 3) {
|
} else if (userInfoParts.length == 3) {
|
||||||
// NOTE: In SmptTransport URIs, the authType comes last!
|
// NOTE: In SmptTransport URIs, the authType comes last!
|
||||||
authType = AuthType.valueOf(userInfoParts[2]);
|
authType = AuthType.valueOf(userInfoParts[2]);
|
||||||
username = UrlEncodingHelper.decodeUtf8(userInfoParts[0]);
|
username = decodeUtf8(userInfoParts[0]);
|
||||||
if (authType == AuthType.EXTERNAL) {
|
if (authType == AuthType.EXTERNAL) {
|
||||||
clientCertificateAlias = UrlEncodingHelper.decodeUtf8(userInfoParts[1]);
|
clientCertificateAlias = decodeUtf8(userInfoParts[1]);
|
||||||
} else {
|
} else {
|
||||||
password = UrlEncodingHelper.decodeUtf8(userInfoParts[1]);
|
password = decodeUtf8(userInfoParts[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -128,11 +127,11 @@ public class SmtpTransport extends Transport {
|
|||||||
*/
|
*/
|
||||||
public static String createUri(ServerSettings server) {
|
public static String createUri(ServerSettings server) {
|
||||||
String userEnc = (server.username != null) ?
|
String userEnc = (server.username != null) ?
|
||||||
UrlEncodingHelper.encodeUtf8(server.username) : "";
|
encodeUtf8(server.username) : "";
|
||||||
String passwordEnc = (server.password != null) ?
|
String passwordEnc = (server.password != null) ?
|
||||||
UrlEncodingHelper.encodeUtf8(server.password) : "";
|
encodeUtf8(server.password) : "";
|
||||||
String clientCertificateAliasEnc = (server.clientCertificateAlias != null) ?
|
String clientCertificateAliasEnc = (server.clientCertificateAlias != null) ?
|
||||||
UrlEncodingHelper.encodeUtf8(server.clientCertificateAlias) : "";
|
encodeUtf8(server.clientCertificateAlias) : "";
|
||||||
|
|
||||||
String scheme;
|
String scheme;
|
||||||
switch (server.connectionSecurity) {
|
switch (server.connectionSecurity) {
|
||||||
|
Loading…
Reference in New Issue
Block a user