Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4bfebe42 authored by Jesse Vincent's avatar Jesse Vincent
Browse files

Allow users to choose whether they want plaintext messages to be

fixed-width when uprezzed to HTML.
parent d2ed40d6
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -293,6 +293,8 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin
    <string name="global_settings_touchable_label">Touch-friendly view</string>
    <string name="global_settings_touchable_summary">Roomier list items with message previews</string>

    <string name="global_settings_messageview_fixedwidth_label">Fixed-width fonts</string>
    <string name="global_settings_messageview_fixedwidth_summary">Use a fixed-width font when showing plain-text messages</string>

	<string name="account_setup_basics_title">Set up a new account</string>
    <string name="account_setup_basics_instructions">Enter this account\'s email address:</string>
@@ -696,6 +698,7 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin
    <string name="operational_preferences">Sync</string>
    <string name="accountlist_preferences">Account List</string>
    <string name="messagelist_preferences">Message Lists</string>
    <string name="messageview_preferences">Messages</string>
    <string name="settings_theme_label">Theme</string>

    <string name="background_ops_label">Background sync</string>
+9 −0
Original line number Diff line number Diff line
@@ -89,6 +89,15 @@

    </PreferenceCategory>

    <PreferenceCategory android:title="@string/messageview_preferences" android:key="messageview_preferences">
        <CheckBoxPreference
            android:key="messageview_fixedwidth_font"
            android:title="@string/global_settings_messageview_fixedwidth_label"
            android:summary="@string/global_settings_messageview_fixedwidth_summary"

            />
    </PreferenceCategory>

    <PreferenceCategory android:title="@string/operational_preferences" android:key="operational_preferences">

        <ListPreference
+19 −0
Original line number Diff line number Diff line
@@ -78,6 +78,9 @@ public class K9 extends Application
    private static boolean mMessageListStars = true;
    private static boolean mMessageListCheckboxes = false;
    private static boolean mMessageListTouchable = false;

    private static boolean mMessageViewFixedWidthFont = false;

    private static boolean mGesturesEnabled = true;
    private static boolean mManageBack = false;
    private static boolean mMeasureAccounts = true;
@@ -304,6 +307,9 @@ public class K9 extends Application
        editor.putBoolean("messageListStars",mMessageListStars);
        editor.putBoolean("messageListCheckboxes",mMessageListCheckboxes);
        editor.putBoolean("messageListTouchable",mMessageListTouchable);

        editor.putBoolean("messageViewFixedWidthFont",mMessageViewFixedWidthFont);

        editor.putInt("theme", theme);
        editor.putBoolean("useGalleryBugWorkaround", useGalleryBugWorkaround);

@@ -330,6 +336,9 @@ public class K9 extends Application
        mMessageListStars = sprefs.getBoolean("messageListStars",true);
        mMessageListCheckboxes = sprefs.getBoolean("messageListCheckboxes",false);
        mMessageListTouchable = sprefs.getBoolean("messageListTouchable",false);

        mMessageViewFixedWidthFont = sprefs.getBoolean("messageViewFixedWidthFont", false);

        useGalleryBugWorkaround = sprefs.getBoolean("useGalleryBugWorkaround", K9.isGalleryBuggy());

        fontSizes.load(sprefs);
@@ -505,6 +514,16 @@ public class K9 extends Application
    }


    public static boolean messageViewFixedWidthFont()
    {
        return mMessageViewFixedWidthFont;
    }

    public static void setMessageViewFixedWidthFont(boolean fixed)
    {
        mMessageViewFixedWidthFont = fixed;
    }

    private static Method getMethod(Class<?> classObject, String methodName)
    {
        try
+11 −1
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ public class Prefs extends K9PreferenceActivity
    private static final String PREFERENCE_MESSAGELIST_CHECKBOXES = "messagelist_checkboxes";
    private static final String PREFERENCE_MESSAGELIST_TOUCHABLE = "messagelist_touchable";

    private static final String PREFERENCE_MESSAGEVIEW_FIXEDWIDTH = "messageview_fixedwidth_font";

    private static final String PREFERENCE_MEASURE_ACCOUNTS = "measure_accounts";
    private static final String PREFERENCE_COUNT_SEARCH = "count_search";
    private static final String PREFERENCE_GALLERY_BUG_WORKAROUND = "use_gallery_bug_workaround";
@@ -47,6 +49,9 @@ public class Prefs extends K9PreferenceActivity
    private CheckBoxPreference mStars;
    private CheckBoxPreference mCheckboxes;
    private CheckBoxPreference mTouchable;

    private CheckBoxPreference mFixedWidth;

    private CheckBoxPreference mMeasureAccounts;
    private CheckBoxPreference mCountSearch;
    private CheckBoxPreference mUseGalleryBugWorkaround;
@@ -161,6 +166,10 @@ public class Prefs extends K9PreferenceActivity
        mTouchable = (CheckBoxPreference)findPreference(PREFERENCE_MESSAGELIST_TOUCHABLE);
        mTouchable.setChecked(K9.messageListTouchable());

        mFixedWidth = (CheckBoxPreference)findPreference(PREFERENCE_MESSAGEVIEW_FIXEDWIDTH);
        mFixedWidth.setChecked(K9.messageViewFixedWidthFont());


        mMeasureAccounts = (CheckBoxPreference)findPreference(PREFERENCE_MEASURE_ACCOUNTS);
        mMeasureAccounts.setChecked(K9.measureAccounts());

@@ -190,9 +199,10 @@ public class Prefs extends K9PreferenceActivity
        K9.setManageBack(mManageBack.isChecked());
        K9.setMessageListStars(mStars.isChecked());
        K9.setMessageListCheckboxes(mCheckboxes.isChecked());

        K9.setMessageListTouchable(mTouchable.isChecked());

        K9.setMessageViewFixedWidthFont(mFixedWidth.isChecked());

        K9.setMeasureAccounts(mMeasureAccounts.isChecked());
        K9.setCountSearchMessages(mCountSearch.isChecked());

+30 −2
Original line number Diff line number Diff line
@@ -2333,9 +2333,11 @@ public class LocalStore extends Store implements Serializable
            text = text.replaceAll("(?m)^([^\r\n]{4,}[\\s\\w,:;+/])(?:\r\n|\n|\r)(?=[a-z]\\S{0,10}[\\s\\n\\r])","$1 ");
            text = text.replaceAll("(?m)(\r\n|\n|\r){4,}","\n\n");


            Matcher m = Regex.WEB_URL_PATTERN.matcher(text);
            StringBuffer sb = new StringBuffer(text.length() + 512);
            sb.append("<html><body><pre style=\"white-space: pre-wrap; word-wrap:break-word; \">");
            sb.append("<html><head></head><body>");
            sb.append(htmlifyMessageHeader());
            while (m.find())
            {
                int start = m.start();
@@ -2353,12 +2355,38 @@ public class LocalStore extends Store implements Serializable


            m.appendTail(sb);
            sb.append("</pre></body></html>");
            sb.append(htmlifyMessageFooter());
            sb.append("</body></html>");
            text = sb.toString();

            return text;
        }

        private String htmlifyMessageHeader()
        {
            if (K9.messageViewFixedWidthFont())
            {
                return "<pre style=\"white-space: pre-wrap; word-wrap:break-word; \">";
            }
            else
            {
                return "<div style=\"white-space: pre-wrap; word-wrap:break-word; \">";
            }
        }


        private String htmlifyMessageFooter()
        {
            if (K9.messageViewFixedWidthFont())
            {
                return "</pre>";
            }
            else
            {
                return "</div>";
            }
        }

        @Override
        public boolean isInTopGroup()
        {