private void Item_Downloaded(object sender, System.ComponentModel.PropertyChangedEventArgs e) { ViewMailItem item = sender as ViewMailItem; if (item.IsLoading) { return; } item.UnregisterHandler("IsLoading", Item_Downloaded); if (item != CurrentItem) { return; } if (!item.HasBody) { LoadHtml("(Unable to load message)"); } else { LoadHtml(item.Body); } }
public async Task LoadMailBody(ViewMailItem item) { if (item.Source == null || item.Source.AccountSource == null) { return; } await((Account)item.Source.AccountSource).LoadMailBody(item); }
private void cMarkUnread_Click(object sender, RoutedEventArgs e) { mLastSelectedItem = null; List <ViewMailItem> items = new List <ViewMailItem>(cList.SelectedItems.Count); foreach (ViewMailItem item in cList.SelectedItems) { item.IsItemRead = false; items.Add(item); } GetClient().SaveMailMetaData(items.ToArray()); }
public async Task <bool> LoadMailBody(ViewMailItem item) { if (!await RefreshToken()) { return(false); } if (item.HasBody) { return(true); } foreach (var i in item.Recipients) { if (i.ImageUrl64 == null) { await mClient.AddLookupAsync(i); } } await mClient.FinishLookupsAsync(); MailApi api = new MailApi(); int id = (int)DBAccount.CharacterId; int mailid = (int)item.MailId; try { var resp = await api.GetCharactersCharacterIdMailMailIdAsync( characterId : id, mailId : mailid, datasource : ESIConfiguration.DataSource, token : DBAccount.AccessToken); item.Body = resp.Body; mReadFailed = false; mViewAccount.AccountState = AccountState; return(true); } catch (Eve.Api.Client.ApiException e) { ExceptionHandler.HandleApiException(null, e); mReadFailed = true; mViewAccount.AccountState = AccountState; return(false); } }
private async Task DownloadText(ViewMailItem item) { item.RegisterHandler("IsLoading", Item_Downloaded); if (item.IsLoading) { return; } item.IsLoading = true; await Client.LoadMailBody(item); item.IsLoading = false; }
public DraftMessageSource CreateDraft(ViewMailItem item, DraftType type) { var ret = new DraftMessageSource(this); ret.Account = item.Source.Account; switch (type) { case DraftType.NewMail: return(ret); case DraftType.Reply: ret.Subject = mRegEx_GetTitle.Replace(item.MailSubject, "Re: ${Title}"); ret.AddRecipients(item.From); break; case DraftType.ReplyAll: ret.Subject = mRegEx_GetTitle.Replace(item.MailSubject, "Re: ${Title}"); ret.AddRecipients(item.From); ret.AddRecipients(item.Recipients); break; case DraftType.Forward: ret.Subject = mRegEx_GetTitle.Replace(item.MailSubject, "Fw: ${Title}"); break; } StringBuilder body = new StringBuilder(); body.Append("<font size=\"12\" color=\"#bfffffff\"><br>--------------------------------<br>"); body.AppendFormat("{0}<br>", item.MailSubject); body.AppendFormat("From: {0}<br>", CreateEveWhoMarkup(item.From)); body.AppendFormat("Sent: {0:yyyy.MM.dd HH:mm}<br>", item.Timestamp); body.Append("To: "); List <string> recipients = new List <string>(); foreach (var i in item.Recipients) { recipients.Add(CreateEveWhoMarkup(i)); } body.Append(string.Join(", ", recipients)); body.AppendFormat("<br><br>{0}", item.Body); ret.Body = body.ToString(); return(ret); }
public async Task <bool> SaveMailMetaData(ViewMailItem item) { if (!await RefreshToken()) { return(false); } MailApi api = new MailApi(); PutCharactersCharacterIdMailMailIdContents content = new PutCharactersCharacterIdMailMailIdContents(); content.Read = item.IsItemRead; content.Labels = new List <int?>(); foreach (var i in item.Labels) { if (i.Subscribed) { content.Labels.Add(i.Label.Id); } } try { int id = (int)DBAccount.CharacterId; int mailid = (int)item.MailId; await api.PutCharactersCharacterIdMailMailIdAsync( characterId : id, contents : content, mailId : mailid, datasource : ESIConfiguration.DataSource, token : DBAccount.AccessToken); return(true); } catch (Eve.Api.Client.ApiException e) { ExceptionHandler.HandleApiException(null, e); mReadFailed = true; mViewAccount.AccountState = AccountState; return(false); } }
private bool GetItemFromCache(long id, out ViewMailItem item) { Predicate <ViewMailItem> search = (q) => q.MailId == id; if (mGlobalCache.IsValid && null != (item = mGlobalCache.MailItems.Find(search))) { return(true); } foreach (var i in mLabelCache.Values) { if (i.IsValid && null != (item = i.MailItems.Find(search))) { return(true); } } item = null; return(false); }
private async Task <bool> LoadDrafts(MailView view) { view.CanDelete = view.CanSend = DBAccount.Permissions.HasFlag(Auth.AccessFlag.MailSend); view.CanDownload = false; view.IsDraft = true; List <MailRecipient> recipients = new List <MailRecipient>(); foreach (var i in mClient.GetDraftsForAccount(this)) { ViewMailItem item = new ViewMailItem(-1, true); item.Draft = i; item.MailSubject = i.Subject; item.Body = i.Body; item.Timestamp = i.LastModified; item.From = new MailRecipient(EntityType.Character, DBAccount.CharacterId); await mClient.AddLookupAsync(item.From); recipients.Clear(); foreach (var j in i.Recipients) { MailRecipient recipient = new MailRecipient(j.EntityType, j.EntityID); await mClient.AddLookupAsync(recipient); recipients.Add(recipient); } item.Recipients = recipients.ToArray(); item.Source = view.Source; view.MailItems.Add(item); } await mClient.FinishLookupsAsync(); view.HasItems = true; view.IsLoading = false; return(true); }
private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e) { RaiseEvent(new RoutedEventArgs(mSelectedItemChangedEvent, this)); var view = DataContext as ViewModel.MailView; if (!view.IsDraft && Properties.Settings.Default.MailReadAction == Config.EmailReadAction.AfterMessageLeave && view.CanDelete && mLastSelectedItem != null && !mLastSelectedItem.IsItemRead) { mLastSelectedItem.IsItemRead = true; GetClient().SaveMailMetaData(mLastSelectedItem); } if (cList.SelectedItems == null || cList.SelectedItems.Count != 1) { mLastSelectedItem = null; } else { mLastSelectedItem = cList.SelectedItem as ViewModel.ViewMailItem; } }
internal async Task <bool> DeleteMail(ViewMailItem item) { if (!await RefreshToken()) { return(false); } MailApi api = new MailApi(); int?charid = (int?)mDBAccount.CharacterId; int?mailid = (int?)item.MailId; try { await api.DeleteCharactersCharacterIdMailMailIdAsync( characterId : charid, mailId : mailid, datasource : ESIConfiguration.DataSource); } catch (Eve.Api.Client.ApiException e) { ExceptionHandler.HandleApiException(null, e); mReadFailed = true; mViewAccount.AccountState = AccountState; return(false); } mGlobalCache.MailItems.Remove(item); foreach (var i in mLabelCache.Values) { i.MailItems.Remove(item); } return(true); }
internal void UpdateAccountCounts(ViewMailItem item) { int[,] statetable = new int[, ] { //Label Added|Label Removed|No Change(True)|No Change(False) { 0, -1, -1, 0 }, /*Read Set*/ { 1, 0, 1, 0 }, /*Read Unset*/ { 1, -1, 0, 0 }, /*No Change(Unread)*/ { 0, 0, 0, 0 } /*No Change(Read)*/ }; int readstate = -1; if (item.MetaState.HasFlag(ViewMailMetaState.ReadFlagSet)) { readstate = 0; UnreadCount--; } else if (item.MetaState.HasFlag(ViewMailMetaState.ReadFlagUnset)) { readstate = 1; UnreadCount++; } else if (item.IsItemUnread) { readstate = 2; } else { readstate = 3; } if (UnreadCount < 0) { UnreadCount = 0; } for (int i = 0; i < item.Labels.Count; i++) { var vlabel = item.Labels[i]; Label label = ((ISourceInfo)vlabel.Label).LabelSource as Label; int labelstate = -1; if (vlabel.MetaState.HasFlag(ViewMailMetaState.LabelAdded)) { labelstate = 0; } else if (vlabel.MetaState.HasFlag(ViewMailMetaState.LabelRemoved)) { labelstate = 1; } else if (vlabel.Subscribed) { labelstate = 2; } else { labelstate = 3; } label.UnreadCount += statetable[readstate, labelstate]; MailCache cache = GetCache(label); if (cache != null && cache.IsValid) { cache.MailItems.Remove(item); if (vlabel.Subscribed) { cache.MailItems.Add(item); } } } ViewAccount.Sync(this); }
private async Task <List <ViewMailItem> > LoadMailsWorker(ILabelSource label, ISourceInfo source, int?from = null, long?to = null, bool fresh = false) { List <int?> labels = null; if (label != null && !label.IsVirtual) { labels = new List <int?>(); labels.Add(label.Id); } MailApi api = new MailApi(); int id = (int)DBAccount.CharacterId; List <GetCharactersCharacterIdMail200Ok> mails; mails = await api.GetCharactersCharacterIdMailAsync( characterId : id, datasource : ESIConfiguration.DataSource, labels : labels, lastMailId : from, token : DBAccount.AccessToken); List <ViewMailItem> viewmails = new List <ViewMailItem>(); List <MailRecipient> recipients = new List <MailRecipient>(); foreach (var i in mails) { if (!i.MailId.HasValue) { continue; } if (to.HasValue && to.Value == i.MailId.Value) { break; } if (label != null && label.Type == LabelType.MailingList) { if (!HasRecipient(i, EntityType.Mailinglist, label.Id)) { continue; } } recipients.Clear(); ViewMailItem item; if (!fresh && GetItemFromCache(i.MailId.Value, out item)) { viewmails.Add(item); continue; } item = new ViewMailItem(i.MailId.Value, i.IsRead.HasValue && i.IsRead.Value); item.Source = source; item.From = new MailRecipient(EntityType.Character, i.From.HasValue ? i.From.Value : -1); await mClient.AddLookupAsync(item.From); item.MailSubject = i.Subject; item.Timestamp = i.Timestamp.HasValue ? i.Timestamp.Value : DateTime.MinValue; foreach (var j in i.Recipients) { MailRecipient recipient = new MailRecipient(ESIConvert.RecipientTypeToEntityType(j.RecipientType.GetValueOrDefault()), j.RecipientId.Value); recipients.Add(recipient); } foreach (var j in mViewAccount.Labels) { if (j.IsVirtual) { continue; } item.Labels.Add(new ViewMailLabelLink(item, j, i.Labels.Contains(j.Id), label != null && label.Id == j.Id)); } item.Recipients = recipients.ToArray(); viewmails.Add(item); } await mClient.FinishLookupsAsync(); return(viewmails); }