Example #1
0
        /// <summary>
        ///   The APPEND command appends the literal argument as a new message
        ///   to the end of the specified destination mailbox.
        ///   http://tools.ietf.org/html/rfc3501#section-6.3.11
        /// </summary>
        /// <param name = "mailboxName">The name of the malbox to insert the message.</param>
        /// <param name = "message">The message to append.</param>
        /// <param name = "flags">Sets the flags of the message. This is optional.</param>
        public ImapResponse Append(string mailboxName, Message message, MessageFlags flags = (MessageFlags)0x0000)
        {
            // we need to convert non ASCII names according to IMAP specs.
            // http://tools.ietf.org/html/rfc2060#section-5.1.3
            var name = MailboxNameEncoder.Encode(mailboxName);

            var mime       = message.ToMime();
            var size       = mime.Length;
            var flagString = flags == 0x0000 ? string.Empty : string.Format(" ({0})", flags.ToMimeFormat());
            var text       = string.Format("APPEND {0}{1} {{{2}}}", name, flagString, size);
            var reader     = SendAndReceive(new ImapCommand(text));

            if (reader.IsContinuation)
            {
                var finalReader = SendAndReceive(new BlankImapCommand(mime));

                var validResponse = new ImapResponse();
                validResponse.Parse(finalReader);
                return(validResponse);
            }

            var invalidResponse = new ImapResponse();

            invalidResponse.Parse(reader);
            return(invalidResponse);
        }
Example #2
0
        /// <summary>
        ///   The STORE command alters data associated with a message in the mailbox.
        ///   http://tools.ietf.org/html/rfc2060#section-6.4.6
        /// </summary>
        /// <param name = "set">The sequence set representing the targeted messages, e.g. "1"; "1,2"; "2:4".</param>
        /// <param name = "value">The keywords to add or remove.</param>
        /// <param name = "procedure">The procedure, whether to add or remove the flags.</param>
        public ImapResponse StoreSilent(SequenceSet set, string value, StoreProcedures procedure)
        {
            var reader   = StoreInternal(set, value, procedure, "FLAGS.SILENT");
            var response = new ImapResponse();

            response.Parse(reader);
            return(response);
        }
Example #3
0
        /// <summary>
        ///   The LOGOUT command informs the server that the client is done with the connection.
        ///   http://tools.ietf.org/html/rfc3501#section-6.1.3
        /// </summary>
        public ImapResponse Logout()
        {
            var command = new ImapCommand("LOGOUT");
            var reader  = SendAndReceive(command);

            var response = new ImapResponse();

            response.Parse(reader);
            return(response);
        }
Example #4
0
        /// <summary>
        ///   The NOOP command always succeeds.  It does nothing.
        ///   http://tools.ietf.org/html/rfc3501#section-6.1.2
        /// </summary>
        public ImapResponse Noop()
        {
            var command = new ImapCommand("NOOP");
            var reader  = SendAndReceive(command);

            var response = new ImapResponse();

            response.Parse(reader);
            return(response);
        }
Example #5
0
        /// <summary>
        ///   The CHECK command requests a checkpoint of the currently selected
        ///   mailbox.  A checkpoint refers to any implementation-dependent
        ///   housekeeping associated with the mailbox (e.g., resolving the
        ///   server's in-memory state of the mailbox with the state on its
        ///   disk) that is not normally executed as part of each command.  A
        ///   checkpoint MAY take a non-instantaneous amount of real time to
        ///   complete.  If a server implementation has no such housekeeping
        ///   considerations, CHECK is equivalent to NOOP.
        ///   http://tools.ietf.org/html/rfc2060#section-6.4.1
        /// </summary>
        public ImapResponse Check()
        {
            var text    = string.Format("CHECK");
            var command = new ImapCommand(text);
            var reader  = SendAndReceive(command);

            var response = new ImapResponse();

            response.Parse(reader);
            return(response);
        }
Example #6
0
        /// <summary>
        ///   The CREATE command creates a mailbox with the given name.
        ///   http://tools.ietf.org/html/rfc3501#section-6.3.3
        /// </summary>
        /// <param name = "mailboxName">The name of the mailbox to create.</param>
        public ImapResponse Create(string mailboxName)
        {
            // we need to convert non ASCII names according to IMAP specs.
            // http://tools.ietf.org/html/rfc2060#section-5.1.3
            var name = MailboxNameEncoder.Encode(mailboxName);

            var text    = string.Format("CREATE \"{0}\"", name);
            var command = new ImapCommand(text);
            var reader  = SendAndReceive(command);

            var response = new ImapResponse();

            response.Parse(reader);
            return(response);
        }
Example #7
0
        /// <summary>
        ///   The COPY command copies the specified message(s) to the end of the specified destination mailbox.
        ///   http://tools.ietf.org/html/rfc3501#section-6.4.7
        /// </summary>
        public ImapResponse Copy(SequenceSet set, string destinationMailboxName)
        {
            // we need to convert non ASCII names according to IMAP specs.
            // http://tools.ietf.org/html/rfc2060#section-5.1.3
            var name = MailboxNameEncoder.Encode(destinationMailboxName);

            var text    = string.Format("COPY {0} \"{1}\"", set, name);
            var command = new ImapCommand(text);
            var reader  = SendAndReceive(command);

            var response = new ImapResponse();

            response.Parse(reader);
            return(response);
        }
Example #8
0
        /// <summary>
        ///   The RENAME command changes the name of a mailbox.  A tagged OK
        ///   response is returned only if the mailbox has been renamed.  It is
        ///   an error to attempt to rename from a mailbox name that does not
        ///   exist or to a mailbox name that already exists.  Any error in
        ///   renaming will return a tagged NO response.
        /// </summary>
        /// <param name = "sourceName">The fullname of the mailbox to rename.</param>
        /// <param name = "targetName">The new name for the mailbox.</param>
        /// <returns>Returns the server response.</returns>
        public ImapResponse Rename(string sourceName, string targetName)
        {
            // we need to convert non ASCII names according to IMAP specs.
            // http://tools.ietf.org/html/rfc2060#section-5.1.3
            var source = MailboxNameEncoder.Encode(sourceName);

            // we need to convert non ASCII names according to IMAP specs.
            // http://tools.ietf.org/html/rfc2060#section-5.1.3
            var target = MailboxNameEncoder.Encode(targetName);

            var text    = string.Format("RENAME \"{0}\" \"{1}\"", source, target);
            var command = new ImapCommand(text);
            var reader  = SendAndReceive(command);

            var response = new ImapResponse();

            response.Parse(reader);
            return(response);
        }