diff --git a/app/src/main/java/eu/faircode/email/ActivityCompose.java b/app/src/main/java/eu/faircode/email/ActivityCompose.java index 06b8bc77cd..d877325161 100644 --- a/app/src/main/java/eu/faircode/email/ActivityCompose.java +++ b/app/src/main/java/eu/faircode/email/ActivityCompose.java @@ -260,11 +260,17 @@ public class ActivityCompose extends ActivityBase implements FragmentManager.OnB boolean attach_new = prefs.getBoolean("attach_new", true); if (!attach_new && !create && - args.size() == 1 && args.containsKey("attachments")) { + args.size() == 1 && + (args.containsKey("to") || + args.containsKey("attachments"))) { List fragments = fm.getFragments(); - if (fragments.size() == 1) { - ((FragmentCompose) fragments.get(0)).onSharedAttachments( - args.getParcelableArrayList("attachments")); + if (fragments.size() == 1 && + fragments.get(0) instanceof FragmentCompose) { + FragmentCompose fragment = ((FragmentCompose) fragments.get(0)); + if (args.containsKey("to")) + fragment.onAddTo(args.getString("to")); + else if (args.containsKey("attachments")) + fragment.onSharedAttachments(args.getParcelableArrayList("attachments")); return; } } diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 7069754590..1d0aff022a 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -3159,14 +3159,15 @@ public class FragmentCompose extends FragmentBase { @Override protected void onExecuted(Bundle args, EntityMessage draft) { + if (draft == null) + return; + if (requestCode == REQUEST_CONTACT_TO) selectIdentityForEmail(args.getString("email")); - if (draft != null) { - etTo.setText(MessageHelper.formatAddressesCompose(draft.to)); - etCc.setText(MessageHelper.formatAddressesCompose(draft.cc)); - etBcc.setText(MessageHelper.formatAddressesCompose(draft.bcc)); - } + etTo.setText(MessageHelper.formatAddressesCompose(draft.to)); + etCc.setText(MessageHelper.formatAddressesCompose(draft.cc)); + etBcc.setText(MessageHelper.formatAddressesCompose(draft.bcc)); // After showDraft/setFocus view.post(new Runnable() { @@ -3203,6 +3204,75 @@ public class FragmentCompose extends FragmentBase { }.serial().execute(this, args, "compose:picked"); } + void onAddTo(String email) { + Bundle args = new Bundle(); + args.putLong("id", working); + args.putString("to", etTo.getText().toString().trim()); + args.putString("email", email); + + new SimpleTask() { + @Override + protected EntityMessage onExecute(Context context, Bundle args) throws Throwable { + long id = args.getLong("id"); + String to = args.getString("to"); + String email = args.getString("email"); + + EntityMessage draft; + DB db = DB.getInstance(context); + + try { + db.beginTransaction(); + + draft = db.message().getMessage(id); + if (draft == null) + return null; + + List
list = new ArrayList<>(); + Address[] _to = MessageHelper.parseAddresses(context, to); + if (_to != null) + list.addAll(Arrays.asList(_to)); + list.add(new InternetAddress(email, null, StandardCharsets.UTF_8.name())); + + draft.to = list.toArray(new Address[0]); + + db.message().updateMessage(draft); + + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } + + return draft; + } + + @Override + protected void onExecuted(Bundle args, EntityMessage draft) { + if (draft == null) + return; + + selectIdentityForEmail(args.getString("email")); + etTo.setText(MessageHelper.formatAddressesCompose(draft.to)); + + // After showDraft/setFocus + view.post(new Runnable() { + @Override + public void run() { + try { + etTo.setSelection(etTo.length()); + } catch (Throwable ex) { + Log.e(ex); + } + } + }); + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Log.unexpectedError(getParentFragmentManager(), ex); + } + }.serial().execute(this, args, "compose:to"); + } + @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { if (pickUri == null)