protected override void AdjustAttachments(MailItem mailItem, List<SendLinkInfo> links, string id) { MessageBodyFormat bodyFormat; using (OutlookMailProxy outlookMailProxy = new OutlookMailProxy(mailItem)) { bodyFormat = OutlookBodyFormat.GetMessageBodyFormat(outlookMailProxy.FormattedBodyText); } // Remove non-Signature attachments and add Link Atachment if required IEnumerable<string> recordKeys = GetListofRecordKeys(mailItem, bodyFormat); if (ShouldAttachSendLinkContentFile()) { Interop.Logging.Logger.LogInfo("Addng Link Content File"); SendLinkInfo filenames = CreateSendLinkContentFile(links, id); if (bodyFormat == MessageBodyFormat.Rtf) { recordKeys.All(recordKey => ReplaceAttachments(mailItem, recordKey, filenames)); } else { int position; recordKeys.All(recordKey => RemoveAttachment(mailItem, recordKey, out position)); AddAttachment(mailItem, filenames); } } else { int position; recordKeys.All(recordKey => RemoveAttachment(mailItem, recordKey, out position)); } }
public Request CreateRequest(string testXMLFilePath) { using (var outlookApp = new WsApplication(new Microsoft.Office.Interop.Outlook.Application(), false)) { using (var mailItem = outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)) { int positionCount = 0; XmlReader reader = new XmlTextReader(testXMLFilePath); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: if (reader.Name.CompareTo("subject") == 0) { mailItem.Subject = reader.ReadElementContentAsString(); } else if (reader.Name.CompareTo("recipient") == 0) { mailItem.Recipients.Add(reader.ReadElementContentAsString()); } else if (reader.Name.CompareTo("attachment") == 0) { string fileName = reader.ReadElementContentAsString(); // We want the parent directory because the scripts live in \succeed and \fail below the folder containg the test files string testFilePath = Path.Combine(Directory.GetParent(Path.GetDirectoryName(testXMLFilePath)).FullName, fileName); if (!File.Exists(testFilePath)) { throw new Exception("Unable to find test file: " + fileName); } mailItem.Attachments.Add(testFilePath, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, ++positionCount, fileName); } break; } } mailItem.Save(); // Now convert to to a request Request request = null; // Yes we are assuming the security has been disabled OK...but we're testing the decryption here, NOT the proxy/security code path _proxy = new OutlookMailProxy(mailItem); _email2Uro = new Email2Request(_proxy); request = _email2Uro.Convert(RequestChannel.Outlook, false); // Tidyup mailItem.Delete(); return request; } } }
internal bool CreateListOfAttachmentsToSendLink(MailItem mailItem, PolicyContent.Attachment[] builtup, RequestManager requestManager, ref List<PolicyContent.Attachment> listAttachments) { Logger.LogInfo("Matching the original attachments with the rebuilt collection and returning a list of items to SendLink"); // ensure we have Recordkey of each non-signature attachment MessageBodyFormat bodyFormat; if (UseOutlookDOMForProcessing) { using (OutlookMailProxy outlookMailProxy = new OutlookMailProxy(mailItem)) { bodyFormat = OutlookBodyFormat.GetMessageBodyFormat(outlookMailProxy.FormattedBodyText); Logger.LogInfo("Email body format: " + bodyFormat.ToString()); } } else { using (RedemptionMailProxy redemptionMailProxy = new RedemptionMailProxy(mailItem, true, DisableAccessToDOMAttachments)) { bodyFormat = OutlookBodyFormat.GetMessageBodyFormat(redemptionMailProxy.FormattedBodyText); Logger.LogInfo("Email body format: " + bodyFormat.ToString()); } } List<string> recordKeys = new List<string>(GetListofRecordKeys(mailItem, bodyFormat)); if (recordKeys.Count <= 0) { Logger.LogDebug("The list of record keys for the email is empty. Assuming the email only contains a signature image so there's nothing to SendLink."); return true; } foreach (PolicyContent.Attachment attachment in builtup) { // .msg files are flattened before normal Protect processing, so they need to be treated as // a special case as their IDs won't match against the processed file list. // i.e. att.Id == attachment.Id will not work (see below). if (!String.IsNullOrEmpty(attachment.FileName) && attachment.FileName.EndsWith(".msg", StringComparison.InvariantCultureIgnoreCase)) { CustomProperty[] properties = attachment.Properties; bool hasRecordKey = false; // .msg files should always have a RecordKey, but check anyway for error cases foreach (CustomProperty cp in properties) { hasRecordKey = (cp.Name == "RecordKey") && (recordKeys.Contains(cp.Value)); if (hasRecordKey) { listAttachments.Add(attachment); Logger.LogInfo(".msg file added to SendLink attachments list. Backing file: " + attachment.FileName); break; } } if (!hasRecordKey) { Logger.LogError("RecordKey was not found in the attachment's custom properties when processing .msg: " + attachment.FileName); return false; } } else { foreach (PolicyContent.Attachment att in requestManager.Request.Attachments) { // Match attachment on mailItem with processed equivalent in builtup collection // and add to SendLink list if (att.Id == attachment.Id) { CustomProperty[] properties = att.Properties; bool hasRecordKey = false; foreach (CustomProperty cp in properties) { hasRecordKey = (cp.Name == "RecordKey") && (recordKeys.Contains(cp.Value)); // we don't want signature images if (hasRecordKey) { if ((attachment.Properties == null) || (attachment.Properties.Length == 0)) { attachment.Properties = new[] { cp }; } listAttachments.Add(attachment); break; } } if (!hasRecordKey) { Logger.LogDebug("Unable to find a RecordKey for attachment. Assuming this is a signature image: " + attachment.Name); } break; } } } } return true; }
internal bool ExecuteSendLinkAction(MailItem mailItem, PolicyContent.Attachment[] builtup, RequestManager requestManager) { Logger.LogInfo("Executing Secure File Transfer Process"); Workshare.Analytics.WsAnalyticsListener analyticsListener = new Workshare.Analytics.WsAnalyticsListener(); analyticsListener.SendSendLinkStatistic(); if (!requestManager.SendAndProtect && !ShowBccWarning(mailItem, requestManager)) { return false; } try { List<PolicyContent.Attachment> listAttachments = new List<PolicyContent.Attachment>(); if (!CreateListOfAttachmentsToSendLink(mailItem, builtup, requestManager, ref listAttachments)) { return false; } if (listAttachments.Count <= 0) { Logger.LogInfo("List of attachments to SendLink is empty"); return true; } string id = Guid.NewGuid().ToString(); List<SendLinkInfo> links = GetLinks(requestManager.Response, mailItem, listAttachments, id); if (links != null && links.Count > 0) { Logger.LogInfo("Secure File Transfer: removing old attachments"); //SetMessageWindowVisible(mailItem, false); //This call will change the mailItem AdjustAttachments(mailItem, links, id); if (!string.IsNullOrEmpty(GetPropertyValue(requestManager.EnforceResponse.ModifiedRequest.Properties, MailMessagePropertyKeys.MimeContent)) || !string.IsNullOrEmpty(GetPropertyValue(requestManager.EnforceResponse.ModifiedRequest.Properties, MailMessagePropertyKeys.LargeMimeContent))) { string body; // Need to create a new proxy object because mailItem was changed in AdjustAttachments() if (UseOutlookDOMForProcessing) { using (OutlookMailProxy outlookMailProxy = new OutlookMailProxy(mailItem)) { body = outlookMailProxy.FormattedBodyText; body = OutlookFormattedTextProcessor.NewFormattedBodyText(body, links, mailItem); } } else { using (RedemptionMailProxy redemptionMailProxy = new RedemptionMailProxy(mailItem, true, DisableAccessToDOMAttachments)) { body = redemptionMailProxy.FormattedBodyText; body = OutlookFormattedTextProcessor.NewFormattedBodyText(body, links, mailItem, false); //private static void InsertHtmlIntoBodyText(ref string body, MessageBodyFormat bodyformat, IEnumerable<SendLinkInfo> links, MailItem mailItem) //sets body as null. if (body != null) { redemptionMailProxy.FormattedBodyText = body; } } } if (body != null) { SetPropertyValue(requestManager.EnforceResponse.ModifiedRequest.Properties, MailMessagePropertyKeys.FormattedBody, body); } } Logger.LogInfo("End Secure File Transfer Process"); // Allow the inspector window to redraw now, so that the attachments // and altered body text are immediately updated. System.Windows.Forms.Application.DoEvents(); } else { Logger.LogInfo("No Links to process"); } StartSendLinkClient(); mailItem.UserProperties.Add("SendLink", OlUserPropertyType.olText); } catch (Exception e) { //SetMessageWindowVisible(mailItem, true); Logger.LogError(e); throw; } return true; }
/// <summary> /// Sets a custom MIME header value to indicate that this email has been processed by Workshare. /// Server components may use this property as a hint to skip any further processing of this message. /// </summary> /// <param name="mail"></param> /// <param name="request"></param> private void SetHeaderProcessingInfo(MailItem mail, Request request) { try { if (UseOutlookDOMForProcessing) { using (OutlookMailProxy proxy = new OutlookMailProxy(mail)) { proxy.SetMIMEHeaderValue(RequestDigestProvider.XHEADER_MESSAGE_PROTECTED, new RequestDigestProvider().GetDigest(request)); } } else { using (RedemptionMailProxy proxy = new RedemptionMailProxy(mail, true, DisableAccessToDOMAttachments)) { proxy.SetMIMEHeaderValue(RequestDigestProvider.XHEADER_MESSAGE_PROTECTED, new RequestDigestProvider().GetDigest(request)); } } } catch (Exception e) { Logger.LogError("Failed to set the Mime Header for Protect Server."); Logger.LogError(e); } }
private void SendLinkUpdateEmailContent(MailItem mailItem, Request request) { if (string.IsNullOrEmpty(PolicyManagerUtils.GetPropertyValue(request.Properties, MailMessagePropertyKeys.MimeContent)) && string.IsNullOrEmpty(PolicyManagerUtils.GetPropertyValue(request.Properties, MailMessagePropertyKeys.LargeMimeContent))) { // We are only intrested in mime based changes here return; } string formattedBody = PolicyManagerUtils.GetPropertyValue(request.Properties, MailMessagePropertyKeys.FormattedBody); bool isRtf = mailItem.BodyFormat == OlBodyFormat.olFormatRichText; string appVersion = m_application.Version; bool isOtl2010 = OutlookVersion.Convert(appVersion) > OutlookVersion.Version.Outlook2007; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Outlook 2010 message boby is updated in OutlookFormattedTextProcessor.NewFormattedBodyText so we don't update body here // Outlook 2007 2003 message boby is updated here EXCEPT for Outlook 2007 Rtf // Outlook 2007 Rtf body is updated in ClientOutlookExtension::MessageEvents::SynchronizeBodyForSendLink (JE 21.06.2012) ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (UseOutlookDOMForProcessing) { using (OutlookMailProxy proxy = new OutlookMailProxy(mailItem)) { proxy.Subject = PolicyManagerUtils.GetPropertyValue(request.Properties, MailMessagePropertyKeys.Subject); if (!isOtl2010 && !isRtf) { proxy.FormattedBodyText = formattedBody; } } } else { using (RedemptionMailProxy proxy = new RedemptionMailProxy(mailItem)) { proxy.Subject = PolicyManagerUtils.GetPropertyValue(request.Properties, MailMessagePropertyKeys.Subject); if (!isOtl2010 && !isRtf) { proxy.FormattedBodyText = formattedBody; } } } if ((OutlookVersion.Convert(appVersion) == OutlookVersion.Version.Outlook2007) && isRtf) { FormattedMsgText = formattedBody; } UpdateHeaderInfo(mailItem, request); UpdateRecipients(mailItem, request); }
// This is used for non-SendLink private void UpdateEmailContent(MailItem mailItem, Request request) { if (string.IsNullOrEmpty(PolicyManagerUtils.GetPropertyValue(request.Properties, MailMessagePropertyKeys.MimeContent)) && string.IsNullOrEmpty(PolicyManagerUtils.GetPropertyValue(request.Properties, MailMessagePropertyKeys.LargeMimeContent))) { return; } if (UseOutlookDOMForProcessing) { using (OutlookMailProxy proxy = new OutlookMailProxy(mailItem)) { proxy.Subject = PolicyManagerUtils.GetPropertyValue(request.Properties, MailMessagePropertyKeys.Subject); proxy.FormattedBodyText = PolicyManagerUtils.GetPropertyValue(request.Properties, MailMessagePropertyKeys.FormattedBody); UpdateHeaderInfo(mailItem, request); UpdateRecipients(mailItem, request); } } else { using (RedemptionMailProxy proxy = new RedemptionMailProxy(mailItem, true, DisableAccessToDOMAttachments)) { proxy.Subject = PolicyManagerUtils.GetPropertyValue(request.Properties, MailMessagePropertyKeys.Subject); proxy.FormattedBodyText = PolicyManagerUtils.GetPropertyValue(request.Properties, MailMessagePropertyKeys.FormattedBody); UpdateHeaderInfo(mailItem, request); UpdateRecipients(mailItem, request); } } }
private Int64 GetTotalAttachmentSize(MailItem mailItem) { MessageBodyFormat bodyFormat; if (UseOutlookDOMForProcessing) { using (OutlookMailProxy outlookMailProxy = new OutlookMailProxy(mailItem)) { bodyFormat = OutlookBodyFormat.GetMessageBodyFormat(outlookMailProxy.FormattedBodyText); } } else { using (RedemptionMailProxy redemptionMailProxy = new RedemptionMailProxy(mailItem, true, DisableAccessToDOMAttachments)) { bodyFormat = OutlookBodyFormat.GetMessageBodyFormat(redemptionMailProxy.FormattedBodyText); } } if (!UseOutlookDOMForProcessing || OutlookVersion.Convert(m_application.Version) < OutlookVersion.Version.Outlook2007) { var mapi = new OutlookSendLinkMAPI() { UseOutlookDOMForProcessing = UseOutlookDOMForProcessing, DisableAccessToDOMAttachments = DisableAccessToDOMAttachments }; return mapi.GetTotalAttachmentSize(mailItem, bodyFormat); } else { var oom = new OutlookSendLinkOOM() { UseOutlookDOMForProcessing = UseOutlookDOMForProcessing, DisableAccessToDOMAttachments = DisableAccessToDOMAttachments }; return oom.GetTotalAttachmentSize(mailItem, bodyFormat); } }
private bool IsRtfBodyFormat(MsOutlook.MailItem mailItem) { try { using (OutlookMailProxy outlookMailProxy = new OutlookMailProxy(mailItem)) { if (outlookMailProxy.BodyFormat == MessageBodyFormat.Rtf) { Interop.Logging.Logger.LogInfo("Message body format is RTF."); return true; } } } catch (Exception ex) { Interop.Logging.Logger.LogError(ex); } return false; }