public async Task<Pop3CommandReply> HandlePass(string username, string password) { var accountRepository = _container.GetInstance<IAccountRepository>(); _account = await accountRepository.ValidatePasswordAsync(username, password); if (_account == null) return new Pop3CommandReply(false, "Invalid username or password"); var folderRepository = _container.GetInstance<IFolderRepository>(); var inbox = await folderRepository.GetInbox(_account.Id); var messageRepository = _container.GetInstance<IMessageRepository>(); _messages = await messageRepository.GetMessages(_account.Id, inbox.Id); return Pop3CommandReply.CreateDefaultSuccess(); }
private string GetAccountMessageDirectory(Account account) { var mailbox = EmailAddressParser.GetMailbox(account.Address); var domain = EmailAddressParser.GetDomain(account.Address); return Path.Combine(_dataDirectory, domain, mailbox); }
private string GetMessageFullFileName(Account account, Message message) { var accountMessageDirectory = GetAccountMessageDirectory(account); var messageDirectory = Path.Combine(accountMessageDirectory, message.Filename.Substring(0, 2)); var messageFileFullPath = Path.Combine(messageDirectory, message.Filename); return messageFileFullPath; }
public Stream GetMessageData(Account account, Message message) { var messageFileFullPath = GetMessageFullFileName(account, message); return File.OpenRead(messageFileFullPath); }
public Task<Message> CreateAccountLevelMessageAsync(Message message, Account account, Folder folder) { if (message == null) throw new ArgumentNullException(nameof(message)); if (account == null) throw new ArgumentNullException(nameof(account)); var clonedMessage = message.Clone(); clonedMessage.Id = 0; clonedMessage.AccountId = account.Id; clonedMessage.FolderId = folder.Id; clonedMessage.Filename = Path.ChangeExtension(Guid.NewGuid().ToString(), ".eml"); clonedMessage.Recipients = new List<Recipient>(); var messageFileFullPath = GetMessageFullFileName(account, clonedMessage); var messageDirectory = Path.GetDirectoryName(messageFileFullPath); // TODO: Should be possible to do this asynchronously. Directory.CreateDirectory(messageDirectory); File.Copy(Path.Combine(_dataDirectory, message.Filename), messageFileFullPath); return Task.FromResult(clonedMessage); }
public async Task DeleteAsync(Account account, Message message) { if (account == null) throw new ArgumentNullException(nameof(account)); if (message == null) throw new ArgumentNullException(nameof(message)); var filename = GetMessageFullFileName(account, message); using (var sqlConnection = new MySqlConnection(_connectionString)) { sqlConnection.Open(); await sqlConnection.DeleteAsync(message); await DeleteRecipientsAsync(message, sqlConnection); } File.Delete(filename); }