示例#1
0
        // Обработка сообщения для вывода списка сообщений
        private void ParseEmailForHeader(string email)
        {
            this.from    = "";
            this.subject = "";
            this.date    = "";

            string emailInLowerCase  = email.ToLower();
            int    index_mime        = 0;
            int    index_Termination = 0;

            // Отправитель
            index_mime = emailInLowerCase.IndexOf("from: ", 0);
            if (index_mime != -1)
            {
                index_Termination = email.IndexOf("\r\n", index_mime + 5);
                this.from         = email.Substring(index_mime + 5, index_Termination - (index_mime + 5)).Trim();
                this.from         = MailDecoder.DecodeEncodedString(this.from);
            }

            // Тема
            index_mime = emailInLowerCase.IndexOf("subject: ", 0);
            if (index_mime != -1)
            {
                index_Termination = email.IndexOf("\r\n", index_mime + 8);
                this.subject      = email.Substring(index_mime + 8, index_Termination - (index_mime + 8)).Trim();
                this.subject      = MailDecoder.DecodeEncodedString(this.subject);
            }

            // Дата
            index_mime = emailInLowerCase.IndexOf("date: ", 0);
            if (index_mime != -1)
            {
                index_Termination = email.IndexOf("\r\n", index_mime + 5);
                this.date         = email.Substring(index_mime + 5, index_Termination - (index_mime + 5)).Trim();
            }
        }
