mirror of https://github.com/M66B/FairEmail.git
Workaround invalid percent encoding
This commit is contained in:
parent
8a92201c41
commit
79b20937e7
|
@ -30,7 +30,6 @@ import android.text.Spanned;
|
|||
import android.text.TextUtils;
|
||||
|
||||
import androidx.core.app.TaskStackBuilder;
|
||||
import androidx.core.net.MailTo;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
|
|
@ -24,7 +24,6 @@ import android.content.SharedPreferences;
|
|||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.core.net.MailTo;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
|
|
|
@ -58,7 +58,6 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.constraintlayout.widget.Group;
|
||||
import androidx.core.net.MailTo;
|
||||
import androidx.core.util.PatternsCompat;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
|
|
@ -25,7 +25,6 @@ import android.net.Uri;
|
|||
import android.util.Pair;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.net.MailTo;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
package eu.faircode.email;
|
||||
|
||||
/*
|
||||
This file is part of FairEmail.
|
||||
|
||||
FairEmail is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FairEmail is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2018-2022 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.net.ParseException;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class MailTo {
|
||||
private final androidx.core.net.MailTo instance;
|
||||
|
||||
// https://en.wikipedia.org/wiki/Mailto
|
||||
private MailTo(androidx.core.net.MailTo instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static MailTo parse(@NonNull String uri) throws ParseException {
|
||||
// Workaround invalid percent encoding
|
||||
// https://en.wikipedia.org/wiki/Percent-encoding
|
||||
int i = 0;
|
||||
int pos = uri.indexOf('%', i);
|
||||
while (pos >= 0 && i + 3 < uri.length()) {
|
||||
try {
|
||||
if (pos + 3 > uri.length())
|
||||
break;
|
||||
String hex = uri.substring(pos + 1, pos + 3);
|
||||
int kar = Integer.parseInt(hex, 16);
|
||||
if (kar > 127)
|
||||
throw new NumberFormatException("Non ASCII: %" + hex);
|
||||
} catch (NumberFormatException ex) {
|
||||
uri = uri.substring(0, pos + 1) + "25" + uri.substring(pos + 1);
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
break;
|
||||
}
|
||||
i = pos + 3;
|
||||
pos = uri.indexOf('%', i);
|
||||
}
|
||||
|
||||
return new MailTo(androidx.core.net.MailTo.parse(uri));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static MailTo parse(@NonNull Uri uri) throws ParseException {
|
||||
return parse(uri.toString());
|
||||
}
|
||||
|
||||
String getTo() {
|
||||
return instance.getTo();
|
||||
}
|
||||
|
||||
String getCc() {
|
||||
return instance.getCc();
|
||||
}
|
||||
|
||||
String getSubject() {
|
||||
return instance.getSubject();
|
||||
}
|
||||
|
||||
Map<String, String> getHeaders() {
|
||||
return instance.getHeaders();
|
||||
}
|
||||
|
||||
String getBody() {
|
||||
return instance.getBody();
|
||||
}
|
||||
}
|
|
@ -30,7 +30,6 @@ import android.text.TextUtils;
|
|||
import android.util.Base64;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.net.MailTo;
|
||||
import androidx.core.util.PatternsCompat;
|
||||
import androidx.documentfile.provider.DocumentFile;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
|
Loading…
Reference in New Issue