Skip to content

Commit ca9aef2

Browse files
committed
Added "Content-ID" header when sending an email with attachments. | #107.
1 parent 04ffaff commit ca9aef2

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Business Source License 1.0 © 2017 FlowCrypt Limited ([email protected]).
3+
* Use limitations apply. See https://github.com/FlowCrypt/flowcrypt-android/blob/master/LICENSE
4+
* Contributors: DenBond7
5+
*/
6+
7+
package com.flowcrypt.email.api.email;
8+
9+
import java.util.UUID;
10+
11+
/**
12+
* @author Denis Bondarenko
13+
* Date: 29.09.2017
14+
* Time: 15:31
15+
16+
*/
17+
18+
public class EmailUtil {
19+
public static String generateContentId() {
20+
return "<" + UUID.randomUUID().toString() + "@flowcrypt" + ">";
21+
}
22+
}

FlowCrypt/src/main/java/com/flowcrypt/email/api/email/sync/tasks/SendMessageSyncTask.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import android.text.TextUtils;
1414
import android.util.Log;
1515

16+
import com.flowcrypt.email.api.email.EmailUtil;
1617
import com.flowcrypt.email.api.email.FoldersManager;
1718
import com.flowcrypt.email.api.email.model.AttachmentInfo;
1819
import com.flowcrypt.email.api.email.model.OutgoingMessageInfo;
@@ -174,8 +175,10 @@ private MimeMessage createMimeMessage(Session session, Context context, File pgp
174175
MimeMultipart mimeMultipart = (MimeMultipart) mimeMessage.getContent();
175176

176177
for (AttachmentInfo attachmentInfo : outgoingMessageInfo.getAttachmentInfoArrayList()) {
177-
mimeMultipart.addBodyPart(generateBodyPartWithAttachment(context, pgpCacheDirectory,
178-
js, pubKeys, attachmentInfo));
178+
MimeBodyPart bodyPart = generateBodyPartWithAttachment(context, pgpCacheDirectory,
179+
js, pubKeys, attachmentInfo);
180+
bodyPart.setContentID(EmailUtil.generateContentId());
181+
mimeMultipart.addBodyPart(bodyPart);
179182
}
180183

181184
mimeMessage.setContent(mimeMultipart);
@@ -193,15 +196,15 @@ private MimeMessage createMimeMessage(Session session, Context context, File pgp
193196
* @param js The {@link Js} tools.
194197
* @param pubKeys The public keys which will be used for generate an encrypted attachments.
195198
* @param attachmentInfo The {@link AttachmentInfo} object, which contains general information about attachment.
196-
* @return Generated {@link BodyPart} with an attachment.
199+
* @return Generated {@link MimeBodyPart} with an attachment.
197200
* @throws IOException
198201
* @throws MessagingException
199202
*/
200203
@NonNull
201-
private BodyPart generateBodyPartWithAttachment(Context context, File pgpCacheDirectory, Js js,
202-
String[] pubKeys, AttachmentInfo attachmentInfo)
204+
private MimeBodyPart generateBodyPartWithAttachment(Context context, File pgpCacheDirectory, Js js,
205+
String[] pubKeys, AttachmentInfo attachmentInfo)
203206
throws IOException, MessagingException {
204-
BodyPart attachmentsBodyPart = new MimeBodyPart();
207+
MimeBodyPart attachmentsBodyPart = new MimeBodyPart();
205208
switch (outgoingMessageInfo.getMessageEncryptionType()) {
206209
case ENCRYPTED:
207210
InputStream inputStream =

FlowCrypt/src/main/java/com/flowcrypt/email/api/email/sync/tasks/SendMessageWithBackupToKeyOwnerSynsTask.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import android.text.TextUtils;
1313

1414
import com.flowcrypt.email.R;
15+
import com.flowcrypt.email.api.email.EmailUtil;
1516
import com.flowcrypt.email.api.email.JavaEmailConstants;
1617
import com.flowcrypt.email.api.email.sync.SyncListener;
1718
import com.flowcrypt.email.database.dao.source.AccountDao;
@@ -115,8 +116,9 @@ private Message generateMessage(Context context, Session session) throws Excepti
115116
List<PrivateKeyInfo> privateKeyInfoList = SecurityUtils.getPrivateKeysInfo(context);
116117

117118
for (int i = 0; i < privateKeyInfoList.size(); i++) {
118-
BodyPart attachmentsBodyPart = generateAttachmentBodyPartWithPrivateKey
119+
MimeBodyPart attachmentsBodyPart = generateAttachmentBodyPartWithPrivateKey
119120
(context, privateKeyInfoList, i);
121+
attachmentsBodyPart.setContentID(EmailUtil.generateContentId());
120122
multipart.addBodyPart(attachmentsBodyPart);
121123
}
122124

@@ -134,13 +136,13 @@ private Message generateMessage(Context context, Session session) throws Excepti
134136
* @throws Exception will occur when generate this {@link BodyPart}.
135137
*/
136138
@NonNull
137-
private BodyPart generateAttachmentBodyPartWithPrivateKey(
139+
private MimeBodyPart generateAttachmentBodyPartWithPrivateKey(
138140
Context context, List<PrivateKeyInfo> privateKeyInfoList, int i)
139141
throws Exception {
140142
Js js = new Js(context, new SecurityStorageConnector(context));
141143

142144
PrivateKeyInfo privateKeyInfo = privateKeyInfoList.get(i);
143-
BodyPart attachmentsBodyPart = new MimeBodyPart();
145+
MimeBodyPart attachmentsBodyPart = new MimeBodyPart();
144146
String attachmentName = SecurityUtils.generateNameForPrivateKey(accountName +
145147
"_" + i);
146148

0 commit comments

Comments
 (0)