aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextActivity.java41
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextFragment.java2
-rw-r--r--OpenKeychain/src/main/res/layout/decrypt_text_fragment.xml135
3 files changed, 89 insertions, 89 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextActivity.java
index 982bed784..8d489b3d4 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextActivity.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextActivity.java
@@ -32,9 +32,7 @@ import org.sufficientlysecure.keychain.service.results.SingletonResult;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.ui.util.Notify;
-import java.io.StreamTokenizer;
import java.util.regex.Matcher;
-import java.util.regex.Pattern;
public class DecryptTextActivity extends ActionBarActivity {
@@ -58,38 +56,51 @@ public class DecryptTextActivity extends ActionBarActivity {
}
/**
- * Fix the message a bit, trailing spaces and newlines break stuff,
- * because GMail sends as HTML and such things break ASCII Armor
- * TODO: things like "<" and ">" also make problems
- * <p/>
- * NOTE: Do not use on cleartext signatures, only on ASCII-armored ciphertext,
- * it would change the signed message
+ * Fixing broken PGP MESSAGE Strings coming from GMail/AOSP Mail
*/
- private String fixAsciiArmoredCiphertext(String message) {
+ private String fixPgpMessage(String message) {
+ // windows newline -> unix newline
+ message = message.replaceAll("\r\n", "\n");
+ // Mac OS before X newline -> unix newline
+ message = message.replaceAll("\r", "\n");
+
+ // remove whitespaces before newline
message = message.replaceAll(" +\n", "\n");
+ // only two consecutive newlines are allowed
message = message.replaceAll("\n\n+", "\n\n");
- message = message.replaceFirst("^\n+", "");
- // make sure there'll be exactly one newline at the end
- message = message.replaceFirst("\n*$", "\n");
+
// replace non breakable spaces
message = message.replaceAll("\\xa0", " ");
return message;
}
+ /**
+ * Fixing broken PGP SIGNED MESSAGE Strings coming from GMail/AOSP Mail
+ */
+ private String fixPgpCleartextSignature(String message) {
+ // windows newline -> unix newline
+ message = message.replaceAll("\r\n", "\n");
+ // Mac OS before X newline -> unix newline
+ message = message.replaceAll("\r", "\n");
+
+ return message;
+ }
+
private String getPgpContent(String input) {
// only decrypt if clipboard content is available and a pgp message or cleartext signature
if (input != null) {
Matcher matcher = PgpHelper.PGP_MESSAGE.matcher(input);
if (matcher.matches()) {
String message = matcher.group(1);
- message = fixAsciiArmoredCiphertext(message);
+ message = fixPgpMessage(message);
return message;
} else {
matcher = PgpHelper.PGP_CLEARTEXT_SIGNATURE.matcher(input);
if (matcher.matches()) {
- // return cleartext signature
- return matcher.group(1);
+ String message = matcher.group(1);
+ message = fixPgpCleartextSignature(message);
+ return message;
} else {
return null;
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextFragment.java
index 134d26c8c..4f25126ee 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextFragment.java
@@ -23,6 +23,7 @@ import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.os.Messenger;
+import android.text.method.ScrollingMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -181,7 +182,6 @@ public class DecryptTextFragment extends DecryptFragment {
byte[] decryptedMessage = returnData
.getByteArray(KeychainIntentService.RESULT_DECRYPTED_BYTES);
mText.setText(new String(decryptedMessage));
- mText.setHorizontallyScrolling(false);
pgpResult.createNotify(getActivity()).show();
diff --git a/OpenKeychain/src/main/res/layout/decrypt_text_fragment.xml b/OpenKeychain/src/main/res/layout/decrypt_text_fragment.xml
index 1c6097495..3bd144fbf 100644
--- a/OpenKeychain/src/main/res/layout/decrypt_text_fragment.xml
+++ b/OpenKeychain/src/main/res/layout/decrypt_text_fragment.xml
@@ -1,89 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
-<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:fillViewport="true">
+ android:orientation="vertical">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical">
+ <include layout="@layout/decrypt_result_include" />
- <include layout="@layout/decrypt_result_include" />
-
- <View
- android:id="@+id/status_divider"
- android:layout_height="1dip"
- android:layout_width="match_parent"
- android:background="?android:attr/listDivider" />
+ <ScrollView
+ android:fillViewport="true"
+ android:paddingTop="8dp"
+ android:layout_width="match_parent"
+ android:scrollbars="vertical"
+ android:layout_height="0dp"
+ android:layout_weight="1">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingTop="4dp"
+ <TextView
+ android:id="@+id/decrypt_text_plaintext"
android:paddingLeft="16dp"
android:paddingRight="16dp"
- android:orientation="vertical">
-
- <TextView
- android:id="@+id/decrypt_text_plaintext"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:layout_width="match_parent"
- android:layout_height="0dip"
- android:gravity="top"
- android:hint=""
- android:scrollHorizontally="true"
- android:layout_weight="1"
- android:textIsSelectable="true" />
-
- <View
- android:layout_width="match_parent"
- android:layout_height="1dip"
- android:background="?android:attr/listDivider" />
-
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:gravity="top"
+ android:hint=""
+ android:textIsSelectable="true" />
- <LinearLayout
- android:id="@+id/action_decrypt_share_plaintext"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:clickable="true"
- style="@style/SelectableItem"
- android:orientation="horizontal">
+ </ScrollView>
- <TextView
- android:paddingLeft="8dp"
- android:paddingRight="8dp"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:minHeight="?android:attr/listPreferredItemHeight"
- android:text="@string/btn_add_share_decrypted_text"
- android:drawableRight="@drawable/ic_action_share"
- android:drawablePadding="8dp"
- android:gravity="center_vertical"
- android:layout_weight="1" />
+ <View
+ android:layout_width="match_parent"
+ android:layout_height="1dip"
+ android:layout_marginLeft="16dp"
+ android:layout_marginRight="16dp"
+ android:background="?android:attr/listDivider" />
- <View
- android:layout_width="1dip"
- android:layout_height="match_parent"
- android:gravity="right"
- android:layout_marginBottom="8dp"
- android:layout_marginTop="8dp"
- android:background="?android:attr/listDivider" />
+ <LinearLayout
+ android:id="@+id/action_decrypt_share_plaintext"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="16dp"
+ android:layout_marginRight="16dp"
+ android:clickable="true"
+ style="@style/SelectableItem"
+ android:orientation="horizontal">
- <ImageButton
- android:id="@+id/action_decrypt_copy_plaintext"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:padding="8dp"
- android:src="@drawable/ic_action_copy"
- android:layout_gravity="center_vertical"
- style="@style/SelectableItem" />
+ <TextView
+ android:paddingLeft="8dp"
+ android:paddingRight="8dp"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:minHeight="?android:attr/listPreferredItemHeight"
+ android:text="@string/btn_add_share_decrypted_text"
+ android:drawableRight="@drawable/ic_action_share"
+ android:drawablePadding="8dp"
+ android:gravity="center_vertical"
+ android:layout_weight="1" />
- </LinearLayout>
+ <View
+ android:layout_width="1dip"
+ android:layout_height="match_parent"
+ android:gravity="right"
+ android:layout_marginBottom="8dp"
+ android:layout_marginTop="8dp"
+ android:background="?android:attr/listDivider" />
- </LinearLayout>
+ <ImageButton
+ android:id="@+id/action_decrypt_copy_plaintext"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:padding="8dp"
+ android:src="@drawable/ic_action_copy"
+ android:layout_gravity="center_vertical"
+ style="@style/SelectableItem" />
</LinearLayout>
-
-</ScrollView>
+</LinearLayout> \ No newline at end of file