/* * The UID command has two forms. In the first form, it takes as its * arguments a COPY, FETCH, or STORE command with arguments * appropriate for the associated command. However, the numbers in * the sequence set argument are unique identifiers instead of * message sequence numbers. Sequence set ranges are permitted, but * there is no guarantee that unique identifiers will be contiguous... * * In the second form, the UID command takes a SEARCH command with * SEARCH command arguments. The interpretation of the arguments is * the same as with SEARCH; however, the numbers returned in a SEARCH * response for a UID SEARCH command are unique identifiers instead of message sequence numbers. */ public static void UID(string command, Connection connectionState) { var tag = command.Split(' ').First(); if (connectionState.SelectedState) { if (command.ToLower().Contains("fetch")) { if (IMAP_Fetch.TryFetch(command, connectionState, true)) { connectionState.SendToStream($"{tag} OK UID FETCH completed"); } } else if (command.ToLower().Contains("search")) { var commandParams = IMAP_Fetch.ParseFetchCommand(command); var messagesNums = IMAP_Search.Search(commandParams.Skip(1).ToArray(), connectionState); if (messagesNums.First() != -1) { string response = ""; foreach (var messageNum in messagesNums) { foreach (var message in connectionState.SelectedMailBox.EmailMessages) { if (message.MsgNum == messageNum) { response += $"{message.MessageId} "; break; } } } connectionState.SendToStream($"* SEARCH {response}"); connectionState.SendToStream($"{command[0]} OK UID completed"); } else { connectionState.SendToStream($"{command[0]} BAD - this command is not supported"); } } } else { connectionState.SendToStream($"{tag} BAD - command unknown or arguments invalid"); } }
/* * The FETCH command retrieves data associated with a message in the * mailbox. The data items to be fetched can be either a single atom * or a parenthesized list. * Most data items, identified in the formal syntax under the * msg-att-static rule, are static and MUST NOT change for any * particular message. Other data items, identified in the formal * syntax under the msg-att-dynamic rule, MAY change, either as a * result of a STORE command or due to external events. * For example, if a client receives an ENVELOPE for a * message when it already knows the envelope, it can * safely ignore the newly transmitted envelope. * There are three macros which specify commonly-used sets of data * items, and can be used instead of data items. A macro must be * used by itself, and not in conjunction with other macros or data * items. */ public static void Fetch(string command, Connection connectionState) { var tag = command.Split(' ').First(); if (connectionState.SelectedState) { if (IMAP_Fetch.TryFetch(command, connectionState, false)) { connectionState.SendToStream($"{tag} OK FETCH completed"); } else { connectionState.SendToStream($"{tag} NO - fetch error: can’t fetch that data"); } } else { connectionState.SendToStream($"{tag} BAD - command unknown or arguments invalid"); } }