private ImapCommandResult GetMetadataInternal(string mailboxName, bool checkName, string[] entrySpecifiers, ImapGetMetadataOptions options, out ImapMetadata[] metadata)
        {
            if (entrySpecifiers == null)
            throw new ArgumentNullException("entrySpecifiers");
              else if (entrySpecifiers.Length == 0)
            throw new ArgumentException("must be non-empty array", "entrySpecifiers");

              if (checkName)
            RejectInvalidMailboxNameArgument(mailboxName);

              if (handlesIncapableAsException)
            CheckServerCapabilityMetadata(mailboxName != null);

              metadata = null;

              using (var t = new GetMetadataTransaction(connection)) {
            // mailbox-name
            t.RequestArguments["mailbox-name"] = (mailboxName == null)
              ? new ImapQuotedString(string.Empty)
              : new ImapMailboxNameString(mailboxName);

            // options
            if (options != null)
              t.RequestArguments["options"] = options;

            // entry-specifier
            if (entrySpecifiers.Length == 1)
              t.RequestArguments["entry-specifier"] = entrySpecifiers[0];
            else
              t.RequestArguments["entry-specifier"] = new ImapParenthesizedString(entrySpecifiers);

            if (ProcessTransaction(t).Succeeded)
              metadata = t.Result.Value;

            return t.Result;
              }
        }
        private ImapCommandResult SetMetadataInternal(string mailboxName, bool checkName, ImapMetadata[] metadata)
        {
            if (metadata == null)
            throw new ArgumentNullException("metadata");

              if (checkName)
            RejectInvalidMailboxNameArgument(mailboxName);

              if (handlesIncapableAsException)
            CheckServerCapabilityMetadata(mailboxName != null);

              using (var t = new SetMetadataTransaction(connection)) {
            // mailbox-name
            t.RequestArguments["mailbox-name"] = (mailboxName == null)
              ? new ImapQuotedString(string.Empty)
              : new ImapMailboxNameString(mailboxName);

            // list of entry, values
            var listOfEntryAndValues = new List<ImapString>(metadata.Length);

            foreach (var m in metadata) {
              if (m == null)
            throw new ArgumentException("contains null", "metadata");

              listOfEntryAndValues.Add(m.EntryName);

              if (m.Value == null)
            listOfEntryAndValues.Add(new ImapNilString());
              else
            listOfEntryAndValues.Add(m.Value);
            }

            t.RequestArguments["list of entry, values"] = new ImapParenthesizedString(listOfEntryAndValues.ToArray());

            return ProcessTransaction(t);
              }
        }
        /// <summary>sends GETMETADATA command</summary>
        /// <remarks>
        /// valid in authenticated/selected state.
        /// this method will fail if server does not support METADATA extension.
        /// </remarks>
        public ImapCommandResult GetMetadata(string mailboxName, string[] entrySpecifiers, ImapGetMetadataOptions options, out ImapMetadata[] metadata)
        {
            if (options == null)
            throw new ArgumentNullException("options");

              return GetMetadataInternal(mailboxName, true, entrySpecifiers, options, out metadata);
        }
 private ImapCommandResult GetMetadataInternal(string[] entrySpecifiers, ImapGetMetadataOptions options, out ImapMetadata[] metadata)
 {
     return GetMetadataInternal(null, false, entrySpecifiers, options, out metadata);
 }
 /// <summary>sends GETMETADATA command</summary>
 /// <remarks>
 /// valid in authenticated/selected state.
 /// this method will fail if server does not support METADATA extension.
 /// </remarks>
 public ImapCommandResult GetMetadata(string mailboxName, string[] entrySpecifiers, out ImapMetadata[] metadata)
 {
     return GetMetadataInternal(mailboxName, true, entrySpecifiers, null, out metadata);
 }
        /// <summary>sends GETMETADATA command</summary>
        /// <remarks>
        /// valid in authenticated/selected state.
        /// this method will fail if server does not support METADATA extension.
        /// </remarks>
        public ImapCommandResult GetMetadata(ImapMailbox mailbox, string[] entrySpecifiers, ImapGetMetadataOptions options, out ImapMetadata[] metadata)
        {
            if (options == null)
            throw new ArgumentNullException("options");

              ValidateMailboxRelationship(mailbox);

              return GetMetadataInternal(mailbox.Name, false, entrySpecifiers, options, out metadata);
        }
        /// <remarks>
        /// valid in authenticated/selected state.
        /// this method will fail if server does not support METADATA extension.
        /// </remarks>
        public ImapCommandResult GetMetadata(ImapMailbox mailbox, string[] entrySpecifiers, out ImapMetadata[] metadata)
        {
            ValidateMailboxRelationship(mailbox);

              return GetMetadataInternal(mailbox.Name, false, entrySpecifiers, null, out metadata);
        }
        /// <summary>sends GETMETADATA command</summary>
        /// <remarks>
        /// valid in authenticated/selected state.
        /// this method will fail if server does not support METADATA or METADATA-SERVER extension.
        /// </remarks>
        public ImapCommandResult GetMetadata(string entrySpecifier, ImapGetMetadataOptions options, out ImapMetadata[] metadata)
        {
            if (options == null)
            throw new ArgumentNullException("options");

              return GetMetadataInternal(new[] {entrySpecifier}, options, out metadata);
        }
 /// <summary>sends GETMETADATA command</summary>
 /// <remarks>
 /// valid in authenticated/selected state.
 /// this method will fail if server does not support METADATA or METADATA-SERVER extension.
 /// </remarks>
 public ImapCommandResult GetMetadata(string[] entrySpecifiers, out ImapMetadata[] metadata)
 {
     return GetMetadataInternal(entrySpecifiers, null, out metadata);
 }
 /// <summary>sends GETMETADATA command</summary>
 /// <remarks>
 /// valid in authenticated/selected state.
 /// this method will fail if server does not support METADATA or METADATA-SERVER extension.
 /// </remarks>
 public ImapCommandResult GetMetadata(string entrySpecifier, out ImapMetadata[] metadata)
 {
     return GetMetadataInternal(new[] {entrySpecifier}, null, out metadata);
 }
        public void TestSetMetadata1()
        {
            using (var session = Authenticate("METADATA")) {
            Assert.IsTrue(session.ServerCapabilities.Has(ImapCapability.Metadata));

            // SETMETADATA transaction
            server.EnqueueResponse("+ ready for data\r\n");
            server.EnqueueResponse(string.Empty);
            server.EnqueueResponse("0002 OK SETMETADATA complete\r\n");

            var metadata = new ImapMetadata("/private/comment",
                                        new ImapLiteralString("My new comment across\n" +
                                                              "two lines.\n"));

            Assert.IsTrue((bool)session.SetMetadata("INBOX", metadata));

            Assert.AreEqual("0002 SETMETADATA \"INBOX\" (/private/comment {33}\r\n" +
                        "My new comment across\n" +
                        "two lines.\n" +
                        ")\r\n",
                        server.DequeueAll());
              }
        }