From 0ba3e9e9df8a75f83efed4b9fb33d0fed3ab4f1d Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 22 May 2020 20:07:58 +0200 Subject: [PATCH] Paste plain text without quoting --- .../eu/faircode/email/EditTextCompose.java | 2 +- .../java/eu/faircode/email/HtmlHelper.java | 38 +++++++++++-------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/EditTextCompose.java b/app/src/main/java/eu/faircode/email/EditTextCompose.java index 20b421f4fa..b16b0783e6 100644 --- a/app/src/main/java/eu/faircode/email/EditTextCompose.java +++ b/app/src/main/java/eu/faircode/email/EditTextCompose.java @@ -77,7 +77,7 @@ public class EditTextCompose extends FixedEditText { CharSequence text = item.getText(); if (text == null) return false; - html = "
" + HtmlHelper.formatPre(text.toString()) + "
"; + html = "
" + HtmlHelper.formatPre(text.toString(), false) + "
"; } Document document = HtmlHelper.sanitizeCompose(context, html, false); diff --git a/app/src/main/java/eu/faircode/email/HtmlHelper.java b/app/src/main/java/eu/faircode/email/HtmlHelper.java index 8502bff27b..c7cc9f049d 100644 --- a/app/src/main/java/eu/faircode/email/HtmlHelper.java +++ b/app/src/main/java/eu/faircode/email/HtmlHelper.java @@ -1293,31 +1293,37 @@ public class HtmlHelper { } static String formatPre(String text) { + return formatPre(text, true); + } + + static String formatPre(String text, boolean quote) { int level = 0; StringBuilder sb = new StringBuilder(); String[] lines = text.split("\\r?\\n"); for (String line : lines) { // Opening quotes // https://tools.ietf.org/html/rfc3676#section-4.5 - int tlevel = 0; - while (line.startsWith(">")) { - tlevel++; - if (tlevel > level) - sb.append("
"); + if (quote) { + int tlevel = 0; + while (line.startsWith(">")) { + tlevel++; + if (tlevel > level) + sb.append("
"); - line = line.substring(1); // > + line = line.substring(1); // > - if (line.startsWith(" >")) - line = line.substring(1); + if (line.startsWith(" >")) + line = line.substring(1); + } + if (tlevel > 0) + if (line.length() > 0 && line.charAt(0) == ' ') + line = line.substring(1); + + // Closing quotes + for (int i = 0; i < level - tlevel; i++) + sb.append("
"); + level = tlevel; } - if (tlevel > 0) - if (line.length() > 0 && line.charAt(0) == ' ') - line = line.substring(1); - - // Closing quotes - for (int i = 0; i < level - tlevel; i++) - sb.append("
"); - level = tlevel; // Tabs characters StringBuilder l = new StringBuilder();