Example #1
0
        /// <summary>
        /// 获取本地已下载的邮件信息
        /// </summary>
        /// <param name="startDate">晚于指定的接收日期的邮件</param>
        /// <param name="endDate">早于指定接收日期的邮件</param>
        /// <param name="titleKeywords">邮件标题中的关键词</param>
        /// <param name="isDelete">是否删除不满足条件的本地邮件</param>
        /// <returns></returns>
        public List <EmailDataInfo> GetDownloadMailDataInfos(DateTime?startDate = null, DateTime?endDate = null, String[] titleKeywords = null, Boolean isDelete = false)
        {
            List <EmailDataInfo> dataInfos = new List <EmailDataInfo>();

            if (!Directory.Exists(this.DownloadFloder))
            {
                return(dataInfos);
            }
            var fileNames = Directory.GetFiles(this.DownloadFloder, "*" + MailFileExt);

            if (fileNames.Length <= 0)
            {
                return(dataInfos);
            }
            foreach (var filename in fileNames)
            {
                Mail mail = new Mail(LicenseCode);
                try
                {
                    mail.Load(filename, true);
                    var infoFilePath = filename + MailInfoFileExt;
                    if (startDate.HasValue)
                    {
                        if (mail.ReceivedDate < startDate)
                        {
                            if (isDelete)
                            {
                                goto DELTE;
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }

                    if (endDate.HasValue)
                    {
                        if (mail.ReceivedDate > endDate && isDelete)
                        {
                            if (isDelete)
                            {
                                goto DELTE;
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }

                    if (titleKeywords != null && titleKeywords.Length > 0)
                    {
                        if (!this.AccordTitleKeywords(mail.Subject, titleKeywords))
                        {
                            if (isDelete)
                            {
                                goto DELTE;
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                    MailInfo info = null;
                    if (File.Exists(infoFilePath))
                    {
                        info = DataSerializer.Deserialize <MailInfo>(infoFilePath);
                    }
                    else
                    {
                        info = new MailInfo();
                        var uldl = Path.GetFileNameWithoutExtension(filename);
                        info.UIDL = uldl;
                    }
                    EmailDataInfo dataInfo = new EmailDataInfo();
                    this.BuildEmailDataInfo(dataInfo, mail, info);
                    dataInfo.IsDownloadedMail = true;
                    dataInfos.Add(dataInfo);
                    continue;
DELTE:
                    this.DeleteDownloadMail(filename, infoFilePath);
                }
                catch
                { }
            }
            return(dataInfos);
        }