public MailJsonSerializer(string description, MailStructure[] mailStructures) { this._description = description; this._mailStructures = mailStructures; }
public MailStructure[] GetMessages(string datefrom = "", string dateto = "", string email = "", int limit = 0, int exitAttachment = 0) { if (this.ic == null) throw new Exception("IMAP connection isn't init"); if (limit == 0) limit = 100; DateTime dateFrom = new DateTime(2000, 1, 1); DateTime dateTo = new DateTime(5000, 1, 1); int currentCount = 0; if (datefrom != String.Empty) dateFrom = new DateTime(Int32.Parse(datefrom.Substring(1, 4)), Int32.Parse(datefrom.Substring(5, 2)), Int32.Parse(datefrom.Substring(7, 2))); if (dateto != String.Empty) dateTo = new DateTime(Int32.Parse(dateto.Substring(1, 4)), Int32.Parse(dateto.Substring(5, 2)), Int32.Parse(dateto.Substring(7, 2))); int mc = this.ic.GetMessageCount(); this.ic.IdleTimeout = 0; List<MailStructure> result = new List<MailStructure>(); int startIndex = (mc - limit < 0 ? 0 : mc - limit); MailMessage[] mm = ic.GetMessages(startIndex, mc -1, false);//(mc-limit-1, limit); int i = 0; //for (int i = mc; i >= 1; i--) foreach (MailMessage m in mm) { bool searchStatus = true; if ((exitAttachment > 0) && (m.Attachments.Count == 0)) searchStatus = false; if (searchStatus && (currentCount++ <= limit - 1)) { try { MailStructure ms = new MailStructure() { Id = i, MailDate = m.Date.ToString(), From = m.From.ToString(), Subject = m.Subject, Body = m.Body, Uuid = m.Uid, AttachmentExist = (m.Attachments.Count > 0) }; string att = ""; int attCnt = 1; foreach (AE.Net.Mail.Attachment attachment in m.Attachments) { if (att != "") att += ";"; att += attachment.Filename; } ms.AttachmentFiles = att; result.Add( ms ); } catch (Exception) { } } else { break; } } return result.ToArray(); }