示例#2
0
        // Обработка сообщения для вывода
        private void FetchEmailCallBack()
        {
            try
            {
                this.email = this.pop.FetchEmail(this.msg_id);
                this.UpdatePopMessageHeader(this.pop.From, this.pop.To, this.pop.Subject);

                string content                    = "";
                string content_type               = "";
                string attached_file_name         = "";
                bool   isHtmlIncluded             = false;
                int    plain_text_message_section = -1;

                for (int i = 1; i <= this.pop.MailSections; i++)
                {
                    this.pop.GetMailSection(i, ref content, ref content_type, ref attached_file_name);

                    if (content_type.ToLower().Equals("text/html"))
                    {
                        try
                        {
                            content = Encoding.GetEncoding("utf-8").GetString(Encoding.GetEncoding("windows-1251").GetBytes(content));

                            content = MailDecoder.DecodeEncodedString(content.Trim());

                            var occurences = new Regex(@"=[0-9A-Z]{2}", RegexOptions.Multiline);
                            var matches    = occurences.Matches(content);
                            foreach (Match match in matches)
                            {
                                char hexChar = (char)Convert.ToInt32(match.Groups[0].Value.Substring(1), 16);
                                content = content.Replace(match.Groups[0].Value, hexChar.ToString());
                            }
                            content.Replace("=\r\n", "");
                        }
                        catch
                        {
                        }

                        this.WritePopMessage(content);
                        isHtmlIncluded = true;
                    }
                    else if (content_type.ToLower().Equals("base64"))
                    {
                        ListViewItem item = new ListViewItem(attached_file_name);
                        item.ImageIndex = 0;
                    }
                    else if (content_type.ToLower().Equals("text/plain"))
                    {
                        plain_text_message_section = i;
                    }
                }

                if (isHtmlIncluded == false && plain_text_message_section != -1)
                {
                    this.pop.GetMailSection(plain_text_message_section, ref content, ref content_type, ref attached_file_name);
                    this.WritePopMessage(content);
                }
            }
            catch (Pop3ClientException err)
            {
                MessageBox.Show(err.ErrorMessage, "EnergyMailClient", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#3
0
        // Обработка сообщения для вывода
        private void ParseEmail(string email)
        {
            string emailInLowerCase  = email.ToLower();
            int    index_mime        = 0;
            int    index_Termination = 0;

            this.from        = "";
            this.to          = "";
            this.subject     = "";
            this.date        = "";
            this.mimeVersion = "";
            this.boundry.Clear();
            this.mailType.Clear();
            this.mailSections.Clear();

            // Отправитель
            index_mime = emailInLowerCase.IndexOf("from: ", 0);
            if (index_mime != -1)
            {
                index_Termination = email.IndexOf("\r\n", index_mime + 5);
                this.from         = email.Substring(index_mime + 5, index_Termination - (index_mime + 5)).Trim();
                this.from         = MailDecoder.DecodeEncodedString(this.from);
            }

            // Получатель
            index_mime = emailInLowerCase.IndexOf("to: ", 0);
            if (index_mime != -1)
            {
                index_Termination = email.IndexOf("\r\n", index_mime + 3);
                this.to           = email.Substring(index_mime + 3, index_Termination - (index_mime + 3)).Trim();
                this.to           = MailDecoder.DecodeEncodedString(this.to);
            }

            // Тема
            index_mime = emailInLowerCase.IndexOf("subject: ", 0);
            if (index_mime != -1)
            {
                index_Termination = email.IndexOf("\r\n", index_mime + 8);
                this.subject      = email.Substring(index_mime + 8, index_Termination - (index_mime + 8)).Trim();
                this.subject      = MailDecoder.DecodeEncodedString(this.subject);
            }

            // Дата
            index_mime = emailInLowerCase.IndexOf("date: ", 0);
            if (index_mime != -1)
            {
                index_Termination = email.IndexOf("\r\n", index_mime + 5);
                this.date         = email.Substring(index_mime + 5, index_Termination - (index_mime + 5)).Trim();
            }

            // MIME-версия
            index_mime = emailInLowerCase.IndexOf("mime-version: ", 0);
            if (index_mime != -1)
            {
                index_Termination = email.IndexOf("\r\n", index_mime + 13);
                this.mimeVersion  = email.Substring(index_mime + 13, index_Termination - (index_mime + 13)).Trim();
            }

            // Разделитель частей сообщения
            index_mime = emailInLowerCase.IndexOf("boundary=", 0);
            string temp = "";

            for (; index_mime != -1; index_mime = emailInLowerCase.IndexOf("boundary=", index_Termination + 1))
            {
                index_Termination = emailInLowerCase.IndexOf("\r\n", index_mime + 9);
                temp = email.Substring(index_mime + 9, index_Termination - (index_mime + 9));
                temp = temp.TrimStart(new char[] { '"' });
                temp = temp.TrimEnd(new char[] { '"' });
                this.boundry.Add("--" + temp);
            }

            // Тип содержимого
            index_mime = emailInLowerCase.IndexOf("\r\ncontent-type:", 0);
            string substring = "";

            while (index_mime != -1)
            {
                substring         = "";
                index_Termination = emailInLowerCase.IndexOf("\r\n\r\n", index_mime + 15);

                if (index_Termination == -1)
                {
                    break;
                }
                substring = email.Substring(index_mime + 15, index_Termination - (index_mime + 15));

                if (substring.ToLower().IndexOf("text/html", 0) != -1)
                {
                    this.mailType.Add("text/html");
                }
                else if (substring.ToLower().IndexOf("base64", 0) != -1)
                {
                    this.mailType.Add("base64");
                    int index1 = substring.ToLower().IndexOf("name=", 0);
                    int index2 = substring.IndexOf("\r\n", index1 + 5);
                }
                else if (substring.ToLower().IndexOf("text/plain", 0) != -1)
                {
                    this.mailType.Add("text/plain");
                }
                else
                {
                    this.mailType.Add("");
                }

                index_Termination += 4;
                int index = emailInLowerCase.IndexOf("\r\ncontent-type:", index_Termination);
                if (index != -1)
                {
                    substring = email.Substring(index_Termination, index - index_Termination);
                }
                else
                {
                    substring = email.Substring(index_Termination);
                }

                this.mailSections.Add(substring);

                if (index != -1)
                {
                    index_mime = index;
                }
                else
                {
                    index_mime = -1;
                }
            }

            if (this.boundry.Count > 0)
            {
                for (int i = 0; i < this.boundry.Count; i++)
                {
                    for (int j = 0; j < this.mailSections.Count; j++)
                    {
                        index_mime = this.mailSections[j].ToString().IndexOf(this.boundry[i].ToString(), 0);

                        if (index_mime != -1)
                        {
                            if (index_mime != 0)
                            {
                                this.mailSections[j] = this.mailSections[j].ToString().Substring(0, index_mime - 1);
                            }
                            else
                            {
                                this.mailSections[j] = "";
                            }
                        }
                    }
                }
            }
        }