From 648e3bd8297b5cf286ee8f2bd488b5d07ec2b5ad Mon Sep 17 00:00:00 2001 From: cketti Date: Sun, 20 Jun 2010 14:07:03 +0000 Subject: [PATCH] Added option to specify the message quote prefix character/string (default ">"). Applied patch provided by fiouzy (Thanks!) with some small modifications. Fixes issue 1830 --- res/values/strings.xml | 1 + res/xml/account_settings_preferences.xml | 7 +++++++ src/com/fsck/k9/Account.java | 17 +++++++++++++++++ src/com/fsck/k9/activity/MessageCompose.java | 8 +++++++- .../k9/activity/setup/AccountSettings.java | 18 +++++++++++++++++- 5 files changed, 49 insertions(+), 2 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 7590b8b90..041559fa6 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -491,6 +491,7 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin Folders Listing messages Viewing messages + Quote prefix Folder poll check frequency 2nd class check frequency diff --git a/res/xml/account_settings_preferences.xml b/res/xml/account_settings_preferences.xml index 4b8d79f3b..f162e5a67 100644 --- a/res/xml/account_settings_preferences.xml +++ b/res/xml/account_settings_preferences.xml @@ -171,6 +171,13 @@ /> + + diff --git a/src/com/fsck/k9/Account.java b/src/com/fsck/k9/Account.java index 518709566..3ab36790b 100644 --- a/src/com/fsck/k9/Account.java +++ b/src/com/fsck/k9/Account.java @@ -44,6 +44,7 @@ public class Account implements BaseAccount public static final String TYPE_OTHER = "OTHER"; private static String[] networkTypes = { TYPE_WIFI, TYPE_MOBILE, TYPE_OTHER }; + private static final String DEFAULT_QUOTE_PREFIX = ">"; /** *
@@ -97,6 +98,7 @@ public class Account implements BaseAccount
     // Tracks if we have sent a notification for this account for
     // current set of fetched messages
     private boolean mRingNotified;
+    private String mQuotePrefix;
 
     private List identities;
 
@@ -146,6 +148,7 @@ public class Account implements BaseAccount
         goToUnreadMessageSearch = false;
         subscribedFoldersOnly = false;
         maximumPolledMessageAge = 10;
+        mQuotePrefix = DEFAULT_QUOTE_PREFIX;
 
         searchableFolders = Searchable.ALL;
 
@@ -215,6 +218,7 @@ public class Account implements BaseAccount
                 false);
         maximumPolledMessageAge = preferences.getPreferences().getInt(mUuid
                 + ".maximumPolledMessageAge", -1);
+        mQuotePrefix = preferences.getPreferences().getString(mUuid + ".quotePrefix", DEFAULT_QUOTE_PREFIX);
         for (String type : networkTypes)
         {
             Boolean useCompression = preferences.getPreferences().getBoolean(mUuid + ".useCompression." + type,
@@ -386,6 +390,7 @@ public class Account implements BaseAccount
         editor.remove(mUuid + ".goToUnreadMessageSearch");
         editor.remove(mUuid + ".subscribedFoldersOnly");
         editor.remove(mUuid + ".maximumPolledMessageAge");
+        editor.remove(mUuid + ".quotePrefix");
         for (String type : networkTypes)
         {
             editor.remove(mUuid + ".useCompression." + type);
@@ -471,6 +476,7 @@ public class Account implements BaseAccount
         editor.putBoolean(mUuid + ".goToUnreadMessageSearch", goToUnreadMessageSearch);
         editor.putBoolean(mUuid + ".subscribedFoldersOnly", subscribedFoldersOnly);
         editor.putInt(mUuid + ".maximumPolledMessageAge", maximumPolledMessageAge);
+        editor.putString(mUuid + ".quotePrefix", mQuotePrefix);
         
         for (String type : networkTypes)
         {
@@ -1242,6 +1248,7 @@ public class Account implements BaseAccount
     {
         this.maximumPolledMessageAge = maximumPolledMessageAge;
     }
+
     public Date getEarliestPollDate()
     {
         int age = getMaximumPolledMessageAge();
@@ -1282,4 +1289,14 @@ public class Account implements BaseAccount
             return null;
         }
     }
+
+    public String getQuotePrefix()
+    {
+        return mQuotePrefix;
+    }
+
+    public void setQuotePrefix(String quotePrefix)
+    {
+        mQuotePrefix = quotePrefix;
+    }
 }
diff --git a/src/com/fsck/k9/activity/MessageCompose.java b/src/com/fsck/k9/activity/MessageCompose.java
index c26360819..977192727 100644
--- a/src/com/fsck/k9/activity/MessageCompose.java
+++ b/src/com/fsck/k9/activity/MessageCompose.java
@@ -1343,7 +1343,13 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
                                             getString(R.string.message_compose_reply_header_fmt),
                                             Address.toString(mSourceMessage.getFrom()));
 
-                    quotedText += MimeUtility.getTextFromPart(part).replaceAll("(?m)^", ">");
+                    final String prefix = mAccount.getQuotePrefix();
+                    // "$" and "\" in the quote prefix have to be escaped for
+                    // the replaceAll() invocation.
+                    final String escapedPrefix = prefix.replaceAll("(\\\\|\\$)", "\\\\$1");
+                    quotedText += MimeUtility.getTextFromPart(part).replaceAll(
+                            "(?m)^", escapedPrefix);
+
                     quotedText = quotedText.replaceAll("\\\r", "");
                     mQuotedText.setText(quotedText);
 
diff --git a/src/com/fsck/k9/activity/setup/AccountSettings.java b/src/com/fsck/k9/activity/setup/AccountSettings.java
index ff53b276b..e3505f38d 100644
--- a/src/com/fsck/k9/activity/setup/AccountSettings.java
+++ b/src/com/fsck/k9/activity/setup/AccountSettings.java
@@ -53,7 +53,7 @@ public class AccountSettings extends K9PreferenceActivity
     private static final String PREFERENCE_LED_COLOR = "led_color";
     private static final String PREFERENCE_NOTIFICATION_OPENS_UNREAD = "notification_opens_unread";
     private static final String PREFERENCE_MESSAGE_AGE = "account_message_age";
-
+    private static final String PREFERENCE_QUOTE_PREFIX = "account_quote_prefix";
 
 
     private Account mAccount;
@@ -81,6 +81,7 @@ public class AccountSettings extends K9PreferenceActivity
     private Preference mLedColor;
     private boolean mIncomingChanged = false;
     private CheckBoxPreference mNotificationOpensUnread;
+    private EditTextPreference mAccountQuotePrefix;
 
 
     public static void actionSettings(Context context, Account account)
@@ -131,6 +132,20 @@ public class AccountSettings extends K9PreferenceActivity
             }
         });
 
+        mAccountQuotePrefix = (EditTextPreference) findPreference(PREFERENCE_QUOTE_PREFIX);
+        mAccountQuotePrefix.setSummary(mAccount.getQuotePrefix());
+        mAccountQuotePrefix.setText(mAccount.getQuotePrefix());
+        mAccountQuotePrefix.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
+        {
+            @Override
+            public boolean onPreferenceChange(Preference preference, Object newValue)
+            {
+                final String value = newValue.toString();
+                mAccountQuotePrefix.setSummary(value);
+                mAccountQuotePrefix.setText(value);
+                return false;
+            }
+        });
 
         mCheckFrequency = (ListPreference) findPreference(PREFERENCE_FREQUENCY);
         mCheckFrequency.setValue(String.valueOf(mAccount.getAutomaticCheckIntervalMinutes()));
@@ -441,6 +456,7 @@ public class AccountSettings extends K9PreferenceActivity
         mAccount.setDeletePolicy(Integer.parseInt(mDeletePolicy.getValue()));
         mAccount.setExpungePolicy(mExpungePolicy.getValue());
         mAccount.setSearchableFolders(Account.Searchable.valueOf(mSearchableFolders.getValue()));
+        mAccount.setQuotePrefix(mAccountQuotePrefix.getText());
 
         boolean needsRefresh = mAccount.setAutomaticCheckIntervalMinutes(Integer.parseInt(mCheckFrequency.getValue()));
         needsRefresh |= mAccount.setFolderSyncMode(Account.FolderMode.valueOf(mSyncMode.getValue()));