private ImapCommandResult SelectExamineInternal(bool selectAsReadOnly, string mailboxName, ImapParenthesizedString selectParameters, ImapCapability selectParametersCapabilityRequirement) { RejectNonAuthenticatedState(); RejectInvalidMailboxNameArgument(mailboxName); var selectingMailbox = mailboxManager.GetExist(mailboxName); var selectingMailboxExists = (selectingMailbox != null); if (selectingMailboxExists) { if (selectedMailbox == selectingMailbox) return new ImapCommandResult(ImapCommandResultCode.RequestDone, "mailbox has already been selected"); else if (selectingMailbox.IsUnselectable) throw new ImapProtocolViolationException("mailbox is not selectable or not existent"); } else { selectingMailbox = new ImapMailbox(mailboxName); } using (var t = selectAsReadOnly ? (SelectTransactionBase)new ExamineTransaction(connection, selectingMailbox, selectParametersCapabilityRequirement) : (SelectTransactionBase)new SelectTransaction (connection, selectingMailbox, selectParametersCapabilityRequirement)) { /* * RFC 4466 - Collected Extensions to IMAP4 ABNF * http://tools.ietf.org/html/rfc4466 * * examine = "EXAMINE" SP mailbox [select-params] * ;; modifies the original IMAP EXAMINE command * ;; to accept optional parameters * select = "SELECT" SP mailbox [select-params] * ;; modifies the original IMAP SELECT command to * ;; accept optional parameters * select-params = SP "(" select-param *(SP select-param) ")" * select-param = select-param-name [SP select-param-value] * ;; a parameter to SELECT may contain one or * ;; more atoms and/or strings and/or lists. * select-param-name= tagged-ext-label * select-param-value= tagged-ext-val * ;; This non-terminal shows recommended syntax * ;; for future extensions */ t.RequestArguments["mailbox name"] = new ImapMailboxNameString(mailboxName); // select-params if (selectParameters != null) t.RequestArguments["select parameters"] = selectParameters; if (ProcessTransaction(t).Succeeded) { if (selectingMailboxExists) selectedMailbox = selectingMailbox; else selectedMailbox = mailboxManager.Add(selectingMailbox); TransitStateTo(ImapSessionState.Selected); } else { selectedMailbox = null; if (state != ImapSessionState.NotConnected) TransitStateTo(ImapSessionState.Authenticated); ProcessMailboxRefferalResponse(t.Result.TaggedStatusResponse); } return t.Result; } }
public void TestPreProcessTransactionSetLiteralOptionsLiteralNonSyncCapable() { using (var session = Connect("LITERAL+")) { session.HandlesIncapableAsException = true; Assert.IsTrue(session.ServerCapabilities.Has(ImapCapability.LiteralNonSync)); server.EnqueueResponse("+ continue\r\n"); server.EnqueueResponse(string.Empty); server.EnqueueResponse("0000 OK done\r\n"); var arguments = new ImapParenthesizedString(new ImapString[] { new ImapLiteralString("literal1", Encoding.ASCII, ImapLiteralOptions.Synchronizing), new ImapLiteralString("literal2", Encoding.ASCII, ImapLiteralOptions.NonSynchronizing), new ImapLiteralString("literal3", Encoding.ASCII, ImapLiteralOptions.NonSynchronizingIfCapable), }); session.GenericCommand("X-TEST", arguments); Assert.AreEqual("0000 X-TEST (" + "{8}\r\nliteral1 " + "{8+}\r\nliteral2 " + "{8+}\r\nliteral3)\r\n", server.DequeueAll()); } }
private ImapCommandResult CreateInternal(CreateTransaction t, string mailboxName, ImapParenthesizedString createParams, out ImapMailbox createdMailbox) { RejectNonAuthenticatedState(); RejectInvalidMailboxNameArgument(mailboxName); /* * 6.3.3. CREATE Command * It is an error to attempt to create INBOX or a mailbox * with a name that refers to an extant mailbox. */ if (ImapMailbox.IsNameInbox(mailboxName)) throw new ImapProtocolViolationException("It is an error to attempt to create INBOX."); var existingMailbox = mailboxManager.GetExist(mailboxName); if (existingMailbox != null && !existingMailbox.Flags.Has(ImapMailboxFlag.NonExistent)) throw new ImapProtocolViolationException(string.Format("It is an error to attempt to create a mailbox with a name that refers to an extent mailbox. (mailboxName: '{0}')", mailboxName)); createdMailbox = null; /* * RFC 4466 - Collected Extensions to IMAP4 ABNF * http://tools.ietf.org/html/rfc4466 * * create = "CREATE" SP mailbox * [create-params] * ;; Use of INBOX gives a NO error. * create-params = SP "(" create-param *( SP create-param) ")" * create-param-name = tagged-ext-label * create-param = create-param-name [SP create-param-value] * create-param-value= tagged-ext-val * ;; This non-terminal shows recommended syntax * ;; for future extensions. */ // mailbox name t.RequestArguments["mailbox name"] = new ImapMailboxNameString(mailboxName); // create-params if (createParams != null) t.RequestArguments["create parameters"] = createParams; if (ProcessTransaction(t).Succeeded) { if (existingMailbox == null) createdMailbox = mailboxManager.Add(new ImapMailbox(mailboxName)); else createdMailbox = mailboxManager.Rename(existingMailbox, mailboxName); } else { ProcessMailboxRefferalResponse(t.Result.TaggedStatusResponse); } return t.Result; }