mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-27 19:52:17 -05:00
Fixes issue 387
Applied patch by achen.code (thanks!) to word wrap the quoted text on replies.
This commit is contained in:
parent
00d30f1b8a
commit
90ee194d0f
@ -76,6 +76,7 @@ import com.fsck.k9.mail.store.LocalStore.LocalAttachmentBody;
|
|||||||
public class MessageCompose extends K9Activity implements OnClickListener, OnFocusChangeListener
|
public class MessageCompose extends K9Activity implements OnClickListener, OnFocusChangeListener
|
||||||
{
|
{
|
||||||
private static final int DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE = 1;
|
private static final int DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE = 1;
|
||||||
|
private static final int REPLY_WRAP_LINE_WIDTH = 72;
|
||||||
|
|
||||||
private static final String ACTION_REPLY = "com.fsck.k9.intent.action.REPLY";
|
private static final String ACTION_REPLY = "com.fsck.k9.intent.action.REPLY";
|
||||||
private static final String ACTION_REPLY_ALL = "com.fsck.k9.intent.action.REPLY_ALL";
|
private static final String ACTION_REPLY_ALL = "com.fsck.k9.intent.action.REPLY_ALL";
|
||||||
@ -1729,15 +1730,13 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
|||||||
// the replaceAll() invocation.
|
// the replaceAll() invocation.
|
||||||
final String escapedPrefix = prefix.replaceAll("(\\\\|\\$)", "\\\\$1");
|
final String escapedPrefix = prefix.replaceAll("(\\\\|\\$)", "\\\\$1");
|
||||||
|
|
||||||
if (mSourceMessageBody != null)
|
final String text = (mSourceMessageBody != null) ?
|
||||||
{
|
mSourceMessageBody :
|
||||||
quotedText += mSourceMessageBody.replaceAll("(?m)^", escapedPrefix);
|
MimeUtility.getTextFromPart(part);
|
||||||
}
|
|
||||||
else
|
final String wrappedText = Utility.wrap(text, REPLY_WRAP_LINE_WIDTH - prefix.length());
|
||||||
{
|
|
||||||
quotedText += MimeUtility.getTextFromPart(part).replaceAll(
|
quotedText += wrappedText.replaceAll("(?m)^", escapedPrefix);
|
||||||
"(?m)^", escapedPrefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
quotedText = quotedText.replaceAll("\\\r", "");
|
quotedText = quotedText.replaceAll("\\\r", "");
|
||||||
mQuotedText.setText(quotedText);
|
mQuotedText.setText(quotedText);
|
||||||
|
@ -228,4 +228,160 @@ public class Utility
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Wraps a multiline string of text, identifying words by <code>' '</code>.</p>
|
||||||
|
*
|
||||||
|
* <p>New lines will be separated by the system property line separator.
|
||||||
|
* Very long words, such as URLs will <i>not</i> be wrapped.</p>
|
||||||
|
*
|
||||||
|
* <p>Leading spaces on a new line are stripped.
|
||||||
|
* Trailing spaces are not stripped.</p>
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* WordUtils.wrap(null, *) = null
|
||||||
|
* WordUtils.wrap("", *) = ""
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* Adapted from the Apache Commons Lang library.
|
||||||
|
* http://svn.apache.org/viewvc/commons/proper/lang
|
||||||
|
* /trunk/src/main/java/org/apache/commons/lang3/text/WordUtils.java
|
||||||
|
* SVN Revision 925967, Mon Mar 22 06:16:49 2010 UTC
|
||||||
|
*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
* @param str the String to be word wrapped, may be null
|
||||||
|
* @param wrapLength the column to wrap the words at, less than 1 is treated as 1
|
||||||
|
* @return a line with newlines inserted, <code>null</code> if null input
|
||||||
|
*/
|
||||||
|
private static final String NEWLINE_REGEX = "(?:\\r?\\n)";
|
||||||
|
public static String wrap(String str, int wrapLength)
|
||||||
|
{
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
for (String piece : str.split(NEWLINE_REGEX))
|
||||||
|
{
|
||||||
|
result.append(wrap(piece, wrapLength, null, false));
|
||||||
|
result.append("\n");
|
||||||
|
}
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Wraps a single line of text, identifying words by <code>' '</code>.</p>
|
||||||
|
*
|
||||||
|
* <p>Leading spaces on a new line are stripped.
|
||||||
|
* Trailing spaces are not stripped.</p>
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* WordUtils.wrap(null, *, *, *) = null
|
||||||
|
* WordUtils.wrap("", *, *, *) = ""
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* This is from the Apache Commons Lang library.
|
||||||
|
* http://svn.apache.org/viewvc/commons/proper/lang
|
||||||
|
* /trunk/src/main/java/org/apache/commons/lang3/text/WordUtils.java
|
||||||
|
* SVN Revision 925967, Mon Mar 22 06:16:49 2010 UTC
|
||||||
|
*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
* @param str the String to be word wrapped, may be null
|
||||||
|
* @param wrapLength the column to wrap the words at, less than 1 is treated as 1
|
||||||
|
* @param newLineStr the string to insert for a new line,
|
||||||
|
* <code>null</code> uses the system property line separator
|
||||||
|
* @param wrapLongWords true if long words (such as URLs) should be wrapped
|
||||||
|
* @return a line with newlines inserted, <code>null</code> if null input
|
||||||
|
*/
|
||||||
|
public static String wrap(String str, int wrapLength, String newLineStr, boolean wrapLongWords)
|
||||||
|
{
|
||||||
|
if (str == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (newLineStr == null)
|
||||||
|
{
|
||||||
|
newLineStr = "\n";
|
||||||
|
}
|
||||||
|
if (wrapLength < 1)
|
||||||
|
{
|
||||||
|
wrapLength = 1;
|
||||||
|
}
|
||||||
|
int inputLineLength = str.length();
|
||||||
|
int offset = 0;
|
||||||
|
StringBuilder wrappedLine = new StringBuilder(inputLineLength + 32);
|
||||||
|
|
||||||
|
while ((inputLineLength - offset) > wrapLength)
|
||||||
|
{
|
||||||
|
if (str.charAt(offset) == ' ')
|
||||||
|
{
|
||||||
|
offset++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int spaceToWrapAt = str.lastIndexOf(' ', wrapLength + offset);
|
||||||
|
|
||||||
|
if (spaceToWrapAt >= offset)
|
||||||
|
{
|
||||||
|
// normal case
|
||||||
|
wrappedLine.append(str.substring(offset, spaceToWrapAt));
|
||||||
|
wrappedLine.append(newLineStr);
|
||||||
|
offset = spaceToWrapAt + 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// really long word or URL
|
||||||
|
if (wrapLongWords)
|
||||||
|
{
|
||||||
|
// wrap really long word one line at a time
|
||||||
|
wrappedLine.append(str.substring(offset, wrapLength + offset));
|
||||||
|
wrappedLine.append(newLineStr);
|
||||||
|
offset += wrapLength;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// do not wrap really long word, just extend beyond limit
|
||||||
|
spaceToWrapAt = str.indexOf(' ', wrapLength + offset);
|
||||||
|
if (spaceToWrapAt >= 0)
|
||||||
|
{
|
||||||
|
wrappedLine.append(str.substring(offset, spaceToWrapAt));
|
||||||
|
wrappedLine.append(newLineStr);
|
||||||
|
offset = spaceToWrapAt + 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wrappedLine.append(str.substring(offset));
|
||||||
|
offset = inputLineLength;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Whatever is left in line is short enough to just pass through
|
||||||
|
wrappedLine.append(str.substring(offset));
|
||||||
|
|
||||||
|
return wrappedLine.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user