Beispiel #1
0
        public static Message FromComposeViewModel(ViewModel.ComposeViewModel model, User user)
        {
            Message msg = new Message();

            if (model.MessageId != null)
            {
                msg.Id = model.MessageId.Value;
            }
            msg.From      = GetFrom(model, user);
            msg.Cc        = ToAddress(model.Cc);
            msg.Bcc       = ToAddress(model.Bcc);
            msg.To        = ToAddress(model.To);
            msg.Subject   = model.Subject;
            msg.AddressId = model.From;
            msg.OutGoing  = true;

            if (model.Attachments != null && model.Attachments.Count > 0)
            {
                // fill in the attachment info.
                foreach (var item in model.Attachments)
                {
                    if (item.Size <= 0)
                    {
                        item.Size = Kooboo.Mail.MultiPart.FileService.GetSize(user, item.FileName);
                    }

                    if (string.IsNullOrEmpty(item.Type) || string.IsNullOrEmpty(item.SubType))
                    {
                        var mimetype = Kooboo.Lib.Compatible.CompatibleManager.Instance.Framework.GetMimeMapping(item.FileName);
                        int index    = mimetype.IndexOf("/");
                        if (index == -1)
                        {
                            index = mimetype.IndexOf("\\");
                        }

                        if (index > 0)
                        {
                            item.Type    = mimetype.Substring(0, index);
                            item.SubType = mimetype.Substring(index + 1);
                        }
                        else
                        {
                            item.Type = mimetype;
                        }
                    }

                    msg.Attachments.Add(item);
                }
            }

            return(msg);
        }
Beispiel #2
0
        public static string GetFrom(ViewModel.ComposeViewModel model, User user)
        {
            var orgdb     = Factory.DBFactory.OrgDb(user.CurrentOrgId);
            var dbaddress = orgdb.EmailAddress.Get(model.From);

            if (dbaddress != null)
            {
                if (!string.IsNullOrEmpty(user.FirstName) && !string.IsNullOrEmpty(user.LastName))
                {
                    return("\"" + user.FirstName + " " + user.LastName + "\"<" + dbaddress.Address + ">");
                }
                else
                {
                    return(dbaddress.Address);
                }
            }
            return(null);
        }
Beispiel #3
0
        public static ViewModel.ComposeViewModel ToComposeViewModel(Message message, User user)
        {
            ViewModel.ComposeViewModel model = new ViewModel.ComposeViewModel();

            var fromaddress = AddressUtility.GetAddress(message.From);
            var orgdb       = Factory.DBFactory.OrgDb(user.CurrentOrgId);
            var dbaddress   = orgdb.EmailAddress.Get(fromaddress);

            if (dbaddress != null)
            {
                model.From = dbaddress.Id;
            }
            model.Cc          = GetAddressList(message.Cc);
            model.Bcc         = GetAddressList(message.Bcc);
            model.To          = GetAddressList(message.To);
            model.Subject     = message.Subject;
            model.Attachments = message.Attachments;
            return(model);
        }
Beispiel #4
0
        public static string ComposeMessageBody(ViewModel.ComposeViewModel model, User user)
        {
            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers.Add("From", GetFrom(model, user));

            var to = model.To;

            to.AddRange(model.Cc);

            headers.Add("To", ToAddress(to));
            headers.Add("Subject", model.Subject);

            string strHeader = Kooboo.Mail.Multipart.HeaderComposer.Compose(headers);

            var bodycomposer = new Kooboo.Mail.Multipart.BodyComposer(model.Html, model.Attachments, user);

            return(strHeader + bodycomposer.Body());
        }