예제 #1
0
파일: HMail.cs 프로젝트: hanwest00/HXMail
        /// <summary>
        /// 返回获取到的邮件条目
        /// </summary>
        /// <param name="start">起始号</param>
        /// <param name="end">结束号</param>
        /// <returns>编号,标题,发件人,收件人</returns>
        public IList <HMailInfo> GetMailInfo(int start, int end, ShortOrWhole type)
        {
            if (PopAccessed)
            {
                if (mailCount > 0)
                {
                    //for (int i = mailCount - start; i >= mailCount - end; i--)
                    //for (int i = 26; i >= mailCount - end; i--)
                    for (int i = start; i <= end; i++)
                    {
                        //i = 183;
                        try
                        {
                            currentMailId = i;
                            if (i == mailCount || i == 0)
                            {
                                // GetMailInfoById(i);
                                continue;
                            }
                            listMsg.Add(GetMailInfoById(i, type));
                        }
                        catch (Exception ex)
                        {
                            throw new Exception(string.Format("{0}{1}{2}", ex.ToString(), "\r\n error message id:", i));
                        }
                    }
                }
            }

            return(listMsg);
        }
예제 #2
0
파일: HMail.cs 프로젝트: hanwest00/HXMail
        //获得单条邮件
        public HMailInfo GetMailInfoById(int id, ShortOrWhole type)
        {
            try
            {
                //for test
                id = 2;

                HMailInfo mailInfo = new HMailInfo();
                string    cmd      = "top " + id.ToString() + " 50";
                if (type == ShortOrWhole.Whole)
                {
                    cmd = "retr " + id.ToString();
                }
                result       = ExcuteMailCommand(cmd, Encoding.UTF8);
                mailEncoding = "UTF-8";

                //if (!(result.Contains("charset=\"UTF-8\"") || result.Contains("charset=\"utf-8\"") || result.Contains("charset=utf-8") || result.Contains("charset=UTF-8")))
                //GetMailEncoding(cmd);
                mailInfo.MailId = id;
                string _partten = "((?=References:)|(?=MIME-Version:)|(?=Mime-version:)|(?=Mime-Version:)|(?=Message-ID:)|(?=Message-Id:)|(?=Date:)|(?=date:)|(?=Content-Type:)|(?=content-type:)|(?=--)|(?=To:)|(?=to:)|(?=TO:)|(?=Subject:)|(?=subject:)|(?=SUBJECT:)|(?=Cc:)|(?=CC:)|(?=cc:)|(?=From:)|(?=from:)|(?=FROM:)|(?=X-Originating-IP:)|(?=X-Coremail-Antispam:)|(?=Sender:)|(?=Reply-To:)|(?=Reply-to)|(?=X-Mailer:)|(?=X-Priority:)|(?=\r\n\r\n))";
                mailInfo.To   = GetAddress(MatchAndDecodeMail(result, string.Format(@"((?<=\r\nTo:)|(?<=\r\nTO:)|(?<=\r\nto:))[\s\S]*?{0}", _partten)));
                mailInfo.From = GetAddress(MatchAndDecodeMail(result, string.Format(@"((?<=\r\nFrom:)|(?<=\r\nfrom:)|(?<=\r\nFROM:))[\s\S]*?{0}", _partten)))[0];

                mailInfo.Cc      = GetAddress(MatchAndDecodeMail(result, string.Format(@"((?<=\r\nCc:)|(?<=\r\nCC:)|(?<=\r\ncc:))[\s\S]*?{0}", _partten)));
                mailInfo.SubJect = MatchAndDecodeMail(result, string.Format(@"((?<=\r\nSubject:)|(?<=\r\nsubject:)|(?<=\r\nSUBJECT:))[\s\S]*?{0}", _partten));
                mailInfo.Date    = MatchAndDecodeMail(result, string.Format(@"((?<=\r\nDate:)|(?<=\r\ndate:))[\s\S]*?{0}", _partten));
                if (type == ShortOrWhole.Whole)
                {
                    IList <HMailAttachmentInfo> mailMentInfo = new List <HMailAttachmentInfo>();
                    mailInfo.ContentInfo = GetMailContent(result, ref mailMentInfo);
                    mailInfo.Attachments = mailMentInfo;
                }
                GetOneMailEvent();
                return(mailInfo);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #3
0
파일: HMail.cs 프로젝트: hanwest00/HXMail
        //获得单条邮件
        public HMailInfo GetMailInfoById(int id, ShortOrWhole type)
        {
            try
            {
                //for test
                id = 2;

                HMailInfo mailInfo = new HMailInfo();
                string cmd = "top " + id.ToString() + " 50";
                if (type == ShortOrWhole.Whole)
                    cmd = "retr " + id.ToString();
                result = ExcuteMailCommand(cmd, Encoding.UTF8);
                mailEncoding = "UTF-8";

                //if (!(result.Contains("charset=\"UTF-8\"") || result.Contains("charset=\"utf-8\"") || result.Contains("charset=utf-8") || result.Contains("charset=UTF-8")))
                    //GetMailEncoding(cmd);
                mailInfo.MailId = id;
                string _partten = "((?=References:)|(?=MIME-Version:)|(?=Mime-version:)|(?=Mime-Version:)|(?=Message-ID:)|(?=Message-Id:)|(?=Date:)|(?=date:)|(?=Content-Type:)|(?=content-type:)|(?=--)|(?=To:)|(?=to:)|(?=TO:)|(?=Subject:)|(?=subject:)|(?=SUBJECT:)|(?=Cc:)|(?=CC:)|(?=cc:)|(?=From:)|(?=from:)|(?=FROM:)|(?=X-Originating-IP:)|(?=X-Coremail-Antispam:)|(?=Sender:)|(?=Reply-To:)|(?=Reply-to)|(?=X-Mailer:)|(?=X-Priority:)|(?=\r\n\r\n))";
                mailInfo.To = GetAddress(MatchAndDecodeMail(result, string.Format(@"((?<=\r\nTo:)|(?<=\r\nTO:)|(?<=\r\nto:))[\s\S]*?{0}", _partten)));
                mailInfo.From = GetAddress(MatchAndDecodeMail(result, string.Format(@"((?<=\r\nFrom:)|(?<=\r\nfrom:)|(?<=\r\nFROM:))[\s\S]*?{0}", _partten)))[0];

                mailInfo.Cc = GetAddress(MatchAndDecodeMail(result, string.Format(@"((?<=\r\nCc:)|(?<=\r\nCC:)|(?<=\r\ncc:))[\s\S]*?{0}", _partten)));
                mailInfo.SubJect = MatchAndDecodeMail(result, string.Format(@"((?<=\r\nSubject:)|(?<=\r\nsubject:)|(?<=\r\nSUBJECT:))[\s\S]*?{0}", _partten));
                mailInfo.Date = MatchAndDecodeMail(result, string.Format(@"((?<=\r\nDate:)|(?<=\r\ndate:))[\s\S]*?{0}", _partten));
                if (type == ShortOrWhole.Whole)
                {
                    IList<HMailAttachmentInfo> mailMentInfo = new List<HMailAttachmentInfo>();
                    mailInfo.ContentInfo = GetMailContent(result, ref mailMentInfo);
                    mailInfo.Attachments = mailMentInfo;
                }
                GetOneMailEvent();
                return mailInfo;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #4
0
파일: HMail.cs 프로젝트: hanwest00/HXMail
        /// <summary>
        /// 返回获取到的邮件条目
        /// </summary>
        /// <param name="start">起始号</param>
        /// <param name="end">结束号</param>
        /// <returns>编号,标题,发件人,收件人</returns>
        public IList<HMailInfo> GetMailInfo(int start, int end, ShortOrWhole type)
        {
            if (PopAccessed)
            {

                if (mailCount > 0)
                {
                    //for (int i = mailCount - start; i >= mailCount - end; i--)
                    //for (int i = 26; i >= mailCount - end; i--)
                    for (int i = start; i <= end; i++)
                    {
                        //i = 183;
                        try
                        {
                            currentMailId = i;
                            if (i == mailCount || i == 0)
                            {
                                // GetMailInfoById(i);
                                continue;
                            }
                            listMsg.Add(GetMailInfoById(i, type));
                        }
                        catch (Exception ex)
                        {
                            throw new Exception(string.Format("{0}{1}{2}", ex.ToString(), "\r\n error message id:", i));
                        }
                    }
                }

            }

            return listMsg;
        }