示例#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);
 }
示例#2
0
 public Task StoreMessageLabelsAsync(MailMessage message)
 {
     return StoreMessageLabelsAsync(message.GetThreadId(), message.GetMessageId(), message.GetLabelsHeader());
 }
示例#3
0
 public Task StoreMessageFlagsAsync(MailMessage message)
 {
     return StoreMessageFlagsAsync(message.GetThreadId(), message.GetMessageId(), Utilities.FlagsToFlagString(message.Flags));
 }
示例#4
0
 // Break the message up into parts: Flags, labels, headers/structure, and body parts
 public async Task StoreMessageAsync(MailMessage message)
 {
     await StoreMessageFlagsAsync(message.GetThreadId(), message.GetMessageId(), Utilities.FlagsToFlagString(message.Flags));
     await StoreMessageLabelsAsync(message.GetThreadId(), message.GetMessageId(), message.GetLabelsHeader());
     await StoreMessageHeadersAsync(message);
     if (message.Scope >= Scope.HeadersAndBodySnyppit)
     {
         // TODO: Verify BodyId is set.
         // Body parts
         if (!message.AlternateViews.Any() && !message.Attachments.Any())
         {
             // Simple body
             await StoreMessagePartAsync(message.GetThreadId(), message.GetMessageId(), message.BodyId, message.Body);
         }
         else
         {
             // Multipart body
             foreach (Attachment view in message.AlternateViews)
             {
                 await StoreMessagePartAsync(message.GetThreadId(), message.GetMessageId(), view.BodyId, view.Body);
             }
             foreach (Attachment attachment in message.Attachments)
             {
                 await StoreMessagePartAsync(message.GetThreadId(), message.GetMessageId(), attachment.BodyId, attachment.Body);
             }
         }
     }
 }
示例#5
0
        public async Task OpenAttachmentAsync(MailMessage message, Attachment attachment)
        {
            // Lazy load
            if (attachment.Scope < Scope.HeadersAndBody)
            {
                // Check local storage
                if (MailStorage.HasMessagePart(message.GetThreadId(), message.GetMessageId(), attachment.BodyId))
                {
                    // TODO: Can we open the attachment directly from isolated storage?
                    attachment.Body = await MailStorage.GetMessagePartAsync(message.GetThreadId(), message.GetMessageId(), attachment.BodyId);
                }
                else
                {
                    // Download from the network
                    await GmailImap.GetBodyPartAsync(message.Uid, attachment, async () =>
                    {
                        if (ActiveLabel.Info.StoreMessages && ActiveLabel.Info.StoreAttachments)
                        {
                            await MailStorage.StoreMessagePartAsync(message.GetThreadId(), message.GetMessageId(), attachment.BodyId, attachment.Body);
                        }
                    }, CancellationToken.None);
                }
            }

            StorageFile file = await MailStorage.SaveAttachmentToTempAsync(attachment);
            // http://architects.dzone.com/articles/lap-around-windows-phone-8-sdk
            await Launcher.LaunchFileAsync(file);

            // TODO: Delete temp files on app close?
        }
示例#6
0
 public virtual async Task LazyLoadBodyPartAsync(MailMessage message, ObjectWHeaders part)
 {
     if (part.Scope < Scope.HeadersAndBody)
     {
         if (MailStorage.HasMessagePart(message.GetThreadId(), message.GetMessageId(), part.BodyId))
         {
             part.Body = await MailStorage.GetMessagePartAsync(message.GetThreadId(), message.GetMessageId(), part.BodyId);
         }
         else
         {
             await GmailImap.GetBodyPartAsync(message.Uid, part, async () =>
             {
                 if (ActiveLabel.Info.StoreMessages)
                 {
                     await MailStorage.StoreMessagePartAsync(message.GetThreadId(), message.GetMessageId(), part.BodyId, part.Body);
                 }
             }, CancellationToken.None);
         }
     }
 }