Exemplo n.º 1
0
        async Task TestMboxAsync(ParserOptions options, string baseName)
        {
            var mbox    = Path.Combine(MboxDataDir, baseName + ".mbox.txt");
            var output  = new MemoryBlockStream();
            var builder = new StringBuilder();
            List <MimeParserOffset> offsets;
            NewLineFormat           newLineFormat;

            using (var stream = File.OpenRead(mbox)) {
                var parser = options != null ? new CustomMimeParser(options, stream, MimeFormat.Mbox) : new CustomMimeParser(stream, MimeFormat.Mbox);
                var format = FormatOptions.Default.Clone();
                int count  = 0;

                format.NewLineFormat = newLineFormat = DetectNewLineFormat(mbox);

                while (!parser.IsEndOfStream)
                {
                    var message = await parser.ParseMessageAsync();

                    builder.AppendFormat("{0}", parser.MboxMarker).Append('\n');
                    if (message.From.Count > 0)
                    {
                        builder.AppendFormat("From: {0}", message.From).Append('\n');
                    }
                    if (message.To.Count > 0)
                    {
                        builder.AppendFormat("To: {0}", message.To).Append('\n');
                    }
                    builder.AppendFormat("Subject: {0}", message.Subject).Append('\n');
                    builder.AppendFormat("Date: {0}", DateUtils.FormatDate(message.Date)).Append('\n');
                    DumpMimeTree(builder, message);
                    builder.Append('\n');

                    var marker = Encoding.UTF8.GetBytes((count > 0 ? format.NewLine : string.Empty) + parser.MboxMarker + format.NewLine);
                    await output.WriteAsync(marker, 0, marker.Length);

                    await message.WriteToAsync(format, output);

                    count++;
                }

                offsets = parser.Offsets;
            }

            AssertMboxResults(baseName, builder.ToString(), output, offsets, newLineFormat);
        }
Exemplo n.º 2
0
        public async void TestJwzMboxAsync()
        {
            var options = FormatOptions.Default.Clone();
            var output  = new MemoryBlockStream();
            var builder = new StringBuilder();

            options.NewLineFormat = NewLineFormat.Unix;

            using (var stream = File.OpenRead(Path.Combine(MboxDataDir, "jwz.mbox.txt"))) {
                var parser = new MimeParser(stream, MimeFormat.Mbox);
                int count  = 0;

                while (!parser.IsEndOfStream)
                {
                    var message = await parser.ParseMessageAsync();

                    builder.AppendFormat("{0}", parser.MboxMarker).Append('\n');
                    if (message.From.Count > 0)
                    {
                        builder.AppendFormat("From: {0}", message.From).Append('\n');
                    }
                    if (message.To.Count > 0)
                    {
                        builder.AppendFormat("To: {0}", message.To).Append('\n');
                    }
                    builder.AppendFormat("Subject: {0}", message.Subject).Append('\n');
                    builder.AppendFormat("Date: {0}", DateUtils.FormatDate(message.Date)).Append('\n');
                    DumpMimeTree(builder, message);
                    builder.Append('\n');

                    var marker = Encoding.UTF8.GetBytes((count > 0 ? "\n" : string.Empty) + parser.MboxMarker + "\n");
                    await output.WriteAsync(marker, 0, marker.Length);

                    await message.WriteToAsync(options, output);

                    count++;
                }
            }

            AssertJwzMboxResults(builder.ToString(), output);
        }
Exemplo n.º 3
0
        public async void TestWriteAsync()
        {
            var bytes    = new byte[9 * 1024];
            int position = 0;

            random.NextBytes(bytes);

            blocks.Position = 0;
            master.Position = 0;

            while (position < bytes.Length)
            {
                int n = Math.Min(bytes.Length - position, random.Next() % 4096);
                await blocks.WriteAsync(bytes, position, n);

                await master.WriteAsync(bytes, position, n);

                position += n;
            }

            await blocks.FlushAsync();

            await master.FlushAsync();
        }