mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-05 08:33:37 +02:00
Refactoring
This commit is contained in:
@@ -3149,27 +3149,12 @@ public class FragmentCompose extends FragmentBase {
|
||||
result.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, identity.sign_key);
|
||||
} else {
|
||||
// Call OpenPGP
|
||||
OpenPgpServiceConnection pgpService = null;
|
||||
try {
|
||||
pgpService = PgpHelper.getConnection(context);
|
||||
if (!pgpService.isBound())
|
||||
throw new OperationCanceledException();
|
||||
|
||||
Log.i("Executing " + data.getAction());
|
||||
Log.logExtras(data);
|
||||
OpenPgpApi api = new OpenPgpApi(context, pgpService.getService());
|
||||
result = api.executeApi(data, new FileInputStream(input), new FileOutputStream(output));
|
||||
} finally {
|
||||
if (pgpService != null && pgpService.isBound())
|
||||
pgpService.unbindFromService();
|
||||
}
|
||||
result = PgpHelper.execute(context, data, new FileInputStream(input), new FileOutputStream(output));
|
||||
}
|
||||
|
||||
// Process result
|
||||
try {
|
||||
int resultCode = result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR);
|
||||
Log.i("Result action=" + data.getAction() + " code=" + resultCode);
|
||||
Log.logExtras(data);
|
||||
switch (resultCode) {
|
||||
case OpenPgpApi.RESULT_CODE_SUCCESS:
|
||||
// Attach key, signed/encrypted data
|
||||
@@ -6450,35 +6435,26 @@ public class FragmentCompose extends FragmentBase {
|
||||
if (recipients == null || recipients.size() == 0)
|
||||
return false;
|
||||
|
||||
OpenPgpServiceConnection pgpService = null;
|
||||
String[] userIds = new String[recipients.size()];
|
||||
for (int i = 0; i < recipients.size(); i++) {
|
||||
InternetAddress recipient = (InternetAddress) recipients.get(i);
|
||||
userIds[i] = recipient.getAddress();
|
||||
}
|
||||
|
||||
Intent intent = new Intent(OpenPgpApi.ACTION_GET_KEY_IDS);
|
||||
intent.putExtra(OpenPgpApi.EXTRA_USER_IDS, userIds);
|
||||
|
||||
try {
|
||||
pgpService = PgpHelper.getConnection(context, MAX_PGP_BIND_DELAY);
|
||||
if (!pgpService.isBound())
|
||||
return false;
|
||||
|
||||
String[] userIds = new String[recipients.size()];
|
||||
for (int i = 0; i < recipients.size(); i++) {
|
||||
InternetAddress recipient = (InternetAddress) recipients.get(i);
|
||||
userIds[i] = recipient.getAddress();
|
||||
Intent result = PgpHelper.execute(context, intent, null, null, MAX_PGP_BIND_DELAY);
|
||||
int resultCode = result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR);
|
||||
if (resultCode == OpenPgpApi.RESULT_CODE_SUCCESS) {
|
||||
long[] keyIds = result.getLongArrayExtra(OpenPgpApi.EXTRA_KEY_IDS);
|
||||
return (keyIds.length > 0);
|
||||
}
|
||||
|
||||
Intent intent = new Intent(OpenPgpApi.ACTION_GET_KEY_IDS);
|
||||
intent.putExtra(OpenPgpApi.EXTRA_USER_IDS, userIds);
|
||||
|
||||
try {
|
||||
OpenPgpApi api = new OpenPgpApi(context, pgpService.getService());
|
||||
Intent result = api.executeApi(intent, (InputStream) null, (OutputStream) null);
|
||||
int resultCode = result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR);
|
||||
if (resultCode == OpenPgpApi.RESULT_CODE_SUCCESS) {
|
||||
long[] keyIds = result.getLongArrayExtra(OpenPgpApi.EXTRA_KEY_IDS);
|
||||
return (keyIds.length > 0);
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
} finally {
|
||||
if (pgpService != null && pgpService.isBound())
|
||||
pgpService.unbindFromService();
|
||||
} catch (OperationCanceledException ignored) {
|
||||
// Do nothing
|
||||
} catch (Throwable ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user