Example #1
0
        private bool HasRecipient(GetCharactersCharacterIdMail200Ok mailitem, EntityType type, int id)
        {
            foreach (var i in mailitem.Recipients)
            {
                if (type == ESIConvert.RecipientTypeToEntityType(i.RecipientType.GetValueOrDefault()) && id == i.RecipientId.GetValueOrDefault())
                {
                    return(true);
                }
            }

            return(false);
        }
Example #2
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);
            }
        }
Example #3
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);
        }