예제 #1
0
        internal async Task <bool> DeleteLabel(Label label)
        {
            if (!await RefreshToken())
            {
                return(false);
            }

            MailApi api = new MailApi();

            int?charid  = (int?)mDBAccount.CharacterId;
            int?labelid = (int?)label.Id;

            try
            {
                await api.DeleteCharactersCharacterIdMailLabelsLabelIdAsync(
                    characterId : charid,
                    labelId : labelid,
                    datasource : ESIConfiguration.DataSource,
                    token : DBAccount.AccessToken);

                mLabels.Remove(label);
                ViewAccount.Sync(this);
                return(true);
            }
            catch (Eve.Api.Client.ApiException e)
            {
                ExceptionHandler.HandleApiException(null, e);
                return(false);
            }
        }
예제 #2
0
        public string GetMail(int id)
        {
            MailApi mailApi  = new MailApi();
            var     jsonData = JsonConvert.SerializeObject(mailApi.GetMail(id));

            return(jsonData);
        }
예제 #3
0
        public async Task UpdateAccount()
        {
            mLog.Info($"{this.UserName}: Updating account");

            await RefreshToken();

            MailApi api = new MailApi();
            GetCharactersCharacterIdMailLabelsOk labels;

            int draft_index = 0;

            try
            {
                labels = await api.GetCharactersCharacterIdMailLabelsAsync(
                    characterId : (int)mDBAccount.CharacterId,
                    datasource : ESIConfiguration.DataSource,
                    token : mDBAccount.AccessToken);


                mReadFailed = false;
                mViewAccount.AccountState = AccountState;

                mLabels.Clear();

                mLog.Info($"{this.UserName}: {labels.TotalUnreadCount.Value} unread mails");

                mDBAccount.UnreadCount = labels.TotalUnreadCount.Value;

                for (int i = 0; i < labels.Labels.Count; i++)
                {
                    var item  = labels.Labels[i];
                    var label = new Label(mClient, this, item);
                    mLabels.Add(label);
                    mLog.Info($"{this.UserName}: Added label '{label.Name}'");
                    if (label.Type == LabelType.Outbox)
                    {
                        draft_index = i + 1;
                    }
                }

                await GetMailingLists(api);
            }
            catch (Eve.Api.Client.ApiException e)
            {
                ExceptionHandler.HandleApiException(null, e);
                mReadFailed = true;
                mLabels.Clear();
            }

            mDraftLabel.UnreadCount = mClient.GetDraftCountForAccount(this);

            mLabels.Insert(draft_index, mDraftLabel);
            mViewAccount.Sync(this);
            mViewAccount.ShowSpinner = false;
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
        internal async Task <bool> SendMail(DraftMessageSource draft)
        {
            ExceptionHandler.LastException = null;

            if (!await RefreshToken())
            {
                return(false);
            }
            try
            {
                MailApi api = new MailApi();
                PostCharactersCharacterIdMailMail mail = new PostCharactersCharacterIdMailMail
                                                         (
                    Recipients: new List <PostCharactersCharacterIdMailRecipient>(),
                    Subject: draft.Subject,
                    Body: draft.Body
                                                         );

                foreach (var i in draft.Recipients)
                {
                    mail.Recipients.Add(new PostCharactersCharacterIdMailRecipient(
                                            RecipientType: ESIConvert.EntityTypeToRecipientType(i.EntityType),
                                            RecipientId: (int?)i.EntityID));
                }

                await api.PostCharactersCharacterIdMailAsync(
                    characterId : (int?)DBAccount.CharacterId,
                    mail : mail,
                    datasource : ESIConfiguration.DataSource,
                    token : DBAccount.AccessToken);

                return(true);
            }
            catch (Eve.Api.Client.ApiException e)
            {
                ExceptionHandler.HandleApiException(null, e);
                return(false);
            }
            catch (Exception e)
            {
                ExceptionHandler.HandleOtherException(null, e);
                return(false);
            }
        }
예제 #6
0
        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);
            }
        }
예제 #7
0
        private async Task GetMailingLists(MailApi api)
        {
            List <GetCharactersCharacterIdMailLists200Ok> list;

            try
            {
                list = await api.GetCharactersCharacterIdMailListsAsync(
                    characterId : (int)mDBAccount.CharacterId,
                    datasource : ESIConfiguration.DataSource,
                    token : mDBAccount.AccessToken);
            }
            catch (Eve.Api.Client.ApiException e)
            {
                ExceptionHandler.HandleApiException(null, e);
                return;
            }

            UserCache.EntityInfo[] info = new UserCache.EntityInfo[list.Count];
            int index = 0;

            foreach (var i in list)
            {
                if (!i.MailingListId.HasValue)
                {
                    continue;
                }
                info[index++] = new UserCache.EntityInfo()
                {
                    EntityType = EntityType.Mailinglist,
                    EntityID   = i.MailingListId.Value,
                    Name       = i.Name
                };
                var label = new Label(mClient, this, i.MailingListId.Value, i.Name, LabelType.MailingList);
                mLabels.Add(label);
                mLog.Info($"{this.UserName}: Added mailing list '{label.Name}'");
            }

            await UserCache.EntityLookupAsync.AddLookups(info);
        }
예제 #8
0
        internal async Task <bool> AddLabel(string label_name)
        {
            if (!await RefreshToken())
            {
                return(false);
            }

            MailApi api = new MailApi();

            int?charid = (int?)mDBAccount.CharacterId;
            PostCharactersCharacterIdMailLabelsLabel label = new PostCharactersCharacterIdMailLabelsLabel(
                PostCharactersCharacterIdMailLabelsLabel.ColorEnum.Ffffff, label_name);

            try
            {
                int?labelid = await api.PostCharactersCharacterIdMailLabelsAsync(
                    characterId : charid,
                    label : label,
                    datasource : ESIConfiguration.DataSource,
                    token : DBAccount.AccessToken);

                if (!labelid.HasValue)
                {
                    return(false);
                }

                mLabels.Add(new Label(mClient, this, labelid ?? -1, label_name, LabelType.Label));
                ViewAccount.Sync(this);
                return(true);
            }
            catch (Eve.Api.Client.ApiException e)
            {
                ExceptionHandler.HandleApiException(null, e);
                return(false);
            }
        }
예제 #9
0
        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);
        }
예제 #10
0
        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);
        }
예제 #11
0
        public void DeleteMail(int id)
        {
            MailApi mailApi = new MailApi();

            mailApi.DeleteMail(id);
        }
예제 #12
0
        public void UpdateMail(Mail mail)
        {
            MailApi mailApi = new MailApi();

            mailApi.AddMail(mail);
        }
예제 #13
0
        public void AddMail(Mail mail)//[FromBody]string value
        {
            MailApi mailApi = new MailApi();

            mailApi.AddMail(mail);
        }