public void Execute(CancellationToken token) { using (var packager = new MailAttachmentPackager()) { foreach (IProtectAttachment attachment in _attachments) { if (token.IsCancellationRequested) return; // it is not possible to process encrypted attachment if (attachment.HasPassword && string.IsNullOrEmpty(attachment.OpenPassword)) continue; packager.RePack(attachment, token); } } }
public void Execute(CancellationToken token) { if (token.IsCancellationRequested) return; Attachment.Status = PropertyNames.Processing; switch (Attachment.FileType) { case FileType.PDFDocument: { if (!string.IsNullOrEmpty(Attachment.OpenPassword)) { Pdf.Security.Add(Attachment.FileName, Attachment.OpenPassword); Attachment.Reload(); Attachment.ReEncrypt = false; } break; } case FileType.ZIP: { using (var packager = new MailAttachmentPackager()) { packager.RePack(Attachment, token); } break; } default: { if (EncryptionManager == null) throw new Exception("Cannot reencrypt file as no encryption manager"); EncryptionManager.ReEncrypt(Attachment); break; } } Attachment.Status = PropertyNames.IsProcessed; }