Exemplo n.º 1
0
        public static string RestoreHtmlOrText(User user, int MsgId)
        {
            var    maildb = Kooboo.Mail.Factory.DBFactory.UserMailDb(user);
            string body   = maildb.Messages.GetContent(MsgId);

            if (string.IsNullOrEmpty(body))
            {
                return(null);
            }

            var mine = MessageUtility.ParseMineMessage(body);

            if (mine == null)
            {
                return(null);
            }

            string html = MessageUtility.GetHtmlBody(mine);

            if (html != null)
            {
                return(Kooboo.Mail.Multipart.BodyComposer.RestoreInlineImages(html, user, MsgId));
            }

            html = MessageUtility.GetTextBody(mine);
            if (!string.IsNullOrEmpty(html))
            {
                return("<pre>" + html + "</pre>");
            }

            int index = body.IndexOf("\r\n\r\n");

            if (index > 0)
            {
                return("<pre>" + body.Substring(index + 2) + "</pre>");
            }
            else
            {
                return("<pre>" + body + "</pre>");
            }
        }
Exemplo n.º 2
0
        // For forward type email address.
        public static string ComposeForwardAddressMessage(string MessageSource)
        {
            string kforwardheader = "x-kforward";

            var newbody = GetMessageBodyPart(ref MessageSource);

            if (string.IsNullOrEmpty(newbody))
            {
                return(null);
            }
            // recompose the email header...
            var mime          = Mail.Utility.MessageUtility.ParseMineMessage(MessageSource);
            var forwardheader = MessageUtility.GetHeaderValue(mime, kforwardheader);

            if (!string.IsNullOrEmpty(forwardheader))
            {
                return(null);
            }

            Dictionary <string, string> headers = new Dictionary <string, string>();

            string prefix = "(Forwarded By Kooboo)";

            var From = MessageUtility.GetHeaderValue(mime, "From");

            if (From.Contains(prefix))
            {
                return(null);
            }

            var to      = MessageUtility.GetHeaderValue(mime, "To");
            var subject = MessageUtility.GetHeaderValue(mime, "Subject");

            string fromaddress = Utility.AddressUtility.GetAddress(From);

            From = "\"" + prefix + "\"<" + fromaddress + ">";

            headers.Add("From", From);
            headers.Add("to", to);
            headers.Add("subject", subject);

            if (mime.ContentType != null && !string.IsNullOrEmpty(mime.ContentType.ValueToString()))
            {
                headers.Add("Content-Type", mime.ContentType.ValueToString());
            }

            if (!string.IsNullOrEmpty(mime.ContentTransferEncoding))
            {
                headers.Add("Content-Transfer-Encoding", mime.ContentTransferEncoding);
            }

            if (!string.IsNullOrEmpty(mime.MimeVersion))
            {
                headers.Add("MIME-Version", mime.MimeVersion);
            }

            List <string> optionalFields = new List <string>();

            //optionalFields.Add("Content-Type");
            //optionalFields.Add("MIME-Version");
            //optionalFields.Add("Content-Transfer-Encoding");
            optionalFields.Add("Charset");

            foreach (var item in optionalFields)
            {
                var optionValue = MessageUtility.GetHeaderValue(mime, item);
                if (!string.IsNullOrEmpty(optionValue))
                {
                    headers.Add(item, optionValue);
                }
            }

            var newheader = Multipart.HeaderComposer.Compose(headers);

            return(newheader + "\r\n" + newbody);
        }