diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index fa1215750a..a45b7b3fbe 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -3836,7 +3836,7 @@ public class FragmentCompose extends FragmentBase { bpContent.setContent(imessage.getContent(), imessage.getContentType()); try (OutputStream out = new MessageHelper.CanonicalizingStream( - new BufferedOutputStream(new FileOutputStream(input)))) { + new BufferedOutputStream(new FileOutputStream(input)), EntityAttachment.PGP_CONTENT, null)) { bpContent.writeTo(out); } } else { @@ -4250,7 +4250,7 @@ public class FragmentCompose extends FragmentBase { // Build content File sinput = new File(tmp, draft.id + ".smime_sign"); try (OutputStream os = new MessageHelper.CanonicalizingStream( - new BufferedOutputStream(new FileOutputStream(sinput)))) { + new BufferedOutputStream(new FileOutputStream(sinput)), EntityAttachment.SMIME_CONTENT, null)) { bpContent.writeTo(os); } diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index db386d269a..317e17c895 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -4101,7 +4101,7 @@ public class MessageHelper { throw new ParseException("Signed boundary missing"); File file = local.getFile(context); - try (OutputStream os = new BufferedOutputStream(new CanonicalizingStream(new FileOutputStream(file), boundary))) { + try (OutputStream os = new BufferedOutputStream(new CanonicalizingStream(new FileOutputStream(file), apart.encrypt, boundary))) { apart.part.writeTo(os); } @@ -5762,6 +5762,7 @@ public class MessageHelper { static class CanonicalizingStream extends FilterOutputStream { private OutputStream os; + private int content; private String boundary; private int boundaries = 0; @@ -5773,15 +5774,10 @@ public class MessageHelper { // PGP: https://datatracker.ietf.org/doc/html/rfc3156#section-5 // S/MIME: https://datatracker.ietf.org/doc/html/rfc8551#section-3.1.1 - public CanonicalizingStream(OutputStream out) { - super(out); - this.os = out; - this.boundary = null; - } - - public CanonicalizingStream(OutputStream out, String boundary) { + public CanonicalizingStream(OutputStream out, int content, String boundary) { super(out); this.os = out; + this.content = content; this.boundary = "--" + boundary; } @@ -5842,7 +5838,8 @@ public class MessageHelper { return false; } - line = line.replaceAll(" +$", ""); + if (EntityAttachment.PGP_CONTENT.equals(content) || boundary == null) + line = line.replaceAll(" +$", ""); os.write(line.getBytes(StandardCharsets.ISO_8859_1));