internal void Add(string actionID, string description, GlobalMessageRuleActionType type, byte[] actionData, bool addToCollection) { Guid.NewGuid().ToString(); SmartStream arg_BD_0 = this.m_pRule.VirtualServer.Server.TCP_Client.TcpStream; string[] array = new string[12]; array[0] = "AddGlobalMessageRuleAction "; array[1] = this.m_pRule.VirtualServer.VirtualServerID; array[2] = " "; array[3] = TextUtils.QuoteString(this.m_pRule.ID); array[4] = " "; array[5] = TextUtils.QuoteString(actionID); array[6] = " "; array[7] = TextUtils.QuoteString(description); array[8] = " "; string[] arg_A2_0 = array; int arg_A2_1 = 9; int num = (int)type; arg_A2_0[arg_A2_1] = num.ToString(); array[10] = " "; array[11] = Convert.ToBase64String(actionData); arg_BD_0.WriteLine(string.Concat(array)); string text = this.m_pRule.VirtualServer.Server.ReadLine(); if (!text.ToUpper().StartsWith("+OK")) { throw new Exception(text); } if (addToCollection) { this.m_pActions.Add(this.GetAction(actionID, description, type, actionData)); } }
public GlobalMessageRuleActionResult DoActions(DataView dvActions, VirtualServer server, Stream message, string sender, string[] to) { bool deleteMessage = false; string storeFolder = null; string errorText = null; foreach (DataRowView dataRowView in dvActions) { GlobalMessageRuleActionType globalMessageRuleAction_enum = (GlobalMessageRuleActionType)dataRowView["ActionType"]; byte[] data = (byte[])dataRowView["ActionData"]; message.Position = 0L; if (globalMessageRuleAction_enum == (GlobalMessageRuleActionType)1) { XmlTable xmlTable = new XmlTable("ActionData"); xmlTable.Parse(data); string value = xmlTable.GetValue("From"); string value2 = xmlTable.GetValue("Message"); MIME_h_Collection mIME_h_Collection = new MIME_h_Collection(new MIME_h_Provider()); mIME_h_Collection.Parse(new SmartStream(message, false)); if (!mIME_h_Collection.Contains("X-LS-MailServer-AutoResponse")) { Mail_Message mail_Message = Mail_Message.ParseFromByte(Encoding.UTF8.GetBytes(value2)); mail_Message.Header.Add(new MIME_h_Unstructured("X-LS-MailServer-AutoResponse", "")); mail_Message.Date = DateTime.Now; if (mail_Message.To == null || mail_Message.To.Count == 0) { if (mail_Message.To == null) { mail_Message.To = new Mail_t_AddressList { new Mail_t_Mailbox(null, sender) }; } else { mail_Message.To.Add(new Mail_t_Mailbox(null, sender)); } } if (mail_Message.Subject != null && mIME_h_Collection.Contains("Subject")) { mail_Message.Subject = mail_Message.Subject.Replace("#SUBJECT", mIME_h_Collection.GetFirst("Subject").ValueToString().Trim()); } if (!string.IsNullOrEmpty(sender)) { server.ProcessAndStoreMessage(value, new string[] { sender }, new MemoryStream(mail_Message.ToByte(new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.Q, Encoding.UTF8), Encoding.UTF8)), null); } } } else if (globalMessageRuleAction_enum == GlobalMessageRuleActionType.DeleteMessage) { XmlTable xmlTable2 = new XmlTable("ActionData"); xmlTable2.Parse(data); deleteMessage = true; } else if (globalMessageRuleAction_enum == GlobalMessageRuleActionType.ExecuteProgram) { XmlTable xmlTable3 = new XmlTable("ActionData"); xmlTable3.Parse(data); Process.Start(new ProcessStartInfo { FileName = xmlTable3.GetValue("Program"), Arguments = xmlTable3.GetValue("Arguments"), CreateNoWindow = true }); } else if (globalMessageRuleAction_enum == GlobalMessageRuleActionType.ForwardToEmail) { XmlTable xmlTable4 = new XmlTable("ActionData"); xmlTable4.Parse(data); MIME_h_Collection mIME_h_Collection2 = new MIME_h_Collection(new MIME_h_Provider()); mIME_h_Collection2.Parse(new SmartStream(message, false)); bool flag = false; if (mIME_h_Collection2.Contains("X-LS-MailServer-ForwardedTo")) { MIME_h[] array = mIME_h_Collection2["X-LS-MailServer-ForwardedTo"]; for (int i = 0; i < array.Length; i++) { MIME_h mIME_h = array[i]; if (mIME_h.ValueToString().Trim() == xmlTable4.GetValue("Email")) { flag = true; break; } } } message.Position = 0L; if (!flag) { MemoryStream memoryStream = new MemoryStream(); byte[] bytes = Encoding.UTF8.GetBytes("X-LS-MailServer-ForwardedTo: " + xmlTable4.GetValue("Email") + "\r\n"); memoryStream.Write(bytes, 0, bytes.Length); SCore.StreamCopy(message, memoryStream); server.ProcessAndStoreMessage(sender, new string[] { xmlTable4.GetValue("Email") }, memoryStream, null); } } else if (globalMessageRuleAction_enum == GlobalMessageRuleActionType.ForwardToHost) { XmlTable xmlTable5 = new XmlTable("ActionData"); xmlTable5.Parse(data); for (int j = 0; j < to.Length; j++) { string to2 = to[j]; message.Position = 0L; server.RelayServer.StoreRelayMessage(Guid.NewGuid().ToString(), null, message, HostEndPoint.Parse(xmlTable5.GetValue("Host") + ":" + xmlTable5.GetValue("Port")), sender, to2, null, SMTP_DSN_Notify.NotSpecified, SMTP_DSN_Ret.NotSpecified); } message.Position = 0L; } else { if (globalMessageRuleAction_enum == GlobalMessageRuleActionType.StoreToDiskFolder) { XmlTable xmlTable6 = new XmlTable("ActionData"); xmlTable6.Parse(data); string text = xmlTable6.GetValue("Folder"); if (!text.EndsWith("\\")) { text += "\\"; } if (!Directory.Exists(text)) { continue; } using (FileStream fileStream = File.Create(string.Concat(new string[] { text, DateTime.Now.ToString("ddMMyyyyHHmmss"), "_", Guid.NewGuid().ToString().Replace('-', '_').Substring(0, 8), ".eml" }))) { SCore.StreamCopy(message, fileStream); continue; } } if (globalMessageRuleAction_enum == GlobalMessageRuleActionType.StoreToIMAPFolder) { XmlTable xmlTable7 = new XmlTable("ActionData"); xmlTable7.Parse(data); storeFolder = xmlTable7.GetValue("Folder"); } else if (globalMessageRuleAction_enum == (GlobalMessageRuleActionType)8) { XmlTable xmlTable8 = new XmlTable("ActionData"); xmlTable8.Parse(data); Mail_Message mail_Message2 = Mail_Message.ParseFromStream(message); mail_Message2.Header.Add(new MIME_h_Unstructured(xmlTable8.GetValue("HeaderFieldName"), xmlTable8.GetValue("HeaderFieldValue"))); message.SetLength(0L); mail_Message2.ToStream(message, new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.Q, Encoding.UTF8), Encoding.UTF8); } else if (globalMessageRuleAction_enum == (GlobalMessageRuleActionType)9) { XmlTable xmlTable9 = new XmlTable("ActionData"); xmlTable9.Parse(data); Mail_Message mail_Message3 = Mail_Message.ParseFromStream(message); mail_Message3.Header.RemoveAll(xmlTable9.GetValue("HeaderFieldName")); message.SetLength(0L); mail_Message3.ToStream(message, new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.Q, Encoding.UTF8), Encoding.UTF8); } else if (globalMessageRuleAction_enum == (GlobalMessageRuleActionType)10) { XmlTable xmlTable10 = new XmlTable("ActionData"); xmlTable10.Parse(data); errorText = xmlTable10.GetValue("ErrorText"); } else if (globalMessageRuleAction_enum == (GlobalMessageRuleActionType)11) { XmlTable xmlTable11 = new XmlTable("ActionData"); xmlTable11.Parse(data); new _MessageRuleAction_FTP_AsyncSend(xmlTable11.GetValue("Server"), Convert.ToInt32(xmlTable11.GetValue("Port")), xmlTable11.GetValue("User"), xmlTable11.GetValue("Password"), xmlTable11.GetValue("Folder"), message, DateTime.Now.ToString("ddMMyyyyHHmmss") + "_" + Guid.NewGuid().ToString().Replace('-', '_').Substring(0, 8) + ".eml"); } else if (globalMessageRuleAction_enum == (GlobalMessageRuleActionType)12) { XmlTable xmlTable12 = new XmlTable("ActionData"); xmlTable12.Parse(data); Mail_Message mail_Message4 = Mail_Message.ParseFromStream(message); if (!mail_Message4.Header.Contains("Newsgroups:")) { mail_Message4.Header.Add(new MIME_h_Unstructured("Newsgroups:", xmlTable12.GetValue("Newsgroup"))); } new _MessageRuleAction_NNTP_Async(xmlTable12.GetValue("Server"), Convert.ToInt32(xmlTable12.GetValue("Port")), xmlTable12.GetValue("Newsgroup"), new MemoryStream(mail_Message4.ToByte(new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.Q, Encoding.UTF8), Encoding.UTF8))); } else if (globalMessageRuleAction_enum == (GlobalMessageRuleActionType)13) { XmlTable xmlTable13 = new XmlTable("ActionData"); xmlTable13.Parse(data); new _MessageRuleAction_HTTP_Async(xmlTable13.GetValue("URL"), message); } } } return(new GlobalMessageRuleActionResult(deleteMessage, storeFolder, errorText)); }
private GlobalMessageRuleActionBase GetAction(string actionID, string description, GlobalMessageRuleActionType actionType, byte[] actionData) { if (actionType == GlobalMessageRuleActionType.AddHeaderField) { return(new AddHeaderField(this.m_pRule, this, actionID, description, actionData)); } if (actionType == GlobalMessageRuleActionType.AutoResponse) { return(new AutoResponse(this.m_pRule, this, actionID, description, actionData)); } if (actionType == GlobalMessageRuleActionType.DeleteMessage) { return(new DeleteMessage(this.m_pRule, this, actionID, description)); } if (actionType == GlobalMessageRuleActionType.ExecuteProgram) { return(new ExecuteProgram(this.m_pRule, this, actionID, description, actionData)); } if (actionType == GlobalMessageRuleActionType.ForwardToEmail) { return(new ForwardToEmail(this.m_pRule, this, actionID, description, actionData)); } if (actionType == GlobalMessageRuleActionType.ForwardToHost) { return(new ForwardToHost(this.m_pRule, this, actionID, description, actionData)); } if (actionType == GlobalMessageRuleActionType.MoveToIMAPFolder) { return(new MoveToImapFolder(this.m_pRule, this, actionID, description, actionData)); } if (actionType == GlobalMessageRuleActionType.PostToHTTP) { return(new GlobalMessageRuleAction_PostToHttp(this.m_pRule, this, actionID, description, actionData)); } if (actionType == GlobalMessageRuleActionType.PostToNNTPNewsGroup) { return(new PostToNntpNewsgroup(this.m_pRule, this, actionID, description, actionData)); } if (actionType == GlobalMessageRuleActionType.RemoveHeaderField) { return(new RemoveHeaderField(this.m_pRule, this, actionID, description, actionData)); } if (actionType == GlobalMessageRuleActionType.SendErrorToClient) { return(new SendError(this.m_pRule, this, actionID, description, actionData)); } if (actionType == GlobalMessageRuleActionType.StoreToDiskFolder) { return(new StoreToDiskFolder(this.m_pRule, this, actionID, description, actionData)); } if (actionType == GlobalMessageRuleActionType.StoreToFTPFolder) { return(new StoreToFtp(this.m_pRule, this, actionID, description, actionData)); } throw new Exception("Invalid action type !"); }