/// <summary> /// Adds specified action to connected server. /// </summary> /// <param name="actionID">Action ID.</param> /// <param name="description">Action description.</param> /// <param name="type">Action type.</param> /// <param name="actionData">Action data.</param> /// <param name="addToCollection">Specifies if added action must be created locally and added to local collection.</param> internal void Add(string actionID, string description, UserMessageRuleAction_enum type, byte[] actionData, bool addToCollection) { /* AddUserMessageRuleAction <virtualServerID> "<userID>" "<messageRuleID>" "<actionID>" "<description>" <actionType> "<actionData>:base64" * Responses: +OK <sizeOfData> * <data> * * -ERR <errorText> */ string id = Guid.NewGuid().ToString(); // Call TCP AddUserMessageRuleAction m_pRule.Owner.VirtualServer.Server.TcpClient.TcpStream.WriteLine("AddUserMessageRuleAction " + m_pRule.Owner.VirtualServer.VirtualServerID + " " + TextUtils.QuoteString(m_pRule.Owner.Owner.UserID) + " " + TextUtils.QuoteString(m_pRule.ID) + " " + TextUtils.QuoteString(actionID) + " " + TextUtils.QuoteString(description) + " " + ((int)type).ToString() + " " + Convert.ToBase64String(actionData) ); string response = m_pRule.Owner.VirtualServer.Server.ReadLine(); if (!response.ToUpper().StartsWith("+OK")) { throw new Exception(response); } if (addToCollection) { m_pActions.Add(GetAction(actionID, description, type, actionData)); } }
/// <summary> /// Default constructor. /// </summary> /// <param name="actionType">Specifies action type.</param> /// <param name="rule">Onwer rule that owns this action.</param> /// <param name="owner">Owner UserMessageRuleActionCollection that owns this action.</param> /// <param name="id">Action ID.</param> /// <param name="description">Action description.</param> internal UserMessageRuleActionBase(UserMessageRuleAction_enum actionType,UserMessageRule rule,UserMessageRuleActionCollection owner,string id,string description) { m_ActionType = actionType; m_pRule = rule; m_pOwner = owner; m_ID = id; m_Description = description; }
/// <summary> /// Default constructor. /// </summary> /// <param name="actionType">Specifies action type.</param> /// <param name="rule">Onwer rule that owns this action.</param> /// <param name="owner">Owner UserMessageRuleActionCollection that owns this action.</param> /// <param name="id">Action ID.</param> /// <param name="description">Action description.</param> internal UserMessageRuleActionBase(UserMessageRuleAction_enum actionType, UserMessageRule rule, UserMessageRuleActionCollection owner, string id, string description) { m_ActionType = actionType; m_pRule = rule; m_pOwner = owner; m_ID = id; m_Description = description; }
/// <summary> /// Gets user message rule action. /// </summary> /// <param name="actionID">Action ID.</param> /// <param name="description">Action description.</param> /// <param name="actionType">Action type.</param> /// <param name="actionData">Action data.</param> /// <returns></returns> private UserMessageRuleActionBase GetAction(string actionID,string description,UserMessageRuleAction_enum actionType,byte[] actionData) { if(actionType == UserMessageRuleAction_enum.AddHeaderField){ return new UserMessageRuleAction_AddHeaderField(m_pRule,this,actionID,description,actionData); } else if(actionType == UserMessageRuleAction_enum.AutoResponse){ return new UserMessageRuleAction_AutoResponse(m_pRule,this,actionID,description,actionData); } else if(actionType == UserMessageRuleAction_enum.DeleteMessage){ return new UserMessageRuleAction_DeleteMessage(m_pRule,this,actionID,description); } else if(actionType == UserMessageRuleAction_enum.ExecuteProgram){ return new UserMessageRuleAction_ExecuteProgram(m_pRule,this,actionID,description,actionData); } else if(actionType == UserMessageRuleAction_enum.ForwardToEmail){ return new UserMessageRuleAction_ForwardToEmail(m_pRule,this,actionID,description,actionData); } else if(actionType == UserMessageRuleAction_enum.ForwardToHost){ return new UserMessageRuleAction_ForwardToHost(m_pRule,this,actionID,description,actionData); } else if(actionType == UserMessageRuleAction_enum.MoveToIMAPFolder){ return new UserMessageRuleAction_MoveToImapFolder(m_pRule,this,actionID,description,actionData); } else if(actionType == UserMessageRuleAction_enum.PostToHTTP){ return new UserMessageRuleAction_PostToHttp(m_pRule,this,actionID,description,actionData); } else if(actionType == UserMessageRuleAction_enum.PostToNNTPNewsGroup){ return new UserMessageRuleAction_PostToNntpNewsgroup(m_pRule,this,actionID,description,actionData); } else if(actionType == UserMessageRuleAction_enum.RemoveHeaderField){ return new UserMessageRuleAction_RemoveHeaderField(m_pRule,this,actionID,description,actionData); } else if(actionType == UserMessageRuleAction_enum.StoreToDiskFolder){ return new UserMessageRuleAction_StoreToDiskFolder(m_pRule,this,actionID,description,actionData); } else if(actionType == UserMessageRuleAction_enum.StoreToFTPFolder){ return new UserMessageRuleAction_StoreToFtp(m_pRule,this,actionID,description,actionData); } throw new Exception("Invalid action type !"); }
/// <summary> /// Adds specified action to connected server. /// </summary> /// <param name="actionID">Action ID.</param> /// <param name="description">Action description.</param> /// <param name="type">Action type.</param> /// <param name="actionData">Action data.</param> /// <param name="addToCollection">Specifies if added action must be created locally and added to local collection.</param> internal void Add(string actionID,string description,UserMessageRuleAction_enum type,byte[] actionData,bool addToCollection) { /* AddUserMessageRuleAction <virtualServerID> "<userID>" "<messageRuleID>" "<actionID>" "<description>" <actionType> "<actionData>:base64" Responses: +OK <sizeOfData> <data> -ERR <errorText> */ string id = Guid.NewGuid().ToString(); // Call TCP AddUserMessageRuleAction m_pRule.Owner.VirtualServer.Server.Socket.WriteLine("AddUserMessageRuleAction " + m_pRule.Owner.VirtualServer.VirtualServerID + " " + TextUtils.QuoteString(m_pRule.Owner.Owner.UserID) + " " + TextUtils.QuoteString(m_pRule.ID) + " " + TextUtils.QuoteString(actionID) + " " + TextUtils.QuoteString(description) + " " + ((int)type).ToString() + " " + Convert.ToBase64String(actionData) ); string response = m_pRule.Owner.VirtualServer.Server.Socket.ReadLine(); if(!response.ToUpper().StartsWith("+OK")){ throw new Exception(response); } if(addToCollection){ m_pActions.Add(GetAction(actionID,description,type,actionData)); } }
/// <summary> /// Gets user message rule action. /// </summary> /// <param name="actionID">Action ID.</param> /// <param name="description">Action description.</param> /// <param name="actionType">Action type.</param> /// <param name="actionData">Action data.</param> /// <returns></returns> private UserMessageRuleActionBase GetAction(string actionID, string description, UserMessageRuleAction_enum actionType, byte[] actionData) { if (actionType == UserMessageRuleAction_enum.AddHeaderField) { return(new UserMessageRuleAction_AddHeaderField(m_pRule, this, actionID, description, actionData)); } else if (actionType == UserMessageRuleAction_enum.AutoResponse) { return(new UserMessageRuleAction_AutoResponse(m_pRule, this, actionID, description, actionData)); } else if (actionType == UserMessageRuleAction_enum.DeleteMessage) { return(new UserMessageRuleAction_DeleteMessage(m_pRule, this, actionID, description)); } else if (actionType == UserMessageRuleAction_enum.ExecuteProgram) { return(new UserMessageRuleAction_ExecuteProgram(m_pRule, this, actionID, description, actionData)); } else if (actionType == UserMessageRuleAction_enum.ForwardToEmail) { return(new UserMessageRuleAction_ForwardToEmail(m_pRule, this, actionID, description, actionData)); } else if (actionType == UserMessageRuleAction_enum.ForwardToHost) { return(new UserMessageRuleAction_ForwardToHost(m_pRule, this, actionID, description, actionData)); } else if (actionType == UserMessageRuleAction_enum.MoveToIMAPFolder) { return(new UserMessageRuleAction_MoveToImapFolder(m_pRule, this, actionID, description, actionData)); } else if (actionType == UserMessageRuleAction_enum.PostToHTTP) { return(new UserMessageRuleAction_PostToHttp(m_pRule, this, actionID, description, actionData)); } else if (actionType == UserMessageRuleAction_enum.PostToNNTPNewsGroup) { return(new UserMessageRuleAction_PostToNntpNewsgroup(m_pRule, this, actionID, description, actionData)); } else if (actionType == UserMessageRuleAction_enum.RemoveHeaderField) { return(new UserMessageRuleAction_RemoveHeaderField(m_pRule, this, actionID, description, actionData)); } else if (actionType == UserMessageRuleAction_enum.StoreToDiskFolder) { return(new UserMessageRuleAction_StoreToDiskFolder(m_pRule, this, actionID, description, actionData)); } else if (actionType == UserMessageRuleAction_enum.StoreToFTPFolder) { return(new UserMessageRuleAction_StoreToFtp(m_pRule, this, actionID, description, actionData)); } throw new Exception("Invalid action type !"); }