Skip to content

Commit 24da3ab

Browse files
committed
Added using ".pgp" in the original file name when we are forwarding attachments to maintain a base logic (Encrypted mode).| Close #350
1 parent a02e47d commit 24da3ab

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

FlowCrypt/src/main/java/com/flowcrypt/email/Constants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,6 @@ public class Constants {
9494
public static final String PASSWORD_QUALITY_REASONABLE = "reasonable";
9595
public static final String PASSWORD_QUALITY_WEAK = "weak";
9696
public static final String PASSWORD_QUALITY_POOR = "poor";
97+
98+
public static final String PGP_FILE_EXT = ".pgp";
9799
}

FlowCrypt/src/main/java/com/flowcrypt/email/jobscheduler/ForwardedAttachmentsDownloaderJobService.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.sun.mail.imap.IMAPFolder;
4040

4141
import org.apache.commons.io.FileUtils;
42+
import org.apache.commons.io.FilenameUtils;
4243
import org.apache.commons.io.IOUtils;
4344

4445
import java.io.File;
@@ -277,7 +278,8 @@ private void downloadForwardedAttachments(Context context, Js js, AccountDao acc
277278
if (inputStream != null) {
278279
if (generalMessageDetails.isEncrypted()) {
279280
byte[] encryptedBytes = this.js.crypto_message_encrypt(pubKeys, IOUtils
280-
.toByteArray(inputStream), attachmentInfo.getName());
281+
.toByteArray(inputStream), FilenameUtils.removeExtension(attachmentInfo
282+
.getName()));
281283
FileUtils.writeByteArrayToFile(tempFile, encryptedBytes);
282284
} else {
283285
FileUtils.copyInputStreamToFile(inputStream, tempFile);
@@ -303,14 +305,10 @@ private void downloadForwardedAttachments(Context context, Js js, AccountDao acc
303305
}
304306
}
305307

306-
if (attachmentInfo.getUri() != null || generalMessageDetails.isEncrypted()) { // need db update
308+
if (attachmentInfo.getUri() != null) {
307309
ContentValues contentValues = new ContentValues();
308-
if(attachmentInfo.getUri() != null) { // update new uri
309-
contentValues.put(AttachmentDaoSource.COL_FILE_URI, attachmentInfo.getUri().toString());
310-
}
311-
if(generalMessageDetails.isEncrypted()) { // update filename with .pgp
312-
contentValues.put(AttachmentDaoSource.COL_NAME, attachmentInfo.getName() + ".pgp");
313-
}
310+
contentValues.put(AttachmentDaoSource.COL_FILE_URI, attachmentInfo.getUri().toString());
311+
314312
attachmentDaoSource.update(context, attachmentInfo.getEmail(), attachmentInfo.getFolder(),
315313
attachmentInfo.getUid(), attachmentInfo.getId(), contentValues);
316314
}

FlowCrypt/src/main/java/com/flowcrypt/email/service/PrepareOutgoingMessagesJobIntentService.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ private void addAttachmentsToCache(OutgoingMessageInfo outgoingMessageInfo, long
231231
InputStream inputStream = getContentResolver().openInputStream(uriOfOriginalFile);
232232
if (inputStream != null) {
233233
File encryptedTempFile = new File(messageAttachmentCacheDirectory,
234-
attachmentInfo.getName() + ".pgp");
234+
attachmentInfo.getName() + Constants.PGP_FILE_EXT);
235235
byte[] encryptedBytes = js.crypto_message_encrypt(pubKeys, IOUtils.toByteArray
236236
(inputStream), attachmentInfo.getName());
237237
FileUtils.writeByteArrayToFile(encryptedTempFile, encryptedBytes);
@@ -274,8 +274,17 @@ private void addAttachmentsToCache(OutgoingMessageInfo outgoingMessageInfo, long
274274
}
275275

276276
if (!CollectionUtils.isEmpty(outgoingMessageInfo.getForwardedAttachmentInfoList())) {
277-
for (AttachmentInfo attachmentInfo : outgoingMessageInfo.getForwardedAttachmentInfoList()) {
278-
cachedAttachments.add(new AttachmentInfo(JavaEmailConstants.FOLDER_OUTBOX, attachmentInfo));
277+
if (outgoingMessageInfo.getMessageEncryptionType() == MessageEncryptionType.ENCRYPTED) {
278+
for (AttachmentInfo attachmentInfo : outgoingMessageInfo.getForwardedAttachmentInfoList()) {
279+
AttachmentInfo attachmentInfoEncrypted =
280+
new AttachmentInfo(JavaEmailConstants.FOLDER_OUTBOX, attachmentInfo);
281+
attachmentInfoEncrypted.setName(attachmentInfoEncrypted.getName() + Constants.PGP_FILE_EXT);
282+
cachedAttachments.add(attachmentInfoEncrypted);
283+
}
284+
} else {
285+
for (AttachmentInfo attachmentInfo : outgoingMessageInfo.getForwardedAttachmentInfoList()) {
286+
cachedAttachments.add(new AttachmentInfo(JavaEmailConstants.FOLDER_OUTBOX, attachmentInfo));
287+
}
279288
}
280289
}
281290

FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/MessageDetailsFragment.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import android.widget.TextView;
3535
import android.widget.Toast;
3636

37+
import com.flowcrypt.email.Constants;
3738
import com.flowcrypt.email.R;
3839
import com.flowcrypt.email.api.email.EmailUtil;
3940
import com.flowcrypt.email.api.email.Folder;
@@ -620,7 +621,7 @@ public void onClick(View v) {
620621
layoutAttachment.setOnClickListener(new View.OnClickListener() {
621622
@Override
622623
public void onClick(View v) {
623-
if (attachmentInfo.getUri().getLastPathSegment().endsWith(".pgp")) {
624+
if (attachmentInfo.getUri().getLastPathSegment().endsWith(Constants.PGP_FILE_EXT)) {
624625
imageButtonDownloadAttachment.performClick();
625626
} else {
626627
Intent intentOpenFile = new Intent(Intent.ACTION_VIEW, attachmentInfo.getUri());

0 commit comments

Comments
 (0)