Exemplo n.º 1
0
 public Task StoreMessageHeadersAsync(MailMessage headers)
 {
     string messageDir = Path.Combine(AccountDir, _accountName, ConversationsDir, headers.GetThreadId(), headers.GetMessageId());
     if (!_storage.DirectoryExists(messageDir))
     {
         _storage.CreateDirectory(messageDir);
     }
     string headersFile = Path.Combine(messageDir, HeadersFile);
     using (Stream stream = _storage.CreateFile(headersFile))
     {
         // TODO: Async
         headers.Save(stream);
     }
     return Task.FromResult(0);
 }
Exemplo n.º 2
0
        public virtual async Task AppendMailAsync(MailMessage email, string mailbox = null)
        {
            await IdlePauseAsync();

            mailbox = ModifiedUtf7Encoding.Encode(mailbox);
            string flags = String.Empty;
            var body = new StringBuilder();
            using (var txt = new System.IO.StringWriter(body))
                email.Save(txt);

            string size = body.Length.ToString();
            if (email.RawFlags.Length > 0)
            {
                flags = " (" + string.Join(" ", email.Flags) + ")";
            }

            if (mailbox == null)
                await CheckMailboxSelectedAsync();
            mailbox = mailbox ?? _SelectedMailbox;

            string command = GetTag() + "APPEND " + (mailbox ?? _SelectedMailbox).QuoteString() + flags + " {" + size + "}";
            string response = await SendCommandGetResponseAsync(command);
            if (response.StartsWith("+"))
            {
                response = await SendCommandGetResponseAsync(body.ToString());
            }
            await IdleResumeAsync();
        }
Exemplo n.º 3
0
        public void SaveAndLoadHeadersOnly()
        {
            MailMessage message1 = new MailMessage();
            message1.Scope = Scope.HeadersAndMime;

            message1.Sender = new MailAddress("*****@*****.**");
            message1.From = new MailAddress("*****@*****.**");
            message1.To.Add(new MailAddress("*****@*****.**"));
            message1.Cc.Add(new MailAddress("*****@*****.**"));
            message1.Bcc.Add(new MailAddress("*****@*****.**"));
            message1.Subject = "Subject line";

            message1.ContentType = "text/plain; charset=utf-8";

            MemoryStream buffer = new MemoryStream();
            TextWriter writer = new StreamWriter(buffer);
            message1.Save(writer);
            writer.Flush();
            buffer.Seek(0, SeekOrigin.Begin);

            MailMessage message2 = new MailMessage();
            message2.Load(buffer, Scope.Headers, 0);

            Assert.Equal(message1.Sender.ToString(), message2.Sender.ToString());
            Assert.Equal(message1.From.ToString(), message2.From.ToString());
            Assert.Equal(message1.To.First().ToString(), message2.To.First().ToString());
            Assert.Equal(message1.Cc.First().ToString(), message2.Cc.First().ToString());
            Assert.Equal(message1.Bcc.First().ToString(), message2.Bcc.First().ToString());

            Assert.Equal(message1.Subject, message2.Subject);
            Assert.Equal(message1.ContentType, message2.ContentType);
            Assert.Equal(message1.Body, message2.Body);
            Assert.Equal(message1.AlternateViews.Count, message1.AlternateViews.Count);
            Assert.Equal(message1.Attachments.Count, message1.Attachments.Count);
        }
Exemplo n.º 4
0
        public void SaveAndLoadHeadersOnlyMultipart()
        {
            MailMessage message1 = new MailMessage();
            message1.Scope = Scope.HeadersAndMime;

            message1.Sender = new MailAddress("*****@*****.**");
            message1.From = new MailAddress("*****@*****.**");
            message1.To.Add(new MailAddress("*****@*****.**"));
            message1.Cc.Add(new MailAddress("*****@*****.**"));
            message1.Bcc.Add(new MailAddress("*****@*****.**"));
            message1.Subject = "Subject line";

            message1.ContentType = "multipart/mixed; boundary=abcdefg";
            message1.AlternateViews.Add(new Attachment()
            {
               ContentType = "text/plain; charset=utf-8",
               ContentTransferEncoding = "7BIT",
            });
            message1.Attachments.Add(new Attachment()
            {
                ContentType = "text/plain; charset=utf-8",
                ContentTransferEncoding = "7BIT",
                IsAttachment = true,
            });

            MemoryStream buffer = new MemoryStream();
            TextWriter writer = new StreamWriter(buffer);
            message1.Save(writer);
            writer.Flush();
            buffer.Seek(0, SeekOrigin.Begin);

            MailMessage message2 = new MailMessage();
            message2.Load(buffer, Scope.HeadersAndMime, 0);

            Assert.Equal(message1.Sender.ToString(), message2.Sender.ToString());
            Assert.Equal(message1.From.ToString(), message2.From.ToString());
            Assert.Equal(message1.To.First().ToString(), message2.To.First().ToString());
            Assert.Equal(message1.Cc.First().ToString(), message2.Cc.First().ToString());
            Assert.Equal(message1.Bcc.First().ToString(), message2.Bcc.First().ToString());

            Assert.Equal(message1.Subject, message2.Subject);
            Assert.Equal(message1.ContentType, message2.ContentType);
            Assert.Equal(message1.Body, message2.Body);
            Assert.Equal(message1.AlternateViews.Count, message1.AlternateViews.Count);
            Assert.Equal(message1.Attachments.Count, message1.Attachments.Count);

            Assert.Equal(message1.AlternateViews.First().ContentType, message2.AlternateViews.First().ContentType);
            Assert.Equal(message1.AlternateViews.First().ContentTransferEncoding, message2.AlternateViews.First().ContentTransferEncoding);
            Assert.Equal(message1.AlternateViews.First().IsAttachment, message2.AlternateViews.First().IsAttachment);

            Assert.Equal(message1.Attachments.First().ContentType, message2.Attachments.First().ContentType);
            Assert.Equal(message1.Attachments.First().ContentTransferEncoding, message2.Attachments.First().ContentTransferEncoding);
            Assert.Equal(message1.Attachments.First().IsAttachment, message2.Attachments.First().IsAttachment);
        }
Exemplo n.º 5
0
        private MailMessage Reparse(MailMessage msg)
        {
            var sb = new StringBuilder();
            using (var w = new StringWriter(sb))
            {
                msg.Save(w);
            }
            // System.Diagnostics.Debug.WriteLine(sb.ToString());

            var parsedMessage = GetMessage(sb.ToString());
            return parsedMessage;
        }