mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-26 17:57:16 +00:00
Store copy of sent message in ...
This commit is contained in:
parent
d73ae7bced
commit
c23eb83496
4 changed files with 116 additions and 16 deletions
|
@ -55,8 +55,12 @@ import org.xbill.DNS.Record;
|
|||
import org.xbill.DNS.SRVRecord;
|
||||
import org.xbill.DNS.Type;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.mail.AuthenticationFailedException;
|
||||
|
@ -91,7 +95,7 @@ public class FragmentIdentity extends FragmentEx {
|
|||
private ImageView ibColorDefault;
|
||||
private CheckBox cbSynchronize;
|
||||
private CheckBox cbPrimary;
|
||||
private CheckBox cbStoreSent;
|
||||
private Spinner spSent;
|
||||
private Button btnSave;
|
||||
private ProgressBar pbSave;
|
||||
private ImageButton ibDelete;
|
||||
|
@ -100,6 +104,7 @@ public class FragmentIdentity extends FragmentEx {
|
|||
|
||||
private long id = -1;
|
||||
private int color = Color.TRANSPARENT;
|
||||
private ArrayAdapter<EntityFolder> adapter;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -147,7 +152,7 @@ public class FragmentIdentity extends FragmentEx {
|
|||
|
||||
cbSynchronize = view.findViewById(R.id.cbSynchronize);
|
||||
cbPrimary = view.findViewById(R.id.cbPrimary);
|
||||
cbStoreSent = view.findViewById(R.id.cbStoreSent);
|
||||
spSent = view.findViewById(R.id.spSent);
|
||||
|
||||
btnSave = view.findViewById(R.id.btnSave);
|
||||
pbSave = view.findViewById(R.id.pbSave);
|
||||
|
@ -204,10 +209,13 @@ public class FragmentIdentity extends FragmentEx {
|
|||
|
||||
// Copy account password
|
||||
tilPassword.getEditText().setText(account.password);
|
||||
|
||||
setFolders(account.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> adapterView) {
|
||||
adapter.clear();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -366,7 +374,7 @@ public class FragmentIdentity extends FragmentEx {
|
|||
args.putInt("color", color);
|
||||
args.putBoolean("synchronize", cbSynchronize.isChecked());
|
||||
args.putBoolean("primary", cbPrimary.isChecked());
|
||||
args.putBoolean("store_sent", cbStoreSent.isChecked());
|
||||
args.putSerializable("sent", (EntityFolder) spSent.getSelectedItem());
|
||||
|
||||
new SimpleTask<Void>() {
|
||||
@Override
|
||||
|
@ -386,7 +394,7 @@ public class FragmentIdentity extends FragmentEx {
|
|||
int auth_type = args.getInt("auth_type");
|
||||
boolean synchronize = args.getBoolean("synchronize");
|
||||
boolean primary = args.getBoolean("primary");
|
||||
boolean store_sent = args.getBoolean("store_sent");
|
||||
EntityFolder sent = (EntityFolder) args.getSerializable("sent");
|
||||
|
||||
if (TextUtils.isEmpty(name))
|
||||
throw new IllegalArgumentException(getContext().getString(R.string.title_no_name));
|
||||
|
@ -457,7 +465,8 @@ public class FragmentIdentity extends FragmentEx {
|
|||
identity.auth_type = auth_type;
|
||||
identity.synchronize = synchronize;
|
||||
identity.primary = (identity.synchronize && primary);
|
||||
identity.store_sent = store_sent;
|
||||
identity.store_sent = false;
|
||||
identity.sent_folder = (sent == null ? null : sent.id);
|
||||
|
||||
if (!identity.synchronize)
|
||||
identity.error = null;
|
||||
|
@ -546,6 +555,10 @@ public class FragmentIdentity extends FragmentEx {
|
|||
}
|
||||
});
|
||||
|
||||
adapter = new ArrayAdapter<>(getContext(), R.layout.spinner_item1, android.R.id.text1, new ArrayList<EntityFolder>());
|
||||
adapter.setDropDownViewResource(R.layout.spinner_item1_dropdown);
|
||||
spSent.setAdapter(adapter);
|
||||
|
||||
// Initialize
|
||||
Helper.setViewsEnabled(view, false);
|
||||
cbInsecure.setVisibility(View.GONE);
|
||||
|
@ -596,7 +609,6 @@ public class FragmentIdentity extends FragmentEx {
|
|||
tilPassword.getEditText().setText(identity == null ? null : identity.password);
|
||||
cbSynchronize.setChecked(identity == null ? true : identity.synchronize);
|
||||
cbPrimary.setChecked(identity == null ? true : identity.primary);
|
||||
cbStoreSent.setChecked(identity == null ? false : identity.store_sent);
|
||||
|
||||
color = (identity == null || identity.color == null ? Color.TRANSPARENT : identity.color);
|
||||
|
||||
|
@ -675,15 +687,18 @@ public class FragmentIdentity extends FragmentEx {
|
|||
|
||||
spAccount.setTag(0);
|
||||
spAccount.setSelection(0);
|
||||
for (int pos = 0; pos < accounts.size(); pos++)
|
||||
if (accounts.get(pos).id == (identity == null ? -1 : identity.account)) {
|
||||
for (int pos = 0; pos < accounts.size(); pos++) {
|
||||
EntityAccount account = accounts.get(pos);
|
||||
if (account.id.equals((identity == null ? -1 : identity.account))) {
|
||||
spAccount.setTag(pos);
|
||||
spAccount.setSelection(pos);
|
||||
// OAuth token could be updated
|
||||
if (pos > 0 && accounts.get(pos).auth_type != Helper.AUTH_TYPE_PASSWORD)
|
||||
tilPassword.getEditText().setText(accounts.get(pos).password);
|
||||
setFolders(account.id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int provider = savedInstanceState.getInt("provider");
|
||||
spProvider.setTag(provider);
|
||||
|
@ -707,4 +722,76 @@ public class FragmentIdentity extends FragmentEx {
|
|||
border.setStroke(1, Helper.resolveColor(getContext(), R.attr.colorSeparator));
|
||||
vwColor.setBackground(border);
|
||||
}
|
||||
|
||||
private void setFolders(long account) {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("account", account);
|
||||
args.putLong("identity", id);
|
||||
|
||||
new SimpleTask<IdentityFolders>() {
|
||||
@Override
|
||||
protected IdentityFolders onLoad(Context context, Bundle args) {
|
||||
long aid = args.getLong("account");
|
||||
long iid = args.getLong("identity");
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
IdentityFolders result = new IdentityFolders();
|
||||
result.identity = db.identity().getIdentity(iid);
|
||||
result.folders = db.folder().getFolders(aid);
|
||||
|
||||
final Collator collator = Collator.getInstance(Locale.getDefault());
|
||||
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc
|
||||
|
||||
Collections.sort(result.folders, new Comparator<EntityFolder>() {
|
||||
@Override
|
||||
public int compare(EntityFolder f1, EntityFolder f2) {
|
||||
int s = Integer.compare(
|
||||
EntityFolder.FOLDER_SORT_ORDER.indexOf(f1.type),
|
||||
EntityFolder.FOLDER_SORT_ORDER.indexOf(f2.type));
|
||||
if (s != 0)
|
||||
return s;
|
||||
int c = -f1.synchronize.compareTo(f2.synchronize);
|
||||
if (c != 0)
|
||||
return c;
|
||||
return collator.compare(
|
||||
f1.name == null ? "" : f1.name,
|
||||
f2.name == null ? "" : f2.name);
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLoaded(Bundle args, IdentityFolders result) {
|
||||
EntityFolder none = new EntityFolder();
|
||||
none.name = "";
|
||||
result.folders.add(0, none);
|
||||
|
||||
adapter.clear();
|
||||
adapter.addAll(result.folders);
|
||||
|
||||
if (result.identity != null)
|
||||
for (int pos = 0; pos < result.folders.size(); pos++) {
|
||||
EntityFolder folder = result.folders.get(pos);
|
||||
if (result.identity.store_sent) {
|
||||
if (EntityFolder.SENT.equals(folder.type)) {
|
||||
spSent.setSelection(pos);
|
||||
break;
|
||||
}
|
||||
} else if (result.identity.sent_folder != null) {
|
||||
if (result.identity.sent_folder.equals(folder.id)) {
|
||||
spSent.setSelection(pos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}.load(this, args);
|
||||
}
|
||||
|
||||
class IdentityFolders {
|
||||
EntityIdentity identity;
|
||||
List<EntityFolder> folders;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1514,8 +1514,12 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
message.ui_seen = true;
|
||||
db.message().updateMessage(message);
|
||||
|
||||
if (ident.store_sent) {
|
||||
EntityFolder sent = db.folder().getFolderByType(ident.account, EntityFolder.SENT);
|
||||
if (ident.store_sent || ident.sent_folder != null) {
|
||||
EntityFolder sent;
|
||||
if (ident.store_sent)
|
||||
sent = db.folder().getFolderByType(ident.account, EntityFolder.SENT);
|
||||
else
|
||||
sent = db.folder().getFolder(ident.sent_folder);
|
||||
if (sent != null) {
|
||||
message.folder = sent.id;
|
||||
message.uid = null;
|
||||
|
|
|
@ -351,15 +351,23 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/cbSynchronize" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbStoreSent"
|
||||
<TextView
|
||||
android:id="@+id/tvSent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_store_sent"
|
||||
android:text="@string/title_store_copy"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/cbPrimary" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/spSent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvSent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnSave"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -367,7 +375,7 @@
|
|||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_save"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/cbStoreSent" />
|
||||
app:layout_constraintTop_toBottomOf="@id/spSent" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/pbSave"
|
||||
|
@ -387,7 +395,7 @@
|
|||
android:layout_marginTop="12dp"
|
||||
android:src="@drawable/baseline_delete_24"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/cbStoreSent" />
|
||||
app:layout_constraintTop_toBottomOf="@id/spSent" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/pbWait"
|
||||
|
@ -404,6 +412,6 @@
|
|||
android:id="@+id/grpAdvanced"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:constraint_referenced_ids="tvEmail,etEmail,tvReplyTo,etReplyTo,tvProvider,spProvider,tvDomain,etDomain,btnAutoConfig,tvSmtp,tvInsecure,tvHost,etHost,cbStartTls,tvPort,etPort,tvUser,etUser,tvPassword,tilPassword,btnColor,vwColor,ibColorDefault,cbSynchronize,cbPrimary,cbStoreSent" />
|
||||
app:constraint_referenced_ids="tvEmail,etEmail,tvReplyTo,etReplyTo,tvProvider,spProvider,tvDomain,etDomain,btnAutoConfig,tvSmtp,tvInsecure,tvHost,etHost,cbStartTls,tvPort,etPort,tvUser,etUser,tvPassword,tilPassword,btnColor,vwColor,ibColorDefault,cbSynchronize,cbPrimary,cbStoreSent,tvSent,spSent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</ScrollView>
|
|
@ -135,6 +135,7 @@
|
|||
<string name="title_authorizing">Authorizing account …</string>
|
||||
<string name="title_setup_advanced">Advanced</string>
|
||||
<string name="title_store_sent">Store sent messages (normally not needed)</string>
|
||||
<string name="title_store_copy">Store a copy of sent messages in:</string>
|
||||
<string name="title_synchronize_account">Synchronize (receive messages)</string>
|
||||
<string name="title_synchronize_identity">Synchronize (send messages)</string>
|
||||
<string name="title_primary_account">Primary (default account)</string>
|
||||
|
|
Loading…
Reference in a new issue