public void TestDocAttachment_01() { byte[] mimebytes = File.ReadAllBytes(Path.Combine(m_testPath, "UnicodeMimeWithDocAttachment01")); using (MimeProxy proxy = new MimeProxy(mimebytes)) { IEmailRecipient sender = proxy.Sender; Assert.AreEqual("*****@*****.**", sender.EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("*****@*****.**", sender.Name, "Mismatch in email display name"); Assert.AreEqual(1, proxy.ToRecipients.Count); Assert.AreEqual(0, proxy.CcRecipients.Count); Assert.AreEqual(0, proxy.BccRecipients.Count); Assert.AreEqual("*****@*****.**", proxy.ToRecipients[0].EmailAddress, "Mismatch in email address"); Assert.AreEqual("*****@*****.**", proxy.ToRecipients[0].Name, "Mismatch in email display name"); Assert.AreEqual(1, proxy.Attachments.Count); Assert.AreEqual("ITA1_2-word2.4.doc", proxy.Attachments[0].DisplayName, "Mismatch in attachment name"); Assert.AreEqual("application/octet-stream; name=ITA1_2-word2.4.doc", proxy.Attachments[0].ContentType, "Mismatch in attachment content type"); Assert.IsTrue(proxy.Attachments[0].FileName.Contains("ITA1_2-word2.4.doc"), "Expected to find a non-empty stream"); Assert.AreEqual("ITA1_2-word2.4.doc", proxy.FormattedBodyText, "Mismatch in Property"); Assert.AreEqual("ITA1_2-word2.4.doc", proxy.Subject, "Mismatch in Property"); } }
public void TestPlainTextMessageBody() { byte[] mimebytes = File.ReadAllBytes(Path.Combine(m_testPath, "TestPlainTextMessageBody")); using (MimeProxy proxy = new MimeProxy(mimebytes)) { Assert.AreEqual("*****@*****.**", proxy.Sender.EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("lnpair", proxy.Sender.Name, "Mismatch in email emailAddress"); Assert.AreEqual(2, proxy.ToRecipients.Count); Assert.AreEqual(1, proxy.CcRecipients.Count); Assert.AreEqual(1, proxy.BccRecipients.Count); Assert.AreEqual("*****@*****.**", proxy.ToRecipients[0].EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("Black Hole", proxy.ToRecipients[0].Name, "Mismatch in email emailAddress"); Assert.AreEqual("*****@*****.**", proxy.ToRecipients[1].EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("Pair Adm", proxy.ToRecipients[1].Name, "Mismatch in email emailAddress"); Assert.AreEqual("*****@*****.**", proxy.CcRecipients[0].EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("lnpair", proxy.CcRecipients[0].Name, "Mismatch in email emailAddress"); Assert.AreEqual("*****@*****.**", proxy.BccRecipients[0].EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("*****@*****.**", proxy.BccRecipients[0].Name, "Mismatch in email emailAddress"); Assert.AreEqual(0, proxy.Attachments.Count); Assert.AreEqual("This body is plain text.", proxy.FormattedBodyText, "Mismatch in Property"); Assert.AreEqual("TestPlainTextMessageBody", proxy.Subject, "Mismatch in Property"); } }
public void TestClearFormattedBody() { using (Stream stream = new MemoryStream()) using (MimeProxy proxy = new MimeProxy(stream)) { proxy.FormattedBodyText = "<html>Some text</html>"; Assert.IsTrue(proxy.FormattedBodyText.Contains("Some text")); proxy.FormattedBodyText = null; Assert.IsTrue(string.IsNullOrEmpty(proxy.FormattedBodyText)); } }
private void Dispose(bool disposing) { if (m_disposed) return; m_disposed = true; if (disposing) { if (null != m_mimeProxy) { m_mimeProxy.Dispose(); m_mimeProxy = null; } } }
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; } }
public MimeProxy Convert() { using (MemoryStream stream = new MemoryStream()) { ProcessOriginalContentBytes(stream); MimeProxy proxy = new MimeProxy(stream); //gotcha: properties must _always_ be processed first. Chilkat returns different representations //of the mimestream if otherwise. And I mean _very different_. Laku ProcessProperties(proxy); ProcessSender(proxy); ProcessRecipients(proxy); ProcessHeaders(proxy); return proxy; } }
public bool IsEmail(IFile file) { if (file.FileType == FileType.TextDocument) // check for .eml { using (System.IO.Stream str = file.RawContents.AsStream()) { using (MimeProxy mime = new MimeProxy(str)) { return mime.IsValidMimeType(); } } } else if (file.FileType == FileType.Unknown || file.FileType == FileType.Email) // check for .msg using storage { return File.IsOutlookMSGType(file); } return false; }
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"); }
public Stream ExecuteMime(IActionData3 data, ActionPropertySet aProperties) { if (aProperties.SystemProperties.ContainsKey(SystemPropertiesStringTable.SysProp_FileType)) { if (!SupportedFileCollection.Supports(aProperties.SystemProperties[SystemPropertiesStringTable.SysProp_FileType].Value as string)) { Logger.LogError(Properties.Resources.UNABLE_TO_TAG_NON_SUPPORTED_FILETYPE); return null; } } if ((bool) aProperties[RPostActionStringTable.SendRegistered].Value == false) { return data.Content; } MimeProxy mime = new MimeProxy(data.Content); foreach (IEmailRecipient recipient in mime.ToRecipients) recipient.EmailAddress = recipient.EmailAddress + ".workshare.rpost.org"; foreach (IEmailRecipient recipient in mime.CcRecipients) recipient.EmailAddress = recipient.EmailAddress + ".workshare.rpost.org"; foreach (IEmailRecipient recipient in mime.BccRecipients) recipient.EmailAddress = recipient.EmailAddress + ".workshare.rpost.org"; if ((bool) aProperties[RPostActionStringTable.Unmarked].Value == true) { string subject = mime.Subject; mime.Subject = "(C) " + subject; } Email2Mime email = new Email2Mime(mime); return email.ConvertToMimeStream(); }
public void TestEmptyHTMLMessageBody() { byte[] mimebytes = File.ReadAllBytes(Path.Combine(m_testPath, "TestEmptyHTMLMessageBody")); using (MimeProxy proxy = new MimeProxy(mimebytes)) { Assert.AreEqual("*****@*****.**", proxy.Sender.EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("lnpair", proxy.Sender.Name, "Mismatch in email emailAddress"); Assert.AreEqual(1, proxy.ToRecipients.Count); Assert.AreEqual(0, proxy.CcRecipients.Count); Assert.AreEqual(0, proxy.BccRecipients.Count); Assert.AreEqual("*****@*****.**", proxy.ToRecipients[0].EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("Pair Adm", proxy.ToRecipients[0].Name, "Mismatch in email emailAddress"); Assert.AreEqual(0, proxy.Attachments.Count); Assert.AreEqual(String.Empty, proxy.FormattedBodyText, "Mismatch in Property"); Assert.AreEqual("TestEmptyHTMLMessageBody", proxy.Subject, "Mismatch in Property"); } }
public Email2Mime(IEmailProxy emailProxy) { m_emailProxy = emailProxy; m_mimeProxy = new MimeProxy(new byte[] { }); }
public void TestInvalidStream() { Stream stream = null; MimeProxy proxy = new MimeProxy(stream); }
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; } }
// 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(); } }
public void TestModifyMimeUsingProxy() { using (Stream mimeStream = new MemoryStream()) using (MimeProxy proxy = new MimeProxy(mimeStream)) { proxy.Sender.Name = "lnpair"; proxy.Sender.EmailAddress = "*****@*****.**"; Assert.AreEqual("lnpair", proxy.Sender.Name); Assert.AreEqual("*****@*****.**", proxy.Sender.EmailAddress); EmailRecipient recipient = new EmailRecipient(); recipient.Name = "blackhole"; recipient.EmailAddress = "blackhole1"; proxy.ToRecipients.Add(recipient); recipient.Name = "blackhole"; recipient.EmailAddress = "blackhole2"; proxy.ToRecipients.Add(recipient); proxy.ToRecipients[0].Name += "1"; proxy.ToRecipients[0].EmailAddress += "@workshare.com"; proxy.ToRecipients[1].Name += "2"; proxy.ToRecipients[1].EmailAddress += "@workshare.com"; recipient.Name = "blackhole3"; recipient.EmailAddress = "*****@*****.**"; proxy.CcRecipients.Add(recipient); recipient.Name = "blackhole4"; recipient.EmailAddress = "*****@*****.**"; proxy.BccRecipients.Add(recipient); proxy.FormattedBodyText = "This body is plain text."; proxy.FormattedBodyText += " And don't forget it!"; Assert.AreEqual("This body is plain text. And don't forget it!", proxy.FormattedBodyText); proxy.Subject = "TestPlainTextMessageBody"; proxy.Subject += " processed."; Assert.AreEqual("TestPlainTextMessageBody processed.", proxy.Subject); Assert.AreEqual(2, proxy.ToRecipients.Count); Assert.AreEqual(1, proxy.CcRecipients.Count); Assert.AreEqual(1, proxy.BccRecipients.Count); Assert.AreEqual("blackhole1", proxy.ToRecipients[0].Name); Assert.AreEqual("*****@*****.**", proxy.ToRecipients[0].EmailAddress); Assert.AreEqual("blackhole2", proxy.ToRecipients[1].Name); Assert.AreEqual("*****@*****.**", proxy.ToRecipients[1].EmailAddress); Assert.AreEqual("blackhole3", proxy.CcRecipients[0].Name); Assert.AreEqual("*****@*****.**", proxy.CcRecipients[0].EmailAddress); Assert.AreEqual("blackhole4", proxy.BccRecipients[0].Name); Assert.AreEqual("*****@*****.**", proxy.BccRecipients[0].EmailAddress); EmailAttachment attachment = new EmailAttachment(); attachment.DisplayName = "test.ppt"; attachment.FileName = Path.Combine(m_testPath, "test.ppt"); proxy.Attachments.Add(attachment); Assert.AreEqual(1, proxy.Attachments.Count); Assert.AreEqual("test.ppt", proxy.Attachments[0].DisplayName); Assert.AreEqual("application/vnd.ms-powerpoint; name=test.ppt", proxy.Attachments[0].ContentType); Assert.IsTrue(proxy.Attachments[0].FileName.Contains("test.ppt"), "Expected to find a non-empty stream"); // Now, lets modify the recipients via the enumerator foreach (IEmailRecipient recip in proxy.ToRecipients) { recip.Name += " Changed"; recip.EmailAddress += "ified"; } Assert.AreEqual(2, proxy.ToRecipients.Count); Assert.AreEqual("blackhole1 Changed", proxy.ToRecipients[0].Name); Assert.AreEqual("*****@*****.**", proxy.ToRecipients[0].EmailAddress); Assert.AreEqual("blackhole2 Changed", proxy.ToRecipients[1].Name); Assert.AreEqual("*****@*****.**", proxy.ToRecipients[1].EmailAddress); } }
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); } } } }
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); } }
public void TestHTMLMessageBody() { byte[] mimebytes = File.ReadAllBytes(Path.Combine(m_testPath, "TestHTMLMessageBody")); using (MimeProxy proxy = new MimeProxy(mimebytes)) { Assert.AreEqual("*****@*****.**", proxy.Sender.EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("lnpair", proxy.Sender.Name, "Mismatch in email emailAddress"); Assert.AreEqual(1, proxy.ToRecipients.Count); Assert.AreEqual(0, proxy.CcRecipients.Count); Assert.AreEqual(0, proxy.BccRecipients.Count); Assert.AreEqual("*****@*****.**", proxy.ToRecipients[0].EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("Pair Adm", proxy.ToRecipients[0].Name, "Mismatch in email emailAddress"); Assert.AreEqual(0, proxy.Attachments.Count); Assert.AreEqual("HTML Message body : link <http://www.google.com/> \r\n\r\n", proxy.BodyText, "Mismatch in Property"); Assert.Less("HTML Message body : link <http://www.google.com/> ".Length, proxy.FormattedBodyText.Length, "Mismatch in Property"); Assert.AreEqual("TestHTMLMessageBody", proxy.Subject, "Mismatch in Property"); } }
public void TestSetBody() { using (MimeProxy proxy = new MimeProxy(new byte[] { })) { proxy.FormattedBodyText = "This body is plain text."; Assert.AreEqual("This body is plain text.", proxy.FormattedBodyText); Assert.IsTrue(proxy.MimeContent.Contains("Content-Type: text/plain")); Assert.IsFalse(proxy.MimeContent.Contains("Content-Type: text/html")); proxy.FormattedBodyText = "<html>This body is plain text.</html>"; Assert.IsTrue(proxy.FormattedBodyText.Contains("This body is plain text.")); Assert.IsFalse(proxy.MimeContent.Contains("Content-Type: text/plain")); Assert.IsTrue(proxy.MimeContent.Contains("Content-Type: text/html")); proxy.FormattedBodyText = @"{\rtf1"; Assert.IsTrue(proxy.MimeContent.Contains("Content-Type: text/richtext")); } }
public void TestSetAttachments() { using (MimeProxy proxy = new MimeProxy(new byte[] { })) using (MimeProxy proxy2 = new MimeProxy(new byte[] { })) { EmailAttachment attachment = new EmailAttachment(); attachment.DisplayName = "test.ppt"; attachment.FileName = Path.Combine(m_testPath, "test.ppt"); proxy.Attachments.Add(attachment); Assert.AreEqual(1, proxy.Attachments.Count); Assert.AreEqual("test.ppt", proxy.Attachments[0].DisplayName); Assert.AreEqual("application/vnd.ms-powerpoint; name=test.ppt", proxy.Attachments[0].ContentType); Assert.IsTrue(proxy.Attachments[0].FileName.Contains("test.ppt"), "Expected to find a non-empty stream"); attachment.DisplayName = "test.doc"; attachment.FileName = Path.Combine(m_testPath, "test.doc"); proxy2.Attachments.Add(attachment); Assert.AreEqual(1, proxy2.Attachments.Count); Assert.AreEqual("test.doc", proxy2.Attachments[0].DisplayName); Assert.AreEqual("application/msword; name=test.doc", proxy2.Attachments[0].ContentType); Assert.IsTrue(proxy2.Attachments[0].FileName.Contains("test.doc"), "Expected to find a non-empty stream"); proxy2.Attachments = proxy.Attachments; Assert.AreEqual(1, proxy2.Attachments.Count); Assert.AreEqual("test.ppt", proxy2.Attachments[0].DisplayName); Assert.AreEqual("application/vnd.ms-powerpoint; name=test.ppt", proxy2.Attachments[0].ContentType); Assert.IsTrue(proxy2.Attachments[0].FileName.Contains("test.ppt"), "Expected to find a non-empty stream"); } }
public void TestSetRecipients() { using (Stream mimeStream = new MemoryStream()) using (MimeProxy proxy = new MimeProxy(mimeStream)) { Assert.AreEqual(0, proxy.ToRecipients.Count); Assert.AreEqual(0, proxy.CcRecipients.Count); Assert.AreEqual(0, proxy.BccRecipients.Count); EmailRecipient recipient = new EmailRecipient(); recipient.Name = "blackhole"; recipient.EmailAddress = "*****@*****.**"; proxy.ToRecipients.Add(recipient); Assert.AreEqual(1, proxy.ToRecipients.Count); Assert.AreEqual(0, proxy.CcRecipients.Count); Assert.AreEqual(0, proxy.BccRecipients.Count); // Copy the To Recipients to Cc Recipients proxy.CcRecipients = proxy.ToRecipients; Assert.AreEqual(1, proxy.ToRecipients.Count); Assert.AreEqual(1, proxy.CcRecipients.Count); Assert.AreEqual(0, proxy.BccRecipients.Count); recipient.Name = "blackhole2"; recipient.EmailAddress = "*****@*****.**"; proxy.CcRecipients.Add(recipient); Assert.AreEqual(1, proxy.ToRecipients.Count); Assert.AreEqual(2, proxy.CcRecipients.Count); Assert.AreEqual(0, proxy.BccRecipients.Count); // Copy the To Recipients to Cc Recipients proxy.CcRecipients = proxy.ToRecipients; Assert.AreEqual(1, proxy.ToRecipients.Count); Assert.AreEqual(1, proxy.CcRecipients.Count); Assert.AreEqual(0, proxy.BccRecipients.Count); recipient.Name = "blackhole2"; recipient.EmailAddress = "*****@*****.**"; proxy.CcRecipients.Add(recipient); Assert.AreEqual(1, proxy.ToRecipients.Count); Assert.AreEqual(2, proxy.CcRecipients.Count); Assert.AreEqual(0, proxy.BccRecipients.Count); // Copy the Cc Recipients to To Recipients proxy.ToRecipients = proxy.CcRecipients; Assert.AreEqual(2, proxy.ToRecipients.Count); Assert.AreEqual(2, proxy.CcRecipients.Count); Assert.AreEqual(0, proxy.BccRecipients.Count); // Copy the Cc Recipients to Bcc Recipients proxy.BccRecipients = proxy.CcRecipients; Assert.AreEqual(2, proxy.ToRecipients.Count); Assert.AreEqual(2, proxy.CcRecipients.Count); Assert.AreEqual(2, proxy.BccRecipients.Count); recipient.Name = "blackhole3"; recipient.EmailAddress = "*****@*****.**"; proxy.CcRecipients.Add(recipient); Assert.AreEqual(2, proxy.ToRecipients.Count); Assert.AreEqual(3, proxy.CcRecipients.Count); Assert.AreEqual(2, proxy.BccRecipients.Count); // Copy the Cc Recipients to Bcc Recipients proxy.BccRecipients = proxy.CcRecipients; Assert.AreEqual(2, proxy.ToRecipients.Count); Assert.AreEqual(3, proxy.CcRecipients.Count); Assert.AreEqual(3, proxy.BccRecipients.Count); recipient.Name = "blackhole4"; recipient.EmailAddress = "*****@*****.**"; proxy.BccRecipients.Add(recipient); Assert.AreEqual(2, proxy.ToRecipients.Count); Assert.AreEqual(3, proxy.CcRecipients.Count); Assert.AreEqual(4, proxy.BccRecipients.Count); } }
public void TestWithMIMEFromWebBasedEmailClient() { byte[] mimebytes = File.ReadAllBytes(Path.Combine(m_testPath, "MIMEFromWebBasedEmailClient")); using (MimeProxy proxy = new MimeProxy(mimebytes)) { Assert.AreEqual("*****@*****.**", proxy.Sender.EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("Someone", proxy.Sender.Name, "Mismatch in email emailAddress"); Assert.AreEqual(3, proxy.ToRecipients.Count); Assert.AreEqual(0, proxy.CcRecipients.Count); Assert.AreEqual(0, proxy.BccRecipients.Count); Assert.AreEqual("*****@*****.**", proxy.ToRecipients[0].EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("*****@*****.**", proxy.ToRecipients[0].Name, "Mismatch in email emailAddress"); Assert.AreEqual("*****@*****.**", proxy.ToRecipients[1].EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("*****@*****.**", proxy.ToRecipients[1].Name, "Mismatch in email emailAddress"); Assert.AreEqual("*****@*****.**", proxy.ToRecipients[2].EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("*****@*****.**", proxy.ToRecipients[2].Name, "Mismatch in email emailAddress"); Assert.AreEqual(2, proxy.Attachments.Count); Assert.AreEqual("testharness__TestTimings.csv", proxy.Attachments[0].DisplayName, "Mismatch in attachment name"); Assert.AreEqual("application/vnd.ms-excel; name=testharness__TestTimings.csv", proxy.Attachments[0].ContentType, "Mismatch in attachment content type"); Assert.IsTrue(proxy.Attachments[0].FileName.Contains("testharness__TestTimings.csv"), "Expected to find a non-empty stream"); Assert.AreEqual("testharness__TestResults.csv", proxy.Attachments[1].DisplayName, "Mismatch in attachment name"); Assert.AreEqual("application/vnd.ms-excel; name=testharness__TestResults.csv", proxy.Attachments[1].ContentType, "Mismatch in attachment content type"); Assert.IsTrue(proxy.Attachments[1].FileName.Contains("testharness__TestResults.csv"), "Expected to find a non-empty stream"); Assert.AreEqual("This is a test email with hyperlink <http://www.google.com>\r\n", proxy.BodyText, "Mismatch in Property"); Assert.Less("This is a test email with hyperlink <http://www.google.com>".Length, proxy.FormattedBodyText.Length, "Mismatch in Property"); Assert.AreEqual("TestWithMIMEFromWebBasedEmailClient", proxy.Subject, "Mismatch in Property"); } }
private void InsertIntoHtml(MimeProxy proxy, EmailAttachment attachment) { string htmlBody = proxy.FormattedBodyText; string testValue = htmlBody.Substring(0, (htmlBody.Length <= 100) ? (htmlBody.Length - 1) : 100).ToLower(System.Globalization.CultureInfo.InvariantCulture); if (!testValue.Contains("<html")) return; StringBuilder contentId = new StringBuilder(attachment.DisplayName); contentId.Append("@"); contentId.Append("0BF8744C.9BF049de"); attachment.ContentId = contentId.ToString(); StringBuilder htmlTag = new StringBuilder("<img id=\""); htmlTag.Append(contentId.ToString()); htmlTag.Append("\" src=\"cid:"); htmlTag.Append(contentId.ToString()); htmlTag.Append("\">"); int insertIndex = htmlBody.LastIndexOf("</body>"); if (-1 != insertIndex) proxy.FormattedBodyText = htmlBody.Insert(insertIndex, htmlTag.ToString()); }
public void TestMultipleAttachments() { byte[] mimebytes = File.ReadAllBytes(Path.Combine(m_testPath, "TestMultipleAttachments")); using (MimeProxy proxy = new MimeProxy(mimebytes)) { Assert.AreEqual("*****@*****.**", proxy.Sender.EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("lnpair", proxy.Sender.Name, "Mismatch in email emailAddress"); Assert.AreEqual(1, proxy.ToRecipients.Count); Assert.AreEqual(0, proxy.CcRecipients.Count); Assert.AreEqual(0, proxy.BccRecipients.Count); Assert.AreEqual("*****@*****.**", proxy.ToRecipients[0].EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("Black Hole", proxy.ToRecipients[0].Name, "Mismatch in email emailAddress"); Assert.AreEqual(3, proxy.Attachments.Count); Assert.AreEqual("Attachment1.doc", proxy.Attachments[0].DisplayName, "Mismatch in attachment name"); Assert.AreEqual("application/msword; name=Attachment1.doc", proxy.Attachments[0].ContentType, "Mismatch in attachment content type"); Assert.IsTrue(proxy.Attachments[0].FileName.Contains("Attachment1.doc"), "Expected to find a non-empty stream"); Assert.AreEqual("Attachment2.ppt", proxy.Attachments[1].DisplayName, "Mismatch in attachment name"); Assert.AreEqual("application/vnd.ms-powerpoint; name=Attachment2.ppt", proxy.Attachments[1].ContentType, "Mismatch in attachment content type"); Assert.IsTrue(proxy.Attachments[1].FileName.Contains("Attachment2.ppt"), "Expected to find a non-empty stream"); Assert.AreEqual("Attachment3.xls", proxy.Attachments[2].DisplayName, "Mismatch in attachment name"); Assert.AreEqual("application/vnd.ms-excel; name=Attachment3.xls", proxy.Attachments[2].ContentType, "Mismatch in attachment content type"); Assert.IsTrue(proxy.Attachments[2].FileName.Contains("Attachment3.xls"), "Expected to find a non-empty stream"); Assert.AreEqual(" \r\n\r\n", proxy.BodyText, "Mismatch in Property"); Assert.Less(" ".Length, proxy.FormattedBodyText.Length, "Mismatch in Property"); Assert.AreEqual("TestMultipleAttachments", proxy.Subject, "Mismatch in Property"); } }
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 TestModifyMimeUsingChilkatDirectly() { byte[] mimebytes = File.ReadAllBytes(Path.Combine(m_testPath, "TestPlainTextMessageBody")); using (MimeProxy proxy = new MimeProxy(mimebytes)) { // Now lets modify it. using (Chilkat.Email email = new Chilkat.Email()) { email.SetFromMimeText(proxy.MimeContent); email.Subject = "Processed: " + email.Subject; email.AddTo("blackhole2", "*****@*****.**"); email.AddCC("blackhole3", "*****@*****.**"); email.AddBcc("blackhole4", "*****@*****.**"); email.Body += " And don't forget it!"; email.AddFileAttachment(Path.Combine(m_testPath, @"test.ppt")); Assert.AreEqual(3, email.NumTo); Assert.AreEqual(2, email.NumCC); Assert.AreEqual(2, email.NumBcc); proxy.MimeContent = MimeProxy.InsertBccRecipientsIntoMime(email); } Assert.AreEqual("*****@*****.**", proxy.Sender.EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("lnpair", proxy.Sender.Name, "Mismatch in email emailAddress"); Assert.AreEqual(3, proxy.ToRecipients.Count); Assert.AreEqual(2, proxy.CcRecipients.Count); Assert.AreEqual(2, proxy.BccRecipients.Count); Assert.AreEqual("*****@*****.**", proxy.ToRecipients[0].EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("Black Hole", proxy.ToRecipients[0].Name, "Mismatch in email emailAddress"); Assert.AreEqual("*****@*****.**", proxy.ToRecipients[1].EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("Pair Adm", proxy.ToRecipients[1].Name, "Mismatch in email emailAddress"); Assert.AreEqual("*****@*****.**", proxy.ToRecipients[2].EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("blackhole2", proxy.ToRecipients[2].Name, "Mismatch in email emailAddress"); Assert.AreEqual("*****@*****.**", proxy.CcRecipients[0].EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("lnpair", proxy.CcRecipients[0].Name, "Mismatch in email emailAddress"); Assert.AreEqual("*****@*****.**", proxy.CcRecipients[1].EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("blackhole3", proxy.CcRecipients[1].Name, "Mismatch in email emailAddress"); Assert.AreEqual("*****@*****.**", proxy.BccRecipients[0].EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("*****@*****.**", proxy.BccRecipients[0].Name, "Mismatch in email emailAddress"); Assert.AreEqual("*****@*****.**", proxy.BccRecipients[1].EmailAddress, "Mismatch in email emailAddress"); Assert.AreEqual("blackhole4", proxy.BccRecipients[1].Name, "Mismatch in email emailAddress"); Assert.AreEqual(1, proxy.Attachments.Count); Assert.AreEqual("test.ppt", proxy.Attachments[0].DisplayName, "Mismatch in attachment name"); Assert.AreEqual("application/vnd.ms-powerpoint; name=test.ppt", proxy.Attachments[0].ContentType, "Mismatch in attachment content type"); Assert.IsTrue(proxy.Attachments[0].FileName.Contains("test.ppt"), "Expected to find a non-empty stream"); Assert.AreEqual("This body is plain text. And don't forget it!", proxy.FormattedBodyText, "Mismatch in Property"); Assert.AreEqual("Processed: TestPlainTextMessageBody", proxy.Subject, "Mismatch in Property"); } }