public async Task MainFolderTest() { MainFolder mainFolder = new MainFolder(Directory.GetCurrentDirectory()); string path = await mainFolder.GetSubFolder(new FileFormatters()); Assert.AreEqual(Directory.GetCurrentDirectory(), path); }
public BaseExeFile(string fileName, IFolder folder = null) : base(NameFunc(fileName, folder)) { if (folder == null) { folder = new MainFolder(); } Exist = folder.CheckExists(fileName) == ExistenceCheckResult.FileExists; }
private static IFile NameFunc(string fileName, IFolder folder = null) { if (folder == null) { folder = new MainFolder(); } return(folder.CheckExists(fileName) == ExistenceCheckResult.FileExists ? folder.GetFile(fileName) : null); }
protected static IFolder FromLocalPath(string path) { path = path.Replace("\\", "|").Replace("/", "|"); IFolder folder = new MainFolder(); foreach (var folderName in path.Split('|')) { folder = folder.CreateFolder(folderName, CreationCollisionOption.OpenIfExists); } return(folder); }
protected override void Execute(NativeActivityContext context) { string username = Email.Get(context); //发送端账号 string password = Password.Get(context); //发送端密码(这个客户端重置后的密码) string server = Server.Get(context); //邮件服务器 Int32 port = Port.Get(context); //端口号 Int32 counts = Counts.Get(context); //检索邮件数 string mainFolder = MainFolder.Get(context); //邮件文件夹 string mailTopicKey = MailTopicKey.Get(context); string mailSenderKey = MailSenderKey.Get(context); string mailTextBodyKey = MailTextBodyKey.Get(context); List <object> configList = new List <object>(); List <MimeMessage> emails = new List <MimeMessage>(); ImapClient client = new ImapClient(); SearchQuery query; IList <UniqueId> uidss; try { client.CheckCertificateRevocation = false; client.ServerCertificateValidationCallback = (s, c, h, e) => true; client.Connect(server, port, SecureConnection); client.Authenticate(username, password); if (OnlyUnreadMessages || _AllUnreadMessages) { query = SearchQuery.NotSeen; } else { query = SearchQuery.All; } List <IMailFolder> mailFolderList = client.GetFolders(client.PersonalNamespaces[0]).ToList(); IMailFolder folder = client.GetFolder(mainFolder); folder.Open(FolderAccess.ReadWrite); emails = new List <MimeMessage>(); if (_AllUnreadMessages) { query = SearchQuery.NotSeen; uidss = folder.Search(query); for (int i = uidss.Count - 1; i >= 0; i--) { MimeMessage message = folder.GetMessage(new UniqueId(uidss[i].Id)); emails.Add(message); if (MarkAsRead) { folder.AddFlags(new UniqueId(uidss[i].Id), MessageFlags.Seen, true);//如果设置为true,则不会发出MessageFlagsChanged事件 } if (DeleteMessages) { folder.AddFlags(new UniqueId(uidss[i].Id), MessageFlags.Deleted, true);//如果设置为true,则不会发出MessageFlagsChanged事件 } } } else { uidss = folder.Search(query); for (int i = uidss.Count - 1, j = 0; i >= 0 && j < counts; i--, j++) { MimeMessage message = folder.GetMessage(new UniqueId(uidss[i].Id)); InternetAddressList Sender = message.From; string SenderStr = Sender.Mailboxes.First().Address; string Topic = message.Subject; if (mailTopicKey != null && mailTopicKey != "") { if (Topic == null || Topic == "") { j--; continue; } if (!Topic.Contains(mailTopicKey)) { j--; continue; } } if (mailSenderKey != null && mailSenderKey != "") { if (SenderStr == null || SenderStr == "") { j--; continue; } if (!SenderStr.Contains(mailSenderKey)) { j--; continue; } } if (mailTextBodyKey != null && mailTextBodyKey != "") { if (message.TextBody == null || message.TextBody == "") { j--; continue; } if (!message.TextBody.Contains(mailTextBodyKey)) { j--; continue; } } emails.Add(message); if (MarkAsRead) { folder.AddFlags(new UniqueId(uidss[i].Id), MessageFlags.Seen, true);//如果设置为true,则不会发出MessageFlagsChanged事件 } if (DeleteMessages) { folder.AddFlags(new UniqueId(uidss[i].Id), MessageFlags.Deleted, true);//如果设置为true,则不会发出MessageFlagsChanged事件 } } } //获取搜索结果的摘要信息(我们需要UID和BODYSTRUCTURE每条消息,以便我们可以提取文本正文和附件)(获取全部邮件) //var items = folder.Fetch(uidss, MessageSummaryItems.UniqueId | MessageSummaryItems.BodyStructure); MailMsgList.Set(context, emails); client.Disconnect(true); configList.Add(server); configList.Add(port); configList.Add(SecureConnection); configList.Add(username); configList.Add(password); configList.Add(mainFolder); } catch (Exception e) { client.Disconnect(true); SharedObject.Instance.Output(SharedObject.enOutputType.Error, "获取IMAP邮件失败", e.Message); } if (Body != null) { object[] buff = configList.ToArray(); context.ScheduleAction(Body, emails, client, buff); } }