private IUniversalRequestObject ConvertToMimeStreamWithAttachment(string mimefilename)
        {
            NotesMailProxy proxy = new NotesMailProxy(m_notesProxy);
            using (Email2Mime mailItem2Mime = new Email2Mime(proxy))
            using (Stream mimeStream = mailItem2Mime.ConvertToMimeStream())
            using (MimeProxy mimeProxy = new MimeProxy(mimeStream))
            {
                Assert.IsNotNull(mimeStream);
                SaveStream(mimefilename, mimeStream);

                Email2Uro email2Uro = new Email2Uro(mimeProxy);
                Assert.IsNotNull(email2Uro);
                IUniversalRequestObject uro = email2Uro.Convert(RequestChannel.LotusNotes);
                Assert.IsNotNull(uro);

                //sender
                Assert.IsTrue(1 == uro.Source.Items.Count, "Should only be a single source item");
                Assert.AreEqual("*****@*****.**", uro.Source.Items[0].Content, "Mismatch in email emailAddress");
                Assert.AreEqual("DevBuild", uro.Source.Items[0].Properties[SMTPPropertyKeys.DisplayName], "Mismatch in email address");

                // recipients
                Assert.AreEqual(3, uro.Destination.Items.Count, "Expected 3 items as the Token are set by default on To/Ccc/Bcc");
                Assert.AreEqual(AddressType.To, uro.Destination.Items[0].Properties[SMTPItemPropertyKeys.AddressType], "Destination should be of AddressType: To");
                Assert.AreEqual("INTERNAL_TOKEN_F19CA8B3B44d13BCE9A38EC838E2C3224F74F2554c9586EA5DEBBCAD7F", uro.Destination.Items[0].Content, "Mismatch in email emailAddress");
                Assert.AreEqual("INTERNAL_TOKEN_F19CA8B3B44d13BCE9A38EC838E2C3224F74F2554c9586EA5DEBBCAD7F", uro.Destination.Items[0].Properties[SMTPPropertyKeys.DisplayName], "Mismatch in email emailAddress");
                Assert.AreEqual("INTERNAL_TOKEN_F19CA8B3B44d13BCE9A38EC838E2C3224F74F2554c9586EA5DEBBCAD7F", uro.Destination.Items[1].Content, "Mismatch in email emailAddress");
                Assert.AreEqual("INTERNAL_TOKEN_F19CA8B3B44d13BCE9A38EC838E2C3224F74F2554c9586EA5DEBBCAD7F", uro.Destination.Items[1].Properties[SMTPPropertyKeys.DisplayName], "Mismatch in email emailAddress");

                //attachments
                Assert.AreEqual(1, uro.Attachments.Count);
                Assert.AreEqual("test.doc", uro.Attachments[0].Name, "Mismatch in attachment name");
                Assert.AreEqual("application/msword; name=test.doc", uro.Attachments[0].ContentType, "Mismatch in attachment content type");

                Assert.IsTrue(0 < uro.Attachments[0].Data.Length, "Expected the attachments data length to be greater then zero");

                using (Stream str = uro.Attachments[0].Data.AsStream())
                {
                    Assert.IsTrue(0 < str.Length, "Expected to find a non-empty stream");
                }

                Assert.AreEqual("LotusNotes", uro.Destination.Properties[SMTPPropertyKeys.RequestChannel]);
                Assert.AreEqual("LotusNotes", uro.Source.Properties[SMTPPropertyKeys.RequestChannel]);

                return uro;
            }
        }
Exemple #2
0
		public void TestNullByteArray()
		{
			try
			{
				byte[] nullArray = null;

				MimeProxy mimeProxy = new MimeProxy(nullArray);
				Email2Uro mime2Uro = new Email2Uro(mimeProxy);
			}
			catch (ArgumentNullException)
			{
				//should come in here
				Assert.IsTrue(true);
				return;
			}

			Assert.Fail("Expected to receive an ArgumentNullException");

		}
