Browse Source

Handle providers without drafts folder

for example free.fr
main
M66B 6 years ago
parent
commit
d32df01e25
3 changed files with 37 additions and 19 deletions
  1. +25
    -18
      app/src/main/java/eu/faircode/email/FragmentAccount.java
  2. +11
    -0
      app/src/main/java/eu/faircode/email/ServiceSynchronize.java
  3. +1
    -1
      app/src/main/res/values/strings.xml

+ 25
- 18
app/src/main/java/eu/faircode/email/FragmentAccount.java View File

@ -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");


+ 11
- 0
app/src/main/java/eu/faircode/email/ServiceSynchronize.java View File

@ -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();


+ 1
- 1
app/src/main/res/values/strings.xml View File

@ -59,7 +59,7 @@
<string name="title_no_name">Name mandatory</string>
<string name="title_no_email">Email address mandatory</string>
<string name="title_no_idle">IDLE not supported</string>
<string name="title_no_drafts">No drafts folder</string>
<string name="title_local_drafts">Local drafts</string>
<string name="title_folder_unseen">%1$s (%2$d)</string>
<string name="title_synchronize_folder">Synchronize (receive messages)</string>


Loading…
Cancel
Save