コード例 #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);
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
0
        /// <summary>
        ///   The LSUB command returns a subset of names from the set of names that the user has declared as being "active" or "subscribed".
        ///   http://tools.ietf.org/html/rfc3501#section-6.3.9
        /// </summary>
        /// <param name = "referenceName">The reference name.</param>
        /// <param name = "wildcardedMailboxName">The mailbox name with possible wildcards.</param>
        public ListImapResponse LSub(string referenceName, string wildcardedMailboxName)
        {
            // we need to convert non ASCII names according to IMAP specs.
            // http://tools.ietf.org/html/rfc2060#section-5.1.3
            referenceName         = MailboxNameEncoder.Encode(referenceName);
            wildcardedMailboxName = MailboxNameEncoder.Encode(wildcardedMailboxName);

            var text    = string.Format("LSUB \"{0}\" \"{1}\"", referenceName, wildcardedMailboxName);
            var command = new ImapCommand(text);
            var reader  = SendAndReceive(command);

            var response = new ListImapResponse();

            response.Parse(reader);
            return(response);
        }
コード例 #5
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);
        }
コード例 #6
0
        /// <summary>
        ///   The SELECT command selects a mailbox so that messages in the mailbox can be accessed.
        ///   http://tools.ietf.org/html/rfc3501#section-6.3.1
        /// </summary>
        /// <param name = "mailboxName">The name of the mailbox to select.</param>
        public SelectExamineImapResponse Select(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("SELECT \"{0}\"", name);
            var command = new ImapCommand(text);
            var reader  = SendAndReceive(command, false);

            var response = new SelectExamineImapResponse(mailboxName);

            response.Parse(reader);

            if (response.IsOk)
            {
                SelectedMailbox = mailboxName;
            }

            return(response);
        }