示例#1
0
        public void TestNonAuthCommand()
        {
            string command  = string.Format("A00000000 APPEND INBOX (\\Seen) \"{0}\" {{4096}}\r\n", ImapUtils.FormatInternalDate(DateTimeOffset.Now));
            var    detector = new ImapAuthenticationSecretDetector();
            var    buffer   = Encoding.ASCII.GetBytes(command);

            detector.IsAuthenticating = true;

            var secrets = detector.DetectSecrets(buffer, 0, buffer.Length);

            Assert.AreEqual(0, secrets.Count, "# of secrets");
        }
示例#2
0
        IList <ImapReplayCommand> CreateAppendWithAnnotationsCommands(bool withInternalDates, out List <MimeMessage> messages, out List <MessageFlags> flags, out List <DateTimeOffset> internalDates, out List <Annotation> annotations)
        {
            var commands = new List <ImapReplayCommand> ();

            commands.Add(new ImapReplayCommand("", "dovecot.greeting.txt"));
            commands.Add(new ImapReplayCommand("A00000000 LOGIN username password\r\n", "dovecot.authenticate+annotate.txt"));
            commands.Add(new ImapReplayCommand("A00000001 NAMESPACE\r\n", "dovecot.namespace.txt"));
            commands.Add(new ImapReplayCommand("A00000002 LIST \"\" \"INBOX\" RETURN (SUBSCRIBED CHILDREN)\r\n", "dovecot.list-inbox.txt"));
            commands.Add(new ImapReplayCommand("A00000003 LIST (SPECIAL-USE) \"\" \"*\" RETURN (SUBSCRIBED CHILDREN)\r\n", "dovecot.list-special-use.txt"));

            internalDates = withInternalDates ? new List <DateTimeOffset> () : null;
            annotations   = new List <Annotation> ();
            messages      = new List <MimeMessage> ();
            flags         = new List <MessageFlags> ();
            var command = new StringBuilder();
            int id      = 4;

            for (int i = 0; i < 8; i++)
            {
                MimeMessage message;
                string      latin1;
                long        length;

                using (var resource = GetResourceStream(string.Format("common.message.{0}.msg", i)))
                    message = MimeMessage.Load(resource);

                messages.Add(message);
                flags.Add(MessageFlags.Seen);
                if (withInternalDates)
                {
                    internalDates.Add(message.Date);
                }
                var annotation = new Annotation(AnnotationEntry.AltSubject);
                annotation.Properties[AnnotationAttribute.PrivateValue] = string.Format("Alternate subject {0}", i);
                annotations.Add(annotation);

                using (var stream = new MemoryStream()) {
                    var options = FormatOptions.Default.Clone();
                    options.NewLineFormat = NewLineFormat.Dos;
                    options.EnsureNewLine = true;

                    message.WriteTo(options, stream);
                    length          = stream.Length;
                    stream.Position = 0;

                    using (var reader = new StreamReader(stream, Latin1))
                        latin1 = reader.ReadToEnd();
                }

                var tag = string.Format("A{0:D8}", id++);
                command.Clear();

                command.AppendFormat("{0} APPEND INBOX (\\Seen) ", tag);

                if (withInternalDates)
                {
                    command.AppendFormat("\"{0}\" ", ImapUtils.FormatInternalDate(message.Date));
                }

                command.AppendFormat("ANNOTATION (/altsubject (value.priv \"Alternate subject {0}\")) ", i);

                command.Append('{').Append(length.ToString()).Append("+}\r\n").Append(latin1).Append("\r\n");
                commands.Add(new ImapReplayCommand(command.ToString(), string.Format("dovecot.append.{0}.txt", i + 1)));
            }

            commands.Add(new ImapReplayCommand(string.Format("A{0:D8} LOGOUT\r\n", id), "gmail.logout.txt"));

            return(commands);
        }