Exemple #1
0
 private string ReplaceVariable(string variable)
 {
     try
     {
         if (variable.StartsWith("<#sys.datetime"))
         {
             string result = DateTime.Now.ToString(TextUtils.UnQuoteString(variable.Substring(variable.IndexOf("(") + 1, variable.IndexOf(")") - variable.IndexOf("(") - 1)));
             return(result);
         }
         if (variable == "<#relay.hostname>")
         {
             string result = Dns.GetHostName();
             return(result);
         }
         if (variable == "<#relay.undelivered_after>")
         {
             string result = Convert.ToString(this.m_pRelayServer.UndeliveredAfter / 60);
             return(result);
         }
         if (variable == "<#relay.error>")
         {
             string result = this.m_ErrorText;
             return(result);
         }
         if (variable == "<#relay.session_id>")
         {
             string result = this.m_pRelaySession.ID;
             return(result);
         }
         if (variable == "<#relay.session_messageid>")
         {
             string result = this.m_pRelaySession.MessageID;
             return(result);
         }
         if (variable == "<#relay.session_hostname>")
         {
             try
             {
                 string result = Dns.GetHostEntry(this.m_pRelaySession.RemoteEndPoint.Address).HostName;
                 return(result);
             }
             catch
             {
                 string result = this.m_pRelaySession.RemoteEndPoint.Address.ToString();
                 return(result);
             }
         }
         if (variable == "<#relay.to>")
         {
             string result = this.m_pRelaySession.To;
             return(result);
         }
         if (variable == "<#relay.from>")
         {
             string result = this.m_pRelaySession.From;
             return(result);
         }
         if (variable == "<#message.bodytext>")
         {
             string bodyText = this.m_pMime.BodyText;
             if (bodyText != null)
             {
                 string result = bodyText;
                 return(result);
             }
         }
         else if (variable.StartsWith("<#message.header"))
         {
             string text = TextUtils.UnQuoteString(variable.Substring(variable.IndexOf("[") + 1, variable.IndexOf("]") - variable.IndexOf("[") - 1)).Trim();
             if (text.EndsWith(":"))
             {
                 text = text.Substring(0, text.Length - 1);
             }
             MIME_h first = this.m_pMime.Header.GetFirst(text);
             if (first != null)
             {
                 string result = first.ToString().Split(new char[]
                 {
                     ':'
                 }, 2)[1].Trim();
                 return(result);
             }
         }
     }
     catch
     {
         string result = variable;
         return(result);
     }
     return("");
 }
Exemple #2
0
        /// <summary>
        /// Replaces specified variable with actual value.
        /// </summary>
        /// <param name="variable">Variable to replace.</param>
        private string ReplaceVariable(string variable)
        {
            try
            {
                // Current date time. Syntax: <#sys.datetime("format")>
                if (variable.StartsWith("<#sys.datetime"))
                {
                    return(DateTime.Now.ToString(TextUtils.UnQuoteString(variable.Substring(variable.IndexOf("(") + 1, variable.IndexOf(")") - variable.IndexOf("(") - 1))));
                }

                // Relay server host name.
                else if (variable == "<#relay.hostname>")
                {
                    return(System.Net.Dns.GetHostName());
                }
                // Specifies after how many hours server will try to deliver message.
                else if (variable == "<#relay.undelivered_after>")
                {
                    return(Convert.ToString(m_pRelayServer.UndeliveredAfter / 60));
                }
                // Error why relay failed.
                else if (variable == "<#relay.error>")
                {
                    return(m_ErrorText);
                }
                // Relay session ID.
                else if (variable == "<#relay.session_id>")
                {
                    return(m_pRelaySession.ID);
                }
                // Relay session message ID.
                else if (variable == "<#relay.session_messageid>")
                {
                    return(m_pRelaySession.MessageID);
                }
                // Relay session connected host name.
                else if (variable == "<#relay.session_hostname>")
                {
                    try
                    {
                        return(System.Net.Dns.GetHostEntry(m_pRelaySession.RemoteEndPoint.Address).HostName);
                    }
                    catch
                    {
                        return(m_pRelaySession.RemoteEndPoint.Address.ToString());
                    }
                }

                /*
                 * // Relay session active(last) log part.
                 * else if(variable == "<#relay.session_activelog>"){
                 *  if(m_pRelaySession.SessionActiveLog != null){
                 *      return m_pRelaySession.SessionActiveLog.ToString();
                 *  }
                 *  else{
                 *      return "<Relay Logging disabled>";
                 *  }
                 * }*/
                // Relay message destination recipient email address.
                else if (variable == "<#relay.to>")
                {
                    return(m_pRelaySession.To);
                }
                // Original sender email address.
                else if (variable == "<#relay.from>")
                {
                    return(m_pRelaySession.From);
                }

                // Message body text.
                else if (variable == "<#message.bodytext>")
                {
                    string bodyText = m_pMime.BodyText;
                    if (bodyText != null)
                    {
                        return(bodyText);
                    }
                }
                // Message header field value. Synatx: <#message.header["headerFieldName:"]>
                else if (variable.StartsWith("<#message.header"))
                {
                    string headerName = TextUtils.UnQuoteString(variable.Substring(variable.IndexOf("[") + 1, variable.IndexOf("]") - variable.IndexOf("[") - 1)).Trim();
                    if (headerName.EndsWith(":"))
                    {
                        headerName = headerName.Substring(0, headerName.Length - 1);
                    }
                    MIME_h headerField = m_pMime.Header.GetFirst(headerName);
                    if (headerField != null)
                    {
                        return(headerField.ToString().Split(new char[] { ':' }, 2)[1].Trim());
                    }
                }
            }
            catch
            {
                // Failed to replace variable value, just invaild synatx or who knows ... .
                // Just leave variable as is.
                return(variable);
            }

            return("");
        }