Ejemplo n.º 1
0
        public static byte[] GetFileBinary(MIME_Message MimeMsg, string FileName)
        {
            if (MimeMsg == null)
            {
                return(null);
            }
            List <Mail.Models.Attachment> result = new List <Models.Attachment>();

            foreach (var item in MimeMsg.AllEntities)
            {
                if ((item.ContentDisposition != null && item.ContentDisposition.DispositionType != null && item.ContentDisposition.Param_FileName == FileName) ||
                    (item.ContentType != null && item.ContentType.Param_Name == FileName))
                {
                    var attachmentbody = item.Body as LumiSoft.Net.MIME.MIME_b_SinglepartBase;

                    if (attachmentbody != null)
                    {
                        if (attachmentbody.Data != null)
                        {
                            return(attachmentbody.Data);
                        }
                        else if (attachmentbody.EncodedData != null)
                        {
                            return(attachmentbody.EncodedData);
                        }
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 2
0
        internal static string ParseSummary(MIME_Message msg, int length = 150)
        {
            var htmlbody = GetHtmlBody(msg);

            if (htmlbody != null)
            {
                htmlbody = Kooboo.Search.Utility.RemoveHtml(htmlbody);
                htmlbody = htmlbody.Replace("\r\n\r\n", "\r\n");
                htmlbody = htmlbody.Replace("\t\t", "\t");
                htmlbody = htmlbody.Replace("  ", " ");
            }

            if (!string.IsNullOrEmpty(htmlbody) && htmlbody.Length > length - 50)
            {
                return(Lib.Helper.StringHelper.SementicSubString(htmlbody, 0, length));
            }

            string text = GetTextBody(msg);

            int htmllen = 0;

            if (htmlbody != null)
            {
                htmllen = htmlbody.Length;
            }

            if (!string.IsNullOrEmpty(text) && text.Length > htmllen)
            {
                return(Lib.Helper.StringHelper.SementicSubString(text, 0, length));
            }
            return(null);
        }
Ejemplo n.º 3
0
        public static List <Models.Attachment> ParseAttachment(MIME_Message MineMessage)
        {
            List <Mail.Models.Attachment> result = new List <Models.Attachment>();

            foreach (var item in MineMessage.AllEntities)
            {
                if (item.ContentDisposition != null && item.ContentDisposition.DispositionType != null && item.ContentDisposition.DispositionType.ToLower() == "attachment")
                {
                    var attachmentbody = item.Body as LumiSoft.Net.MIME.MIME_b_SinglepartBase;

                    if (attachmentbody != null)
                    {
                        Models.Attachment attach = new Models.Attachment();
                        attach.FileName = item.ContentDisposition.Param_FileName;
                        attach.Type     = item.ContentType.Type;
                        attach.SubType  = item.ContentType.SubType;

                        long size = item.ContentDisposition.Param_Size;

                        if (size <= 0)
                        {
                            var x = item.Body as LumiSoft.Net.MIME.MIME_b_SinglepartBase;
                            size = x.Data.Length;
                        }
                        attach.Size = size;

                        if (!string.IsNullOrEmpty(attach.FileName) && attach.Size > 0)
                        {
                            result.Add(attach);
                        }
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 4
0
        private static DateTime GetSentDate(MIME_Message msg)
        {
            var value = GetHeaderValue(msg, "date");

            if (value != null)
            {
                return(LumiSoft.Net.MIME.MIME_Utils.ParseRfc2822DateTime(value).ToUniversalTime());
            }
            return(DateTime.UtcNow);
        }
Ejemplo n.º 5
0
        private static string GetHeader(MIME_Message msg, string header)
        {
            string value = MessageUtility.GetHeaderValue(msg, header);

            if (header.ToLower() == "from" || header.ToLower() == "to")
            {
                value = value.Replace("\"", "");
                value = value.Replace("'", "");
            }
            return(value);
        }
Ejemplo n.º 6
0
        public static string ComposeHeader(MIME_Message mime, RenderContext context)
        {
            string result = "<br/><br/><hr/><div color=\"#000000\" style=\"font-size:12px;background:#efefef;padding:8px;\">\r\n";

            result += "<b>" + Hardcoded.GetValue("From", context) + "</b>: " + GetHeader(mime, "from") + "</br>\r\n";
            result += "<b>" + Hardcoded.GetValue("To", context) + "</b>: " + GetHeader(mime, "to") + "</br>\r\n";
            result += "<b>" + Hardcoded.GetValue("Subject", context) + "</b>: " + GetHeader(mime, "subject") + "</br>\r\n";
            result += "<b>" + Hardcoded.GetValue("Date", context) + "</b>: " + GetHeader(mime, "date") + "</br>\r\n";
            result += "</div><div>{{htmlbody}}</div>";
            return(result);
        }
Ejemplo n.º 7
0
 public static Kooboo.Mail.Message ParseMeta(MIME_Message MimeMsg)
 {
     Kooboo.Mail.Message message = new Message();
     message.From          = GetHeaderValue(MimeMsg, "from");
     message.To            = GetHeaderValue(MimeMsg, "to");
     message.SmtpMessageId = GetHeaderValue(MimeMsg, "Message-Id");
     message.Subject       = GetHeaderValue(MimeMsg, "subject");
     message.Date          = GetSentDate(MimeMsg);
     message.Attachments   = ParseAttachment(MimeMsg);
     message.Summary       = ParseSummary(MimeMsg);
     return(message);
 }
Ejemplo n.º 8
0
        public static string GetHeaderValue(MIME_Message msg, string headername)
        {
            foreach (var item in msg.Header)
            {
                var header = item as MIME_h_Unstructured;

                if (header != null && Lib.Helper.StringHelper.IsSameValue(header.Name, headername))
                {
                    return(header.Value);
                }
            }
            return(null);
        }
Ejemplo n.º 9
0
 internal static string GetTextBody(MIME_Message MimeMsg)
 {
     foreach (var item in MimeMsg.AllEntities)
     {
         if (item.ContentType != null)
         {
             if (Lib.Helper.StringHelper.IsSameValue(item.ContentType.Type, "text") && Lib.Helper.StringHelper.IsSameValue(item.ContentType.SubType, "plain"))
             {
                 var btext = item.Body as MIME_b_Text;
                 if (btext != null)
                 {
                     return(btext.Text);
                 }
             }
         }
     }
     return(null);
 }
Ejemplo n.º 10
0
        private Mail_Message CreateMessage()
        {
            Mail_Message mail_Message = new Mail_Message();

            mail_Message.MimeVersion = "1.0";
            mail_Message.MessageID   = MIME_Utils.CreateMessageID();
            mail_Message.Date        = DateTime.Now;
            mail_Message.From        = Mail_h_MailboxList.Parse("From: " + this.m_pFrom.Text).Addresses;
            mail_Message.To          = new Mail_t_AddressList();
            mail_Message.To.Add(new Mail_t_Mailbox(this.m_pFolder.User.FullName, this.m_pFolder.User.FullName + "@localhost"));
            mail_Message.Subject = this.m_pSubject.Text;
            MIME_b_MultipartMixed mIME_b_MultipartMixed = new MIME_b_MultipartMixed(new MIME_h_ContentType(MIME_MediaTypes.Multipart.mixed)
            {
                Param_Boundary = Guid.NewGuid().ToString().Replace('-', '.')
            });

            mail_Message.Body = mIME_b_MultipartMixed;
            MIME_Entity mIME_Entity = new MIME_Entity();
            MIME_b_MultipartAlternative mIME_b_MultipartAlternative = new MIME_b_MultipartAlternative(new MIME_h_ContentType(MIME_MediaTypes.Multipart.alternative)
            {
                Param_Boundary = Guid.NewGuid().ToString().Replace('-', '.')
            });

            mIME_Entity.Body = mIME_b_MultipartAlternative;
            mIME_b_MultipartMixed.BodyParts.Add(mIME_Entity);
            MIME_Entity mIME_Entity2 = new MIME_Entity();
            MIME_b_Text mIME_b_Text  = new MIME_b_Text(MIME_MediaTypes.Text.plain);

            mIME_Entity2.Body = mIME_b_Text;
            mIME_b_Text.SetText(MIME_TransferEncodings.QuotedPrintable, Encoding.UTF8, this.m_pText.Text);
            mIME_b_MultipartAlternative.BodyParts.Add(mIME_Entity2);
            MIME_Entity mIME_Entity3 = new MIME_Entity();
            MIME_b_Text mIME_b_Text2 = new MIME_b_Text(MIME_MediaTypes.Text.html);

            mIME_Entity3.Body = mIME_b_Text2;
            mIME_b_Text2.SetText(MIME_TransferEncodings.QuotedPrintable, Encoding.UTF8, this.RtfToHtml());
            mIME_b_MultipartAlternative.BodyParts.Add(mIME_Entity3);
            foreach (ListViewItem listViewItem in this.m_pAttachments.Items)
            {
                mIME_b_MultipartMixed.BodyParts.Add(MIME_Message.CreateAttachment(listViewItem.Tag.ToString()));
            }
            return(mail_Message);
        }
Ejemplo n.º 11
0
        public static string ComposeRefMsg(MIME_Message mime, RenderContext context, int MsgId)
        {
            var bodywithheader = ComposeHeader(mime, context);

            string mailbody = MessageUtility.GetHtmlBody(mime);

            if (mailbody == null)
            {
                mailbody = MessageUtility.GetTextBody(mime);
            }

            if (mailbody == null)
            {
                mailbody = MessageUtility.GetAnyTextBody(mime);
            }

            string htmlbody = BodyComposer.RestoreInlineImages(mailbody, context.User, MsgId);

            return(bodywithheader.Replace("{{htmlbody}}", htmlbody));
        }