Esempio n. 1
0
File: Mail.cs Progetto: xhute/Kooboo
        internal MailObject PrepareData(object dataobj)
        {
            Dictionary <string, object> data = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);

            System.Collections.IDictionary idict = dataobj as System.Collections.IDictionary;

            if (idict != null)
            {
                foreach (var item in idict.Keys)
                {
                    var value = idict[item];
                    if (value != null)
                    {
                        data.Add(item.ToString(), value.ToString());
                    }
                }
            }
            else
            {
                var dynamicobj = dataobj as IDictionary <string, object>;
                if (dynamicobj != null)
                {
                    foreach (var item in dynamicobj.Keys)
                    {
                        var value = dynamicobj[item];
                        if (value != null)
                        {
                            data.Add(item.ToString(), value.ToString());
                        }
                    }
                }
            }

            MailObject result = new MailObject();

            char[] sep = ";".ToCharArray();

            if (data.ContainsKey("to"))
            {
                var value = data["to"];
                if (value != null)
                {
                    string values = value.ToString();
                    result.To = values.Split(sep, StringSplitOptions.RemoveEmptyEntries).ToList();
                    result.originalToString = values;
                }
            }


            if (data.ContainsKey("from"))
            {
                var value = data["from"];
                if (value != null)
                {
                    result.From = value.ToString();
                }
            }

            if (data.ContainsKey("subject"))
            {
                var value = data["subject"];
                if (value != null)
                {
                    result.Subject = value.ToString();
                }
            }

            if (data.ContainsKey("textbody"))
            {
                var value = data["textbody"];
                if (value != null)
                {
                    result.TextBody = value.ToString();
                }
            }

            if (data.ContainsKey("htmlbody"))
            {
                var value = data["htmlbody"];
                if (value != null)
                {
                    result.HtmlBody = value.ToString();
                }
            }

            if (result.HtmlBody == null && result.TextBody == null)
            {
                if (data.ContainsKey("body"))
                {
                    var value = data["body"];
                    if (value != null)
                    {
                        result.HtmlBody = value.ToString();
                    }
                }
            }


            if (result.To == null || result.To.Count() == 0 || result.From == null)
            {
                return(null);
            }

            if (result.HtmlBody == null && result.TextBody == null)
            {
                return(null);
            }

            if (result.Subject == null)
            {
                result.Subject = "undefined";
            }

            return(result);
        }
Esempio n. 2
0
File: Mail.cs Progetto: xhute/Kooboo
        private bool isLocalFromAddress(MailObject mailobj)
        {
            var from = Kooboo.Mail.Utility.AddressUtility.GetAddress(mailobj.From);

            return(Kooboo.Mail.Utility.AddressUtility.IsLocalEmailAddress(from));
        }