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

Commit 55dac7ee authored by Bao-Long Nguyen-Trong's avatar Bao-Long Nguyen-Trong
Browse files

Added option to have attachments store on sd card

(this is still a rough implementation)
parent 49b223e2
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -655,4 +655,10 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin

    <string name="remote_control_label">K-9 Mail remote control</string>
    <string name="remote_control_desc">Allows this application to control K-9 Mail activities and settings.</string>

    <string name="account_setup_store_attachment_on_sd_card_label">Attachments On SD Cards</string>
    <string name="account_setup_store_attachment_on_sd_card_summary">Whether or not attachments are store on the SD card</string>
    <string name="account_setup_store_attachment_on_sd_card_error">No SD card found</string>

    <string name="sd_card_error">No SD card found</string>
</resources>
+15 −8
Original line number Diff line number Diff line
@@ -30,8 +30,15 @@
            android:key="account_default"
            android:title="@string/account_settings_default_label"
            android:summary="@string/account_settings_default_summary" />

        <CheckBoxPreference
            android:key="account_setup_store_attachment_on_sd_card"
            android:title="@string/account_setup_store_attachment_on_sd_card_label"
            android:summary="@string/account_setup_store_attachment_on_sd_card_summary" />

    </PreferenceCategory>

	
	<PreferenceCategory android:title="@string/account_settings_message_lists">

        <ListPreference
+14 −2
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ public class Account implements Serializable
    boolean mIsSignatureBeforeQuotedText;
    private String mExpungePolicy = EXPUNGE_IMMEDIATELY;
    private int mMaxPushFolders;
    private boolean mStoreAttachmentsOnSdCard;

    List<Identity> identities;

@@ -274,7 +275,6 @@ public class Account implements Serializable
            mFolderPushMode = FolderMode.FIRST_CLASS;
        }


        try
        {
            mFolderTargetMode = FolderMode.valueOf(preferences.getPreferences().getString(mUuid  + ".folderTargetMode",
@@ -286,6 +286,7 @@ public class Account implements Serializable
        }

        mIsSignatureBeforeQuotedText = preferences.getPreferences().getBoolean(mUuid  + ".signatureBeforeQuotedText", false);
        mStoreAttachmentsOnSdCard = preferences.getPreferences().getBoolean(mUuid  + ".storeAttachmentOnSdCard", true);
        identities = loadIdentities(preferences.getPreferences());
    }

@@ -530,6 +531,7 @@ public class Account implements Serializable
        editor.remove(mUuid + ".signatureBeforeQuotedText");
        editor.remove(mUuid + ".expungePolicy");
        editor.remove(mUuid + ".maxPushFolders");
        editor.remove(mUuid + ".storeAttachmentOnSdCard");
        deleteIdentities(preferences.getPreferences(), editor);
        editor.commit();
    }
@@ -602,6 +604,7 @@ public class Account implements Serializable
        editor.putBoolean(mUuid + ".signatureBeforeQuotedText", this.mIsSignatureBeforeQuotedText);
        editor.putString(mUuid + ".expungePolicy", mExpungePolicy);
        editor.putInt(mUuid + ".maxPushFolders", mMaxPushFolders);
        editor.putBoolean(mUuid + ".storeAttachmentOnSdCard", mStoreAttachmentsOnSdCard);
        saveIdentities(preferences.getPreferences(), editor);

        editor.commit();
