public void TestRecipients()
		{
			using (WsActivationContext wsac = new WsActivationContext())
			using (OutlookEmailWrapper outlookEmailWrapper = new OutlookEmailWrapper(m_outlookSession))
			{
				outlookEmailWrapper.ToRecipients = "Test <*****@*****.**>;blackhole <*****@*****.**>;[email protected]";
				outlookEmailWrapper.CcRecipients = "[email protected];[email protected];[email protected]";
				outlookEmailWrapper.BccRecipients = "[email protected];[email protected]";

				outlookEmailWrapper.MailItem.Save();

				RedemptionRecipientTableProxy outlookRecipientTableProxy = new RedemptionRecipientTableProxy(outlookEmailWrapper.MailItem,
																												false/*Use Cache*/);

				NameValueCollection recipients = outlookRecipientTableProxy.GetProcessRecipients(OutlookRecipientTypes.ToRecipient);
				Assert.AreEqual(3, recipients.Count);

				int index = 0;
				// sometimes (x64 xp, o2007, vs2008) we don't get the single quotes round the names, which doesn't seem a problem
				Assert.AreEqual("Test", recipients.Keys[index].Trim('\''));
				Assert.AreEqual("*****@*****.**", recipients[index++]);
				Assert.AreEqual("blackhole", recipients.Keys[index].Trim('\''));
				Assert.AreEqual("*****@*****.**", recipients[index++]);
				Assert.AreEqual("*****@*****.**", recipients.Keys[index].Trim('\''));
				Assert.AreEqual("*****@*****.**", recipients[index++]);

				recipients = recipients = outlookRecipientTableProxy.GetProcessRecipients(OutlookRecipientTypes.CcRecipient);
				Assert.AreEqual(3, recipients.Count);

				index = 0;
				Assert.AreEqual("*****@*****.**", recipients.Keys[index].Trim('\''));
				Assert.AreEqual("*****@*****.**", recipients[index++]);
				Assert.AreEqual("*****@*****.**", recipients.Keys[index].Trim('\''));
				Assert.AreEqual("*****@*****.**", recipients[index++]);
				Assert.AreEqual("*****@*****.**", recipients.Keys[index].Trim('\''));
				Assert.AreEqual("*****@*****.**", recipients[index++]);

				recipients = recipients = outlookRecipientTableProxy.GetProcessRecipients(OutlookRecipientTypes.BccRecipient);
				Assert.AreEqual(2, recipients.Count);

				index = 0;
				Assert.AreEqual("*****@*****.**", recipients.Keys[index].Trim('\''));
				Assert.AreEqual("*****@*****.**", recipients[index++]);
				Assert.AreEqual("*****@*****.**", recipients.Keys[index].Trim('\''));
				Assert.AreEqual("*****@*****.**", recipients[index++]);

				outlookEmailWrapper.MailItem.Delete();
			}
		}
		public void TestOutlookSendLinkMapi_ReplaceAttachments()
		{
			SendLinkInfo sendLink = new SendLinkInfo();
            sendLink.DisplayName = "Attachments.html";
			sendLink.Link = "A Link";
            sendLink.FilePath = Path.Combine(TestRoot, "Attachments.html");
			OutlookEmailWrapper email = new OutlookEmailWrapper(_outlookSession, Path.Combine(TestRoot, "Test RTF 2010.msg"));
			OutlookSendLinkMAPI mapi = new OutlookSendLinkMAPI();

            int count = email.MailItem.Attachments.Count;
            int[] posArray = new int[count];
            string[] recordKeyArray = new string[count];

            using (var wsMailItem = new WsMailItem(email.MailItem))
            {
                for (int i = 1; i <= count; i++)
                {
                    posArray[i - 1] = wsMailItem.Attachments[i].Position;
                    recordKeyArray[i - 1] = mapi.GetRecordKey(wsMailItem, i);
                }

                for (int i = 1; i <= count; i++)
                {
                    IWSMailAttachmentTransform mat = new OutlookIImplFactory().CreateWSMailAttachmentTransform();
                    mat.SendLinkReplaceRtfAttachments(wsMailItem, sendLink.FilePath, sendLink.DisplayName);
                }

                Redemption.SafeMailItem safeMailItem = RedemptionLoader.new_SafeMailItem();
                using (new ComRelease(safeMailItem))
                {
                    safeMailItem.Item = wsMailItem.UnSafeMailItem;// email.MailItem;

                    int[] posArray2 = new int[safeMailItem.Attachments.Count];
                    string[] names = new string[count];
                    for (int i = 1; i <= safeMailItem.Attachments.Count; i++)
                    {
                        posArray2[i - 1] = safeMailItem.Attachments[i].Position;
                        names[i - 1] = safeMailItem.Attachments[i].DisplayName;
                    }

                    for (int i = 0; i < safeMailItem.Attachments.Count; i++)
                    {
                        Assert.AreEqual(posArray[i], posArray2[i]);
                        Assert.AreEqual(names[i], "Attachments.html");
                    }
                }
            }
		}
		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 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 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 TestConvertToMimeStreamRtfBodyWithAttachmentAddedByRef()
		{
			using (WsActivationContext wsac = new WsActivationContext())
			using (OutlookEmailWrapper outlookEmailWrapper = new OutlookEmailWrapper(m_outlookSession))
			{
				string subject = "RTF text e-mail: This is a test mail";
				outlookEmailWrapper.Subject = subject;
				outlookEmailWrapper.ToRecipients = "*****@*****.**";
				outlookEmailWrapper.BccRecipients = "*****@*****.**";
				outlookEmailWrapper.BodyFormat = Outlook.OlBodyFormat.olFormatRichText;
				string rtfBody = "We have a body that looks like something";
				outlookEmailWrapper.Body = rtfBody;
				outlookEmailWrapper.AddAttachment(m_testPath + "test.doc", "test.doc", Outlook.OlAttachmentType.olByReference);
				outlookEmailWrapper.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceLow;

                Request request = ConvertToRequestWithAttachment(m_testPath + "TestResultConvertToMimeStreamRtfBodyAddedByRef.txt", "test.doc", outlookEmailWrapper.MailItem);

				//properties
				Assert.AreEqual(8, request.Properties.Length);
				Assert.AreEqual(String.Empty, GetPropertyValue(MailMessagePropertyKeys.FileHeader, request.Properties), "Mismatch in Property");

				Assert.IsTrue( GetPropertyValue(MailMessagePropertyKeys.Body,request.Properties ).Contains(rtfBody));

				string resultantRtf = GetPropertyValue(MailMessagePropertyKeys.FormattedBody, request.Properties) ;
				Assert.IsTrue(resultantRtf.Contains("{\\rtf1"), "Mismatch in Property - body is not in RTF format");
				Assert.IsTrue(resultantRtf.Contains(rtfBody), "Mismatch in Property - RTF body does not contain the correct body text");

				Assert.AreEqual(subject, GetPropertyValue(MailMessagePropertyKeys.Subject,request.Properties ), "Mismatch in Property");
				Assert.AreEqual("Outlook", GetPropertyValue(SMTPPropertyKeys.RequestChannel, request.Properties), "Mismatch in Property");
				Assert.AreEqual("test.doc ", GetPropertyValue(MailMessagePropertyKeys.Attachments, request.Properties), "Mismatch in Property");

				Assert.AreEqual( GetPropertyValue(MailMessagePropertyKeys.xPriority, request.Properties ), "5");
			}
		}
		public void TestConvertToMimeStreamWithAttachmentAddedWhereDisplayNameDoesntHaveExtension()
		{
			using (WsActivationContext wsac = new WsActivationContext())
			using (OutlookEmailWrapper outlookEmailWrapper = new OutlookEmailWrapper(m_outlookSession))
			{
				string subject = "Plain text e-mail: This is a test mail";
				outlookEmailWrapper.Subject = subject;
				outlookEmailWrapper.ToRecipients = "*****@*****.**";
				outlookEmailWrapper.BccRecipients = "*****@*****.**";
				outlookEmailWrapper.BodyFormat = Outlook.OlBodyFormat.olFormatPlain;
				outlookEmailWrapper.Body = "We have a body that looks like something";
				outlookEmailWrapper.AddAttachment(m_testPath + "test.doc", "test with no extension", Outlook.OlAttachmentType.olByValue);
				outlookEmailWrapper.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceLow;

                Request request = ConvertToRequestWithAttachment(m_testPath + "TestResultConvertToMimeStreamAddedByValue.txt", "test with no extension", outlookEmailWrapper.MailItem);

				//properties
				Assert.AreEqual(8, request.Properties.Length);
				Assert.AreEqual(String.Empty, GetPropertyValue(MailMessagePropertyKeys.FileHeader, request.Properties), "Mismatch in Property");
				Assert.IsTrue(GetPropertyValue(MailMessagePropertyKeys.Body, request.Properties).Contains("We have a body that looks like something"), "Mismatch in Property");
				Assert.IsTrue(GetPropertyValue(MailMessagePropertyKeys.FormattedBody, request.Properties).Contains("We have a body that looks like something"), "Mismatch in Property");
				Assert.AreEqual(subject, GetPropertyValue(MailMessagePropertyKeys.Subject, request.Properties), "Mismatch in Property");
				Assert.AreEqual("Outlook", GetPropertyValue(SMTPPropertyKeys.RequestChannel, request.Properties), "Mismatch in Property");
				Assert.AreEqual("test with no extension ", GetPropertyValue(MailMessagePropertyKeys.Attachments, request.Properties), "Mismatch in Property");

				Assert.AreEqual("5", GetPropertyValue(MailMessagePropertyKeys.xPriority, request.Properties));
			}
		}
        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 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();
                }
            }
        }
        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();
                }
            }
        }
        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();
                }
            }
        }
        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 TestOutlookSendLinkOOM_ReplaceAttachments()
		{
			SendLinkInfo sendLink = new SendLinkInfo();
			sendLink.DisplayName = "Attachments.html";
			sendLink.Link = "A Link";
			sendLink.FilePath = Path.Combine(TestRoot, "Attachments.html");
			OutlookEmailWrapper email = new OutlookEmailWrapper(_outlookSession, Path.Combine(TestRoot, "Test Rtf 2010.msg"));
			OutlookSendLinkOOM oom = new OutlookSendLinkOOM();
			int count = email.MailItem.Attachments.Count;
			int[] posArray = new int[count];
			string[] recordKeyArray = new string[count];

			using (var wsMailItem = new WsMailItem(email.MailItem))
			{
				for (int i = 1; i <= count; i++)
				{
					posArray[i - 1] = wsMailItem.Attachments[i].Position;
					recordKeyArray[i - 1] = oom.GetRecordKey(wsMailItem, i);
				}

				for (int i = 1; i <= count; i++)
				{
					oom.ReplaceAttachments(wsMailItem, recordKeyArray[i - 1], sendLink);
				}

				int[] posArray2 = new int[wsMailItem.Attachments.Count];
				string[] names = new string[count];
				for (int i = 1; i <= wsMailItem.Attachments.Count; i++)
				{
					posArray2[i - 1] = wsMailItem.Attachments[i].Position;
					names[i - 1] = wsMailItem.Attachments[i].DisplayName;
				}

				for (int i = 0; i < wsMailItem.Attachments.Count; i++)
				{
					Assert.AreEqual(posArray[i], posArray2[i]);
					Assert.AreEqual(names[i], "Attachments.html");
				}
			}
		}