public static bool IsSignature(Attachment attachment, OlBodyFormat bodyFormat) { switch (bodyFormat) { case OlBodyFormat.olFormatHTML: return IsSignatureHtml(attachment); case OlBodyFormat.olFormatRichText: return IsSignatureRtf(attachment); } return false; }
private string[] RemoveAllAttachmentsFromMSGPreserveSignature(Redemption.SafeMailItem msgItem, OlBodyFormat format) { var recordKeys = new List<string>(); Redemption.Attachments attachments = msgItem.Attachments; using (new ComRelease(attachments)) { for (int i = attachments.Count; i > 0; i--) { Redemption.Attachment attachment = attachments.Item(i); using (var rwsAttachment = new RWSAttachment(attachment)) { if (!MapiSignatureInspector.IsSignature(rwsAttachment, format)) { try { object data = attachment.get_Fields(MapiDefines.PR_RECORD_KEY); if (data != null) { string recordkey = GetStringFromBytes(data); recordKeys.Add(recordkey); } } catch(Exception ex) { Interop.Logging.Logger.LogError(ex); } attachment.Delete(); } } } } return recordKeys.ToArray(); }
private static void RemoveAllAttachmentsFromMsg(Attachments attachments, OlBodyFormat bodyFormat) { for (int i = attachments.Count; i > 0; i--) { Microsoft.Office.Interop.Outlook.Attachment attachment = attachments[i]; if (bodyFormat != OlBodyFormat.olFormatUnspecified) { if (OomSignatureInspector.IsSignature(attachment, bodyFormat)) continue; } attachment.Delete(); } }
private void ZipAttachments(Attachments attachments, IEnumerable<Attachment> processedAttachments, ZipAllOptions zipAll, OlBodyFormat bodyFormat) { IFile zipfile; const string groupName = "attachments.zip"; string filename = string.Empty; string attachName = string.Empty; string tempDir = string.Empty; try { RemoveAllAttachmentsFromMsg(attachments, bodyFormat); const int iRenderingPosition = 1; zipfile = FileFactory.Create(groupName, FileType.ZIP); foreach (Attachment attachment in processedAttachments) { if (!attachment.IsSignature) { IFile attachmentFile = FileFactory.Create(attachment.FileName, attachment.Name); zipfile.Add(attachmentFile); } } SetEncryption(zipfile, zipAll); zipfile.PackContainer(zipAll.PassWord); tempDir = FileToDisk(zipfile.FileName, zipfile); attachName = Path.Combine(tempDir, zipfile.FileName); Microsoft.Office.Interop.Outlook.Attachment newAttachment = attachments.Add(attachName, OlAttachmentType.olByValue, iRenderingPosition, zipfile.DisplayName); Encoding ansiEncoding = Encoding.GetEncoding(Encoding.Default.CodePage, new EncoderExceptionFallback(), new DecoderExceptionFallback()); try { byte[] ansiBytes = ansiEncoding.GetBytes(zipfile.FileName); } catch (EncoderFallbackException /*ex*/) { newAttachment.PropertyAccessor.SetProperty(MAPIStringDefines.PR_ATTACH_LONG_FILENAME_W, zipfile.FileName); newAttachment.PropertyAccessor.SetProperty(MAPIStringDefines.PR_ATTACH_FILENAME_W, zipfile.FileName); newAttachment.PropertyAccessor.SetProperty(MAPIStringDefines.PR_DISPLAY_NAME_W, zipfile.DisplayName); } } catch (Exception ex) { Interop.Logging.Logger.LogError(ex); throw; } finally { if (!string.IsNullOrEmpty(filename) && File.Exists(filename)) { File.Delete(filename); } if (!string.IsNullOrEmpty(attachName) && File.Exists(attachName)) { File.Delete(attachName); } if (!string.IsNullOrEmpty(tempDir) && Directory.Exists(tempDir)) { Directory.Delete(tempDir); } } }
private void RemoveAllAttachmentsFromMessage(SafeMailItem msgItem, OlBodyFormat format) { Attachments attachments = msgItem.Attachments; for (int i = attachments.Count; i > 0; i--) { Attachment attachment = attachments.Item(i); if (!MapiSignatureInspector.IsSignature(attachment, format)) { attachment.Delete(); } Marshal.ReleaseComObject(attachment); } Marshal.ReleaseComObject(attachments); }
public void SetMailBodyFormat(OlBodyFormat olBodyFormat) { mailItem.GetType().InvokeMember("BodyFormat", BindingFlags.SetProperty, null, mailItem, new object[] { olBodyFormat }); }