diff --git a/app/src/main/java/eu/faircode/email/FragmentAccount.java b/app/src/main/java/eu/faircode/email/FragmentAccount.java
index 886d1703..e07dcc2a 100644
--- a/app/src/main/java/eu/faircode/email/FragmentAccount.java
+++ b/app/src/main/java/eu/faircode/email/FragmentAccount.java
@@ -243,8 +243,14 @@ public class FragmentAccount extends Fragment {
}
}
}
- if (account.primary && !drafts)
- throw new MessagingException(getContext().getString(R.string.title_no_drafts));
+ if (!drafts) {
+ EntityFolder folder = new EntityFolder();
+ folder.name = getContext().getString(R.string.title_local_drafts);
+ folder.type = EntityFolder.TYPE_DRAFTS;
+ folder.synchronize = false;
+ folder.after = 0;
+ folders.add(folder);
+ }
} finally {
if (istore != null)
istore.close();
@@ -254,30 +260,31 @@ public class FragmentAccount extends Fragment {
if (account.primary)
db.account().resetPrimary();
- if (update)
- db.account().updateAccount(account);
- else
- try {
- db.beginTransaction();
+ try {
+ db.beginTransaction();
+ if (update)
+ db.account().updateAccount(account);
+ else
account.id = db.account().insertAccount(account);
- EntityFolder inbox = new EntityFolder();
- inbox.name = "INBOX";
- inbox.type = EntityFolder.TYPE_INBOX;
- inbox.synchronize = true;
- inbox.after = DEFAULT_INBOX_SYNC;
- folders.add(0, inbox);
+ EntityFolder inbox = new EntityFolder();
+ inbox.name = "INBOX";
+ inbox.type = EntityFolder.TYPE_INBOX;
+ inbox.synchronize = true;
+ inbox.after = DEFAULT_INBOX_SYNC;
+ folders.add(0, inbox);
- for (EntityFolder folder : folders) {
+ for (EntityFolder folder : folders)
+ if (db.folder().getFolder(account.id, folder.name) == null) {
folder.account = account.id;
Log.i(Helper.TAG, "Creating folder=" + folder.name + " (" + folder.type + ")");
folder.id = db.folder().insertFolder(folder);
}
- db.setTransactionSuccessful();
- } finally {
- db.endTransaction();
- }
+ db.setTransactionSuccessful();
+ } finally {
+ db.endTransaction();
+ }
ServiceSynchronize.restart(getContext(), "account");
diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java
index 58fe1461..21b5ec00 100644
--- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java
+++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java
@@ -64,6 +64,7 @@ import javax.mail.FetchProfile;
import javax.mail.Flags;
import javax.mail.Folder;
import javax.mail.FolderClosedException;
+import javax.mail.FolderNotFoundException;
import javax.mail.Message;
import javax.mail.MessageRemovedException;
import javax.mail.MessagingException;
@@ -549,6 +550,10 @@ public class ServiceSynchronize extends LifecycleService {
lbm.unregisterReceiver(receiver);
Log.i(Helper.TAG, folder.name + " unlisten process id=" + folder.id);
}
+ } catch (FolderNotFoundException ex) {
+ Log.w(Helper.TAG, folder.name + " " + ex + "\n" + Log.getStackTraceString(ex));
+ folder.synchronize = false;
+ DB.getInstance(this).folder().updateFolder(folder);
} finally {
if (ifolder != null && ifolder.isOpen()) {
try {
@@ -584,6 +589,12 @@ public class ServiceSynchronize extends LifecycleService {
imessage.setFlag(Flags.Flag.SEEN, jargs.getBoolean(0));
} else if (EntityOperation.ADD.equals(op.name)) {
+ if (!folder.synchronize) {
+ // Local drafts
+ Log.w(Helper.TAG, "Folder synchronization disabled");
+ return;
+ }
+
// Append message
EntityMessage msg = message.getMessage(op.message);
Properties props = MessageHelper.getSessionProperties();
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 17a8d8cd..e2b71029 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -59,7 +59,7 @@
Name mandatory
Email address mandatory
IDLE not supported
- No drafts folder
+ Local drafts
%1$s (%2$d)
Synchronize (receive messages)