예제 #1
0
		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;
				}
			}
		}
예제 #2
0
		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;
			}
		}
예제 #3
0
		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));
				}
			}
		}
예제 #4
0
		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);
				}
			}
		}
예제 #5
0
		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);
					}
				}
			}
		}
예제 #6
0
		internal PolicyContent.Request CreateRequest(IProxy mailItem)
		{
			NotesMailProxy proxy = new NotesMailProxy(mailItem);
			Email2Request email2Uro = new Email2Request(proxy);
			return email2Uro.Convert(RequestChannel.LotusNotes, false);
		}
예제 #7
0
		public Request CreateRequest(MailItem mailItem)
		{
			if (null == m_application)
			{
				Init(mailItem.Application);
			}
			
			ResolveRedemptionUsage(mailItem);

            m_email2Uro = new Email2Request(m_emailProxy);
			return m_email2Uro.Convert(RequestChannel.Outlook, SendAndProtect);
		}