protected override void AdjustAttachments(MailItem mailItem, List<SendLinkInfo> links, string id) { MessageBodyFormat bodyFormat; using (RedemptionMailProxy redemptionMailProxy = new RedemptionMailProxy(mailItem)) { bodyFormat = OutlookBodyFormat.GetMessageBodyFormat(redemptionMailProxy.FormattedBodyText); } // Remove non-Signature attachments and add Link Atachment if required IEnumerable<string> recordKeys = GetListofRecordKeys(mailItem, bodyFormat); if (ShouldAttachSendLinkContentFile()) { Interop.Logging.Logger.LogInfo("Adding Link Content File"); SendLinkInfo filenames = CreateSendLinkContentFile(links, id); if (bodyFormat == MessageBodyFormat.Rtf) { IWSMailAttachmentTransform mat = new OutlookIImplFactory().CreateWSMailAttachmentTransform(); mat.SendLinkReplaceRtfAttachments(mailItem, filenames.FilePath, filenames.DisplayName); } else { // We put a single link attachment in place of all non-Signature attachments in the message RemoveAllAttachments(mailItem, recordKeys); AddAttachment(mailItem, filenames); } } else { RemoveAllAttachments(mailItem, recordKeys); } }
private Request ConvertToRequestWithAttachment(string mimefilename, string displayName, Outlook.MailItem mailItem) { // We have to save the message in order to access all its contents :( mailItem.Save(); using (RedemptionMailProxy proxy = new RedemptionMailProxy(mailItem)) { Email2Request email2Uro = new Email2Request(proxy); Request request = email2Uro.Convert(RequestChannel.Outlook, false); Assert.IsNotNull(request); //sender Assert.IsTrue(1 == request.Source.Items.Length, "Should only be a single source item"); if (Environment.UserName == "lnpair") { Assert.AreEqual("*****@*****.**", request.Source.Items[0].Content, "Mismatch in email emailAddress"); Assert.AreEqual("lnpair", GetPropertyValue(SMTPItemPropertyKeys.DisplayName, request.Source.Items[0].Properties), "Mismatch in email emailAddress"); Assert.AreEqual(true.ToString(), GetPropertyValue(SMTPItemPropertyKeys.Internal, request.Source.Items[0].Properties), "Not resolved as internal"); } // recipients Assert.AreEqual(2, request.Destination.Items.Length, "Should only be a single destination item"); Assert.AreEqual(AddressType.To, GetPropertyValue(SMTPItemPropertyKeys.AddressType, request.Destination.Items[0].Properties ), "Destination should be of AddressType: To"); Assert.AreEqual("*****@*****.**", request.Destination.Items[0].Content, "Mismatch in email emailAddress"); Assert.AreEqual("*****@*****.**", GetPropertyValue(SMTPPropertyKeys.DisplayName, request.Destination.Items[0].Properties), "Mismatch in email emailAddress"); Assert.AreEqual("*****@*****.**", request.Destination.Items[1].Content, "Mismatch in email emailAddress"); Assert.AreEqual("*****@*****.**", GetPropertyValue(SMTPPropertyKeys.DisplayName, request.Destination.Items[1].Properties).Trim('\''), "Mismatch in email emailAddress"); if (Environment.UserName == "lnpair") { Assert.AreEqual(false.ToString(), GetPropertyValue(SMTPItemPropertyKeys.Internal, request.Destination.Items[1].Properties), "Not resolved as external"); } //attachments Assert.AreEqual(1, request.Attachments.Length); Assert.AreEqual(displayName, request.Attachments[0].Name, "Mismatch in attachment name"); Assert.AreEqual("application/msword; name=" + displayName, request.Attachments[0].ContentType, "Mismatch in attachment content type"); Assert.IsTrue(!String.IsNullOrEmpty(request.Attachments[0].FileName) && File.Exists(request.Attachments[0].FileName), "Expected a vaild file"); Assert.AreEqual("Outlook", GetPropertyValue(SMTPPropertyKeys.RequestChannel, request.Destination.Properties)); Assert.AreEqual("Outlook", GetPropertyValue(SMTPPropertyKeys.RequestChannel, request.Source.Properties)); mailItem.Delete(); return request; } }
public void TestSetHtmlFormattedBody() { using (WsActivationContext wsac = new WsActivationContext()) using (OutlookEmailWrapper outlookEmailWrapper = new OutlookEmailWrapper(m_outlookSession)) { outlookEmailWrapper.BodyFormat = Outlook.OlBodyFormat.olFormatHTML; string bodyText = "We have a body that looks like something"; outlookEmailWrapper.Body = bodyText; // We have to save the message in order to access all its contents :( outlookEmailWrapper.MailItem.Save(); using (RedemptionMailProxy proxy = new RedemptionMailProxy(outlookEmailWrapper.MailItem)) { Assert.IsTrue(proxy.BodyText.Contains(bodyText)); Assert.IsTrue(proxy.FormattedBodyText.Contains(bodyText)); string phrase = "Some HTML text"; bodyText = string.Format("<html>{0}</html>", phrase); proxy.BodyText = phrase; proxy.FormattedBodyText = bodyText; outlookEmailWrapper.MailItem.Save(); Assert.IsTrue(proxy.BodyText.Contains(phrase)); Assert.IsTrue(proxy.FormattedBodyText.Contains(phrase)); outlookEmailWrapper.MailItem.Delete(); } } }
public void TestSetNullFormattedBody() { using (WsActivationContext wsac = new WsActivationContext()) using (OutlookEmailWrapper outlookEmailWrapper = new OutlookEmailWrapper(m_outlookSession)) { outlookEmailWrapper.BodyFormat = Outlook.OlBodyFormat.olFormatPlain; string bodyText = "We have a body that looks like something"; outlookEmailWrapper.Body = bodyText; // We have to save the message in order to access all its contents :( outlookEmailWrapper.MailItem.Save(); using (RedemptionMailProxy proxy = new RedemptionMailProxy(outlookEmailWrapper.MailItem)) { Assert.IsTrue(proxy.BodyText.Contains(bodyText)); Assert.IsTrue(proxy.FormattedBodyText.Contains(bodyText)); proxy.FormattedBodyText = null; outlookEmailWrapper.MailItem.Save(); Assert.IsTrue(string.IsNullOrEmpty(proxy.BodyText)); Assert.IsFalse(proxy.FormattedBodyText.Contains(bodyText)); outlookEmailWrapper.MailItem.Delete(); } } }
public void TestEmbeddedAttachments() { throw new IgnoreException("TODO: TEST DISABLED FOR CHECKIN (RPC_E_SERVERFAULT in Outlook.Attachment.SaveAsFile()) - RNP 2010-04-16"); using (WsActivationContext wsac = new WsActivationContext()) using (OutlookEmailWrapper outlookEmailWrapper = new OutlookEmailWrapper(m_outlookSession, m_testPath + "HTML text e-mail This is a test mail with an embedded attachment.msg")) { byte[] originalDocBytes = System.IO.File.ReadAllBytes(m_testPath + "test.doc"); byte[] originalJpgBytes = System.IO.File.ReadAllBytes(m_testPath + "test.jpg"); // We have to save the message in order to access all its contents :( outlookEmailWrapper.MailItem.Save(); using (RedemptionMailProxy proxy = new RedemptionMailProxy(outlookEmailWrapper.MailItem)) { Assert.AreEqual(2, proxy.Attachments.Count); IEmailAttachment attachment1 = proxy.Attachments[0]; Assert.IsNotNull(attachment1); IEmailAttachment attachment2 = proxy.Attachments[1]; Assert.IsNotNull(attachment2); byte[] mimeDocBytes = System.IO.File.ReadAllBytes(attachment1.FileName); byte[] mimeJpgBytes = System.IO.File.ReadAllBytes(attachment2.FileName); TestHelpers.CompareByteArrays(originalDocBytes, mimeDocBytes, "The docs do not match"); TestHelpers.CompareByteArrays(originalJpgBytes, mimeJpgBytes, "The JPGs do not match"); Assert.IsTrue(string.IsNullOrEmpty(attachment1.ContentId)); Assert.IsFalse(string.IsNullOrEmpty(attachment2.ContentId)); Assert.AreEqual("[email protected]", attachment2.ContentId); outlookEmailWrapper.MailItem.Delete(); } } }
public void TestExtractCustomPropertiesFromNewMessage() { using (WsActivationContext wsac = new WsActivationContext()) using (OutlookEmailWrapper outlookEmailWrapper = new OutlookEmailWrapper(m_outlookSession)) { outlookEmailWrapper.Subject = "I have some properties"; outlookEmailWrapper.ToRecipients = "*****@*****.**"; outlookEmailWrapper.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatPlain; outlookEmailWrapper.Body = "We have a body that looks like something"; // Add some internet properties // We have to save the message in order to access all its contents :( outlookEmailWrapper.MailItem.Save(); using (RedemptionMailProxy proxy = new RedemptionMailProxy(outlookEmailWrapper.MailItem)) { // Only interested in Internet properties for this test outlookEmailWrapper.MailItem.Delete(); } } }
// 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); } } }
public void TestRecipientAddressInX400Format() { using (WsActivationContext wsac = new WsActivationContext()) using (OutlookEmailWrapper outlookEmailWrapper = new OutlookEmailWrapper(m_outlookSession)) { string subject = "Test outlook proxy: TestRecipientAddressInX400Format"; outlookEmailWrapper.Subject = subject; outlookEmailWrapper.ToRecipients = "BlackHole<*****@*****.**>"; outlookEmailWrapper.BodyFormat = Outlook.OlBodyFormat.olFormatRichText; string rtfBody = "We have a body that looks like something"; outlookEmailWrapper.Body = rtfBody; // We have to save the message in order to access all its contents :( outlookEmailWrapper.MailItem.Save(); using (RedemptionMailProxy proxy = new RedemptionMailProxy(outlookEmailWrapper.MailItem)) using (Email2Mime mailItem2Mime = new Email2Mime(proxy)) using (Stream mimeStream = mailItem2Mime.ConvertToMimeStream()) using (MimeProxy mimeProxy = new MimeProxy(mimeStream)) { Email2Request email2Request = new Email2Request(mimeProxy); Request request = email2Request.Convert(RequestChannel.Outlook, false); outlookEmailWrapper.MailItem.Delete(); // Now fake an X400 email address Workshare.PolicyContent.RoutingItem routingItem = request.Destination.Items[0]; Workshare.PolicyContent.RoutingItem modifiedRoutingItem = new Workshare.PolicyContent.RoutingItem(); modifiedRoutingItem.Content = "/O=WSDEV/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=BlackHole"; System.Collections.Generic.List< CustomProperty> custProps = new System.Collections.Generic.List<CustomProperty>(); foreach (CustomProperty prop in routingItem.Properties) { custProps.Add(prop); } custProps.Add(new CustomProperty(EmailProperties.ReadOnlyKey, bool.TrueString)); modifiedRoutingItem.Properties = custProps.ToArray(); request.Destination.Items = new Workshare.PolicyContent.RoutingItem[] { modifiedRoutingItem }; // Now do a convert again with the modified uro email2Request.Convert(RequestChannel.Outlook, request, false); Assert.AreEqual(1, request.Destination.Items.Length); routingItem = request.Destination.Items[0]; Assert.AreEqual("/O=WSDEV/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=BlackHole", routingItem.Content); Assert.AreEqual("BlackHole", GetPropertyValue(SMTPItemPropertyKeys.DisplayName, routingItem.Properties)); Assert.AreEqual(AddressType.To, GetPropertyValue(SMTPItemPropertyKeys.AddressType, routingItem.Properties)); Assert.AreEqual(bool.TrueString, GetPropertyValue(EmailProperties.ReadOnlyKey, routingItem.Properties)); } } }
public void TestRoundTripDropAttachments() { using (WsActivationContext wsac = new WsActivationContext()) using (OutlookEmailWrapper outlookEmailWrapper = new OutlookEmailWrapper(m_outlookSession)) { string subject = "Test outlook proxy: TestRoundTripDropAttachments"; outlookEmailWrapper.Subject = subject; outlookEmailWrapper.ToRecipients = "*****@*****.**"; outlookEmailWrapper.CcRecipients = "*****@*****.**"; outlookEmailWrapper.BccRecipients = "[email protected];[email protected]"; outlookEmailWrapper.BodyFormat = Outlook.OlBodyFormat.olFormatRichText; string rtfBody = "We have a body that looks like something"; outlookEmailWrapper.Body = rtfBody; outlookEmailWrapper.AddAttachment(m_testPath + "test.doc", "Mickey Mouse", Outlook.OlAttachmentType.olByValue); outlookEmailWrapper.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh; // We have to save the message in order to access all its contents :( outlookEmailWrapper.MailItem.Save(); using (RedemptionMailProxy proxy = new RedemptionMailProxy(outlookEmailWrapper.MailItem)) { Assert.AreEqual(1, proxy.Attachments.Count); // DE9310, requires to change this test behavior Assert.AreEqual("Mickey Mouse", proxy.Attachments[0].DisplayName); Assert.AreEqual("application/msword; name=Mickey Mouse", proxy.Attachments[0].ContentType); Assert.IsTrue(proxy.Attachments[0].FileName.Contains("test.doc"), "Expected to find a non-empty stream"); // Lets convert the outlook mail message to MIME using (Email2Mime mailItem2Mime = new Email2Mime(proxy)) using (Stream mimeStream = mailItem2Mime.ConvertToMimeStream()) using (MimeProxy mimeProxy = new MimeProxy(mimeStream)) { // Drop the attachments in the MIME stream mimeProxy.Attachments.Clear(); Email2Request email2Request = new Email2Request(mimeProxy); Request request = email2Request.Convert(RequestChannel.Outlook, false); outlookEmailWrapper.MailItem.Delete(); Assert.AreEqual(0, request.Attachments.Length); // Synchronise the email with the changes made to the URO //Assert.AreEqual(0, proxy.Attachments.Count); } } } }
public void TestNullMailItem() { RedemptionMailProxy proxy = new RedemptionMailProxy(null); }
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); }
public void TestSetRtfFormattedBody() { using (WsActivationContext wsac = new WsActivationContext()) using (OutlookEmailWrapper outlookEmailWrapper = new OutlookEmailWrapper(m_outlookSession)) { outlookEmailWrapper.BodyFormat = Outlook.OlBodyFormat.olFormatRichText; string bodyText = "We have a body that looks like something"; outlookEmailWrapper.Body = bodyText; // We have to save the message in order to access all its contents :( outlookEmailWrapper.MailItem.Save(); using (RedemptionMailProxy proxy = new RedemptionMailProxy(outlookEmailWrapper.MailItem)) { Assert.IsTrue(proxy.BodyText.Contains(bodyText)); Assert.IsTrue(proxy.FormattedBodyText.Contains(bodyText)); string phrase = "Some RTF text"; StringBuilder rtfText = new StringBuilder(); rtfText.Append("{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fswiss\\fcharset0 Arial;}}"); rtfText.Append("{\\*\\generator Riched20 5.50.99.2014;}\\viewkind4\\uc1\\pard\\f0\\fs20\\par "); rtfText.Append(phrase); rtfText.Append("}"); proxy.BodyText = phrase; proxy.FormattedBodyText = rtfText.ToString(); outlookEmailWrapper.MailItem.Save(); Assert.IsTrue(proxy.BodyText.Contains(phrase)); Assert.IsTrue(proxy.FormattedBodyText.Contains(phrase)); outlookEmailWrapper.MailItem.Delete(); } } }
private void CreateProxy(Outlook.OlBodyFormat bodyFormat, out string proxyBodyText) { using (WsActivationContext wsac = new WsActivationContext()) using (OutlookEmailWrapper outlookEmailWrapper = new OutlookEmailWrapper(m_outlookSession)) { string subject = "Test outlook proxy: This is a test mail"; outlookEmailWrapper.Subject = subject; outlookEmailWrapper.ToRecipients = "*****@*****.**"; outlookEmailWrapper.CcRecipients = "*****@*****.**"; outlookEmailWrapper.BccRecipients = "[email protected];[email protected]"; outlookEmailWrapper.BodyFormat = bodyFormat; outlookEmailWrapper.Body = "We have a body that looks like something"; outlookEmailWrapper.AddAttachment(m_testPath + "test.doc", "Mickey Mouse", Outlook.OlAttachmentType.olByValue); outlookEmailWrapper.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh; // We have to save the message in order to access all its contents :( outlookEmailWrapper.MailItem.Save(); using (RedemptionMailProxy proxy = new RedemptionMailProxy(outlookEmailWrapper.MailItem)) { Assert.AreEqual("Test outlook proxy: This is a test mail", proxy.Subject); Assert.IsTrue(proxy.FormattedBodyText.Contains("We have a body that looks like something")); proxyBodyText = proxy.FormattedBodyText; if (Environment.UserName == "lnpair") { Assert.AreEqual("lnpair", proxy.Sender.Name); Assert.AreEqual("*****@*****.**", proxy.Sender.EmailAddress); Assert.IsTrue(proxy.Sender.Internal); } Assert.IsTrue(proxy.ToRecipients.IsReadOnly); Assert.IsTrue(proxy.CcRecipients.IsReadOnly); Assert.IsTrue(proxy.BccRecipients.IsReadOnly); Assert.AreEqual(1, proxy.ToRecipients.Count); Assert.AreEqual(1, proxy.CcRecipients.Count); Assert.AreEqual(2, proxy.BccRecipients.Count); Assert.AreEqual("*****@*****.**", proxy.ToRecipients[0].Name.Trim('\'')); Assert.AreEqual("*****@*****.**", proxy.ToRecipients[0].EmailAddress); if (Environment.UserName == "lnpair") { Assert.IsFalse(proxy.ToRecipients[0].Internal); } Assert.AreEqual("*****@*****.**", proxy.CcRecipients[0].Name.Trim('\'')); Assert.AreEqual("*****@*****.**", proxy.CcRecipients[0].EmailAddress); if (Environment.UserName == "lnpair") { Assert.IsFalse(proxy.CcRecipients[0].Internal); } Assert.AreEqual("*****@*****.**", proxy.BccRecipients[0].Name.Trim('\'')); Assert.AreEqual("*****@*****.**", proxy.BccRecipients[0].EmailAddress); Assert.AreEqual("*****@*****.**", proxy.BccRecipients[1].Name.Trim('\'')); Assert.AreEqual("*****@*****.**", proxy.BccRecipients[1].EmailAddress); if (Environment.UserName == "lnpair") { Assert.IsFalse(proxy.BccRecipients[1].Internal); } Assert.AreEqual(Workshare.Mime.Conversions.Priority.High, proxy.Priority); // Lets test the recipient iterator as well foreach (IEmailRecipient recipient in proxy.ToRecipients) { Assert.IsTrue(recipient.Name.Contains("blackhole")); } Assert.AreEqual(1, proxy.Attachments.Count); // DE9310, requires to change this test behavior Assert.AreEqual("Mickey Mouse", proxy.Attachments[0].DisplayName); Assert.AreEqual("application/msword; name=Mickey Mouse", proxy.Attachments[0].ContentType); Assert.IsTrue(proxy.Attachments[0].FileName.Contains("test.doc"), "Expected to find a non-empty stream"); // Lets test the attachment iterator as well foreach (IEmailAttachment attachment in proxy.Attachments) { // DE9310, requires to change this test behavior Assert.IsTrue(attachment.DisplayName.Contains("Mickey Mouse")); Assert.IsTrue(attachment.FileName.Contains("test.doc")); } outlookEmailWrapper.MailItem.Delete(); } } }
public void TestNoneMailItem() { RedemptionMailProxy proxy = new RedemptionMailProxy(new object()); }
public void TestEmbeddedAttachments() { throw new IgnoreException("TODO: TEST DISABLED FOR CHECKIN (RPC_E_SERVERFAULT in Outlook.Attachment.SaveAsFile()) - RNP 2010-04-16"); using (WsActivationContext wsac = new WsActivationContext()) using (OutlookEmailWrapper outlookEmailWrapper = new OutlookEmailWrapper(m_outlookSession, m_testPath + "HTML text e-mail This is a test mail with an embedded attachment.msg")) { byte[] originalDocBytes = System.IO.File.ReadAllBytes(m_testPath + "test.doc"); byte[] originalJpgBytes = System.IO.File.ReadAllBytes(m_testPath + "test.jpg"); // We have to save the message in order to access all its contents :( outlookEmailWrapper.MailItem.Save(); using (RedemptionMailProxy proxy = new RedemptionMailProxy(outlookEmailWrapper.MailItem)) { Email2Request email2Request = new Email2Request(proxy); Request request = email2Request.Convert(RequestChannel.Outlook, false); Assert.IsNotNull(request); outlookEmailWrapper.MailItem.Delete(); Assert.AreEqual("Outlook", GetPropertyValue(SMTPPropertyKeys.RequestChannel, request.Destination.Properties)); Assert.AreEqual("Outlook", GetPropertyValue(SMTPPropertyKeys.RequestChannel, request.Source.Properties)); Assert.AreEqual(2, request.Attachments.Length); Attachment attachment1 = request.Attachments[0]; Assert.IsNotNull(attachment1); Attachment attachment2 = request.Attachments[1]; Assert.IsNotNull(attachment2); TestHelpers.CompareByteArrays(originalDocBytes, attachment1.Content, "The docs do not match"); TestHelpers.CompareByteArrays(originalJpgBytes, attachment2.Content, "The JPGs do not match"); Assert.AreEqual("test.doc", attachment1.Name, "Mismatch in attachment name"); Assert.AreEqual("application/msword; name=test.doc", attachment1.ContentType, "Mismatch in attachment content type"); Assert.IsFalse(string.IsNullOrEmpty(attachment1.Id)); Assert.AreEqual("image001.jpg", attachment2.Name, "Mismatch in attachment name"); Assert.AreEqual("image/jpeg; name=image001.jpg", attachment2.ContentType, "Mismatch in attachment content type"); Assert.IsFalse(string.IsNullOrEmpty(attachment2.Id)); Assert.AreEqual("[email protected]", attachment2.Id); } } }
public void TestSetSubject() { using (WsActivationContext wsac = new WsActivationContext()) using (OutlookEmailWrapper outlookEmailWrapper = new OutlookEmailWrapper(m_outlookSession)) { outlookEmailWrapper.Subject = "Any old thing"; string testString = "This is a test"; using (RedemptionMailProxy proxy = new RedemptionMailProxy(outlookEmailWrapper.MailItem)) { proxy.Subject = testString; } Assert.AreEqual(testString, outlookEmailWrapper.Subject); } }
public void TestExtractCustomPropertiesFromSaveMsgFile() { using (WsActivationContext wsac = new WsActivationContext()) using (OutlookEmailWrapper outlookEmailWrapper = new OutlookEmailWrapper(m_outlookSession, m_testPath + "I have some MAPI properties.msg")) { // We have to save the message in order to access all its contents :( outlookEmailWrapper.MailItem.Save(); using (RedemptionMailProxy proxy = new RedemptionMailProxy(outlookEmailWrapper.MailItem)) { // We only interested in getting hold of the custom internet properties for this test System.Collections.Hashtable xHeaders = proxy.XHeaders; Assert.AreEqual(1, xHeaders.Count); Assert.IsTrue(xHeaders.ContainsKey("workshare_test3")); Assert.IsTrue(xHeaders.ContainsValue("test")); outlookEmailWrapper.MailItem.Delete(); } } }
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); } }