diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java index c9c55a9c98..b08311302c 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java @@ -125,6 +125,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc private SwitchCompat swLogInfo; private SwitchCompat swDebug; + private Button btnRepair; private TextView tvRoomQueryThreads; private SeekBar sbRoomQueryThreads; private ImageButton ibRoom; @@ -246,6 +247,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc swLogInfo = view.findViewById(R.id.swLogInfo); swDebug = view.findViewById(R.id.swDebug); + btnRepair = view.findViewById(R.id.btnRepair); tvRoomQueryThreads = view.findViewById(R.id.tvRoomQueryThreads); sbRoomQueryThreads = view.findViewById(R.id.sbRoomQueryThreads); ibRoom = view.findViewById(R.id.ibRoom); @@ -1144,6 +1146,62 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc swLogInfo.setChecked(prefs.getInt("log_level", Log.getDefaultLogLevel()) <= android.util.Log.INFO); swDebug.setChecked(prefs.getBoolean("debug", false)); + btnRepair.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + new SimpleTask() { + @Override + protected void onPostExecute(Bundle args) { + ToastEx.makeText(v.getContext(), R.string.title_completed, Toast.LENGTH_LONG).show(); + } + + @Override + protected Void onExecute(Context context, Bundle args) throws Throwable { + DB db = DB.getInstance(context); + + List accounts = db.account().getAccounts(); + if (accounts == null) + return null; + + for (EntityAccount account : accounts) { + if (account.protocol != EntityAccount.TYPE_IMAP) + continue; + + List folders = db.folder().getFolders(account.id, false, false); + if (folders == null) + continue; + + EntityFolder inbox = db.folder().getFolderByType(account.id, EntityFolder.INBOX); + for (EntityFolder folder : folders) { + if (inbox == null && "inbox".equalsIgnoreCase(folder.name)) + folder.type = EntityFolder.INBOX; + + if (!EntityFolder.USER.equals(folder.type) && + !EntityFolder.SYSTEM.equals(folder.type)) { + EntityLog.log(context, "Repairing " + account.name + ":" + folder.type); + folder.setProperties(); + folder.setSpecials(account); + db.folder().updateFolder(folder); + } + } + } + + return null; + } + + @Override + protected void onExecuted(Bundle args, Void data) { + ServiceSynchronize.reload(v.getContext(), null, true, "repair"); + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Log.unexpectedError(getParentFragmentManager(), ex); + } + }.execute(FragmentOptionsMisc.this, new Bundle(), "repair"); + } + }); + int query_threads = prefs.getInt("query_threads", DB.DEFAULT_QUERY_THREADS); tvRoomQueryThreads.setText(getString(R.string.title_advanced_room_query_threads, NF.format(query_threads))); sbRoomQueryThreads.setProgress(query_threads); diff --git a/app/src/main/res/layout/fragment_options_misc.xml b/app/src/main/res/layout/fragment_options_misc.xml index 6191a9a77a..a2aa269ac7 100644 --- a/app/src/main/res/layout/fragment_options_misc.xml +++ b/app/src/main/res/layout/fragment_options_misc.xml @@ -610,6 +610,18 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> +