示例#1
0
        /// <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, GlobalMessageRuleAction_enum type, byte[] actionData, bool addToCollection)
        {
            /* AddGlobalMessageRuleAction <virtualServerID> "<messageRuleID>" "<actionID>" "<description>" <actionType> "<actionData>:base64"
             *    Responses:
             +OK <sizeOfData>
             *      <data>
             *
             *      -ERR <errorText>
             */

            string id = Guid.NewGuid().ToString();

            // Call TCP AddGlobalMessageRuleAction
            m_pRule.VirtualServer.Server.TcpClient.TcpStream.WriteLine("AddGlobalMessageRuleAction " +
                                                                       m_pRule.VirtualServer.VirtualServerID + " " +
                                                                       TextUtils.QuoteString(m_pRule.ID) + " " +
                                                                       TextUtils.QuoteString(actionID) + " " +
                                                                       TextUtils.QuoteString(description) + " " +
                                                                       ((int)type).ToString() + " " +
                                                                       Convert.ToBase64String(actionData)
                                                                       );

            string response = m_pRule.VirtualServer.Server.ReadLine();

            if (!response.ToUpper().StartsWith("+OK"))
            {
                throw new Exception(response);
            }

            if (addToCollection)
            {
                m_pActions.Add(GetAction(actionID, description, type, actionData));
            }
        }
        /// <summary>
        /// Executes specified actions.
        /// </summary>
        /// <param name="dvActions">Dataview what contains actions to be executed.</param>
        /// <param name="server">Reference to owner virtual server.</param>
        /// <param name="message">Recieved message.</param>
        /// <param name="sender">MAIL FROM: command value.</param>
        /// <param name="to">RCPT TO: commands values.</param>
        public GlobalMessageRuleActionResult DoActions(DataView dvActions, VirtualServer server, Stream message, string sender, string[] to)
        {
            // TODO: get rid of MemoryStream, move to Stream

            //    bool   messageChanged = false;
            bool   deleteMessage = false;
            string storeFolder   = null;
            string errorText     = null;

            // Loop actions
            foreach (DataRowView drV in dvActions)
            {
                GlobalMessageRuleAction_enum action = (GlobalMessageRuleAction_enum)drV["ActionType"];
                byte[] actionData = (byte[])drV["ActionData"];

                // Reset stream position
                message.Position = 0;

                #region AutoResponse

                /* Description: Sends specified autoresponse message to sender.
                 *  Action data structure:
                 *      <ActionData>
                 *          <From></From>
                 *          <Message></Message>
                 *      </ActionData>
                 */

                if (action == GlobalMessageRuleAction_enum.AutoResponse)
                {
                    XmlTable table = new XmlTable("ActionData");
                    table.Parse(actionData);

                    string smtp_from   = table.GetValue("From");
                    string responseMsg = table.GetValue("Message");

                    // See if we have header field X-LS-MailServer-AutoResponse, never answer to auto response.
                    MIME_h_Collection header = new MIME_h_Collection(new MIME_h_Provider());
                    header.Parse(new SmartStream(message, false));
                    if (header.Contains("X-LS-MailServer-AutoResponse"))
                    {
                        // Just skip
                    }
                    else
                    {
                        Mail_Message autoresponseMessage = Mail_Message.ParseFromByte(System.Text.Encoding.Default.GetBytes(responseMsg));

                        // Add header field 'X-LS-MailServer-AutoResponse:'
                        autoresponseMessage.Header.Add(new MIME_h_Unstructured("X-LS-MailServer-AutoResponse", ""));
                        // Update message date
                        autoresponseMessage.Date = DateTime.Now;

                        // Set To: if not explicity set
                        if (autoresponseMessage.To == null || autoresponseMessage.To.Count == 0)
                        {
                            if (autoresponseMessage.To == null)
                            {
                                Mail_t_AddressList t = new Mail_t_AddressList();
                                t.Add(new Mail_t_Mailbox(null, sender));
                                autoresponseMessage.To = t;
                            }
                            else
                            {
                                autoresponseMessage.To.Add(new Mail_t_Mailbox(null, sender));
                            }
                        }
                        // Update Subject: variables, if any
                        if (autoresponseMessage.Subject != null)
                        {
                            if (header.Contains("Subject"))
                            {
                                autoresponseMessage.Subject = autoresponseMessage.Subject.Replace("#SUBJECT", header.GetFirst("Subject").ValueToString().Trim());
                            }
                        }

                        // Sender missing, we can't send auto response.
                        if (string.IsNullOrEmpty(sender))
                        {
                            continue;
                        }

                        server.ProcessAndStoreMessage(smtp_from, new string[] { sender }, new MemoryStream(autoresponseMessage.ToByte(new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.Q, Encoding.UTF8), Encoding.UTF8)), null);
                    }
                }

                #endregion

                #region Delete Message

                /* Description: Deletes message.
                 *  Action data structure:
                 *      <ActionData>
                 *      </ActionData>
                 */

                else if (action == GlobalMessageRuleAction_enum.DeleteMessage)
                {
                    XmlTable table = new XmlTable("ActionData");
                    table.Parse(actionData);

                    deleteMessage = true;
                }

                #endregion

                #region ExecuteProgram

                /* Description: Executes specified program.
                 *  Action data structure:
                 *      <ActionData>
                 *          <Program></Program>
                 *          <Arguments></Arguments>
                 *      </ActionData>
                 */

                else if (action == GlobalMessageRuleAction_enum.ExecuteProgram)
                {
                    XmlTable table = new XmlTable("ActionData");
                    table.Parse(actionData);

                    System.Diagnostics.ProcessStartInfo pInfo = new System.Diagnostics.ProcessStartInfo();
                    pInfo.FileName       = table.GetValue("Program");
                    pInfo.Arguments      = table.GetValue("Arguments");
                    pInfo.CreateNoWindow = true;
                    System.Diagnostics.Process.Start(pInfo);
                }

                #endregion

                #region ForwardToEmail

                /* Description: Forwards email to specified email.
                 *  Action data structure:
                 *      <ActionData>
                 *          <Email></Email>
                 *      </ActionData>
                 */

                else if (action == GlobalMessageRuleAction_enum.ForwardToEmail)
                {
                    XmlTable table = new XmlTable("ActionData");
                    table.Parse(actionData);

                    // See If message has X-LS-MailServer-ForwardedTo: and equals to "Email".
                    // If so, then we have cross reference forward, don't forward that message
                    MIME_h_Collection header = new MIME_h_Collection(new MIME_h_Provider());
                    header.Parse(new SmartStream(message, false));
                    bool forwardedAlready = false;
                    if (header.Contains("X-LS-MailServer-ForwardedTo"))
                    {
                        foreach (MIME_h headerField in header["X-LS-MailServer-ForwardedTo"])
                        {
                            if (headerField.ValueToString().Trim() == table.GetValue("Email"))
                            {
                                forwardedAlready = true;
                                break;
                            }
                        }
                    }

                    // Reset stream position
                    message.Position = 0;

                    if (forwardedAlready)
                    {
                        // Just skip
                    }
                    else
                    {
                        // Add header field 'X-LS-MailServer-ForwardedTo:'
                        MemoryStream msFwMessage = new MemoryStream();
                        byte[]       fwField     = System.Text.Encoding.Default.GetBytes("X-LS-MailServer-ForwardedTo: " + table.GetValue("Email") + "\r\n");
                        msFwMessage.Write(fwField, 0, fwField.Length);
                        SCore.StreamCopy(message, msFwMessage);

                        server.ProcessAndStoreMessage(sender, new string[] { table.GetValue("Email") }, msFwMessage, null);
                    }
                }

                #endregion

                #region ForwardToHost

                /* Description: Forwards email to specified host.
                 *              All RCPT TO: recipients are preserved.
                 *  Action data structure:
                 *      <ActionData>
                 *          <Host></Host>
                 *          <Port></Port>
                 *      </ActionData>
                 */

                else if (action == GlobalMessageRuleAction_enum.ForwardToHost)
                {
                    XmlTable table = new XmlTable("ActionData");
                    table.Parse(actionData);

                    foreach (string t in to)
                    {
                        message.Position = 0;
                        server.RelayServer.StoreRelayMessage(
                            Guid.NewGuid().ToString(),
                            null,
                            message,
                            HostEndPoint.Parse(table.GetValue("Host") + ":" + table.GetValue("Port")),
                            sender,
                            t,
                            null,
                            SMTP_DSN_Notify.NotSpecified,
                            SMTP_DSN_Ret.NotSpecified
                            );
                    }
                    message.Position = 0;
                }

                #endregion

                #region StoreToDiskFolder

                /* Description: Stores message to specified disk folder.
                 *  Action data structure:
                 *      <ActionData>
                 *          <Folder></Folder>
                 *      </ActionData>
                 */

                else if (action == GlobalMessageRuleAction_enum.StoreToDiskFolder)
                {
                    XmlTable table = new XmlTable("ActionData");
                    table.Parse(actionData);

                    string folder = table.GetValue("Folder");
                    if (!folder.EndsWith("\\"))
                    {
                        folder += "\\";
                    }

                    if (Directory.Exists(folder))
                    {
                        using (FileStream fs = File.Create(folder + DateTime.Now.ToString("ddMMyyyyHHmmss") + "_" + Guid.NewGuid().ToString().Replace('-', '_').Substring(0, 8) + ".eml")){
                            SCore.StreamCopy(message, fs);
                        }
                    }
                    else
                    {
                        // TODO: log error somewhere
                    }
                }

                #endregion

                #region StoreToIMAPFolder

                /* Description: Stores message to specified IMAP folder.
                 *  Action data structure:
                 *      <ActionData>
                 *          <Folder></Folder>
                 *      </ActionData>
                 */

                else if (action == GlobalMessageRuleAction_enum.StoreToIMAPFolder)
                {
                    XmlTable table = new XmlTable("ActionData");
                    table.Parse(actionData);
                    storeFolder = table.GetValue("Folder");
                }

                #endregion

                #region AddHeaderField

                /* Description: Add specified header field to message main header.
                 *  Action data structure:
                 *      <ActionData>
                 *          <HeaderFieldName></HeaderFieldName>
                 *          <HeaderFieldValue></HeaderFieldValue>
                 *      </ActionData>
                 */

                else if (action == GlobalMessageRuleAction_enum.AddHeaderField)
                {
                    XmlTable table = new XmlTable("ActionData");
                    table.Parse(actionData);

                    Mail_Message mime = Mail_Message.ParseFromStream(message);
                    mime.Header.Add(new MIME_h_Unstructured(table.GetValue("HeaderFieldName"), table.GetValue("HeaderFieldValue")));
                    message.SetLength(0);
                    mime.ToStream(message, new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.Q, Encoding.UTF8), Encoding.UTF8);

                    //  messageChanged = true;
                }

                #endregion

                #region RemoveHeaderField

                /* Description: Removes specified header field from message mian header.
                 *  Action data structure:
                 *      <ActionData>
                 *          <HeaderFieldName></HeaderFieldName>
                 *      </ActionData>
                 */

                else if (action == GlobalMessageRuleAction_enum.RemoveHeaderField)
                {
                    XmlTable table = new XmlTable("ActionData");
                    table.Parse(actionData);

                    Mail_Message mime = Mail_Message.ParseFromStream(message);
                    mime.Header.RemoveAll(table.GetValue("HeaderFieldName"));
                    message.SetLength(0);
                    mime.ToStream(message, new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.Q, Encoding.UTF8), Encoding.UTF8);

                    //    messageChanged = true;
                }

                #endregion

                #region SendErrorToClient

                /* Description: Sends error to currently connected client. NOTE: Error text may contain ASCII printable chars only and maximum length is 500.
                 *  Action data structure:
                 *      <ActionData>
                 *          <ErrorText></ErrorText>
                 *      </ActionData>
                 */

                else if (action == GlobalMessageRuleAction_enum.SendErrorToClient)
                {
                    XmlTable table = new XmlTable("ActionData");
                    table.Parse(actionData);

                    errorText = table.GetValue("ErrorText");
                }

                #endregion

                #region StoreToFTPFolder

                /* Description: Stores message to specified FTP server folder.
                 *  Action data structure:
                 *      <ActionData>
                 *          <Server></Server>
                 *          <Port></Server>
                 *          <User></User>
                 *          <Password></Password>
                 *          <Folder></Folder>
                 *      </ActionData>
                 */

                else if (action == GlobalMessageRuleAction_enum.StoreToFTPFolder)
                {
                    XmlTable table = new XmlTable("ActionData");
                    table.Parse(actionData);

                    _MessageRuleAction_FTP_AsyncSend ftpSend = new _MessageRuleAction_FTP_AsyncSend(
                        table.GetValue("Server"),
                        Convert.ToInt32(table.GetValue("Port")),
                        table.GetValue("User"),
                        table.GetValue("Password"),
                        table.GetValue("Folder"),
                        message,
                        DateTime.Now.ToString("ddMMyyyyHHmmss") + "_" + Guid.NewGuid().ToString().Replace('-', '_').Substring(0, 8) + ".eml"
                        );
                }

                #endregion

                #region PostToNNTPNewsGroup

                /* Description: Posts message to specified NNTP newsgroup.
                 *  Action data structure:
                 *      <ActionData>
                 *          <Server></Server>
                 *          <Port></Server>
                 *          <User></User>
                 *          <Password></Password>
                 *          <Newsgroup></Newsgroup>
                 *      </ActionData>
                 */

                else if (action == GlobalMessageRuleAction_enum.PostToNNTPNewsGroup)
                {
                    XmlTable table = new XmlTable("ActionData");
                    table.Parse(actionData);

                    // Add header field "Newsgroups: newsgroup", NNTP server demands it.
                    Mail_Message mime = Mail_Message.ParseFromStream(message);
                    if (!mime.Header.Contains("Newsgroups:"))
                    {
                        mime.Header.Add(new MIME_h_Unstructured("Newsgroups:", table.GetValue("Newsgroup")));
                    }

                    _MessageRuleAction_NNTP_Async nntp = new _MessageRuleAction_NNTP_Async(
                        table.GetValue("Server"),
                        Convert.ToInt32(table.GetValue("Port")),
                        table.GetValue("Newsgroup"),
                        new MemoryStream(mime.ToByte(new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.Q, Encoding.UTF8), Encoding.UTF8))
                        );
                }

                #endregion

                #region PostToHTTP

                /* Description: Posts message to specified page via HTTP.
                 *  Action data structure:
                 *      <ActionData>
                 *          <URL></URL>
                 *          <FileName></FileName>
                 *      </ActionData>
                 */

                else if (action == GlobalMessageRuleAction_enum.PostToHTTP)
                {
                    XmlTable table = new XmlTable("ActionData");
                    table.Parse(actionData);

                    _MessageRuleAction_HTTP_Async http = new _MessageRuleAction_HTTP_Async(
                        table.GetValue("URL"),
                        message
                        );
                }

                #endregion
            }

            return(new GlobalMessageRuleActionResult(deleteMessage, storeFolder, errorText));
        }
        /// <summary>
        /// Adds action to specified user message rule.
        /// </summary>
        /// <param name="userID">User who owns specified rule.</param>
        /// <param name="ruleID">Rule ID to which to add this action.</param>
        /// <param name="actionID">Action ID. Guid.NewID().ToString() is suggested.</param>
        /// <param name="description">Action description.</param>
        /// <param name="actionType">Action type.</param>
        /// <param name="actionData">Action data. Data structure depends on action type.</param>
        public void AddUserMessageRuleAction(string userID,string ruleID,string actionID,string description,GlobalMessageRuleAction_enum actionType,byte[] actionData)
        {
            if(userID == null || userID == ""){
                throw new Exception("Invalid userID value, userID can't be '' or null !");
            }
            if(ruleID == null || ruleID == ""){
                throw new Exception("Invalid ruleID value, ruleID can't be '' or null !");
            }
            if(actionID == null || actionID == ""){
                throw new Exception("Invalid actionID value, actionID can't be '' or null !");
            }

            using(WSqlCommand sqlCmd = new WSqlCommand(m_ConStr,"lspr_AddUserMessageRuleAction")){
                sqlCmd.AddParameter("_userID"      ,NpgsqlDbType.Varchar,userID);
                sqlCmd.AddParameter("_ruleID"      ,NpgsqlDbType.Varchar,ruleID);
                sqlCmd.AddParameter("_actionID"    ,NpgsqlDbType.Varchar,actionID);
                sqlCmd.AddParameter("_description" ,NpgsqlDbType.Varchar,description);
                sqlCmd.AddParameter("_actionType"  ,NpgsqlDbType.Integer,(int)actionType);
                sqlCmd.AddParameter("_actionData"  ,NpgsqlDbType.Bytea  ,actionData);

                DataSet ds = sqlCmd.Execute();
            }
        }
