diff --git a/k9mail/src/main/java/com/fsck/k9/activity/MessageCompose.java b/k9mail/src/main/java/com/fsck/k9/activity/MessageCompose.java index 6580f94cf..114c4c115 100644 --- a/k9mail/src/main/java/com/fsck/k9/activity/MessageCompose.java +++ b/k9mail/src/main/java/com/fsck/k9/activity/MessageCompose.java @@ -74,6 +74,7 @@ import com.fsck.k9.helper.IdentityHelper; import com.fsck.k9.helper.MailTo; import com.fsck.k9.helper.ReplyToParser; import com.fsck.k9.helper.SimpleTextWatcher; +import com.fsck.k9.helper.Utility; import com.fsck.k9.mail.Address; import com.fsck.k9.mail.Flag; import com.fsck.k9.mail.Message; @@ -636,7 +637,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, builder = SimpleMessageBuilder.newInstance(); } - builder.setSubject(subjectView.getText().toString()) + builder.setSubject(Utility.stripNewLines(subjectView.getText().toString())) .setSentDate(new Date()) .setHideTimeZone(K9.hideTimeZone()) .setTo(recipientPresenter.getToAddresses()) diff --git a/k9mail/src/main/java/com/fsck/k9/helper/Utility.java b/k9mail/src/main/java/com/fsck/k9/helper/Utility.java index 69d906f11..84591fef9 100644 --- a/k9mail/src/main/java/com/fsck/k9/helper/Utility.java +++ b/k9mail/src/main/java/com/fsck/k9/helper/Utility.java @@ -397,6 +397,10 @@ public class Utility { } } + public static String stripNewLines(String multiLineString) { + return multiLineString.replaceAll("[\\r\\n]", ""); + } + private static final String IMG_SRC_REGEX = "(?is:]+src\\s*=\\s*['\"]?([a-z]+)\\:)"; private static final Pattern IMG_PATTERN = Pattern.compile(IMG_SRC_REGEX); diff --git a/k9mail/src/main/res/layout/message_compose.xml b/k9mail/src/main/res/layout/message_compose.xml index fbd0bec80..24a5786c1 100644 --- a/k9mail/src/main/res/layout/message_compose.xml +++ b/k9mail/src/main/res/layout/message_compose.xml @@ -33,7 +33,7 @@ android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="@string/message_compose_subject_hint" - android:inputType="textEmailSubject|textAutoCorrect|textCapSentences|textImeMultiLine" + android:inputType="textEmailSubject|textAutoCorrect|textCapSentences" android:imeOptions="actionNext" android:singleLine="true" android:background="@android:color/transparent" diff --git a/k9mail/src/test/java/com/fsck/k9/helper/UtilityTest.java b/k9mail/src/test/java/com/fsck/k9/helper/UtilityTest.java new file mode 100644 index 000000000..efc88aaa5 --- /dev/null +++ b/k9mail/src/test/java/com/fsck/k9/helper/UtilityTest.java @@ -0,0 +1,44 @@ +package com.fsck.k9.helper; + + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class UtilityTest { + + @Test + public void stripNewLines_removesLeadingCarriageReturns() { + String result = Utility.stripNewLines("\r\rTest"); + + assertEquals("Test", result); + } + + @Test + public void stripNewLines_removesLeadingLineFeeds() { + String result = Utility.stripNewLines("\n\nTest\n\n"); + + assertEquals("Test", result); + } + + @Test + public void stripNewLines_removesTrailingCarriageReturns() { + String result = Utility.stripNewLines("Test\r\r"); + + assertEquals("Test", result); + } + + @Test + public void stripNewLines_removesMidCarriageReturns() { + String result = Utility.stripNewLines("Test\rTest"); + + assertEquals("TestTest", result); + } + + @Test + public void stripNewLines_removesMidLineFeeds() { + String result = Utility.stripNewLines("Test\nTest"); + + assertEquals("TestTest", result); + } +}