Encrypt for CC/BCC

This commit is contained in:
M66B 2019-10-30 11:22:33 +01:00
parent 0668f77968
commit ffe0bbcad8
1 changed files with 49 additions and 19 deletions

View File

@ -1243,17 +1243,25 @@ public class FragmentCompose extends FragmentBase {
onAction(R.id.action_check, extras); onAction(R.id.action_check, extras);
} }
private void onEncrypt() { private void onEncrypt(EntityMessage draft) {
if (pgpService.isBound()) if (pgpService.isBound())
try { try {
String to = etTo.getText().toString(); List<Address> recipients = new ArrayList<>();
InternetAddress ato[] = (TextUtils.isEmpty(to) ? new InternetAddress[0] : InternetAddress.parse(to)); if (draft.to != null)
if (ato.length == 0) recipients.addAll(Arrays.asList(draft.to));
if (draft.cc != null)
recipients.addAll(Arrays.asList(draft.cc));
if (draft.bcc != null)
recipients.addAll(Arrays.asList(draft.bcc));
if (recipients.size() == 0)
throw new IllegalArgumentException(getString(R.string.title_to_missing)); throw new IllegalArgumentException(getString(R.string.title_to_missing));
pgpUserIds = new String[ato.length]; pgpUserIds = new String[recipients.size()];
for (int i = 0; i < ato.length; i++) for (int i = 0; i < recipients.size(); i++) {
pgpUserIds[i] = ato[i].getAddress().toLowerCase(Locale.ROOT); InternetAddress recipient = (InternetAddress) recipients.get(i);
pgpUserIds[i] = recipient.getAddress().toLowerCase(Locale.ROOT);
}
Intent intent = new Intent(OpenPgpApi.ACTION_GET_KEY_IDS); Intent intent = new Intent(OpenPgpApi.ACTION_GET_KEY_IDS);
intent.putExtra(OpenPgpApi.EXTRA_USER_IDS, pgpUserIds); intent.putExtra(OpenPgpApi.EXTRA_USER_IDS, pgpUserIds);
@ -1336,8 +1344,8 @@ public class FragmentCompose extends FragmentBase {
onActionDiscardConfirmed(); onActionDiscardConfirmed();
break; break;
case REQUEST_SEND: case REQUEST_SEND:
if (resultCode == RESULT_OK && data != null) if (resultCode == RESULT_OK)
onActionSend(data.getBundleExtra("args")); onActionSend();
break; break;
} }
} catch (Throwable ex) { } catch (Throwable ex) {
@ -1863,9 +1871,36 @@ public class FragmentCompose extends FragmentBase {
onAction(R.id.action_delete); onAction(R.id.action_delete);
} }
private void onActionSend(Bundle data) { private void onActionSend() {
if (data.getBoolean("encrypt")) Bundle args = new Bundle();
onEncrypt(); args.putLong("id", working);
new SimpleTask<EntityMessage>() {
@Override
protected EntityMessage onExecute(Context context, Bundle args) throws Throwable {
long id = args.getLong("id");
DB db = DB.getInstance(context);
return db.message().getMessage(id);
}
@Override
protected void onExecuted(Bundle args, EntityMessage draft) {
if (draft != null)
onActionSend(draft);
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(this, args, "draft:get");
}
private void onActionSend(EntityMessage draft) {
if (draft.encrypt != null && draft.encrypt)
onEncrypt(draft);
else else
onAction(R.id.action_send); onAction(R.id.action_send);
} }
@ -3120,12 +3155,8 @@ public class FragmentCompose extends FragmentBase {
fragment.setArguments(args); fragment.setArguments(args);
fragment.setTargetFragment(FragmentCompose.this, REQUEST_SEND); fragment.setTargetFragment(FragmentCompose.this, REQUEST_SEND);
fragment.show(getParentFragmentManager(), "compose:send"); fragment.show(getParentFragmentManager(), "compose:send");
} else { } else
if (encrypt) onActionSend(draft);
onEncrypt();
else
onAction(R.id.action_send);
}
} else if (action == R.id.action_send) { } else if (action == R.id.action_send) {
autosave = false; autosave = false;
@ -3739,7 +3770,6 @@ public class FragmentCompose extends FragmentBase {
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
getArguments().putBoolean("encrypt", cbEncrypt.isChecked());
sendResult(Activity.RESULT_OK); sendResult(Activity.RESULT_OK);
} }
}) })