public void TestAttachmentRemoval() { var antiVirusSettings = SingletonProvider <TestSetup> .Instance.GetApp().Settings.AntiVirus; antiVirusSettings.EnableAttachmentBlocking = true; Account account1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Send a message to the account. string messageText = @"Date: Thu, 03 Jul 2008 22:01:53 +0200\r\n" + "From: Test <*****@*****.**>\r\n" + "MIME-Version: 1.0\r\n" + "To: [email protected]\r\n" + "Subject: test\r\n" + "Content-Type: multipart/mixed;\r\n" + " boundary=\"------------050908050500020808050006\"\r\n" + "\r\n" + "This is a multi-part message in MIME format.\r\n" + "--------------050908050500020808050006\r\n" + "Content-Type: text/plain; charset=ISO-8859-1; format=flowed\r\n" + "Content-Transfer-Encoding: 7bit\r\n" + "\r\n" + "Test\r\n" + "\r\n" + "--------------050908050500020808050006\r\n" + "Content-Type: text/plain;\r\n" + " name=\"AUTOEXEC.BAT\"\r\n" + "Content-Transfer-Encoding: base64\r\n" + "Content-Disposition: inline;\r\n" + " filename=\"AUTOEXEC.BAT\"\r\n" + "\r\n" + "\r\n" + "--------------050908050500020808050006--\r\n"; SMTPClientSimulator.StaticSendRaw("*****@*****.**", "*****@*****.**", messageText); Message message = TestSetup.AssertRetrieveFirstMessage(account1.IMAPFolders.get_ItemByName("INBOX")); CustomAssert.AreEqual(1, message.Attachments.Count); CustomAssert.AreEqual("AUTOEXEC.BAT.txt", message.Attachments[0].Filename); string tempFile = Path.GetTempFileName(); message.Attachments[0].SaveAs(tempFile); string contents = File.ReadAllText(tempFile); string removedMessage = SingletonProvider <TestSetup> .Instance.GetApp().Settings.ServerMessages.get_ItemByName( "ATTACHMENT_REMOVED").Text; removedMessage = removedMessage.Replace("%MACRO_FILE%", message.Attachments[0].Filename.Substring(0, message.Attachments[0]. Filename.Length - 4)); CustomAssert.IsTrue(contents.Contains(removedMessage)); File.Delete(tempFile); }
public void TestAddTextToEmptyBody() { Account account1 = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Send a message to the account. string messageText = @"Date: Thu, 03 Jul 2008 22:01:53 +0200\r\n" + "From: Test <*****@*****.**>\r\n" + "MIME-Version: 1.0\r\n" + "To: [email protected]\r\n" + "Subject: test\r\n" + "Content-Type: multipart/mixed;\r\n" + " boundary=\"------------050908050500020808050006\"\r\n" + "\r\n" + "This is a multi-part message in MIME format.\r\n" + "--------------050908050500020808050006\r\n" + "Content-Type: text/plain; charset=ISO-8859-1; format=flowed\r\n" + "Content-Transfer-Encoding: 7bit\r\n" + "\r\n" + "Test\r\n" + "\r\n" + "--------------050908050500020808050006\r\n" + "Content-Type: text/plain;\r\n" + " name=\"AUTOEXEC.BAT\"\r\n" + "Content-Transfer-Encoding: base64\r\n" + "Content-Disposition: inline;\r\n" + " filename=\"AUTOEXEC.BAT\"\r\n" + "\r\n" + "\r\n" + "--------------050908050500020808050006--\r\n"; SMTPClientSimulator.StaticSendRaw("*****@*****.**", "*****@*****.**", messageText); hMailServer.Message message = TestSetup.AssertRetrieveFirstMessage(account1.IMAPFolders.get_ItemByName("INBOX")); CustomAssert.AreEqual(1, message.Attachments.Count); CustomAssert.AreEqual("AUTOEXEC.BAT", message.Attachments[0].Filename); }