Exemplo n.º 1
0
        public async Task DeleteMailboxAsync(string mailbox)
        {
            var encodedName = ImapMailbox.EncodeName(mailbox);
            var command     = string.Format("DELETE \"{0}\"", encodedName);
            var id          = await _connection.WriteCommandAsync(command);

            await ReadBasicResponseAsync(id);
        }
Exemplo n.º 2
0
        public async Task CreateMailboxAsync(string fullname)
        {
            var encodedName = ImapMailbox.EncodeName(fullname);
            var command     = string.Format("CREATE \"{0}\"", encodedName);
            var id          = await _connection.WriteCommandAsync(command);

            await ReadBasicResponseAsync(id);
        }
Exemplo n.º 3
0
        /// <summary>
        ///     The SUBSCRIBE command adds the specified mailbox name to the
        ///     server's set of "active" or "subscribed" mailboxes as returned by
        ///     the LSUB command.  This command returns a tagged OK response only
        ///     if the subscription is successful.
        ///     http://tools.ietf.org/html/rfc3501#section-6.3.6
        /// </summary>
        /// <param name="name">mailbox</param>
        /// <returns>no specific responses for this command</returns>
        public async Task SubscribeAsync(string name)
        {
            // we need to convert non ASCII names according to IMAP specs.
            // http://tools.ietf.org/html/rfc2060#section-5.1.3
            var encodedName = ImapMailbox.EncodeName(name);

            var command = string.Format("{0} \"{1}\"", ImapCommands.Subscribe, encodedName);
            var id      = await _connection.WriteCommandAsync(command);

            await ReadNamespaceResponseAsync(id);
        }
Exemplo n.º 4
0
        internal static ImapMailboxInfo Parse(ImapResponseLine line)
        {
            const string pattern = "\\(.*?\\)|\".+?\"|\\w+";
            var          parts   = Regex.Matches(line.Text, pattern)
                                   .OfType <Match>()
                                   .Select(x => x.Value)
                                   .ToArray();

            var name = ImapMailbox.DecodeName(parts[3].TrimQuotes());
            var info = new ImapMailboxInfo(name, parts[2].TrimQuotes().ToCharArray().First())
            {
                Flags = Regex.Match(parts[1], @"\(.*\)").Value.Trim(new[] { '(', ')' }).Split(' ')
            };

            return(info);
        }
Exemplo n.º 5
0
        private async Task <ImapMailbox> ReadSelectResponseAsync(string name, string commandId)
        {
            var mailbox = new ImapMailbox(this, name);

            while (true)
            {
                var line = await _connection.ReadAsync();

                if (line.TerminatesCommand(commandId))
                {
                    if (line.Text.ContainsIgnoreCase("[READ-WRITE]"))
                    {
                        mailbox.Permissions = MailboxPermissions.Read | MailboxPermissions.Write;
                    }
                    break;
                }

                if (line.IsUntagged && !line.IsUntaggedOk && line.Text.ContainsIgnoreCase("FLAGS"))
                {
                    const string pattern = @"\\[A-za-z0-9\*]+";
                    mailbox.AddFlags(Regex.Matches(line.Text, pattern, RegexOptions.CultureInvariant)
                                     .Cast <Match>()
                                     .Select(x => x.Value));
                }

                if (line.IsUntaggedOk && line.Text.ContainsIgnoreCase("PERMANENTFLAGS"))
                {
                    const string pattern = @"\\[A-za-z0-9\*]+";
                    mailbox.AddPermanentFlags(Regex.Matches(line.Text, pattern, RegexOptions.CultureInvariant)
                                              .Cast <Match>()
                                              .Select(x => x.Value));
                    continue;
                }

                if (line.IsUntaggedOk && line.Text.ContainsIgnoreCase("UIDVALIDITY"))
                {
                    const string pattern = @"[0-9]+";
                    var          value   = Regex.Match(line.Text, pattern, RegexOptions.CultureInvariant).Value;
                    mailbox.UidValidity = long.Parse(value);
                    continue;
                }

                if (line.IsUntagged && Regex.IsMatch(line.Text, @"\d+ EXISTS", RegexOptions.IgnoreCase))
                {
                    const string pattern = @"[0-9]+";
                    var          value   = Regex.Match(line.Text, pattern, RegexOptions.CultureInvariant).Value;
                    mailbox.Exists = int.Parse(value);
                    continue;
                }

                if (line.IsUntagged && Regex.IsMatch(line.Text, @"\d+ RECENT", RegexOptions.IgnoreCase))
                {
                    const string pattern = @"[0-9]+";
                    var          value   = Regex.Match(line.Text, pattern, RegexOptions.CultureInvariant).Value;
                    mailbox.Recent = int.Parse(value);
                    continue;
                }

                if (line.IsUntagged && line.Text.ContainsIgnoreCase("UIDNEXT"))
                {
                    const string pattern = @"[0-9]+";
                    var          value   = Regex.Match(line.Text, pattern, RegexOptions.CultureInvariant).Value;
                    mailbox.UidNext = int.Parse(value);
                }
            }

            return(mailbox);
        }