|
26 | 26 | import android.widget.Toast; |
27 | 27 |
|
28 | 28 | import com.flowcrypt.email.BuildConfig; |
| 29 | +import com.flowcrypt.email.Constants; |
29 | 30 | import com.flowcrypt.email.R; |
30 | 31 | import com.flowcrypt.email.api.email.JavaEmailConstants; |
31 | 32 | import com.flowcrypt.email.api.email.model.AttachmentInfo; |
@@ -463,6 +464,8 @@ public void run() { |
463 | 464 | AccountDao accountDao = new AccountDaoSource().getAccountInformation(context, attachmentInfo.getEmail()); |
464 | 465 |
|
465 | 466 | try { |
| 467 | + checkMaxDecryptedFileSize(); |
| 468 | + |
466 | 469 | Session session = OpenStoreHelper.getAttachmentSession(accountDao); |
467 | 470 | Store store = OpenStoreHelper.openAndConnectToStore(context, accountDao, session); |
468 | 471 | IMAPFolder imapFolder = (IMAPFolder) store.getFolder(new ImapLabelsDaoSource() |
@@ -542,6 +545,23 @@ public void setOnDownloadAttachmentListener(OnDownloadAttachmentListener onDownl |
542 | 545 | this.onDownloadAttachmentListener = onDownloadAttachmentListener; |
543 | 546 | } |
544 | 547 |
|
| 548 | + /** |
| 549 | + * Check is decrypted file has size not more than |
| 550 | + * {@link Constants#MAX_ATTACHMENT_SIZE_WHICH_CAN_BE_DECRYPTED}. If the file greater then |
| 551 | + * {@link Constants#MAX_ATTACHMENT_SIZE_WHICH_CAN_BE_DECRYPTED} we throw an exception. This is only for files |
| 552 | + * with the "pgp" extension. |
| 553 | + */ |
| 554 | + private void checkMaxDecryptedFileSize() { |
| 555 | + if ("pgp".equalsIgnoreCase(FilenameUtils.getExtension(attachmentInfo.getName()))) { |
| 556 | + if (attachmentInfo.getEncodedSize() > Constants.MAX_ATTACHMENT_SIZE_WHICH_CAN_BE_DECRYPTED) { |
| 557 | + throw new IllegalArgumentException(context.getString(R.string |
| 558 | + .template_warning_max_attachments_size_for_decryption, |
| 559 | + FileUtils.byteCountToDisplaySize(Constants |
| 560 | + .MAX_ATTACHMENT_SIZE_WHICH_CAN_BE_DECRYPTED))); |
| 561 | + } |
| 562 | + } |
| 563 | + } |
| 564 | + |
545 | 565 | /** |
546 | 566 | * Do decryption of the downloaded file if it need. |
547 | 567 | * |
@@ -594,10 +614,12 @@ private File decryptFileIfNeed(Context context, File file) throws IOException { |
594 | 614 | * @param attachmentFile The file which will be removed. |
595 | 615 | */ |
596 | 616 | private void removeNotCompleteDownloadFile(File attachmentFile) { |
597 | | - if (!attachmentFile.delete()) { |
598 | | - Log.d(TAG, "Cannot delete file: " + attachmentFile); |
599 | | - } else { |
600 | | - Log.d(TAG, "Canceled attachment \"" + attachmentFile + "\" was deleted"); |
| 617 | + if (attachmentFile != null && attachmentFile.exists()) { |
| 618 | + if (!attachmentFile.delete()) { |
| 619 | + Log.d(TAG, "Cannot delete file: " + attachmentFile); |
| 620 | + } else { |
| 621 | + Log.d(TAG, "Canceled attachment \"" + attachmentFile + "\" was deleted"); |
| 622 | + } |
601 | 623 | } |
602 | 624 | } |
603 | 625 |
|
|
0 commit comments