@@ -965,4 +968,13 @@ public class Account implements Serializable
        mRing = ring;
    }

    public boolean isStoreAttachmentOnSdCard()
    {
        return mStoreAttachmentsOnSdCard;
    }

    public void setStoreAttachmentOnSdCard(boolean mStoreAttachmentOnSdCard)
    {
        this.mStoreAttachmentsOnSdCard = mStoreAttachmentOnSdCard;
    }
}
+32 −6
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.os.PowerManager;
import android.os.Process;
import android.os.PowerManager.WakeLock;
@@ -46,7 +47,6 @@ import com.fsck.k9.mail.Folder;
import com.fsck.k9.mail.Message;
import com.fsck.k9.mail.MessageRemovalListener;
import com.fsck.k9.mail.MessageRetrievalListener;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.Part;
import com.fsck.k9.mail.PushReceiver;
import com.fsck.k9.mail.Pusher;
@@ -54,6 +54,7 @@ import com.fsck.k9.mail.Store;
import com.fsck.k9.mail.Transport;
import com.fsck.k9.mail.Folder.FolderType;
import com.fsck.k9.mail.Folder.OpenMode;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.internet.MimeMessage;
import com.fsck.k9.mail.internet.MimeUtility;
import com.fsck.k9.mail.internet.TextBody;
@@ -61,6 +62,10 @@ import com.fsck.k9.mail.store.LocalStore;
import com.fsck.k9.mail.store.LocalStore.LocalFolder;
import com.fsck.k9.mail.store.LocalStore.LocalMessage;
import com.fsck.k9.mail.store.LocalStore.PendingCommand;
import com.fsck.k9.mail.transport.EOLConvertingOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * Starts a long running (application) Thread that will run through commands
@@ -3858,13 +3863,19 @@ public class MessagingController implements Runnable

                    for (final Account account : accounts)
                    {
                        if (account.isStoreAttachmentOnSdCard()
                            && !Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
                        {
                            if (K9.DEBUG)
                                Log.i(K9.LOG_TAG, "SD card not mounted: skipping synchronizing account " + account.getDescription());
                            continue;
                        }

                        final long accountInterval = account.getAutomaticCheckIntervalMinutes() * 60 * 1000;
                        if (ignoreLastCheckedTime == false && accountInterval <= 0)
                        {
                            if (K9.DEBUG)
                                Log.i(K9.LOG_TAG, "Skipping synchronizing account " + account.getDescription());


                            continue;
                        }

@@ -3947,8 +3958,6 @@ public class MessagingController implements Runnable
                                    continue;
                                }



                                if (K9.DEBUG)
                                    Log.v(K9.LOG_TAG, "Folder " + folder.getName() + " was last synced @ " +
                                          new Date(folder.getLastChecked()));
@@ -3967,6 +3976,16 @@ public class MessagingController implements Runnable
                                {
                                    public void run()
                                    {
                                        //Let's be conservative and check the sd card
                                        //in case it was unmounted while we are sync'ing this account
                                        if (account.isStoreAttachmentOnSdCard()
                                            && !Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
                                        {
                                            if (K9.DEBUG)
                                                Log.i(K9.LOG_TAG, "SD card not mounted: skipping synchronizing: account " + account.getDescription() + " folder=" + folder.getName());
                                            return;
                                        }

                                        LocalFolder tLocalFolder = null;
                                        try
                                        {
@@ -4010,7 +4029,6 @@ public class MessagingController implements Runnable
                                            {
                                                synchronizeMailboxSynchronous(account, folder.getName(), listener);
                                            }

                                            finally
                                            {
                                                if (account.isShowOngoing())
@@ -4523,6 +4541,14 @@ public class MessagingController implements Runnable
        {
            public void run()
            {
                if (account.isStoreAttachmentOnSdCard()
                    && !Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
                {
                    if (K9.DEBUG)
                        Log.i(K9.LOG_TAG, "SD card not mounted: skipping reception of pushed messages: account=" + account.getDescription() + ", folder=" + remoteFolder.getName() + ", message count=" + messages.size());
                    return;
                }

                LocalFolder localFolder = null;
                try
                {
+8 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.view.*;
import android.view.ContextMenu.ContextMenuInfo;
@@ -377,6 +378,13 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC

    private void onCheckMail(Account account)
    {
        if (account.isStoreAttachmentOnSdCard()
            && !Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
        {
            Toast.makeText(this, R.string.sd_card_error, Toast.LENGTH_SHORT).show();
            return;
        }

        MessagingController.getInstance(getApplication()).checkMail(this, account, true, true, null);
    }

Loading