public IEnumerable<ImapMessage> FetchMessages(long beginUid, long endUid, ImapFetchOption option, IEnumerable<string> extensionParameterNames) { List<KeyValuePair<Exception, string>> parseFailureLines = new List<KeyValuePair<Exception, string>>(); List<ImapMessage> messages = new List<ImapMessage>(); StringBuilder commandBuilder = new StringBuilder("UID FETCH "); commandBuilder.Append(FormatSequence(beginUid, endUid)); commandBuilder.Append(" (UID"); if ((option & ImapFetchOption.Envelope) != 0) { commandBuilder.Append(" ENVELOPE"); } if ((option & ImapFetchOption.Flags) != 0) { commandBuilder.Append(" FLAGS"); } if ((option & ImapFetchOption.BodyStructure) != 0) { commandBuilder.Append(" BODYSTRUCTURE"); } if (null != extensionParameterNames) { foreach (var paramName in extensionParameterNames) { commandBuilder.Append(" "); commandBuilder.Append(paramName.Trim()); } } commandBuilder.Append(')'); SendReceiveResult result = SendReceive(commandBuilder.ToString()); if (result.Status == SendReceiveStatus.OK) { SafeEnumerateLines(result.Lines, (line) => { ImapList list = ImapList.Parse(line); if (list.GetStringAt(0) == "*" && list.GetStringAt(2) == "FETCH" && list.IsStringAt(1) && list.IsListAt(3)) { messages.Add(new ImapMessage(long.Parse(list.GetStringAt(1)), list.GetListAt(3), extensionParameterNames)); } return true; }); } else if (result.Status == SendReceiveStatus.Bad) { throw new InvalidOperationException(); } return messages; }
public IEnumerable<ImapMessage> FetchMessages(long beginUid, long endUid, ImapFetchOption option) { return FetchMessages(beginUid, endUid, option, null); }