Store copy of sent message in ...

pull/146/head
M66B 7 years ago
parent d73ae7bced
commit c23eb83496

@ -55,8 +55,12 @@ import org.xbill.DNS.Record;
import org.xbill.DNS.SRVRecord; import org.xbill.DNS.SRVRecord;
import org.xbill.DNS.Type; import org.xbill.DNS.Type;
import java.text.Collator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Properties; import java.util.Properties;
import javax.mail.AuthenticationFailedException; import javax.mail.AuthenticationFailedException;
@ -91,7 +95,7 @@ public class FragmentIdentity extends FragmentEx {
private ImageView ibColorDefault; private ImageView ibColorDefault;
private CheckBox cbSynchronize; private CheckBox cbSynchronize;
private CheckBox cbPrimary; private CheckBox cbPrimary;
private CheckBox cbStoreSent; private Spinner spSent;
private Button btnSave; private Button btnSave;
private ProgressBar pbSave; private ProgressBar pbSave;
private ImageButton ibDelete; private ImageButton ibDelete;
@ -100,6 +104,7 @@ public class FragmentIdentity extends FragmentEx {
private long id = -1; private long id = -1;
private int color = Color.TRANSPARENT; private int color = Color.TRANSPARENT;
private ArrayAdapter<EntityFolder> adapter;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -147,7 +152,7 @@ public class FragmentIdentity extends FragmentEx {
cbSynchronize = view.findViewById(R.id.cbSynchronize); cbSynchronize = view.findViewById(R.id.cbSynchronize);
cbPrimary = view.findViewById(R.id.cbPrimary); cbPrimary = view.findViewById(R.id.cbPrimary);
cbStoreSent = view.findViewById(R.id.cbStoreSent); spSent = view.findViewById(R.id.spSent);
btnSave = view.findViewById(R.id.btnSave); btnSave = view.findViewById(R.id.btnSave);
pbSave = view.findViewById(R.id.pbSave); pbSave = view.findViewById(R.id.pbSave);
@ -204,10 +209,13 @@ public class FragmentIdentity extends FragmentEx {
// Copy account password // Copy account password
tilPassword.getEditText().setText(account.password); tilPassword.getEditText().setText(account.password);
setFolders(account.id);
} }
@Override @Override
public void onNothingSelected(AdapterView<?> adapterView) { public void onNothingSelected(AdapterView<?> adapterView) {
adapter.clear();
} }
}); });
@ -366,7 +374,7 @@ public class FragmentIdentity extends FragmentEx {
args.putInt("color", color); args.putInt("color", color);
args.putBoolean("synchronize", cbSynchronize.isChecked()); args.putBoolean("synchronize", cbSynchronize.isChecked());
args.putBoolean("primary", cbPrimary.isChecked()); args.putBoolean("primary", cbPrimary.isChecked());
args.putBoolean("store_sent", cbStoreSent.isChecked()); args.putSerializable("sent", (EntityFolder) spSent.getSelectedItem());
new SimpleTask<Void>() { new SimpleTask<Void>() {
@Override @Override
@ -386,7 +394,7 @@ public class FragmentIdentity extends FragmentEx {
int auth_type = args.getInt("auth_type"); int auth_type = args.getInt("auth_type");
boolean synchronize = args.getBoolean("synchronize"); boolean synchronize = args.getBoolean("synchronize");
boolean primary = args.getBoolean("primary"); boolean primary = args.getBoolean("primary");
boolean store_sent = args.getBoolean("store_sent"); EntityFolder sent = (EntityFolder) args.getSerializable("sent");
if (TextUtils.isEmpty(name)) if (TextUtils.isEmpty(name))
throw new IllegalArgumentException(getContext().getString(R.string.title_no_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.auth_type = auth_type;
identity.synchronize = synchronize; identity.synchronize = synchronize;
identity.primary = (identity.synchronize && primary); 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) if (!identity.synchronize)
identity.error = null; 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 // Initialize
Helper.setViewsEnabled(view, false); Helper.setViewsEnabled(view, false);
cbInsecure.setVisibility(View.GONE); cbInsecure.setVisibility(View.GONE);
@ -596,7 +609,6 @@ public class FragmentIdentity extends FragmentEx {
tilPassword.getEditText().setText(identity == null ? null : identity.password); tilPassword.getEditText().setText(identity == null ? null : identity.password);
cbSynchronize.setChecked(identity == null ? true : identity.synchronize); cbSynchronize.setChecked(identity == null ? true : identity.synchronize);
cbPrimary.setChecked(identity == null ? true : identity.primary); 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); color = (identity == null || identity.color == null ? Color.TRANSPARENT : identity.color);
@ -675,15 +687,18 @@ public class FragmentIdentity extends FragmentEx {
spAccount.setTag(0); spAccount.setTag(0);
spAccount.setSelection(0); spAccount.setSelection(0);
for (int pos = 0; pos < accounts.size(); pos++) for (int pos = 0; pos < accounts.size(); pos++) {
if (accounts.get(pos).id == (identity == null ? -1 : identity.account)) { EntityAccount account = accounts.get(pos);
if (account.id.equals((identity == null ? -1 : identity.account))) {
spAccount.setTag(pos); spAccount.setTag(pos);
spAccount.setSelection(pos); spAccount.setSelection(pos);
// OAuth token could be updated // OAuth token could be updated
if (pos > 0 && accounts.get(pos).auth_type != Helper.AUTH_TYPE_PASSWORD) if (pos > 0 && accounts.get(pos).auth_type != Helper.AUTH_TYPE_PASSWORD)
tilPassword.getEditText().setText(accounts.get(pos).password); tilPassword.getEditText().setText(accounts.get(pos).password);
setFolders(account.id);
break; break;
} }
}
} else { } else {
int provider = savedInstanceState.getInt("provider"); int provider = savedInstanceState.getInt("provider");
spProvider.setTag(provider); spProvider.setTag(provider);
@ -707,4 +722,76 @@ public class FragmentIdentity extends FragmentEx {
border.setStroke(1, Helper.resolveColor(getContext(), R.attr.colorSeparator)); border.setStroke(1, Helper.resolveColor(getContext(), R.attr.colorSeparator));
vwColor.setBackground(border); 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; message.ui_seen = true;
db.message().updateMessage(message); db.message().updateMessage(message);
if (ident.store_sent) { if (ident.store_sent || ident.sent_folder != null) {
EntityFolder sent = db.folder().getFolderByType(ident.account, EntityFolder.SENT); 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) { if (sent != null) {
message.folder = sent.id; message.folder = sent.id;
message.uid = null; message.uid = null;

@ -351,15 +351,23 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbSynchronize" /> app:layout_constraintTop_toBottomOf="@id/cbSynchronize" />
<CheckBox <TextView
android:id="@+id/cbStoreSent" android:id="@+id/tvSent"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="12dp" 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_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbPrimary" /> 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 <Button
android:id="@+id/btnSave" android:id="@+id/btnSave"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -367,7 +375,7 @@
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:text="@string/title_save" android:text="@string/title_save"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbStoreSent" /> app:layout_constraintTop_toBottomOf="@id/spSent" />
<ProgressBar <ProgressBar
android:id="@+id/pbSave" android:id="@+id/pbSave"
@ -387,7 +395,7 @@
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:src="@drawable/baseline_delete_24" android:src="@drawable/baseline_delete_24"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbStoreSent" /> app:layout_constraintTop_toBottomOf="@id/spSent" />
<ProgressBar <ProgressBar
android:id="@+id/pbWait" android:id="@+id/pbWait"
@ -404,6 +412,6 @@
android:id="@+id/grpAdvanced" android:id="@+id/grpAdvanced"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="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> </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView> </ScrollView>

@ -135,6 +135,7 @@
<string name="title_authorizing">Authorizing account &#8230;</string> <string name="title_authorizing">Authorizing account &#8230;</string>
<string name="title_setup_advanced">Advanced</string> <string name="title_setup_advanced">Advanced</string>
<string name="title_store_sent">Store sent messages (normally not needed)</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_account">Synchronize (receive messages)</string>
<string name="title_synchronize_identity">Synchronize (send messages)</string> <string name="title_synchronize_identity">Synchronize (send messages)</string>
<string name="title_primary_account">Primary (default account)</string> <string name="title_primary_account">Primary (default account)</string>

Loading…
Cancel
Save