|
|
|
@ -115,7 +115,6 @@ import org.openintents.openpgp.util.OpenPgpApi;
|
|
|
|
|
import org.openintents.openpgp.util.OpenPgpServiceConnection;
|
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
@ -3841,23 +3840,23 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|
|
|
|
Intent data = args.getParcelable("data");
|
|
|
|
|
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
|
List<EntityAttachment> attachments = db.attachment().getAttachments(id);
|
|
|
|
|
|
|
|
|
|
InputStream in = null;
|
|
|
|
|
boolean inline = false;
|
|
|
|
|
InputStream encrypted = null;
|
|
|
|
|
|
|
|
|
|
// Find encrypted data
|
|
|
|
|
List<EntityAttachment> attachments = db.attachment().getAttachments(id);
|
|
|
|
|
for (EntityAttachment attachment : attachments)
|
|
|
|
|
if (EntityAttachment.PGP_MESSAGE.equals(attachment.encryption)) {
|
|
|
|
|
if (!attachment.available)
|
|
|
|
|
throw new IllegalArgumentException(context.getString(R.string.title_attachments_missing));
|
|
|
|
|
|
|
|
|
|
File file = attachment.getFile(context);
|
|
|
|
|
encrypted = new FileInputStream(file);
|
|
|
|
|
in = new FileInputStream(file);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (encrypted == null) {
|
|
|
|
|
if (in == null) {
|
|
|
|
|
EntityMessage message = db.message().getMessage(id);
|
|
|
|
|
if (message != null && message.content) {
|
|
|
|
|
File file = message.getFile(context);
|
|
|
|
@ -3876,20 +3875,27 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|
|
|
|
section = TextUtils.join("\n\r", disarmored);
|
|
|
|
|
|
|
|
|
|
inline = true;
|
|
|
|
|
encrypted = new ByteArrayInputStream(section.getBytes());
|
|
|
|
|
in = new ByteArrayInputStream(section.getBytes());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (encrypted == null)
|
|
|
|
|
if (in == null)
|
|
|
|
|
throw new IllegalArgumentException(context.getString(R.string.title_not_encrypted));
|
|
|
|
|
|
|
|
|
|
ByteArrayOutputStream decrypted = new ByteArrayOutputStream();
|
|
|
|
|
|
|
|
|
|
Intent result;
|
|
|
|
|
File plain = File.createTempFile("plain", "." + id, context.getCacheDir());
|
|
|
|
|
try {
|
|
|
|
|
// Decrypt message
|
|
|
|
|
try {
|
|
|
|
|
try (OutputStream out = new FileOutputStream(plain)) {
|
|
|
|
|
OpenPgpApi api = new OpenPgpApi(context, pgpService.getService());
|
|
|
|
|
Intent result = api.executeApi(data, encrypted, decrypted);
|
|
|
|
|
result = api.executeApi(data, in, out);
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
in.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log.i("PGP result=" + result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR));
|
|
|
|
|
switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
|
|
|
|
@ -3903,8 +3909,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|
|
|
|
db.beginTransaction();
|
|
|
|
|
|
|
|
|
|
// Write decrypted body
|
|
|
|
|
Helper.writeText(message.getFile(context), decrypted.toString());
|
|
|
|
|
|
|
|
|
|
Helper.copy(plain, message.getFile(context));
|
|
|
|
|
db.message().setMessageStored(id, new Date().getTime());
|
|
|
|
|
|
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
@ -3914,12 +3919,14 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
// Decode message
|
|
|
|
|
MessageHelper.MessageParts parts;
|
|
|
|
|
Properties props = MessageHelper.getSessionProperties();
|
|
|
|
|
Session isession = Session.getInstance(props, null);
|
|
|
|
|
ByteArrayInputStream is = new ByteArrayInputStream(decrypted.toByteArray());
|
|
|
|
|
MimeMessage imessage = new MimeMessage(isession, is);
|
|
|
|
|
try (InputStream fis = new FileInputStream(plain)) {
|
|
|
|
|
MimeMessage imessage = new MimeMessage(isession, fis);
|
|
|
|
|
MessageHelper helper = new MessageHelper(imessage);
|
|
|
|
|
MessageHelper.MessageParts parts = helper.getMessageParts();
|
|
|
|
|
parts = helper.getMessageParts();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
db.beginTransaction();
|
|
|
|
@ -3977,6 +3984,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|
|
|
|
OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR);
|
|
|
|
|
throw new IllegalArgumentException(error.getMessage());
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
plain.delete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|