body = uri.getQueryParameters("body");
if (!body.isEmpty()) {
- mMessageContentView.setText(body.get(0));
+ mMessageContentView.setCharacters(body.get(0));
}
}
@@ -3970,4 +3976,35 @@ public class MessageCompose extends K9Activity implements OnClickListener,
private boolean includeQuotedText() {
return (mQuotedTextMode == QuotedTextMode.SHOW);
}
+
+ /**
+ * An {@link EditText} extension with methods that convert line endings from
+ * {@code \r\n} to {@code \n} and back again when setting and getting text.
+ *
+ */
+ private static class EolConvertingEditText extends EditText {
+
+ public EolConvertingEditText(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ /**
+ * Return the text the EolConvertingEditText is displaying.
+ *
+ * @return A string with any line endings converted to {@code \r\n}.
+ */
+ public String getCharacters() {
+ return getText().toString().replace("\n", "\r\n");
+ }
+
+ /**
+ * Sets the string value of the EolConvertingEditText. Any line endings
+ * in the string will be converted to {@code \n}.
+ *
+ * @param text
+ */
+ public void setCharacters(CharSequence text) {
+ setText(text.toString().replace("\r\n", "\n"));
+ }
+ }
}
diff --git a/src/com/fsck/k9/mail/internet/MimeUtility.java b/src/com/fsck/k9/mail/internet/MimeUtility.java
index c80100389..0bc532a60 100644
--- a/src/com/fsck/k9/mail/internet/MimeUtility.java
+++ b/src/com/fsck/k9/mail/internet/MimeUtility.java
@@ -3416,7 +3416,7 @@ public class MimeUtility {
if (part.isMimeType("text/plain")) {
String bodyText = getTextFromPart(part);
if (bodyText != null) {
- text = fixDraftTextBody(bodyText);
+ text = bodyText;
html = HtmlConverter.textToHtml(text);
}
} else if (part.isMimeType("multipart/alternative") &&
@@ -3427,9 +3427,9 @@ public class MimeUtility {
String bodyText = getTextFromPart(bodyPart);
if (bodyText != null) {
if (text.length() == 0 && bodyPart.isMimeType("text/plain")) {
- text = fixDraftTextBody(bodyText);
+ text = bodyText;
} else if (html.length() == 0 && bodyPart.isMimeType("text/html")) {
- html = fixDraftTextBody(bodyText);
+ html = bodyText;
}
}
}
@@ -3437,21 +3437,4 @@ public class MimeUtility {
return new ViewableContainer(text, html, attachments);
}
-
- /**
- * Fix line endings of text bodies in draft messages.
- *
- *
- * We create drafts with LF line endings. The values in the identity header are based on that.
- * So we replace CRLF with LF when loading messages (from the server).
- *
- *
- * @param text
- * The body text with CRLF line endings
- *
- * @return The text with LF line endings
- */
- private static String fixDraftTextBody(String text) {
- return text.replace("\r\n", "\n");
- }
}