示例#4
0
文件: mssql_API.cs 项目: dioptre/nkd
 public void UpdateGlobalMessageRuleAction(string ruleID, string actionID, string description, GlobalMessageRuleAction_enum actionType, byte[] actionData)
 {
     if (ruleID == null || ruleID == "")
     {
         throw new Exception("Invalid ruleID value, ruleID can't be '' or null !");
     }
     if (actionID == null || actionID == "")
     {
         throw new Exception("Invalid actionID value, actionID can't be '' or null !");
     }
     this.m_UpdSync.BeginUpdate();
     try
     {
         if (!this.GlobalMessageRuleExists(ruleID))
         {
             throw new Exception("Invalid ruleID '" + ruleID + "', specified ruleID doesn't exist !");
         }
         bool flag = false;
         foreach (DataRow dataRow in this.dsRuleActions.Tables["GlobalMessageRuleActions"].Rows)
         {
             if (dataRow["RuleID"].ToString().ToLower() == ruleID && dataRow["ActionID"].ToString().ToLower() == actionID)
             {
                 dataRow["RuleID"] = ruleID;
                 dataRow["ActionID"] = actionID;
                 dataRow["Description"] = description;
                 dataRow["ActionType"] = actionType;
                 dataRow["ActionData"] = actionData;
                 this.dsRuleActions.WriteXml(this.m_DataPath + "GlobalMessageRuleActions.xml", XmlWriteMode.IgnoreSchema);
                 flag = true;
                 break;
             }
         }
         if (!flag)
         {
             throw new Exception("Invalid actionID '" + actionID + "', specified actionID doesn't exist !");
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         this.m_UpdSync.EndUpdate();
     }
 }
示例#5
0
文件: mssql_API.cs 项目: dioptre/nkd
 public void AddGlobalMessageRuleAction(string ruleID, string actionID, string description, GlobalMessageRuleAction_enum actionType, byte[] actionData)
 {
     if (ruleID == null || ruleID == "")
     {
         throw new Exception("Invalid ruleID value, ruleID can't be '' or null !");
     }
     if (actionID == null || actionID == "")
     {
         throw new Exception("Invalid actionID value, actionID can't be '' or null !");
     }
     this.m_UpdSync.BeginUpdate();
     try
     {
         if (!this.GlobalMessageRuleExists(ruleID))
         {
             throw new Exception("Invalid ruleID '" + ruleID + "', specified ruleID doesn't exist !");
         }
         if (this.ContainsID(this.dsRuleActions.Tables["GlobalMessageRuleActions"], "ActionID", ruleID))
         {
             throw new Exception("Specified actionID '" + actionID + "' already exists, choose another actionID !");
         }
         DataRow dataRow = this.dsRuleActions.Tables["GlobalMessageRuleActions"].NewRow();
         dataRow["RuleID"] = ruleID;
         dataRow["ActionID"] = actionID;
         dataRow["Description"] = description;
         dataRow["ActionType"] = actionType;
         dataRow["ActionData"] = actionData;
         this.dsRuleActions.Tables["GlobalMessageRuleActions"].Rows.Add(dataRow);
         this.dsRuleActions.WriteXml(this.m_DataPath + "GlobalMessageRuleActions.xml", XmlWriteMode.IgnoreSchema);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         this.m_UpdSync.EndUpdate();
     }
 }
示例#6
0
文件: xml_API.cs 项目: dioptre/nkd
        /// <summary>
        /// Updates specified rule action.
        /// </summary>
        /// <param name="userID">User who owns specified rule.</param>
        /// <param name="ruleID">Rule ID which action to update.</param>
        /// <param name="actionID">Action ID of action which to update.</param>
        /// <param name="description">Action description.</param>
        /// <param name="actionType">Action type.</param>
        /// <param name="actionData">Action data. Data structure depends on action type.</param>
        public void UpdateUserMessageRuleAction(string userID,string ruleID,string actionID,string description,GlobalMessageRuleAction_enum actionType,byte[] actionData)
        {
            if(userID == null || userID == ""){
                throw new Exception("Invalid userID value, userID can't be '' or null !");
            }
            if(ruleID == null || ruleID == ""){
                throw new Exception("Invalid ruleID value, ruleID can't be '' or null !");
            }
            if(actionID == null || actionID == ""){
                throw new Exception("Invalid actionID value, actionID can't be '' or null !");
            }

            m_UpdSync.BeginUpdate();

			try{
                // Check that specified user exists
                if(!ContainsID(dsUsers.Tables["Users"],"UserID",userID)){
                    throw new Exception("User with specified id '" + userID + "' doesn't exist !");
                }

                // Check that specified rule exists
                if(!ContainsID(dsUserMessageRules.Tables["UserMessageRules"],"RuleID",ruleID)){
                    throw new Exception("Invalid ruleID '" + ruleID + "', specified ruleID doesn't exist !");
                }

                bool actionExists = false;
                foreach(DataRow dr in dsUserMessageRuleActions.Tables["UserMessageRuleActions"].Rows){
                    if(dr["RuleID"].ToString().ToLower() == ruleID && dr["ActionID"].ToString().ToLower() == actionID){
                        dr["RuleID"]      = ruleID;
					    dr["ActionID"]    = actionID;
					    dr["Description"] = description;
                        dr["ActionType"]  = actionType;
                        dr["ActionData"]  = actionData;

                        dsUserMessageRuleActions.WriteXml(m_DataPath + "UserMessageRuleActions.xml",XmlWriteMode.IgnoreSchema);
                        actionExists = true;
                        break;
                    }
                }

                if(!actionExists){
                    throw new Exception("Invalid actionID '" + actionID + "', specified actionID doesn't exist !");
                }
			}
			catch(Exception x){
				throw x;
			}
			finally{
				m_UpdSync.EndUpdate();
			}
        }
示例#7
0
文件: xml_API.cs 项目: dioptre/nkd
        /// <summary>
        /// Adds action to specified user message rule.
        /// </summary>
        /// <param name="userID">User who owns specified rule.</param>
        /// <param name="ruleID">Rule ID to which to add this action.</param>
        /// <param name="actionID">Action ID. Guid.NewID().ToString() is suggested.</param>
        /// <param name="description">Action description.</param>
        /// <param name="actionType">Action type.</param>
        /// <param name="actionData">Action data. Data structure depends on action type.</param>
        public void AddUserMessageRuleAction(string userID,string ruleID,string actionID,string description,GlobalMessageRuleAction_enum actionType,byte[] actionData)
        {
            if(userID == null || userID == ""){
                throw new Exception("Invalid userID value, userID can't be '' or null !");
            }
            if(ruleID == null || ruleID == ""){
                throw new Exception("Invalid ruleID value, ruleID can't be '' or null !");
            }
            if(actionID == null || actionID == ""){
                throw new Exception("Invalid actionID value, actionID can't be '' or null !");
            }
            
            m_UpdSync.BeginUpdate();

			try{
                // Check that specified user exists
                if(!ContainsID(dsUsers.Tables["Users"],"UserID",userID)){
                    throw new Exception("User with specified id '" + userID + "' doesn't exist !");
                }

                // Check that specified rule exists
                if(!ContainsID(dsUserMessageRules.Tables["UserMessageRules"],"RuleID",ruleID)){
                    throw new Exception("Invalid ruleID '" + ruleID + "', specified ruleID doesn't exist !");
                }

				if(!ContainsID(dsUserMessageRuleActions.Tables["UserMessageRuleActions"],"ActionID",ruleID)){
					DataRow dr = dsUserMessageRuleActions.Tables["UserMessageRuleActions"].NewRow();
                    dr["UserID"]      = userID;
					dr["RuleID"]      = ruleID;
					dr["ActionID"]    = actionID;
					dr["Description"] = description;
                    dr["ActionType"]  = actionType;
                    dr["ActionData"]  = actionData;
							
					dsUserMessageRuleActions.Tables["UserMessageRuleActions"].Rows.Add(dr);
					dsUserMessageRuleActions.WriteXml(m_DataPath + "UserMessageRuleActions.xml",XmlWriteMode.IgnoreSchema);
				}
				else{
					throw new Exception("Specified actionID '" + actionID + "' already exists, choose another actionID !");
				}
			}
			catch(Exception x){
				throw x;
			}
			finally{
				m_UpdSync.EndUpdate();
			}
        }
示例#8
0
        /// <summary>
        /// Gets global 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 GlobalMessageRuleActionBase GetAction(string actionID, string description, GlobalMessageRuleAction_enum actionType, byte[] actionData)
        {
            if (actionType == GlobalMessageRuleAction_enum.AddHeaderField)
            {
                return(new GlobalMessageRuleAction_AddHeaderField(m_pRule, this, actionID, description, actionData));
            }
            else if (actionType == GlobalMessageRuleAction_enum.AutoResponse)
            {
                return(new GlobalMessageRuleAction_AutoResponse(m_pRule, this, actionID, description, actionData));
            }
            else if (actionType == GlobalMessageRuleAction_enum.DeleteMessage)
            {
                return(new GlobalMessageRuleAction_DeleteMessage(m_pRule, this, actionID, description));
            }
            else if (actionType == GlobalMessageRuleAction_enum.ExecuteProgram)
            {
                return(new GlobalMessageRuleAction_ExecuteProgram(m_pRule, this, actionID, description, actionData));
            }
            else if (actionType == GlobalMessageRuleAction_enum.ForwardToEmail)
            {
                return(new GlobalMessageRuleAction_ForwardToEmail(m_pRule, this, actionID, description, actionData));
            }
            else if (actionType == GlobalMessageRuleAction_enum.ForwardToHost)
            {
                return(new GlobalMessageRuleAction_ForwardToHost(m_pRule, this, actionID, description, actionData));
            }
            else if (actionType == GlobalMessageRuleAction_enum.MoveToIMAPFolder)
            {
                return(new GlobalMessageRuleAction_MoveToImapFolder(m_pRule, this, actionID, description, actionData));
            }
            else if (actionType == GlobalMessageRuleAction_enum.PostToHTTP)
            {
                return(new GlobalMessageRuleAction_PostToHttp(m_pRule, this, actionID, description, actionData));
            }
            else if (actionType == GlobalMessageRuleAction_enum.PostToNNTPNewsGroup)
            {
                return(new GlobalMessageRuleAction_PostToNntpNewsgroup(m_pRule, this, actionID, description, actionData));
            }
            else if (actionType == GlobalMessageRuleAction_enum.RemoveHeaderField)
            {
                return(new GlobalMessageRuleAction_RemoveHeaderField(m_pRule, this, actionID, description, actionData));
            }
            else if (actionType == GlobalMessageRuleAction_enum.SendErrorToClient)
            {
                return(new GlobalMessageRuleAction_SendError(m_pRule, this, actionID, description, actionData));
            }
            else if (actionType == GlobalMessageRuleAction_enum.StoreToDiskFolder)
            {
                return(new GlobalMessageRuleAction_StoreToDiskFolder(m_pRule, this, actionID, description, actionData));
            }
            else if (actionType == GlobalMessageRuleAction_enum.StoreToFTPFolder)
            {
                return(new GlobalMessageRuleAction_StoreToFtp(m_pRule, this, actionID, description, actionData));
            }

            throw new Exception("Invalid action type !");
        }
        /// <summary>
        /// Gets global 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 GlobalMessageRuleActionBase GetAction(string actionID,string description,GlobalMessageRuleAction_enum actionType,byte[] actionData)
        {
            if(actionType == GlobalMessageRuleAction_enum.AddHeaderField){
                return new GlobalMessageRuleAction_AddHeaderField(m_pRule,this,actionID,description,actionData);
            }
            else if(actionType == GlobalMessageRuleAction_enum.AutoResponse){
                return new GlobalMessageRuleAction_AutoResponse(m_pRule,this,actionID,description,actionData);
            }
            else if(actionType == GlobalMessageRuleAction_enum.DeleteMessage){
                return new GlobalMessageRuleAction_DeleteMessage(m_pRule,this,actionID,description);
            }
            else if(actionType == GlobalMessageRuleAction_enum.ExecuteProgram){
                return new GlobalMessageRuleAction_ExecuteProgram(m_pRule,this,actionID,description,actionData);
            }
            else if(actionType == GlobalMessageRuleAction_enum.ForwardToEmail){
                return new GlobalMessageRuleAction_ForwardToEmail(m_pRule,this,actionID,description,actionData);
            }
            else if(actionType == GlobalMessageRuleAction_enum.ForwardToHost){
                return new GlobalMessageRuleAction_ForwardToHost(m_pRule,this,actionID,description,actionData);
            }
            else if(actionType == GlobalMessageRuleAction_enum.MoveToIMAPFolder){
                return new GlobalMessageRuleAction_MoveToImapFolder(m_pRule,this,actionID,description,actionData);
            }
            else if(actionType == GlobalMessageRuleAction_enum.PostToHTTP){
                return new GlobalMessageRuleAction_PostToHttp(m_pRule,this,actionID,description,actionData);
            }
            else if(actionType == GlobalMessageRuleAction_enum.PostToNNTPNewsGroup){
                return new GlobalMessageRuleAction_PostToNntpNewsgroup(m_pRule,this,actionID,description,actionData);
            }
            else if(actionType == GlobalMessageRuleAction_enum.RemoveHeaderField){
                return new GlobalMessageRuleAction_RemoveHeaderField(m_pRule,this,actionID,description,actionData);
            }
            else if(actionType == GlobalMessageRuleAction_enum.SendErrorToClient){
                return new GlobalMessageRuleAction_SendError(m_pRule,this,actionID,description,actionData);
            }
            else if(actionType == GlobalMessageRuleAction_enum.StoreToDiskFolder){
                return new GlobalMessageRuleAction_StoreToDiskFolder(m_pRule,this,actionID,description,actionData);
            }
            else if(actionType == GlobalMessageRuleAction_enum.StoreToFTPFolder){
                return new GlobalMessageRuleAction_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,GlobalMessageRuleAction_enum type,byte[] actionData,bool addToCollection)
        {
            /* AddGlobalMessageRuleAction <virtualServerID> "<messageRuleID>" "<actionID>" "<description>" <actionType> "<actionData>:base64"
                  Responses:
                    +OK <sizeOfData>
                    <data>
                    
                    -ERR <errorText>
            */

            string id = Guid.NewGuid().ToString();

            // Call TCP AddGlobalMessageRuleAction
            m_pRule.VirtualServer.Server.TcpClient.TcpStream.WriteLine("AddGlobalMessageRuleAction " +
                m_pRule.VirtualServer.VirtualServerID + " " +
                TextUtils.QuoteString(m_pRule.ID) + " " +
                TextUtils.QuoteString(actionID) + " " +
                TextUtils.QuoteString(description) + " " +
                ((int)type).ToString() + " " + 
                Convert.ToBase64String(actionData)
            );
                        
            string response = m_pRule.VirtualServer.Server.ReadLine();
            if(!response.ToUpper().StartsWith("+OK")){
                throw new Exception(response);
            }

            if(addToCollection){
                m_pActions.Add(GetAction(actionID,description,type,actionData));
            }
        }
        /// <summary>
        /// Adds action to specified user message rule.
        /// </summary>
        /// <param name="userID">User who owns specified rule.</param>
        /// <param name="ruleID">Rule ID to which to add this action.</param>
        /// <param name="actionID">Action ID. Guid.NewID().ToString() is suggested.</param>
        /// <param name="description">Action description.</param>
        /// <param name="actionType">Action type.</param>
        /// <param name="actionData">Action data. Data structure depends on action type.</param>
        public void AddUserMessageRuleAction(string userID,string ruleID,string actionID,string description,GlobalMessageRuleAction_enum actionType,byte[] actionData)
        {
            if(userID == null || userID == ""){
                throw new Exception("Invalid userID value, userID can't be '' or null !");
            }
            if(ruleID == null || ruleID == ""){
                throw new Exception("Invalid ruleID value, ruleID can't be '' or null !");
            }
            if(actionID == null || actionID == ""){
                throw new Exception("Invalid actionID value, actionID can't be '' or null !");
            }

            using(WSqlCommand sqlCmd = new WSqlCommand(m_ConStr,"lspr_AddUserMessageRuleAction")){
                sqlCmd.AddParameter("@userID"      ,SqlDbType.NVarChar,userID);
                sqlCmd.AddParameter("@ruleID"      ,SqlDbType.NVarChar,ruleID);
                sqlCmd.AddParameter("@actionID"    ,SqlDbType.NVarChar,actionID);
                sqlCmd.AddParameter("@description" ,SqlDbType.NVarChar,description);
                sqlCmd.AddParameter("@actionType"  ,SqlDbType.Int     ,(int)actionType);
                sqlCmd.AddParameter("@actionData"  ,SqlDbType.Image   ,actionData);

                DataSet ds = sqlCmd.Execute();
                ds.Tables[0].TableName = "UserMessageRuleActions";

                if(ds.Tables["UserMessageRuleActions"].Rows.Count > 0 && ds.Tables["UserMessageRuleActions"].Rows[0]["ErrorText"].ToString().Length > 0){
                    throw new Exception(ds.Tables["UserMessageRuleActions"].Rows[0]["ErrorText"].ToString());
                }
            }
        }