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 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 TestSetArrayItem() { NotesAttachmentsProxy proxy = new NotesAttachmentsProxy(null); proxy[0] = new EmailAttachment(); }
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); } }