private async Task <MailMessage> EncryptMessageAsync(MailAccountContext account, IEnumerable <PublicKeyModel> keys, string recipient, string content) { var message = CreateMailMessage(account, recipient, content); var mime = await message.ToMimeAsync(); var bytes = Encoding.UTF8.GetBytes(mime); var wrapper = CreateMailMessage(account, recipient, "blubbi"); var publicKey = Convert.ToBase64String(App.Context.KeyContainer.PublicKey); wrapper.Headers.Add(ParanoiaHeaderKeys.PublicKey, publicKey); foreach (var key in keys) { var keyBytes = Convert.FromBase64String(key.Data); var nonceBytes = PublicKeyCrypto.GenerateNonce(); var encryptedBytes = await Task.Factory.StartNew(() => App.Context.KeyContainer.EncryptWithPublicKey(bytes, keyBytes, nonceBytes)); var writer = new BinaryWriter(new MemoryStream()); writer.Write(nonceBytes); writer.Write(encryptedBytes); writer.Flush(); writer.BaseStream.Seek(0, SeekOrigin.Begin); var view = new AlternateView(writer.BaseStream, new ContentType("application/x-setolicious")); wrapper.AlternateViews.Add(view); } return(wrapper); }
internal MailboxContext(MailAccountContext account, MailboxModel mailbox) { _account = account; _mailbox = mailbox; _showAllMessages = true; _deleteMailboxCommand = new RelayCommand(OnDeleteMailbox); _createMailboxCommand = new RelayCommand(OnCreateMailbox); _syncMailboxCommand = new RelayCommand(OnSyncMailbox); }
public MailCompositionContext() { _accounts = App.Context.Accounts; _selectedAccount = _accounts.FirstOrDefault(); _recipients = new ObservableCollection <string>(); _sendCommand = new SendCommand(this); _addAttachmentCommand = new AddAttachmentCommand(this); _attachments = new ObservableCollection <AttachmentContext>(); }
private MailMessage CreateMailMessage(MailAccountContext account, string recipient, string content) { var message = new MailMessage { From = new MailAddress(account.Address, account.Name) }; message.To.Add(new MailAddress(recipient)); message.IsBodyHtml = true; message.Subject = Subject; message.BodyEncoding = Encoding.UTF8; message.BodyTransferEncoding = TransferEncoding.Base64; message = HandleEmbeddedImages(message, content); _attachments.ForEach(x => message.Attachments.Add(new Attachment(x.FullName))); return(message); }
public OutboxContext(MailAccountContext account) { _account = account; _smtpRequests = new ObservableCollection <SmtpRequestContext>(); _smtpRequests.CollectionChanged += OnSmtpRequestsCollectionChanged; _sendMessagesCommand = new RelayCommand(OnSendMessages); Observable.FromEventPattern <QueryStringEventArgs>( action => QueryStringChanged += action, action => QueryStringChanged -= action) .Select(x => x.EventArgs) .Where(x => (x.Text.Length > 1 || string.IsNullOrEmpty(x.Text))) .Throttle(TimeSpan.FromMilliseconds(200)) .Select(x => x.Text) .ObserveOn(new DispatcherSynchronizationContext(Application.Current.Dispatcher)) .Subscribe(OnQueryReceived); }
private async Task <IEnumerable <MailMessage> > CreateSmtpMessagesAsync(MailAccountContext account) { var e = new DocumentTextRequestedEventArgs(); OnDocumentTextRequested(e); var messages = new List <MailMessage>(); using (var database = new DatabaseContext()) { foreach (var recipient in Recipients) { if (string.IsNullOrEmpty(recipient)) { continue; } var rec = recipient; var contact = await database.MailContacts.FirstOrDefaultAsync(x => x.Address == rec); if (contact == null) { var message = CreateMailMessage(account, recipient, e.Document); messages.Add(message); continue; } var keys = await database.PublicKeys.Where(x => x.ContactId == contact.Id).ToArrayAsync(); if (keys == null || keys.Length == 0) { var message = CreateMailMessage(account, recipient, e.Document); messages.Add(message); continue; } var cryptMessage = await EncryptMessageAsync(account, keys, recipient, e.Document); messages.Add(cryptMessage); } return(messages); } }
internal void NotifyAccountCreated(MailAccountContext account) { _accounts.Add(account); }
internal void NotifyAccountDeleted(MailAccountContext account) { _accounts.Remove(account); RaisePropertyChanged(() => Accounts); }