diff --git a/App.xaml.cs b/App.xaml.cs index 181d13b..63564dc 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -26,8 +26,9 @@ sealed partial class App : Application /// /// 注入依赖 /// - public static IServiceProvider Services { get; private set; } = new ServiceCollection() + public static IServiceProvider services { get; private set; } = new ServiceCollection() .AddSingleton() + .AddSingleton() .BuildServiceProvider(); diff --git a/Models/Enums/MailType.cs b/Models/Enums/MailType.cs index b26eeca..25807d6 100644 --- a/Models/Enums/MailType.cs +++ b/Models/Enums/MailType.cs @@ -9,8 +9,8 @@ namespace MicaApps.Upw.Mail.Models.Enums /// /// 邮件类型 /// - internal enum MailType + public enum MailType { - Receiving, Sending + Receive, Send , Junk ,Deleted } } diff --git a/Models/Letter.cs b/Models/Letter.cs index d09cecd..1609874 100644 --- a/Models/Letter.cs +++ b/Models/Letter.cs @@ -10,10 +10,16 @@ namespace MicaApps.Upw.Mail.Models /// /// 专门用于储存每封信件 /// - internal class Letter :MimeMessage + internal class Letter { - public string title { get => this.Subject; } + public MimeMessage mimeMessage { get;private set; } + public string title { get => this.mimeMessage.Subject; } + public Letter(MimeMessage mimeMessage) + { + this.mimeMessage = mimeMessage; + } + } } diff --git a/Models/UserData.cs b/Models/UserData.cs index 33a17ac..5906943 100644 --- a/Models/UserData.cs +++ b/Models/UserData.cs @@ -19,7 +19,7 @@ internal abstract class UserData - public abstract Task CollectLetter(); + public abstract Task CollectLetter(ObservableCollection letters,Enums.MailType mailType); public abstract Task LoginIn(); diff --git a/Models/UserDataByImap.cs b/Models/UserDataByImap.cs index 4a8527e..65836f8 100644 --- a/Models/UserDataByImap.cs +++ b/Models/UserDataByImap.cs @@ -8,6 +8,9 @@ using MailKit.Security; using Windows.UI.Xaml; using MailKit; +using MailKit.Search; +using System.Collections.ObjectModel; +using Windows.Media.Protection.PlayReady; namespace MicaApps.Upw.Mail.Models { @@ -36,15 +39,44 @@ public override async Task LoginIn() await this.imapInfo.ConnectAsync(this.username,this.authorizationCode); } - public override async Task CollectLetter() + public override async Task CollectLetter(ObservableCollection letters,Enums.MailType mailType) { var inbox = this.imapInfo.Inbox; - await inbox.OpenAsync(FolderAccess.ReadOnly); - for (int i = 0; i < inbox.Count; i++) + + + + + IList ids = null; + switch (mailType) + { + case Enums.MailType.Receive: + await inbox.OpenAsync(FolderAccess.ReadOnly); + ids = await inbox.SearchAsync(SearchQuery.All); + break; + case Enums.MailType.Send: + inbox = this.imapInfo.GetFolder(SpecialFolder.Sent); + await inbox.OpenAsync(FolderAccess.ReadOnly); + ids = await inbox.SearchAsync(SearchQuery.All); + break; + case Enums.MailType.Deleted: + await inbox.OpenAsync(FolderAccess.ReadOnly); + ids = await inbox.SearchAsync(SearchQuery.Deleted); + break; + } + + + + letters.Clear(); + + if(ids != null) { - var message = await inbox.GetMessageAsync(i); - this.letters.Add(message as Letter); + foreach (var id in ids) + { + var message = await inbox.GetMessageAsync(id); + letters.Add(new Letter(message)); + } } + } diff --git a/Pages/HomePagel.xaml b/Pages/HomePagel.xaml index 6172785..b3e0969 100644 --- a/Pages/HomePagel.xaml +++ b/Pages/HomePagel.xaml @@ -5,13 +5,16 @@ xmlns:local="using:MicaApps.Upw.Mail.Pages" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:enum="using:MicaApps.Upw.Mail.Models.Enums" mc:Ignorable="d" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> - 收件箱 + 收件箱 + 发件箱 + 已删邮件 diff --git a/Pages/HomePagel.xaml.cs b/Pages/HomePagel.xaml.cs index c68b38f..7f0513a 100644 --- a/Pages/HomePagel.xaml.cs +++ b/Pages/HomePagel.xaml.cs @@ -30,15 +30,8 @@ public HomePagel() private void NavigationView_ItemInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args) { // 获取点击的菜单项的 Tag - string tag = args.InvokedItemContainer.Tag.ToString(); - - // 根据 Tag 导航到相应的页面 - switch (tag) - { - case @"receive": - this.frame_main.Navigate(typeof(MailPage),tag); - break; - } + Models.Enums.MailType tag = (Models.Enums.MailType)args.InvokedItemContainer.Tag; + this.frame_main.Navigate(typeof(MailPage), tag); } } } diff --git a/Pages/Login/LoginByImapPage.xaml.cs b/Pages/Login/LoginByImapPage.xaml.cs index f121cc4..d2aa65c 100644 --- a/Pages/Login/LoginByImapPage.xaml.cs +++ b/Pages/Login/LoginByImapPage.xaml.cs @@ -25,8 +25,8 @@ namespace MicaApps.Upw.Mail.Pages.Login /// public sealed partial class LoginByImapPage : Page { - private readonly Services.StaticValues staticValues = App.Services.GetService(); - private readonly Services.LoginStatus loginStatus = App.Services.GetService(); + private readonly Services.StaticValues staticValues = App.services.GetService(); + private readonly Services.LoginStatus loginStatus = App.services.GetService(); public LoginByImapPage() { @@ -35,14 +35,16 @@ public LoginByImapPage() private void combox_mailhost_SelectionChanged(object sender, SelectionChangedEventArgs e) { - Grid grid = new Grid(); - var m = grid.Margin; + if (this.staticValues.imapInfos.ContainsKey(this.combox_mailhost.Text)) + { + this.host = this.staticValues.imapInfos[this.combox_mailhost.Text].host; + } } private string username { get => this.textbox_username.Text + '@' + this.combox_mailhost.Text; } private string password { get => this.textbox_password.Text; } - private string host { get=>this.textbox_host.Text; } + private string host { get => this.textbox_host.Text; set => this.textbox_host.Text = value; } private int port { get => Convert.ToInt32(this.textbox_port.Text); } diff --git a/Pages/MailPage.xaml b/Pages/MailPage.xaml index e90c2d7..c76f14d 100644 --- a/Pages/MailPage.xaml +++ b/Pages/MailPage.xaml @@ -12,25 +12,24 @@ - - + - - + + - + + -