protected override string getAllMessagesFlag(MailFlag flag, out IEnumerable <int> mailIds) { Trace(new TraceEventArg(() => "ImapClient::GetAllMessagesFlag > Entry")); Trace(new TraceEventArg(() => "ImapClient::GetAllMessagesFlag > Calling SendCommand")); mailIds = new List <int>(); _response = SendCommandGetResponse(FETCH + " 1:* FLAGS", true); if (!_response.StartsWith("Error:")) { while (_response.StartsWith("*")) { Match m = Regex.Match(_response, "\\* (\\d+) FETCH \\((.*)\\)"); if (m.Success) { var mailId = Convert.ToInt32(m.Groups[1].Value); var seenFlag = m.Groups[2].Value.ToLower(); switch (flag) { case MailFlag.All: ((List <int>)mailIds).Add(mailId); break; case MailFlag.Seen: if (seenFlag.Contains("\\seen")) { ((List <int>)mailIds).Add(mailId); } break; case MailFlag.Unseen: if (!seenFlag.Contains("\\seen")) { ((List <int>)mailIds).Add(mailId); } break; } } _response = GetResponse(true); } if (isSuccess(_response)) { _response = string.Empty; } } // check error handling return(_response); }
protected override string getAllMessagesFlag(MailFlag flag, out IEnumerable<int> mailIds) { Trace(new TraceEventArg(() => "ImapClient::GetAllMessagesFlag > Entry")); Trace(new TraceEventArg(() => "ImapClient::GetAllMessagesFlag > Calling SendCommand")); mailIds = new List<int>(); _response = SendCommandGetResponse(FETCH + " 1:* FLAGS", true); if (!_response.StartsWith("Error:")) { while (_response.StartsWith("*")) { Match m = Regex.Match(_response, "\\* (\\d+) FETCH \\((.*)\\)"); if (m.Success) { var mailId = Convert.ToInt32(m.Groups[1].Value); var seenFlag = m.Groups[2].Value.ToLower(); switch (flag) { case MailFlag.All: ((List<int>)mailIds).Add(mailId); break; case MailFlag.Seen: if (seenFlag.Contains("\\seen")) ((List<int>)mailIds).Add(mailId); break; case MailFlag.Unseen: if (!seenFlag.Contains("\\seen")) ((List<int>)mailIds).Add(mailId); break; } } _response = GetResponse(true); } if (isSuccess(_response)) _response = string.Empty; } // check error handling return _response; }
protected override string getAllMessagesFlag(MailFlag flag, out IEnumerable <int> mailIds) { Trace(new TraceEventArg(() => "POP3::GetAllMessagesFlag > Entry")); mailIds = new List <int>(); _response = SendCommandGetResponse(LIST, false); if (isSuccess(_response)) { while ((_response = GetResponse()) != ".") { Match m = Regex.Match(_response, @"(\d+)\s(\d+)"); if (!m.Success) { continue; } int number = Convert.ToInt32(m.Groups[1].Value); ((IList <int>)mailIds).Add(number); } _response = string.Empty; } Trace(new TraceEventArg(() => $"POP3::GetAllMessagesFlag > Exit with _response as: {_response}")); return(_response); }
private void Pop3Client_GetMessageFlags_Test(string input, MailFlag flag, int totalIndexCount, int[] indexes, string expected) { IEnumerable<int> outMailboxes = null; var dict = new Dictionary<TcpCommand, string>(); dict.Add(TcpCommand.LIST, input); using (var stream = new Pop3Stream(dict)) { var client = GetMailClient(stream); var result = client.GetAllMessagesFlag(flag, out outMailboxes); Assert.Equal(expected, result); Assert.Equal(totalIndexCount, outMailboxes.Count()); Assert.True(CompareMailIndexes(indexes, outMailboxes)); } }
protected abstract string getAllMessagesFlag(MailFlag flag, out IEnumerable<int> mailIds);
public string GetAllMessagesFlag(MailFlag flag, out IEnumerable<int> mailIds, string mailbox = "Inbox") { selectMailbox(mailbox); return getAllMessagesFlag(flag, out mailIds); }
public string GetAllMessageFlags(MailFlag flag, out IEnumerable <int> mailIndexes, string mailbox = "Inbox") { selectMailbox(mailbox); return(getAllMessagesFlag(flag, out mailIndexes)); }
protected abstract string getAllMessagesFlag(MailFlag flag, out IEnumerable <int> mailIds);
protected override string getAllMessagesFlag(MailFlag flag, out IEnumerable<int> mailIds) { Trace(new TraceEventArg(() => "POP3::GetAllMessagesFlag > Entry")); mailIds = new List<int>(); _response = SendCommandGetResponse(LIST, false); if (isSuccess(_response)) { while ((_response = GetResponse()) != ".") { Match m = Regex.Match(_response, @"(\d+)\s(\d+)"); if (!m.Success) continue; int number = Convert.ToInt32(m.Groups[1].Value); ((IList<int>)mailIds).Add(number); } _response = string.Empty; } Trace(new TraceEventArg(() => $"POP3::GetAllMessagesFlag > Exit with _response as: {_response}")); return _response; }
/// <summary> /// Mail constructor /// </summary> /// <param name="mailId">Mail ID in database</param> public Mail(int mailId) { _mailId = mailId; var si = new SqlIntegrate(ConnStr); si.AddParameter("@messageid", SqlIntegrate.DataType.Int, mailId); var mailInfo = si.Reader("SELECT * FROM hm_messages WHERE messageid = @messageid"); si.ResetParameter(); si.AddParameter("@messageid", SqlIntegrate.DataType.Int, mailId); Username = si.Query("DECLARE @uid int; SELECT @uid = messageaccountid FROM hm_messages WHERE messageid = @messageid; SELECT accountaddress FROM hm_accounts WHERE accountid = @uid;").ToString().Split('@')[0]; /* The eml file is storage in this way: * * When hmailserver receives an email, it writes information in database and stores the eml file. * * [A] = Hmailserver data path (need to set mailStoragePath in Web.config) * * [B] = Domain name (SAAO.Mail.mailDomain, need to set mailDomainName in Web.config) * * [C] = Username (without domain name, "szhang140" for example) * * [D] = Initial two characters (contain no open brace '{') of eml file name (store in [messagefilename] in database) * * [E] = Eml file name * * [F] = [A] \ [B] \ [C] \ [D] \ [E] ("D:\Mail_Data\xuehuo.org\szhang140\1B\{1B961C98-4FC8-40E3-BC8E-FA5A1D374381}.eml" for example) * * [F] is the absolute path to eml file. */ _emlPath = _mailPath + Username + @"\" + mailInfo["messagefilename"].ToString().Substring(1, 2) + @"\" + mailInfo["messagefilename"]; _message = ReadEml(_emlPath); Flag = (MailFlag)Convert.ToInt32(mailInfo["messageflags"]); Subject = _message.Subject; // Remove '<' and '>' From = new MailAddress( name: _message.From.Split('<')[0].Trim(), mail: _message.From.Split('<')[1].Replace(">", "").Trim() ); var toCount = _message.To.Trim().Split(',').Length; To = new List<MailAddress>(); for (var i = 0; i < toCount; i++) To.Add(new MailAddress( name: _message.To.Split(',')[i].Split('<')[0].Trim(), mail: _message.To.Split(',')[i].Split('<')[1].Replace(">","").Trim() )); SentOn = _message.SentOn; AttachmentCount = _message.Attachments.Count; }
/// <summary> /// Set a new flag of the mail /// </summary> /// <param name="newflag">New flag</param> public void SetFlag(MailFlag newflag) { var si = new SqlIntegrate(ConnStr); si.AddParameter("@messageflags", SqlIntegrate.DataType.Int, (int)newflag); si.AddParameter("@messageid", SqlIntegrate.DataType.Int, _mailId); si.Execute("UPDATE hm_messages SET messageflags = @messageflags WHERE messageid = @messageid"); Flag = newflag; }