Exemple #3
0
		private IUniversalRequestObject UroFromMimeBytes(string mimeFile)
		{
			byte[] mimebytes = File.ReadAllBytes(Path.Combine(TEST_FILE_PATH, mimeFile));

			using (MimeProxy proxy = new MimeProxy(mimebytes))
			{
				Email2Uro email2Uro = new Email2Uro(proxy);

				IUniversalRequestObject uro = email2Uro.Convert(RequestChannel.Outlook);

				Assert.IsNotNull(uro, "Uro instance should not by null.");
				Assert.IsNotNull(uro.OriginalContentBytes);
				Assert.IsNotNull(uro.OriginalContentBytes.Data);

				Assert.AreEqual("MIME", uro.OriginalContentBytes.Name);
				Assert.IsFalse(string.IsNullOrEmpty(uro.OriginalContentBytes.ContentType));

				Assert.IsTrue(0 < uro.OriginalContentBytes.Data.Length, "Expected a valid requestAttachmentMime string");

				Assert.AreEqual("Outlook", uro.Destination.Properties[SMTPPropertyKeys.RequestChannel]);
				Assert.AreEqual("Outlook", uro.Source.Properties[SMTPPropertyKeys.RequestChannel]);

				return uro;
			}
		}
Exemple #4
0
		// TODO: ProtectProcess - fix test, bring back mime
		//[Test]
		public void TestModifyMime()
		{
			IUniversalRequestObject uro = UroFromMimeBytes("TestPlainTextMessageBody");

			// Lets change some properties on the mime
			string mimeContent = uro.OriginalContentBytes.Data.AsString(uro.OriginalContentBytes.Data.Length, Encoding.Unicode);

			// Lets get ride of the old mime
			uro.OriginalContentBytes.Data.Dispose();

			// Now lets modify it.
			using (Chilkat.Email email = new Chilkat.Email())
			{
				email.SetFromMimeText(mimeContent);
				email.Subject = "Processed: " + email.Subject;
				email.AddTo("blackhole2", "*****@*****.**");
				email.AddCC("blackhole3", "*****@*****.**");
				email.AddBcc("blackhole4", "*****@*****.**");
				email.Body += " And don't forget it!";
				email.AddFileAttachment(TEST_FILE_PATH + @"\test.ppt");

				Assert.AreEqual(3, email.NumTo);
				Assert.AreEqual(2, email.NumCC);
				Assert.AreEqual(2, email.NumBcc);

				UnicodeEncoding encoding = new UnicodeEncoding();
				string modifiedMime = MimeProxy.InsertBccRecipientsIntoMime(email);
				MemoryStream mimeStream = new MemoryStream(encoding.GetBytes(modifiedMime));
				uro.OriginalContentBytes.Data = new Workshare.Policy.BinaryData(mimeStream);
			}

			// Lets synchronize the URO with the MIME.
			using (Stream str = uro.OriginalContentBytes.Data.AsStream())
			{
				MimeProxy mimeProxy = new MimeProxy(str);
				Email2Uro email2Uro = new Email2Uro(mimeProxy);
				email2Uro.Convert(RequestChannel.Outlook, uro);
			}

			//sender
			Assert.IsTrue(1 == uro.Source.Items.Count, "Should only be a single source item");
			Assert.AreEqual("*****@*****.**", uro.Source.Items[0].Content, "Mismatch in email emailAddress");
			Assert.AreEqual("lnpair", uro.Source.Items[0].Properties[SMTPPropertyKeys.DisplayName], "Mismatch in email emailAddress");

			//recips
			Assert.AreEqual(7, uro.Destination.Items.Count);

			Assert.AreEqual("*****@*****.**", uro.Destination.Items[0].Content, "Mismatch in email emailAddress");
			Assert.AreEqual("Black Hole", uro.Destination.Items[0].Properties[SMTPItemPropertyKeys.DisplayName], "Mismatch in email emailAddress");
			Assert.AreEqual(AddressType.To, uro.Destination.Items[0].Properties[SMTPItemPropertyKeys.AddressType], "Destination item 1 should be of AddressType: To");
			Assert.AreEqual("*****@*****.**", uro.Destination.Items[1].Content, "Mismatch in email emailAddress");
			Assert.AreEqual("Pair Adm", uro.Destination.Items[1].Properties[SMTPItemPropertyKeys.DisplayName], "Mismatch in email emailAddress");
			Assert.AreEqual(AddressType.To, uro.Destination.Items[1].Properties[SMTPItemPropertyKeys.AddressType], "Destination item 2 should be of AddressType: To");

			Assert.AreEqual("*****@*****.**", uro.Destination.Items[2].Content, "Mismatch in email emailAddress");
			Assert.AreEqual("lnpair", uro.Destination.Items[2].Properties[SMTPItemPropertyKeys.DisplayName], "Mismatch in email emailAddress");
			Assert.AreEqual(AddressType.CC, uro.Destination.Items[2].Properties[SMTPItemPropertyKeys.AddressType], "Destination item 3 should be of AddressType: Cc");

			Assert.AreEqual("*****@*****.**", uro.Destination.Items[3].Content, "Mismatch in email emailAddress");
			Assert.AreEqual("*****@*****.**", uro.Destination.Items[3].Properties[SMTPItemPropertyKeys.DisplayName], "Mismatch in email emailAddress");
			Assert.AreEqual(AddressType.BCC, uro.Destination.Items[3].Properties[SMTPItemPropertyKeys.AddressType], "Destination item 3 should be of AddressType: Bcc");

			// New recipients added.
			Assert.AreEqual("*****@*****.**", uro.Destination.Items[4].Content, "Mismatch in email emailAddress");
			Assert.AreEqual("blackhole2", uro.Destination.Items[4].Properties[SMTPItemPropertyKeys.DisplayName], "Mismatch in email emailAddress");
			Assert.AreEqual(AddressType.To, uro.Destination.Items[4].Properties[SMTPItemPropertyKeys.AddressType], "Destination item 3 should be of AddressType: Bcc");
			Assert.AreEqual("*****@*****.**", uro.Destination.Items[5].Content, "Mismatch in email emailAddress");
			Assert.AreEqual("blackhole3", uro.Destination.Items[5].Properties[SMTPItemPropertyKeys.DisplayName], "Mismatch in email emailAddress");
			Assert.AreEqual(AddressType.CC, uro.Destination.Items[5].Properties[SMTPItemPropertyKeys.AddressType], "Destination item 3 should be of AddressType: Bcc");
			Assert.AreEqual("*****@*****.**", uro.Destination.Items[6].Content, "Mismatch in email emailAddress");
			Assert.AreEqual("blackhole4", uro.Destination.Items[6].Properties[SMTPItemPropertyKeys.DisplayName], "Mismatch in email emailAddress");
			Assert.AreEqual(AddressType.BCC, uro.Destination.Items[6].Properties[SMTPItemPropertyKeys.AddressType], "Destination item 3 should be of AddressType: Bcc");

			//attachments
			Assert.AreEqual(1, uro.Attachments.Count);
			Assert.AreEqual("test.ppt", uro.Attachments[0].Name, "Mismatch in attachment name");
			Assert.AreEqual("application/vnd.ms-powerpoint; name=test.ppt", uro.Attachments[0].ContentType, "Mismatch in attachment content type");
			Assert.IsTrue(0 < uro.Attachments[0].Data.Length, "Expected the attachments data length to be greater then zero");
			using (Stream str = uro.Attachments[0].Data.AsStream())
			{
				Assert.IsTrue(0 < str.Length, "Expected to find a non-empty stream");
			}

			//properties
			Assert.AreEqual(8, uro.Properties.Count);
			Assert.AreEqual(String.Empty, uro.Properties[MailMessagePropertyKeys.FileHeader], "Mismatch in Property");
			Assert.AreEqual("This body is plain text. And don't forget it!", uro.Properties[MailMessagePropertyKeys.Body], "Mismatch in Property");
			Assert.AreEqual("This body is plain text. And don't forget it!", uro.Properties[MailMessagePropertyKeys.FormattedBody], "Mismatch in Property");
			Assert.AreEqual("Processed: TestPlainTextMessageBody", uro.Properties[MailMessagePropertyKeys.Subject], "Mismatch in Property");
			Assert.AreEqual("Outlook", uro.Properties[SMTPPropertyKeys.RequestChannel], "Mismatch in Property");
			Assert.AreEqual("test.ppt ", uro.Properties[MailMessagePropertyKeys.Attachments], "Mismatch in Property");
			Assert.AreEqual("3", uro.Properties[MailMessagePropertyKeys.xPriority], "Mismatch in Property");

			uro.OriginalContentBytes.Data.Dispose();

			foreach (RequestAttachment ra in uro.Attachments)
			{
				ra.Dispose();
			}
		}
Exemple #5
0
		private void UpdateUroOriginalContentBytes(IUniversalRequestObject uro, Stream modifiedStream)
		{
			if (null == uro)
				return;

			// Discard old contents.
			if (null != uro.OriginalContentBytes)
			{
				uro.OriginalContentBytes.Dispose();
			}

			using (MimeProxy mimeProxy = new MimeProxy(modifiedStream))
			{
				Email2Uro email2Uro = new Email2Uro(mimeProxy);

				RequestChannel rq = RequestChannel.Unknown;

				string srq;
				if (uro.Properties.TryGetValue(SMTPPropertyKeys.RequestChannel, out srq))
				{
					rq = GetRequestChannel(srq);
				}

				email2Uro.Convert(rq, uro);
			}
		}