1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 11:42:16 -05:00

Remove URLEncodingHelper dependency

This commit is contained in:
Jan Berkel 2014-12-14 15:54:27 +00:00
parent 8ef9eae0d6
commit 238c1650c5
6 changed files with 74 additions and 40 deletions

View File

@ -1,6 +1,9 @@
package com.fsck.k9.mail;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.List;
/**
@ -47,4 +50,20 @@ public abstract class Store {
public Pusher getPusher(PushReceiver receiver) {
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");
}
}
}

View File

@ -5,6 +5,10 @@ import com.fsck.k9.mail.store.StoreConfig;
import com.fsck.k9.mail.transport.SmtpTransport;
import com.fsck.k9.mail.transport.WebDavTransport;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
public abstract class Transport {
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 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");
}
}
}

View File

@ -57,7 +57,6 @@ import android.util.Log;
import com.fsck.k9.K9;
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.TracingWakeLock;
import com.fsck.k9.mail.AuthType;
@ -197,19 +196,19 @@ public class ImapStore extends RemoteStore {
if (userinfo.endsWith(":")) {
// Password is empty. This can only happen after an account was imported.
authenticationType = AuthType.valueOf(userInfoParts[0]);
username = UrlEncodingHelper.decodeUtf8(userInfoParts[1]);
username = decodeUtf8(userInfoParts[1]);
} else if (userInfoParts.length == 2) {
authenticationType = AuthType.PLAIN;
username = UrlEncodingHelper.decodeUtf8(userInfoParts[0]);
password = UrlEncodingHelper.decodeUtf8(userInfoParts[1]);
username = decodeUtf8(userInfoParts[0]);
password = decodeUtf8(userInfoParts[1]);
} else if (userInfoParts.length == 3) {
authenticationType = AuthType.valueOf(userInfoParts[0]);
username = UrlEncodingHelper.decodeUtf8(userInfoParts[1]);
username = decodeUtf8(userInfoParts[1]);
if (AuthType.EXTERNAL == authenticationType) {
clientCertificateAlias = UrlEncodingHelper.decodeUtf8(userInfoParts[2]);
clientCertificateAlias = decodeUtf8(userInfoParts[2]);
} else {
password = UrlEncodingHelper.decodeUtf8(userInfoParts[2]);
password = decodeUtf8(userInfoParts[2]);
}
}
}
@ -248,11 +247,11 @@ public class ImapStore extends RemoteStore {
* @see ImapStore#decodeUri(String)
*/
public static String createUri(ServerSettings server) {
String userEnc = UrlEncodingHelper.encodeUtf8(server.username);
String userEnc = encodeUtf8(server.username);
String passwordEnc = (server.password != null) ?
UrlEncodingHelper.encodeUtf8(server.password) : "";
encodeUtf8(server.password) : "";
String clientCertificateAliasEnc = (server.clientCertificateAlias != null) ?
UrlEncodingHelper.encodeUtf8(server.clientCertificateAlias) : "";
encodeUtf8(server.clientCertificateAlias) : "";
String scheme;
switch (server.connectionSecurity) {

View File

@ -5,7 +5,6 @@ import android.util.Log;
import com.fsck.k9.K9;
import com.fsck.k9.R;
import com.fsck.k9.helper.UrlEncodingHelper;
import com.fsck.k9.mail.*;
import com.fsck.k9.mail.filter.Base64;
import com.fsck.k9.mail.filter.Hex;
@ -125,12 +124,12 @@ public class Pop3Store extends RemoteStore {
passwordIndex++;
authType = AuthType.valueOf(userInfoParts[0]);
}
username = UrlEncodingHelper.decodeUtf8(userInfoParts[userIndex]);
username = decodeUtf8(userInfoParts[userIndex]);
if (userInfoParts.length > passwordIndex) {
if (authType == AuthType.EXTERNAL) {
clientCertificateAlias = UrlEncodingHelper.decodeUtf8(userInfoParts[passwordIndex]);
clientCertificateAlias = decodeUtf8(userInfoParts[passwordIndex]);
} else {
password = UrlEncodingHelper.decodeUtf8(userInfoParts[passwordIndex]);
password = decodeUtf8(userInfoParts[passwordIndex]);
}
}
}
@ -151,11 +150,11 @@ public class Pop3Store extends RemoteStore {
* @see Pop3Store#decodeUri(String)
*/
public static String createUri(ServerSettings server) {
String userEnc = UrlEncodingHelper.encodeUtf8(server.username);
String userEnc = encodeUtf8(server.username);
String passwordEnc = (server.password != null) ?
UrlEncodingHelper.encodeUtf8(server.password) : "";
encodeUtf8(server.password) : "";
String clientCertificateAliasEnc = (server.clientCertificateAlias != null) ?
UrlEncodingHelper.encodeUtf8(server.clientCertificateAlias) : "";
encodeUtf8(server.clientCertificateAlias) : "";
String scheme;
switch (server.connectionSecurity) {

View File

@ -4,7 +4,6 @@ import android.util.Log;
import com.fsck.k9.K9;
import com.fsck.k9.helper.UrlEncodingHelper;
import com.fsck.k9.mail.*;
import com.fsck.k9.mail.filter.Base64;
import com.fsck.k9.mail.filter.EOLConvertingOutputStream;
@ -137,7 +136,7 @@ public class WebDavStore extends RemoteStore {
String userInfo = webDavUri.getUserInfo();
if (userInfo != null) {
String[] userInfoParts = userInfo.split(":");
username = UrlEncodingHelper.decodeUtf8(userInfoParts[0]);
username = decodeUtf8(userInfoParts[0]);
String userParts[] = username.split("\\\\", 2);
if (userParts.length > 1) {
@ -146,7 +145,7 @@ public class WebDavStore extends RemoteStore {
alias = username;
}
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)
*/
public static String createUri(ServerSettings server) {
String userEnc = UrlEncodingHelper.encodeUtf8(server.username);
String userEnc = encodeUtf8(server.username);
String passwordEnc = (server.password != null) ?
UrlEncodingHelper.encodeUtf8(server.password) : "";
encodeUtf8(server.password) : "";
String scheme;
switch (server.connectionSecurity) {
@ -474,7 +473,7 @@ public class WebDavStore extends RemoteStore {
// Decodes the url-encoded folder name (i.e. "My%20folder" => "My Folder"
return UrlEncodingHelper.decodeUtf8(fullPathName);
return decodeUtf8(fullPathName);
}
return null;
@ -1237,9 +1236,9 @@ public class WebDavStore extends RemoteStore {
String url = "";
for (int i = 0, count = urlParts.length; i < count; i++) {
if (i != 0) {
url = url + "/" + UrlEncodingHelper.encodeUtf8(urlParts[i]);
url = url + "/" + encodeUtf8(urlParts[i]);
} else {
url = UrlEncodingHelper.encodeUtf8(urlParts[i]);
url = encodeUtf8(urlParts[i]);
}
}
encodedName = url;
@ -1880,7 +1879,7 @@ public class WebDavStore extends RemoteStore {
if (!messageURL.endsWith("/")) {
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);
@ -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
*/
try {
end = UrlEncodingHelper.decodeUtf8(end);
end = UrlEncodingHelper.encodeUtf8(end);
end = decodeUtf8(end);
end = encodeUtf8(end);
end = end.replaceAll("\\+", "%20");
} catch (IllegalArgumentException iae) {
Log.e(K9.LOG_TAG, "IllegalArgumentException caught in setUrl: " + iae + "\nTrace: "
@ -2372,8 +2371,8 @@ public class WebDavStore extends RemoteStore {
*/
try {
if (length > 3) {
end = UrlEncodingHelper.decodeUtf8(end);
end = UrlEncodingHelper.encodeUtf8(end);
end = decodeUtf8(end);
end = encodeUtf8(end);
end = end.replaceAll("\\+", "%20");
}
} catch (IllegalArgumentException iae) {

View File

@ -5,7 +5,6 @@ import android.util.Log;
import com.fsck.k9.K9;
import com.fsck.k9.R;
import com.fsck.k9.helper.UrlEncodingHelper;
import com.fsck.k9.mail.*;
import com.fsck.k9.mail.Message.RecipientType;
import com.fsck.k9.mail.filter.Base64;
@ -94,19 +93,19 @@ public class SmtpTransport extends Transport {
String[] userInfoParts = smtpUri.getUserInfo().split(":");
if (userInfoParts.length == 1) {
authType = AuthType.PLAIN;
username = UrlEncodingHelper.decodeUtf8(userInfoParts[0]);
username = decodeUtf8(userInfoParts[0]);
} else if (userInfoParts.length == 2) {
authType = AuthType.PLAIN;
username = UrlEncodingHelper.decodeUtf8(userInfoParts[0]);
password = UrlEncodingHelper.decodeUtf8(userInfoParts[1]);
username = decodeUtf8(userInfoParts[0]);
password = decodeUtf8(userInfoParts[1]);
} else if (userInfoParts.length == 3) {
// NOTE: In SmptTransport URIs, the authType comes last!
authType = AuthType.valueOf(userInfoParts[2]);
username = UrlEncodingHelper.decodeUtf8(userInfoParts[0]);
username = decodeUtf8(userInfoParts[0]);
if (authType == AuthType.EXTERNAL) {
clientCertificateAlias = UrlEncodingHelper.decodeUtf8(userInfoParts[1]);
clientCertificateAlias = decodeUtf8(userInfoParts[1]);
} 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) {
String userEnc = (server.username != null) ?
UrlEncodingHelper.encodeUtf8(server.username) : "";
encodeUtf8(server.username) : "";
String passwordEnc = (server.password != null) ?
UrlEncodingHelper.encodeUtf8(server.password) : "";
encodeUtf8(server.password) : "";
String clientCertificateAliasEnc = (server.clientCertificateAlias != null) ?
UrlEncodingHelper.encodeUtf8(server.clientCertificateAlias) : "";
encodeUtf8(server.clientCertificateAlias) : "";
String scheme;
switch (server.connectionSecurity) {