public void TestUpdateSubjectOnMessageWithNoMessageWideCharacterSet() { hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); string script = "Sub OnAcceptMessage(oClient, oMessage) " + Environment.NewLine + " oMessage.Subject = \"[ov]\" + oMessage.Subject " + Environment.NewLine + " oMessage.Save() " + Environment.NewLine + "End Sub" + Environment.NewLine + Environment.NewLine; hMailServer.Scripting scripting = _settings.Scripting; System.IO.File.WriteAllText(scripting.CurrentScriptFile, script); scripting.Enabled = true; scripting.Reload(); Assert.IsEmpty(scripting.CheckSyntax()); string body = @"From: <*****@*****.**>" + Environment.NewLine + "Subject: =?windows-1251?B?yuDr7Pvq7uLzIMji4O3zIC0g7/Do7OXwICLy5fXt6Pfl8eru4+4g8OX4?=" + Environment.NewLine + " =?windows-1251?B?5e3o/yIgW0Z3ZDog0tAg4uXw8ejoIDEuMl0=?=" + Environment.NewLine + Environment.NewLine + "Hej!" + Environment.NewLine; SMTPClientSimulator.StaticSendRaw("*****@*****.**", "*****@*****.**", body); POP3Simulator.AssertMessageCount(account.Address, "test", 1); Utilities.AssertMessageExistsInFolder(account.IMAPFolders[0], 1); string subject = account.IMAPFolders[0].Messages[0].Subject; }
public void TestOnBackupFailedJScript() { hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); hMailServer.Scripting scripting = _settings.Scripting; scripting.Language = "JScript"; // First set up a script string script = @"function OnBackupFailed(reason) { EventLog.Write('Failed: ' + reason) }"; string file = scripting.CurrentScriptFile; Utilities.WriteFile(file, script); scripting.Enabled = true; scripting.Reload(); BackupRestore back = new BackupRestore(); back.InitializeBackupSettings(); back.SetBackupDir(@"C:\some-non-existant-directory"); Assert.IsFalse(back.Execute()); Utilities.AssertReportedError(); string eventLogText = Utilities.ReadExistingTextFile(Utilities.GetEventLogFileName()); Assert.IsTrue(eventLogText.Contains("The specified backup directory is not accessible")); }
public void TestOnBackupCompletedJScript() { hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); hMailServer.Scripting scripting = _settings.Scripting; scripting.Language = "JScript"; // First set up a script string script = @"function OnBackupCompleted() { EventLog.Write('Backup process completed') }"; string file = scripting.CurrentScriptFile; Utilities.WriteFile(file, script); scripting.Enabled = true; scripting.Reload(); BackupRestore back = new BackupRestore(); back.InitializeBackupSettings(); back.TestWithMessages(); string eventLogText = Utilities.ReadExistingTextFile(Utilities.GetEventLogFileName()); Assert.IsTrue(eventLogText.Contains("Backup process completed")); }
public void TestOnDeliveryFailedJScript() { hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); hMailServer.Scripting scripting = _settings.Scripting; scripting.Language = "JScript"; // First set up a script string script = "function OnDeliveryFailed(oMessage, sRecipient, sErrorMessage) {" + Environment.NewLine + " EventLog.Write('File: ' + oMessage.FileName); " + Environment.NewLine + " EventLog.Write('Recipient: ' + sRecipient); " + Environment.NewLine + " EventLog.Write('Error: ' + sErrorMessage); " + Environment.NewLine + "}"; string file = scripting.CurrentScriptFile; Utilities.WriteFile(file, script); scripting.Enabled = true; scripting.Reload(); // Add an account and send a message to it. hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator.StaticSend(oAccount1.Address, "*****@*****.**", "Test", "SampleBody"); // Make sure that the message is deliverd and bounced. Utilities.AssertRecipientsInDeliveryQueue(0); string eventLogText = Utilities.ReadExistingTextFile(Utilities.GetEventLogFileName()); Assert.IsTrue(eventLogText.Contains("File: "), eventLogText); Assert.IsTrue(eventLogText.Contains("Recipient: [email protected]"), eventLogText); Assert.IsTrue(eventLogText.Contains("No mail servers appear to exists"), eventLogText); }
public void TestOnDeliverMessageJScript() { hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); hMailServer.Scripting scripting = _settings.Scripting; scripting.Language = "JScript"; // First set up a script string script = @"function OnDeliverMessage(oMessage) { oMessage.HeaderValue('X-SpamResult') = 'TEST2'; oMessage.Save(); }"; string file = scripting.CurrentScriptFile; Utilities.WriteFile(file, script); scripting.Enabled = true; scripting.Reload(); // Add an account and send a message to it. hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator.StaticSend(oAccount1.Address, oAccount1.Address, "Test", "SampleBody"); // Check that the message exists string message = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsNotEmpty(message); Assert.Less(0, message.IndexOf("X-SpamResult: TEST2")); }
public void TestOnDeliveryStartVBScript() { hMailServer.Application app = SingletonProvider <Utilities> .Instance.GetApp(); hMailServer.Scripting scripting = app.Settings.Scripting; string script = "Sub OnDeliveryStart(oMessage) " + Environment.NewLine + " EventLog.Write(\"Delivering message: \" & oMessage.FileName) " + Environment.NewLine + "End Sub" + Environment.NewLine + Environment.NewLine; File.WriteAllText(scripting.CurrentScriptFile, script); scripting.Enabled = true; scripting.Reload(); hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); // Wait for the message to be delivered. POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); string eventLogText = Utilities.ReadExistingTextFile(app.Settings.Logging.CurrentEventLog); Assert.IsTrue(eventLogText.Contains("Delivering message")); }
public void TestEventLog() { hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); // First set up a script string script = @"Sub OnAcceptMessage(oClient, oMessage) EventLog.Write(""HOWDY"") End Sub"; hMailServer.Scripting scripting = _settings.Scripting; string file = scripting.CurrentScriptFile; Utilities.WriteFile(file, script); scripting.Enabled = true; scripting.Reload(); // Drop the current event log string eventLogFile = _settings.Logging.CurrentEventLog; SingletonProvider <Utilities> .Instance.DeleteEventLog(); // Add an account and send a message to it. hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SendMessageToTest(); POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Utilities.AssertFileExists(eventLogFile, false); // Check that it starts with Unicode markers. for (int i = 0; i <= 400; i++) { try { FileStream fs = new FileStream(eventLogFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); BinaryReader br = new BinaryReader(fs); int i1 = br.ReadByte(); int i2 = br.ReadByte(); br.Close(); fs.Close(); Assert.AreEqual(255, i1); Assert.AreEqual(254, i2); break; } catch (Exception e) { if (i == 40) { throw e; } } Thread.Sleep(25); } }
public void TestOnAcceptMessageVBScript() { hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); string eventLogFile = _settings.Logging.CurrentEventLog; if (File.Exists(eventLogFile)) { File.Delete(eventLogFile); } // First set up a script string script = @"Sub OnAcceptMessage(oClient, oMessage) oMessage.HeaderValue(""X-SpamResult"") = ""TEST"" oMessage.Save() EventLog.Write(""Port: "" & oClient.Port) EventLog.Write(""Address: "" & oClient.IPAddress) EventLog.Write(""Username: "" & oClient.Username) End Sub"; hMailServer.Scripting scripting = _settings.Scripting; string file = scripting.CurrentScriptFile; Utilities.WriteFile(file, script); scripting.Enabled = true; scripting.Reload(); // Add an account and send a message to it. hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator.StaticSend(oAccount1.Address, oAccount1.Address, "Test", "SampleBody"); // Check that the message exists string message = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsNotEmpty(message); Assert.Less(0, message.IndexOf("X-SpamResult: TEST")); // Check that the message exists message = Utilities.ReadExistingTextFile(eventLogFile); Assert.IsNotEmpty(message); Assert.IsTrue(message.Contains("Port: 25")); Assert.IsTrue(message.Contains("Address: 127")); Assert.IsTrue(message.Contains("Username: \"")); // Should be empty, Username isn't available at this time. }
public ucScripts() { InitializeComponent(); DirtyChecker.SubscribeToChange(this, OnContentChanged); new TabOrderManager(this).SetTabOrder(TabOrderManager.TabScheme.AcrossFirst); comboLanguage.AddItem("VBScript", "VBScript"); comboLanguage.AddItem("JScript", "JScript"); hMailServer.Application app = APICreator.Application; hMailServer.Settings settings = app.Settings; _scriptingSettings = app.Settings.Scripting; Marshal.ReleaseComObject(settings); }
public void TestAddTextDuringSendingAttachment() { hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Send a message to the account. hMailServer.Message oMessage = new hMailServer.Message(); Assert.AreEqual(0, oMessage.State); hMailServer.Scripting scripting = SingletonProvider <Utilities> .Instance.GetApp().Settings.Scripting; string signature = "MySignature"; string script = "Sub OnAcceptMessage(oClient, oMessage) " + Environment.NewLine + " oMessage.Body = oMessage.Body & \"" + signature + "\" " + Environment.NewLine + " oMessage.Save() " + Environment.NewLine + "End Sub" + Environment.NewLine + Environment.NewLine; System.IO.File.WriteAllText(scripting.CurrentScriptFile, script); scripting.Enabled = true; scripting.Reload(); Assembly a = Assembly.GetExecutingAssembly(); MailMessage mail = new MailMessage(); mail.From = new System.Net.Mail.MailAddress("*****@*****.**"); mail.To.Add("*****@*****.**"); mail.Subject = "Automatiskt servertest"; mail.Body = "Detta är ett automatiskt test av epostservern."; mail.BodyEncoding = System.Text.Encoding.GetEncoding(1252); mail.SubjectEncoding = System.Text.Encoding.GetEncoding(1252); mail.Attachments.Add(new Attachment(a.Location)); SmtpClient oClient = new SmtpClient("localhost", 25); oClient.Send(mail); // Check that the message exists string message = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsNotEmpty(message, message); Assert.IsTrue(message.Contains(signature), message); }
public void TestInternalDateCombinedWithOnDeliverMessage() { hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); hMailServer.Scripting scripting = _settings.Scripting; scripting.Language = "JScript"; // First set up a script string script = @"function OnDeliverMessage(oMessage) { EventLog.Write(oMessage.InternalDate); }"; string file = scripting.CurrentScriptFile; Utilities.WriteFile(file, script); scripting.Enabled = true; scripting.Reload(); // Add an account and send a message to it. hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator.StaticSend(oAccount1.Address, oAccount1.Address, "Test", "SampleBody"); POP3Simulator.AssertMessageCount(oAccount1.Address, "test", 1); string text = Utilities.ReadExistingTextFile(_settings.Logging.CurrentEventLog); string[] columns = text.Split('\t'); if (columns.Length != 3) { Assert.Fail("Wrong number of cols: " + text); } string lastColumn = columns[columns.Length - 1]; Assert.IsFalse(lastColumn.Contains("00:00:00"), lastColumn); Assert.IsTrue(lastColumn.Contains(DateTime.Now.Year.ToString()), lastColumn); Assert.IsTrue(lastColumn.Contains(DateTime.Now.Month.ToString()), lastColumn); Assert.IsTrue(lastColumn.Contains(DateTime.Now.Day.ToString()), lastColumn); }
public void TestOnClientConnectJScript() { hMailServer.Application app = SingletonProvider <Utilities> .Instance.GetApp(); hMailServer.Scripting scripting = app.Settings.Scripting; scripting.Language = "JScript"; string script = "function OnClientConnect(oClient) " + Environment.NewLine + "{" + Environment.NewLine + " EventLog.Write('Port: ' + oClient.Port); " + Environment.NewLine + " EventLog.Write('Address: ' + oClient.IPAddress); " + Environment.NewLine + " EventLog.Write('Username: '******'t available at this time. }
public void TestAddTextDuringSending() { hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Send a message to the account. hMailServer.Message oMessage = new hMailServer.Message(); Assert.AreEqual(0, oMessage.State); hMailServer.Scripting scripting = SingletonProvider <Utilities> .Instance.GetApp().Settings.Scripting; string signature = "MySignature"; string script = "Sub OnAcceptMessage(oClient, oMessage) " + Environment.NewLine + " Call EventLog.Write(\"Subject:\" +oMessage.Subject)" + Environment.NewLine + " Call EventLog.Write(\"Date:\" +oMessage.Date)" + Environment.NewLine + " Call EventLog.Write(\"Body:\" +oMessage.Body)" + Environment.NewLine + " oMessage.Body = oMessage.Body & \"" + signature + "\" " + Environment.NewLine + " oMessage.Save() " + Environment.NewLine + "End Sub" + Environment.NewLine + Environment.NewLine; System.IO.File.WriteAllText(scripting.CurrentScriptFile, script); scripting.Enabled = true; scripting.Reload(); Assert.IsEmpty(scripting.CheckSyntax()); // Send the message. List <string> recipients = new List <string>(); recipients.Add("*****@*****.**"); SMTPClientSimulator.StaticSend("*****@*****.**", recipients, "Hej", "Välkommen till verkligheten"); // Check that the message exists string message = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsNotEmpty(message); Assert.IsTrue(message.Contains(signature)); Assert.Less(0, message.IndexOf("Hej")); }
public void TestOnErrorVBScript() { hMailServer.Application app = SingletonProvider <Utilities> .Instance.GetApp(); hMailServer.Scripting scripting = app.Settings.Scripting; string script = "Sub OnError(iSeverity, iError, sSource, sDescription) " + Environment.NewLine + " EventLog.Write(\"Severity: \" & iSeverity) " + Environment.NewLine + " EventLog.Write(\"Error: \" & iError) " + Environment.NewLine + " EventLog.Write(\"Source: \" & sSource) " + Environment.NewLine + " EventLog.Write(\"Description: \" & sDescription) " + Environment.NewLine + "End Sub" + Environment.NewLine + Environment.NewLine; File.WriteAllText(scripting.CurrentScriptFile, script); scripting.Enabled = true; scripting.Reload(); hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.IMAPFolder inbox = account.IMAPFolders.get_ItemByName("Inbox");; string deletedMessageText = app.Settings.ServerMessages.get_ItemByName("MESSAGE_FILE_MISSING").Text; SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); Utilities.AssertMessageExistsInFolder(inbox, 1); hMailServer.Message message = inbox.Messages[0]; System.IO.File.Delete(message.Filename); string text = POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(text.Contains(deletedMessageText.Replace("%MACRO_FILE%", message.Filename))); Utilities.AssertReportedError(); string eventLogText = Utilities.ReadExistingTextFile(app.Settings.Logging.CurrentEventLog); Assert.IsTrue(eventLogText.Contains("Description: Message retrieval failed")); }
public void TestOnExternalAccountDownload() { Utilities.DeleteCurrentDefaultLog(); List <string> messages = new List <string>(); messages.Add("From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Message 1\r\n" + "\r\n" + "Message 1!"); messages.Add("From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Message 2\r\n" + "\r\n" + "Message 2!"); messages.Add("From: [email protected]\r\n" + "To: [email protected]\r\n" + "Subject: Message 3\r\n" + "\r\n" + "Message 3!"); // First set up a script hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); // The second message should be deleted after 5 days. string script = "Sub OnExternalAccountDownload(oFetchAccount, oMessage, sRemoteUID)" + Environment.NewLine + " EventLog.Write(\"UID: \" & sRemoteUID) " + Environment.NewLine + " EventLog.Write(\"FetchAccount: \" & oFetchAccount.Name) " + Environment.NewLine + " If Not oMessage Is Nothing Then " + Environment.NewLine + " EventLog.Write(\"From: \" & oMessage.FromAddress) " + Environment.NewLine + " EventLog.Write(\"Filename: \" & oMessage.FileName) " + Environment.NewLine + " Else " + Environment.NewLine + " EventLog.Write(\"Message details missing\") " + Environment.NewLine + " End If" + Environment.NewLine + " if sRemoteUID = \"UniqueID-" + messages[1].GetHashCode() + "\" Then " + Environment.NewLine + " Result.Value = 2 " + Environment.NewLine + " Result.Parameter = 5 " + Environment.NewLine + " End If " + Environment.NewLine + " End Sub"; hMailServer.Scripting scripting = _settings.Scripting; string file = scripting.CurrentScriptFile; Utilities.WriteFile(file, script); scripting.Enabled = true; scripting.Reload(); int port = 43132; POP3Server pop3Server = new POP3Server(1, port, messages); pop3Server.StartListen(); hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); hMailServer.FetchAccount fa = account.FetchAccounts.Add(); fa.Enabled = true; fa.MinutesBetweenFetch = 10; fa.Name = "TestFA"; fa.Username = "******"; fa.Password = "******"; fa.UseSSL = false; fa.ServerAddress = "localhost"; fa.Port = port; fa.ProcessMIMERecipients = false; fa.DaysToKeepMessages = -1; fa.Save(); fa.DownloadNow(); pop3Server.WaitForCompletion(); string eventLogFile = _settings.Logging.CurrentEventLog; string logContents = Utilities.ReadExistingTextFile(eventLogFile); Assert.IsTrue(logContents.Contains("FetchAccount: " + fa.Name)); Assert.IsTrue(logContents.Contains("From: [email protected]")); Assert.IsTrue(logContents.Contains("From: [email protected]")); Assert.IsTrue(logContents.Contains("From: [email protected]")); string appLogContent = Utilities.ReadCurrentDefaultLog(); Assert.IsTrue(pop3Server.DeletedMessages.Contains(1)); Assert.IsFalse(pop3Server.DeletedMessages.Contains(2)); Assert.IsTrue(pop3Server.DeletedMessages.Contains(3)); Assert.IsTrue(pop3Server.RetrievedMessages.Contains(1)); Assert.IsTrue(pop3Server.RetrievedMessages.Contains(2)); Assert.IsTrue(pop3Server.RetrievedMessages.Contains(3)); POP3Simulator.AssertMessageCount(account.Address, "test", 3); pop3Server.StartListen(); // Download again... fa.DownloadNow(); pop3Server.WaitForCompletion(); // Make sure that no messages are deleted. Assert.AreEqual(0, pop3Server.DeletedMessages.Count); Assert.AreEqual(0, pop3Server.RetrievedMessages.Count); POP3Simulator.AssertMessageCount(account.Address, "test", 3); }