コード例 #1
0
        /// <summary>
        /// Deletes specified action from global message rule.
        /// </summary>
        /// <param name="action">Action to remove.</param>
        public void Remove(GlobalMessageRuleActionBase action)
        {
            /* DeleteGlobalMessageRuleAction <virtualServerID> "<ruleID>" "<actionID>"
             *    Responses:
             +OK
             *      -ERR <errorText>
             */

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

            // Call TCP DeleteGlobalMessageRuleAction
            m_pRule.VirtualServer.Server.TcpClient.TcpStream.WriteLine("DeleteGlobalMessageRuleAction " +
                                                                       m_pRule.VirtualServer.VirtualServerID + " " +
                                                                       TextUtils.QuoteString(m_pRule.ID) + " " +
                                                                       TextUtils.QuoteString(action.ID)
                                                                       );

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

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

            m_pActions.Remove(action);
        }
        private void m_Ok_Click(object sender, EventArgs e)
        {
            #region AutoResponse

            if(m_pAction.SelectedItem.ToString() == "Auto Response"){
                //--- Validate values ------------------------------------------------//
                if(m_pAutoResponse_FullMEssage.Text == ""){
                    MessageBox.Show(this,"Full Message: value can't empty !","Error:",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    return;
                }
                //--------------------------------------------------------------------//

                if(m_pActionData == null){
                    m_pActionData = m_pRule.Actions.Add_AutoResponse(
                        m_pDescription.Text,
                        m_pAutoResponse_From.Text,
                        System.Text.Encoding.Default.GetBytes(m_pAutoResponse_FullMEssage.Text)
                    );
                }
                else{
                    GlobalMessageRuleAction_AutoResponse a = (GlobalMessageRuleAction_AutoResponse)m_pActionData;
                    a.Description = m_pDescription.Text;
                    a.From        = m_pAutoResponse_From.Text;
                    a.Message     = System.Text.Encoding.Default.GetBytes(m_pAutoResponse_FullMEssage.Text);
                    a.Commit();
                }
            }

            #endregion

            #region DeleteMessage

            else if(m_pAction.SelectedItem.ToString() == "Delete Message"){
                if(m_pActionData == null){
                    m_pActionData = m_pRule.Actions.Add_DeleteMessage(m_pDescription.Text);
                }
                else{
                    GlobalMessageRuleAction_DeleteMessage a = (GlobalMessageRuleAction_DeleteMessage)m_pActionData;
                    a.Description = m_pDescription.Text;
                    a.Commit();
                }
            }

            #endregion

            #region ExecuteProgram

            else if(m_pAction.SelectedItem.ToString() == "Execute Program"){
                //--- Validate values ------------------------------------------------//
                if(m_pExecuteProgram_ProgramToExecute.Text == ""){
                    MessageBox.Show(this,"Program to Execute: value can't empty !","Error:",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    return;
                }
                //--------------------------------------------------------------------//

                if(m_pActionData == null){
                    m_pActionData = m_pRule.Actions.Add_ExecuteProgram(
                        m_pDescription.Text,
                        m_pExecuteProgram_ProgramToExecute.Text,
                        m_pExecuteProgram_ProgramArguments.Text
                    );
                }
                else{
                    GlobalMessageRuleAction_ExecuteProgram a = (GlobalMessageRuleAction_ExecuteProgram)m_pActionData;
                    a.Description      = m_pDescription.Text;
                    a.Program          = m_pExecuteProgram_ProgramToExecute.Text;
                    a.ProgramArguments = m_pExecuteProgram_ProgramArguments.Text;
                    a.Commit();
                }
            }

            #endregion

            #region ForwardToEmail

            else if(m_pAction.SelectedItem.ToString() == "Forward To Email"){
                //--- Validate values ------------------------------------------------//
                if(m_pForwardToEmail_Email.Text == ""){
                    MessageBox.Show(this,"Forward to Email: value can't empty !","Error:",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    return;
                }
                //--------------------------------------------------------------------//

                if(m_pActionData == null){
                    m_pActionData = m_pRule.Actions.Add_ForwardToEmail(
                        m_pDescription.Text,
                        m_pForwardToEmail_Email.Text
                    );
                }
                else{
                    GlobalMessageRuleAction_ForwardToEmail a = (GlobalMessageRuleAction_ForwardToEmail)m_pActionData;
                    a.Description  = m_pDescription.Text;
                    a.EmailAddress = m_pForwardToEmail_Email.Text;
                    a.Commit();
                }
            }

            #endregion

            #region ForwartToHost

            else if(m_pAction.SelectedItem.ToString() == "Forward To Host"){
                //--- Validate values ------------------------------------------------//
                if(m_pForwardToHost_Host.Text == ""){
                    MessageBox.Show(this,"Forward to Host: value can't empty !","Error:",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    return;
                }
                //--------------------------------------------------------------------//

                if(m_pActionData == null){
                    m_pActionData = m_pRule.Actions.Add_ForwardToHost(
                        m_pDescription.Text,
                        m_pForwardToHost_Host.Text,
                        (int)m_pForwardToHost_HostPort.Value
                    );
                }
                else{
                    GlobalMessageRuleAction_ForwardToHost a = (GlobalMessageRuleAction_ForwardToHost)m_pActionData;
                    a.Description = m_pDescription.Text;
                    a.Host        = m_pForwardToHost_Host.Text;
                    a.Port        = (int)m_pForwardToHost_HostPort.Value;
                    a.Commit();
                }
            }

            #endregion

            #region StoreToDiskFolder

            else if(m_pAction.SelectedItem.ToString() == "Store To Disk Folder"){
                //--- Validate values ------------------------------------------------//
                if(m_pStoreToDiskFolder_Folder.Text == ""){
                    MessageBox.Show(this,"Store to Disk Folder: value can't empty !","Error:",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    return;
                }
                //--------------------------------------------------------------------//

                if(m_pActionData == null){
                    m_pActionData = m_pRule.Actions.Add_StoreToDisk(
                        m_pDescription.Text,
                        m_pStoreToDiskFolder_Folder.Text
                    );
                }
                else{
                    GlobalMessageRuleAction_StoreToDiskFolder a = (GlobalMessageRuleAction_StoreToDiskFolder)m_pActionData;
                    a.Description = m_pDescription.Text;
                    a.Folder      = m_pStoreToDiskFolder_Folder.Text;
                    a.Commit();
                }
            }

            #endregion

            #region MoveToIMAPFolder

            else if(m_pAction.SelectedItem.ToString() == "Move To IMAP Folder"){
                //--- Validate values ------------------------------------------------//
                if(m_pMoveToIMAPFolder_Folder.Text == ""){
                    MessageBox.Show(this,"Move to IMAP Folder: value can't empty !","Error:",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    return;
                }
                //--------------------------------------------------------------------//

                if(m_pActionData == null){
                    m_pActionData = m_pRule.Actions.Add_MoveToImapFolder(
                        m_pDescription.Text,
                        m_pMoveToIMAPFolder_Folder.Text
                    );
                }
                else{
                    GlobalMessageRuleAction_MoveToImapFolder a = (GlobalMessageRuleAction_MoveToImapFolder)m_pActionData;
                    a.Description = m_pDescription.Text;
                    a.Folder      = m_pMoveToIMAPFolder_Folder.Text;
                    a.Commit();
                }
            }

            #endregion

            #region AddHeaderField

            else if(m_pAction.SelectedItem.ToString() == "Add Header Field"){
                //--- Validate values ------------------------------------------------//
                if(m_pAddHeaderField_FieldName.Text == ""){
                    MessageBox.Show(this,"Header Field Name: value can't empty !","Error:",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    return;
                }
                //--------------------------------------------------------------------//

                if(m_pActionData == null){
                    m_pActionData = m_pRule.Actions.Add_AddHeaderField(
                        m_pDescription.Text,
                        m_pAddHeaderField_FieldName.Text,
                        m_pAddHeaderField_FieldValue.Text
                    );
                }
                else{
                    GlobalMessageRuleAction_AddHeaderField a = (GlobalMessageRuleAction_AddHeaderField)m_pActionData;
                    a.Description      = m_pDescription.Text;
                    a.HeaderFieldName  = m_pAddHeaderField_FieldName.Text;
                    a.HeaderFieldValue = m_pAddHeaderField_FieldValue.Text;
                    a.Commit();
                }
            }

            #endregion

            #region RemoveHeaderField

            else if(m_pAction.SelectedItem.ToString() == "Remove Header Field"){
                //--- Validate values ------------------------------------------------//
                if(m_pRemoveHeaderField_FieldName.Text == ""){
                    MessageBox.Show(this,"Header Field Name: value can't empty !","Error:",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    return;
                }
                //--------------------------------------------------------------------//

                if(m_pActionData == null){
                    m_pActionData = m_pRule.Actions.Add_RemoveHeaderField(
                        m_pDescription.Text,
                        m_pAddHeaderField_FieldName.Text
                    );
                }
                else{
                    GlobalMessageRuleAction_RemoveHeaderField a = (GlobalMessageRuleAction_RemoveHeaderField)m_pActionData;
                    a.Description      = m_pDescription.Text;
                    a.HeaderFieldName  = m_pAddHeaderField_FieldName.Text;
                    a.Commit();
                }
            }

            #endregion

            #region SendErrorToClient

            else if(m_pAction.SelectedItem.ToString() == "Send Error To Client"){
                //--- Validate values ------------------------------------------------//
                if(m_pSendErrorToClient_ErrorText.Text == ""){
                    MessageBox.Show(this,"SMTP Error Text: value can't empty !","Error:",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    return;
                }
                if(!LumiSoft.Net.Core.IsAscii(m_pSendErrorToClient_ErrorText.Text)){
                    MessageBox.Show(this,"SMTP Error Text: value can contain only printable ASCII chars !","Error:",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    return;
                }
                //--------------------------------------------------------------------//

                if(m_pActionData == null){
                    m_pActionData = m_pRule.Actions.Add_SendError(
                        m_pDescription.Text,
                        m_pSendErrorToClient_ErrorText.Text
                    );
                }
                else{
                    GlobalMessageRuleAction_SendError a = (GlobalMessageRuleAction_SendError)m_pActionData;
                    a.Description   = m_pDescription.Text;
                    a.SmtpErrorText = m_pSendErrorToClient_ErrorText.Text;
                    a.Commit();
                }
            }

            #endregion

            #region StoreToFTPFolder

            else if(m_pAction.SelectedItem.ToString() == "Store To FTP Folder"){
                //--- Validate values ------------------------------------------------//
                if(m_pStoreToFTPFolder_Server.Text == ""){
                    MessageBox.Show(this,"FTP Server: value can't empty !","Error:",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    return;
                }
                //--------------------------------------------------------------------//

                if(m_pActionData == null){
                    m_pActionData = m_pRule.Actions.Add_StoreToFtp(
                        m_pDescription.Text,
                        m_pStoreToFTPFolder_Server.Text,
                        (int)m_pStoreToFTPFolder_Port.Value,
                        m_pStoreToFTPFolder_User.Text,
                        m_pStoreToFTPFolder_Password.Text,
                        m_pStoreToFTPFolder_Folder.Text
                    );
                }
                else{
                    GlobalMessageRuleAction_StoreToFtp a = (GlobalMessageRuleAction_StoreToFtp)m_pActionData;
                    a.Description = m_pDescription.Text;
                    a.Server      = m_pStoreToFTPFolder_Server.Text;
                    a.Port        = (int)m_pStoreToFTPFolder_Port.Value;
                    a.UserName    = m_pStoreToFTPFolder_User.Text;
                    a.Password    = m_pStoreToFTPFolder_Password.Text;
                    a.Folder      = m_pStoreToFTPFolder_Folder.Text;
                    a.Commit();
                }
            }

            #endregion

            #region PostToNNTPNewsgroup

            else if(m_pAction.SelectedItem.ToString() == "Post To NNTP Newsgroup"){
                //--- Validate values ------------------------------------------------//
                if(m_pPostToNNTPNewsgroup_Server.Text == ""){
                    MessageBox.Show(this,"NNTP Server: value can't empty !","Error:",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    return;
                }
                if(m_pPostToNNTPNewsgroup_Newsgroup.Text == ""){
                    MessageBox.Show(this,"Newsgroup: value can't empty !","Error:",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    return;
                }
                //--------------------------------------------------------------------//

                if(m_pActionData == null){
                    m_pActionData = m_pRule.Actions.Add_PostToNntp(
                        m_pDescription.Text,
                        m_pPostToNNTPNewsgroup_Server.Text,
                        (int)m_pPostToNNTPNewsgroup_Port.Value,
                        m_pPostToNNTPNewsgroup_Newsgroup.Text
                    );
                }
                else{
                    GlobalMessageRuleAction_PostToNntpNewsgroup a = (GlobalMessageRuleAction_PostToNntpNewsgroup)m_pActionData;
                    a.Description = m_pDescription.Text;
                    a.Server      = m_pPostToNNTPNewsgroup_Server.Text;
                    a.Port        = (int)m_pPostToNNTPNewsgroup_Port.Value;
                    a.Newsgroup   = m_pPostToNNTPNewsgroup_Newsgroup.Text;
                    a.Commit();
                }
            }

            #endregion

            #region PostToHTTP

            else if(m_pAction.SelectedItem.ToString() == "Post To HTTP"){
                if(m_pActionData == null){
                    m_pActionData = m_pRule.Actions.Add_PostToHttp(
                        m_pDescription.Text,
                        m_pPostToHTTP_URL.Text
                    );
                }
                else{
                    GlobalMessageRuleAction_PostToHttp a = (GlobalMessageRuleAction_PostToHttp)m_pActionData;
                    a.Description = m_pDescription.Text;
                    a.Url         = m_pPostToHTTP_URL.Text;
                    a.Commit();
                }
            }

            #endregion

            this.DialogResult = DialogResult.OK;
        }
        /// <summary>
        /// Edit constructor.
        /// </summary>
        /// <param name="rule">Owner rule.</param>
        /// <param name="action">Global messgae rule action action.</param>
        public wfrm_GlobalMessageRule_Action(GlobalMessageRule rule,GlobalMessageRuleActionBase action)
        {
            m_pRule       = rule;
            m_pActionData = action;

            InitUI();

            m_pDescription.Text = action.Description;
            m_pAction.Enabled = false;

            //--- Pase action data -------------------------------------------------//

            #region AutoResponse

            if(action.ActionType == GlobalMessageRuleAction_enum.AutoResponse){
                GlobalMessageRuleAction_AutoResponse a = (GlobalMessageRuleAction_AutoResponse)action;
                m_pAutoResponse_From.Text        = a.From;
                m_pAutoResponse_FullMEssage.Text = System.Text.Encoding.Default.GetString(a.Message);

                m_pAction.SelectedIndex = 0;
            }

            #endregion

            #region DeleteMessage

            else if(action.ActionType == GlobalMessageRuleAction_enum.DeleteMessage){
                GlobalMessageRuleAction_DeleteMessage a = (GlobalMessageRuleAction_DeleteMessage)action;

                m_pAction.SelectedIndex = 1;
            }

            #endregion

            #region ExecuteProgram

            else if(action.ActionType == GlobalMessageRuleAction_enum.ExecuteProgram){
                GlobalMessageRuleAction_ExecuteProgram a = (GlobalMessageRuleAction_ExecuteProgram)action;
                m_pExecuteProgram_ProgramToExecute.Text = a.Program;
                m_pExecuteProgram_ProgramArguments.Text = a.ProgramArguments;

                m_pAction.SelectedIndex = 2;
            }

            #endregion

            #region ForwardToEmail

            else if(action.ActionType == GlobalMessageRuleAction_enum.ForwardToEmail){
                GlobalMessageRuleAction_ForwardToEmail a = (GlobalMessageRuleAction_ForwardToEmail)action;
                m_pForwardToEmail_Email.Text = a.EmailAddress;

                m_pAction.SelectedIndex = 3;
            }

            #endregion

            #region ForwardToHost

            else if(action.ActionType == GlobalMessageRuleAction_enum.ForwardToHost){
                GlobalMessageRuleAction_ForwardToHost a = (GlobalMessageRuleAction_ForwardToHost)action;
                m_pForwardToHost_Host.Text      = a.Host;
                m_pForwardToHost_HostPort.Value = a.Port;

                m_pAction.SelectedIndex = 4;
            }

            #endregion

            #region StoreToDiskFolder

            else if(action.ActionType == GlobalMessageRuleAction_enum.StoreToDiskFolder){
                GlobalMessageRuleAction_StoreToDiskFolder a = (GlobalMessageRuleAction_StoreToDiskFolder)action;
                m_pStoreToDiskFolder_Folder.Text = a.Folder;

                m_pAction.SelectedIndex = 5;
            }

            #endregion

            #region StoreToIMAPFolder

            else if(action.ActionType == GlobalMessageRuleAction_enum.MoveToIMAPFolder){
                GlobalMessageRuleAction_MoveToImapFolder a = (GlobalMessageRuleAction_MoveToImapFolder)action;
                m_pMoveToIMAPFolder_Folder.Text = a.Folder;

                m_pAction.SelectedIndex = 6;
            }

            #endregion

            #region AddHeaderField

            else if(action.ActionType == GlobalMessageRuleAction_enum.AddHeaderField){
                GlobalMessageRuleAction_AddHeaderField a = (GlobalMessageRuleAction_AddHeaderField)action;
                m_pAddHeaderField_FieldName.Text  = a.HeaderFieldName;
                m_pAddHeaderField_FieldValue.Text = a.HeaderFieldValue;

                m_pAction.SelectedIndex = 7;
            }

            #endregion

            #region RemoveHeaderField

            else if(action.ActionType == GlobalMessageRuleAction_enum.RemoveHeaderField){
                GlobalMessageRuleAction_RemoveHeaderField a = (GlobalMessageRuleAction_RemoveHeaderField)action;
                m_pRemoveHeaderField_FieldName.Text = a.HeaderFieldName;

                m_pAction.SelectedIndex = 8;
            }

            #endregion

            #region SendErrorToClient

            else if(action.ActionType == GlobalMessageRuleAction_enum.SendErrorToClient){
                GlobalMessageRuleAction_SendError a = (GlobalMessageRuleAction_SendError)action;
                m_pSendErrorToClient_ErrorText.Text = a.SmtpErrorText;

                m_pAction.SelectedIndex = 9;
            }

            #endregion

            #region StoreToFTPFolder

            else if(action.ActionType == GlobalMessageRuleAction_enum.StoreToFTPFolder){
                GlobalMessageRuleAction_StoreToFtp a = (GlobalMessageRuleAction_StoreToFtp)action;
                m_pStoreToFTPFolder_Server.Text   = a.Server;
                m_pStoreToFTPFolder_Port.Value    = a.Port;
                m_pStoreToFTPFolder_User.Text     = a.UserName;
                m_pStoreToFTPFolder_Password.Text = a.Password;
                m_pStoreToFTPFolder_Folder.Text   = a.Folder;

                m_pAction.SelectedIndex = 10;
            }

            #endregion

            #region PostToNNTPNewsGroup

            else if(action.ActionType == GlobalMessageRuleAction_enum.PostToNNTPNewsGroup){
                GlobalMessageRuleAction_PostToNntpNewsgroup a = (GlobalMessageRuleAction_PostToNntpNewsgroup)action;
                m_pPostToNNTPNewsgroup_Server.Text = a.Server;
                m_pPostToNNTPNewsgroup_Port.Value  = a.Port;
                // table.Add("User","");
                // table.Add("Password","");
                m_pPostToNNTPNewsgroup_Newsgroup.Text = a.Newsgroup;

                m_pAction.SelectedIndex = 11;
            }

            #endregion

            #region PostToHTTP

            else if(action.ActionType == GlobalMessageRuleAction_enum.PostToHTTP){
                GlobalMessageRuleAction_PostToHttp a = (GlobalMessageRuleAction_PostToHttp)action;
                m_pPostToHTTP_URL.Text = a.Url;
                // table.GetValue("FileName");

                m_pAction.SelectedIndex = 12;
            }

            #endregion

            //---------------------------------------------------------------------//
        }
コード例 #4
0
 /// <summary>
 /// Adds specified action to global message rule.
 /// </summary>
 /// <param name="action">Action to add.</param>
 private void Add(GlobalMessageRuleActionBase action)
 {
     Add(action.ID, action.Description, action.ActionType, action.Serialize(), false);
 }
コード例 #5
0
        /// <summary>
        /// Deletes specified action from global message rule.
        /// </summary>
        /// <param name="action">Action to remove.</param>
        public void Remove(GlobalMessageRuleActionBase action)
        {
            /* DeleteGlobalMessageRuleAction <virtualServerID> "<ruleID>" "<actionID>"
                  Responses:
                    +OK                     
                    -ERR <errorText>
            */

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

            // Call TCP DeleteGlobalMessageRuleAction
            m_pRule.VirtualServer.Server.TcpClient.TcpStream.WriteLine("DeleteGlobalMessageRuleAction " + 
                m_pRule.VirtualServer.VirtualServerID + " " + 
                TextUtils.QuoteString(m_pRule.ID) + " " + 
                TextUtils.QuoteString(action.ID)
            );
                        
            string response = m_pRule.VirtualServer.Server.ReadLine();
            if(!response.ToUpper().StartsWith("+OK")){
                throw new Exception(response);
            }

            m_pActions.Remove(action);
        }
コード例 #6
0
 /// <summary>
 /// Adds specified action to global message rule.
 /// </summary>
 /// <param name="action">Action to add.</param>
 private void Add(GlobalMessageRuleActionBase action)
 {
     Add(action.ID,action.Description,action.ActionType,action.Serialize(),false);
 }