|
|
@ -489,226 +489,228 @@ public class MessageHelper {
|
|
|
|
|
|
|
|
|
|
|
|
List<EntityAttachment> attachments = db.attachment().getAttachments(message.id);
|
|
|
|
List<EntityAttachment> attachments = db.attachment().getAttachments(message.id);
|
|
|
|
|
|
|
|
|
|
|
|
if (message.from != null && message.from.length > 0)
|
|
|
|
if (message.dsn == null || EntityMessage.DSN_NONE.equals(message.dsn)) {
|
|
|
|
for (EntityAttachment attachment : attachments)
|
|
|
|
if (message.from != null && message.from.length > 0)
|
|
|
|
if (EntityAttachment.PGP_KEY.equals(attachment.encryption)) {
|
|
|
|
for (EntityAttachment attachment : attachments)
|
|
|
|
InternetAddress from = (InternetAddress) message.from[0];
|
|
|
|
if (EntityAttachment.PGP_KEY.equals(attachment.encryption)) {
|
|
|
|
|
|
|
|
InternetAddress from = (InternetAddress) message.from[0];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (autocrypt) {
|
|
|
|
|
|
|
|
String mode = (mutual ? "mutual" : "nopreference");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
File file = attachment.getFile(context);
|
|
|
|
|
|
|
|
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
|
|
|
|
|
|
|
|
String line = br.readLine();
|
|
|
|
|
|
|
|
while (line != null) {
|
|
|
|
|
|
|
|
String data = null;
|
|
|
|
|
|
|
|
if (line.length() > 0 &&
|
|
|
|
|
|
|
|
!line.startsWith("-----BEGIN ") &&
|
|
|
|
|
|
|
|
!line.startsWith("-----END "))
|
|
|
|
|
|
|
|
data = line;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
line = br.readLine();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// https://www.w3.org/Protocols/rfc822/3_Lexical.html#z0
|
|
|
|
|
|
|
|
if (data != null &&
|
|
|
|
|
|
|
|
line != null && !line.startsWith("-----END "))
|
|
|
|
|
|
|
|
sb.append("\r\n ").append(data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (autocrypt) {
|
|
|
|
// https://autocrypt.org/level1.html#the-autocrypt-header
|
|
|
|
String mode = (mutual ? "mutual" : "nopreference");
|
|
|
|
imessage.addHeader("Autocrypt",
|
|
|
|
|
|
|
|
"addr=" + from.getAddress() + ";" +
|
|
|
|
|
|
|
|
" prefer-encrypt=" + mode + ";" +
|
|
|
|
|
|
|
|
" keydata=" + sb.toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
// PGP: https://tools.ietf.org/html/rfc3156
|
|
|
|
File file = attachment.getFile(context);
|
|
|
|
// S/MIME: https://tools.ietf.org/html/rfc8551
|
|
|
|
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
|
|
|
|
for (final EntityAttachment attachment : attachments)
|
|
|
|
String line = br.readLine();
|
|
|
|
if (EntityAttachment.PGP_SIGNATURE.equals(attachment.encryption)) {
|
|
|
|
while (line != null) {
|
|
|
|
Log.i("Sending PGP signed message");
|
|
|
|
String data = null;
|
|
|
|
|
|
|
|
if (line.length() > 0 &&
|
|
|
|
for (final EntityAttachment content : attachments)
|
|
|
|
!line.startsWith("-----BEGIN ") &&
|
|
|
|
if (EntityAttachment.PGP_CONTENT.equals(content.encryption)) {
|
|
|
|
!line.startsWith("-----END "))
|
|
|
|
BodyPart bpContent = new MimeBodyPart(new FileInputStream(content.getFile(context)));
|
|
|
|
data = line;
|
|
|
|
|
|
|
|
|
|
|
|
final ContentType cts = new ContentType(attachment.type);
|
|
|
|
line = br.readLine();
|
|
|
|
String micalg = cts.getParameter("micalg");
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(micalg)) {
|
|
|
|
// https://www.w3.org/Protocols/rfc822/3_Lexical.html#z0
|
|
|
|
// Some providers strip parameters
|
|
|
|
if (data != null &&
|
|
|
|
// https://tools.ietf.org/html/rfc3156#section-5
|
|
|
|
line != null && !line.startsWith("-----END "))
|
|
|
|
Log.w("PGP micalg missing type=" + attachment.type);
|
|
|
|
sb.append("\r\n ").append(data);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ParameterList params = cts.getParameterList();
|
|
|
|
|
|
|
|
if (params != null)
|
|
|
|
|
|
|
|
params.remove("micalg");
|
|
|
|
|
|
|
|
cts.setParameterList(params);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Build signature
|
|
|
|
|
|
|
|
BodyPart bpSignature = new MimeBodyPart();
|
|
|
|
|
|
|
|
bpSignature.setFileName(attachment.name);
|
|
|
|
|
|
|
|
FileDataSource dsSignature = new FileDataSource(attachment.getFile(context));
|
|
|
|
|
|
|
|
dsSignature.setFileTypeMap(new FileTypeMap() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public String getContentType(File file) {
|
|
|
|
|
|
|
|
return cts.toString();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// https://autocrypt.org/level1.html#the-autocrypt-header
|
|
|
|
@Override
|
|
|
|
imessage.addHeader("Autocrypt",
|
|
|
|
public String getContentType(String filename) {
|
|
|
|
"addr=" + from.getAddress() + ";" +
|
|
|
|
return cts.toString();
|
|
|
|
" prefer-encrypt=" + mode + ";" +
|
|
|
|
}
|
|
|
|
" keydata=" + sb.toString());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
bpSignature.setDataHandler(new DataHandler(dsSignature));
|
|
|
|
}
|
|
|
|
bpSignature.setDisposition(Part.INLINE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Build message
|
|
|
|
|
|
|
|
ContentType ct = new ContentType("multipart/signed");
|
|
|
|
|
|
|
|
if (micalg != null)
|
|
|
|
|
|
|
|
ct.setParameter("micalg", micalg);
|
|
|
|
|
|
|
|
ct.setParameter("protocol", "application/pgp-signature");
|
|
|
|
|
|
|
|
String ctx = ct.toString();
|
|
|
|
|
|
|
|
int slash = ctx.indexOf("/");
|
|
|
|
|
|
|
|
Multipart multipart = new MimeMultipart(ctx.substring(slash + 1));
|
|
|
|
|
|
|
|
multipart.addBodyPart(bpContent);
|
|
|
|
|
|
|
|
multipart.addBodyPart(bpSignature);
|
|
|
|
|
|
|
|
imessage.setContent(multipart);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return imessage;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new IllegalStateException("PGP content not found");
|
|
|
|
|
|
|
|
} else if (EntityAttachment.PGP_MESSAGE.equals(attachment.encryption)) {
|
|
|
|
|
|
|
|
Log.i("Sending PGP encrypted message");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Build header
|
|
|
|
|
|
|
|
// https://tools.ietf.org/html/rfc3156
|
|
|
|
|
|
|
|
BodyPart bpHeader = new MimeBodyPart();
|
|
|
|
|
|
|
|
bpHeader.setContent("Version: 1\n", "application/pgp-encrypted");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Build content
|
|
|
|
|
|
|
|
BodyPart bpContent = new MimeBodyPart();
|
|
|
|
|
|
|
|
bpContent.setFileName(attachment.name);
|
|
|
|
|
|
|
|
FileDataSource dsContent = new FileDataSource(attachment.getFile(context));
|
|
|
|
|
|
|
|
dsContent.setFileTypeMap(new FileTypeMap() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public String getContentType(File file) {
|
|
|
|
|
|
|
|
return attachment.type;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// PGP: https://tools.ietf.org/html/rfc3156
|
|
|
|
@Override
|
|
|
|
// S/MIME: https://tools.ietf.org/html/rfc8551
|
|
|
|
public String getContentType(String filename) {
|
|
|
|
for (final EntityAttachment attachment : attachments)
|
|
|
|
return attachment.type;
|
|
|
|
if (EntityAttachment.PGP_SIGNATURE.equals(attachment.encryption)) {
|
|
|
|
|
|
|
|
Log.i("Sending PGP signed message");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (final EntityAttachment content : attachments)
|
|
|
|
|
|
|
|
if (EntityAttachment.PGP_CONTENT.equals(content.encryption)) {
|
|
|
|
|
|
|
|
BodyPart bpContent = new MimeBodyPart(new FileInputStream(content.getFile(context)));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final ContentType cts = new ContentType(attachment.type);
|
|
|
|
|
|
|
|
String micalg = cts.getParameter("micalg");
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(micalg)) {
|
|
|
|
|
|
|
|
// Some providers strip parameters
|
|
|
|
|
|
|
|
// https://tools.ietf.org/html/rfc3156#section-5
|
|
|
|
|
|
|
|
Log.w("PGP micalg missing type=" + attachment.type);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ParameterList params = cts.getParameterList();
|
|
|
|
});
|
|
|
|
if (params != null)
|
|
|
|
bpContent.setDataHandler(new DataHandler(dsContent));
|
|
|
|
params.remove("micalg");
|
|
|
|
bpContent.setDisposition(Part.INLINE);
|
|
|
|
cts.setParameterList(params);
|
|
|
|
|
|
|
|
|
|
|
|
// Build message
|
|
|
|
// Build signature
|
|
|
|
ContentType ct = new ContentType("multipart/encrypted");
|
|
|
|
BodyPart bpSignature = new MimeBodyPart();
|
|
|
|
ct.setParameter("protocol", "application/pgp-encrypted");
|
|
|
|
bpSignature.setFileName(attachment.name);
|
|
|
|
String ctx = ct.toString();
|
|
|
|
FileDataSource dsSignature = new FileDataSource(attachment.getFile(context));
|
|
|
|
int slash = ctx.indexOf("/");
|
|
|
|
dsSignature.setFileTypeMap(new FileTypeMap() {
|
|
|
|
Multipart multipart = new MimeMultipart(ctx.substring(slash + 1));
|
|
|
|
@Override
|
|
|
|
multipart.addBodyPart(bpHeader);
|
|
|
|
public String getContentType(File file) {
|
|
|
|
multipart.addBodyPart(bpContent);
|
|
|
|
return cts.toString();
|
|
|
|
imessage.setContent(multipart);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (encrypt_subject)
|
|
|
|
|
|
|
|
imessage.setSubject("...");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return imessage;
|
|
|
|
|
|
|
|
} else if (EntityAttachment.SMIME_SIGNATURE.equals(attachment.encryption)) {
|
|
|
|
|
|
|
|
Log.i("Sending S/MIME signed message");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (final EntityAttachment content : attachments)
|
|
|
|
|
|
|
|
if (EntityAttachment.SMIME_CONTENT.equals(content.encryption)) {
|
|
|
|
|
|
|
|
BodyPart bpContent = new MimeBodyPart(new FileInputStream(content.getFile(context)));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final ContentType cts = new ContentType(attachment.type);
|
|
|
|
|
|
|
|
String micalg = cts.getParameter("micalg");
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(micalg)) {
|
|
|
|
|
|
|
|
// Some providers strip parameters
|
|
|
|
|
|
|
|
Log.w("S/MIME micalg missing type=" + attachment.type);
|
|
|
|
|
|
|
|
micalg = "sha-256";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ParameterList params = cts.getParameterList();
|
|
|
|
|
|
|
|
if (params != null)
|
|
|
|
|
|
|
|
params.remove("micalg");
|
|
|
|
|
|
|
|
cts.setParameterList(params);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Build signature
|
|
|
|
|
|
|
|
BodyPart bpSignature = new MimeBodyPart();
|
|
|
|
|
|
|
|
bpSignature.setFileName(attachment.name);
|
|
|
|
|
|
|
|
FileDataSource dsSignature = new FileDataSource(attachment.getFile(context));
|
|
|
|
|
|
|
|
dsSignature.setFileTypeMap(new FileTypeMap() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public String getContentType(File file) {
|
|
|
|
|
|
|
|
return cts.toString();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public String getContentType(String filename) {
|
|
|
|
public String getContentType(String filename) {
|
|
|
|
return cts.toString();
|
|
|
|
return cts.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
bpSignature.setDataHandler(new DataHandler(dsSignature));
|
|
|
|
bpSignature.setDataHandler(new DataHandler(dsSignature));
|
|
|
|
bpSignature.setDisposition(Part.INLINE);
|
|
|
|
bpSignature.setDisposition(Part.INLINE);
|
|
|
|
|
|
|
|
|
|
|
|
// Build message
|
|
|
|
// Build message
|
|
|
|
ContentType ct = new ContentType("multipart/signed");
|
|
|
|
ContentType ct = new ContentType("multipart/signed");
|
|
|
|
if (micalg != null)
|
|
|
|
|
|
|
|
ct.setParameter("micalg", micalg);
|
|
|
|
ct.setParameter("micalg", micalg);
|
|
|
|
ct.setParameter("protocol", "application/pgp-signature");
|
|
|
|
ct.setParameter("protocol", "application/pkcs7-signature");
|
|
|
|
String ctx = ct.toString();
|
|
|
|
ct.setParameter("smime-type", "signed-data");
|
|
|
|
int slash = ctx.indexOf("/");
|
|
|
|
String ctx = ct.toString();
|
|
|
|
Multipart multipart = new MimeMultipart(ctx.substring(slash + 1));
|
|
|
|
int slash = ctx.indexOf("/");
|
|
|
|
multipart.addBodyPart(bpContent);
|
|
|
|
Multipart multipart = new MimeMultipart(ctx.substring(slash + 1));
|
|
|
|
multipart.addBodyPart(bpSignature);
|
|
|
|
multipart.addBodyPart(bpContent);
|
|
|
|
imessage.setContent(multipart);
|
|
|
|
multipart.addBodyPart(bpSignature);
|
|
|
|
|
|
|
|
imessage.setContent(multipart);
|
|
|
|
return imessage;
|
|
|
|
|
|
|
|
}
|
|
|
|
return imessage;
|
|
|
|
throw new IllegalStateException("PGP content not found");
|
|
|
|
}
|
|
|
|
} else if (EntityAttachment.PGP_MESSAGE.equals(attachment.encryption)) {
|
|
|
|
throw new IllegalStateException("S/MIME content not found");
|
|
|
|
Log.i("Sending PGP encrypted message");
|
|
|
|
} else if (EntityAttachment.SMIME_MESSAGE.equals(attachment.encryption)) {
|
|
|
|
|
|
|
|
Log.i("Sending S/MIME encrypted message");
|
|
|
|
// Build header
|
|
|
|
|
|
|
|
// https://tools.ietf.org/html/rfc3156
|
|
|
|
|
|
|
|
BodyPart bpHeader = new MimeBodyPart();
|
|
|
|
|
|
|
|
bpHeader.setContent("Version: 1\n", "application/pgp-encrypted");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Build content
|
|
|
|
|
|
|
|
BodyPart bpContent = new MimeBodyPart();
|
|
|
|
|
|
|
|
bpContent.setFileName(attachment.name);
|
|
|
|
|
|
|
|
FileDataSource dsContent = new FileDataSource(attachment.getFile(context));
|
|
|
|
|
|
|
|
dsContent.setFileTypeMap(new FileTypeMap() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public String getContentType(File file) {
|
|
|
|
|
|
|
|
return attachment.type;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
// Build message
|
|
|
|
public String getContentType(String filename) {
|
|
|
|
imessage.setDisposition(Part.ATTACHMENT);
|
|
|
|
return attachment.type;
|
|
|
|
imessage.setFileName(attachment.name);
|
|
|
|
}
|
|
|
|
imessage.setDescription("S/MIME Encrypted Message");
|
|
|
|
});
|
|
|
|
|
|
|
|
bpContent.setDataHandler(new DataHandler(dsContent));
|
|
|
|
ContentType ct = new ContentType("application/pkcs7-mime");
|
|
|
|
bpContent.setDisposition(Part.INLINE);
|
|
|
|
ct.setParameter("name", attachment.name);
|
|
|
|
|
|
|
|
ct.setParameter("smime-type", "enveloped-data");
|
|
|
|
// Build message
|
|
|
|
|
|
|
|
ContentType ct = new ContentType("multipart/encrypted");
|
|
|
|
File file = attachment.getFile(context);
|
|
|
|
ct.setParameter("protocol", "application/pgp-encrypted");
|
|
|
|
FileDataSource dataSource = new FileDataSource(file);
|
|
|
|
String ctx = ct.toString();
|
|
|
|
dataSource.setFileTypeMap(new FileTypeMap() {
|
|
|
|
int slash = ctx.indexOf("/");
|
|
|
|
@Override
|
|
|
|
Multipart multipart = new MimeMultipart(ctx.substring(slash + 1));
|
|
|
|
public String getContentType(File file) {
|
|
|
|
multipart.addBodyPart(bpHeader);
|
|
|
|
return ct.toString();
|
|
|
|
multipart.addBodyPart(bpContent);
|
|
|
|
|
|
|
|
imessage.setContent(multipart);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (encrypt_subject)
|
|
|
|
|
|
|
|
imessage.setSubject("...");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return imessage;
|
|
|
|
|
|
|
|
} else if (EntityAttachment.SMIME_SIGNATURE.equals(attachment.encryption)) {
|
|
|
|
|
|
|
|
Log.i("Sending S/MIME signed message");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (final EntityAttachment content : attachments)
|
|
|
|
|
|
|
|
if (EntityAttachment.SMIME_CONTENT.equals(content.encryption)) {
|
|
|
|
|
|
|
|
BodyPart bpContent = new MimeBodyPart(new FileInputStream(content.getFile(context)));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final ContentType cts = new ContentType(attachment.type);
|
|
|
|
|
|
|
|
String micalg = cts.getParameter("micalg");
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(micalg)) {
|
|
|
|
|
|
|
|
// Some providers strip parameters
|
|
|
|
|
|
|
|
Log.w("S/MIME micalg missing type=" + attachment.type);
|
|
|
|
|
|
|
|
micalg = "sha-256";
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ParameterList params = cts.getParameterList();
|
|
|
|
|
|
|
|
if (params != null)
|
|
|
|
|
|
|
|
params.remove("micalg");
|
|
|
|
|
|
|
|
cts.setParameterList(params);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Build signature
|
|
|
|
|
|
|
|
BodyPart bpSignature = new MimeBodyPart();
|
|
|
|
|
|
|
|
bpSignature.setFileName(attachment.name);
|
|
|
|
|
|
|
|
FileDataSource dsSignature = new FileDataSource(attachment.getFile(context));
|
|
|
|
|
|
|
|
dsSignature.setFileTypeMap(new FileTypeMap() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public String getContentType(File file) {
|
|
|
|
|
|
|
|
return cts.toString();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public String getContentType(String filename) {
|
|
|
|
public String getContentType(String filename) {
|
|
|
|
return cts.toString();
|
|
|
|
return ct.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
bpSignature.setDataHandler(new DataHandler(dsSignature));
|
|
|
|
|
|
|
|
bpSignature.setDisposition(Part.INLINE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Build message
|
|
|
|
|
|
|
|
ContentType ct = new ContentType("multipart/signed");
|
|
|
|
|
|
|
|
ct.setParameter("micalg", micalg);
|
|
|
|
|
|
|
|
ct.setParameter("protocol", "application/pkcs7-signature");
|
|
|
|
|
|
|
|
ct.setParameter("smime-type", "signed-data");
|
|
|
|
|
|
|
|
String ctx = ct.toString();
|
|
|
|
|
|
|
|
int slash = ctx.indexOf("/");
|
|
|
|
|
|
|
|
Multipart multipart = new MimeMultipart(ctx.substring(slash + 1));
|
|
|
|
|
|
|
|
multipart.addBodyPart(bpContent);
|
|
|
|
|
|
|
|
multipart.addBodyPart(bpSignature);
|
|
|
|
|
|
|
|
imessage.setContent(multipart);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return imessage;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new IllegalStateException("S/MIME content not found");
|
|
|
|
|
|
|
|
} else if (EntityAttachment.SMIME_MESSAGE.equals(attachment.encryption)) {
|
|
|
|
|
|
|
|
Log.i("Sending S/MIME encrypted message");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Build message
|
|
|
|
|
|
|
|
imessage.setDisposition(Part.ATTACHMENT);
|
|
|
|
|
|
|
|
imessage.setFileName(attachment.name);
|
|
|
|
|
|
|
|
imessage.setDescription("S/MIME Encrypted Message");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ContentType ct = new ContentType("application/pkcs7-mime");
|
|
|
|
|
|
|
|
ct.setParameter("name", attachment.name);
|
|
|
|
|
|
|
|
ct.setParameter("smime-type", "enveloped-data");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
File file = attachment.getFile(context);
|
|
|
|
|
|
|
|
FileDataSource dataSource = new FileDataSource(file);
|
|
|
|
|
|
|
|
dataSource.setFileTypeMap(new FileTypeMap() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public String getContentType(File file) {
|
|
|
|
|
|
|
|
return ct.toString();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
imessage.setDataHandler(new DataHandler(dataSource));
|
|
|
|
public String getContentType(String filename) {
|
|
|
|
|
|
|
|
return ct.toString();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
imessage.setDataHandler(new DataHandler(dataSource));
|
|
|
|
return imessage;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return imessage;
|
|
|
|
if (EntityMessage.PGP_SIGNENCRYPT.equals(message.ui_encrypt) ||
|
|
|
|
|
|
|
|
EntityMessage.SMIME_SIGNENCRYPT.equals(message.ui_encrypt)) {
|
|
|
|
|
|
|
|
String msg = "Storing unencrypted message" +
|
|
|
|
|
|
|
|
" encrypt=" + message.encrypt + "/" + message.ui_encrypt;
|
|
|
|
|
|
|
|
Log.w(msg);
|
|
|
|
|
|
|
|
throw new IllegalArgumentException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (EntityMessage.PGP_SIGNENCRYPT.equals(message.ui_encrypt) ||
|
|
|
|
|
|
|
|
EntityMessage.SMIME_SIGNENCRYPT.equals(message.ui_encrypt)) {
|
|
|
|
|
|
|
|
String msg = "Storing unencrypted message" +
|
|
|
|
|
|
|
|
" encrypt=" + message.encrypt + "/" + message.ui_encrypt;
|
|
|
|
|
|
|
|
Log.w(msg);
|
|
|
|
|
|
|
|
throw new IllegalArgumentException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
build(context, message, attachments, identity, send, imessage);
|
|
|
|
build(context, message, attachments, identity, send, imessage);
|
|
|
|