示例#1
0
        public async Task <bool> SendMail(DraftMessageSource draft)
        {
            var  sourceinfo = draft.Account as ISourceInfo;
            var  account    = sourceinfo.AccountSource as Account;
            bool ret        = await account.SendMail(draft);

            if (ret)
            {
                await DeleteDraft(draft);
            }

            return(ret);
        }
示例#2
0
        public DraftMessageSource CreateDraft()
        {
            var ret = new DraftMessageSource(this);

            if (MailView.Source != null && MailView.Source.Account != null)
            {
                ret.Account = MailView.Source.Account;
            }
            else if (mSendAccounts.Count > 0)
            {
                ret.Account = mSendAccounts[0];
            }

            return(ret);
        }
示例#3
0
        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);
        }
示例#4
0
        public bool OpenDraft <T>(DraftMessageSource draft, out T result)
            where T : class, IDraftWindow, new()
        {
            IDraftWindow window;

            if (mDraftWindows.TryGetValue(draft.DraftId, out window))
            {
                window.SetFocus();
                result = (T)window;
                return(false);
            }

            result = new T();
            result.SetDraft(draft);
            mDraftWindows.Add(draft.DraftId, result);
            return(true);
        }
示例#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
        private async Task DeleteDraft(DraftMessageSource draft)
        {
            await mAccountDB.DeleteDraftAsync(draft.DBDraft);

            mDrafts.Remove(draft);
            IDraftWindow window;

            if (mDraftWindows.TryGetValue(draft.DraftId, out window))
            {
                window.DraftDeleted();
            }

            if (MailView.Source != null && MailView.Source.AccountSource == draft.Account && MailView.Source.LabelSource != null && MailView.Source.LabelSource.Type == LabelType.Drafts)
            {
                await((Account)MailView.Source.AccountSource).LoadMailView(MailView.Source.LabelSource);
            }

            UpdateAccountDraftCounts();
        }
示例#7
0
        private async Task DeleteMailAsync(IEnumerable <ViewMailItem> items)
        {
            foreach (var i in items)
            {
                if (i.Draft != null)
                {
                    DraftMessageSource draft = i.Draft as DraftMessageSource;
                    await DeleteDraft(draft);

                    continue;
                }
                var account = i.Source.AccountSource as Account;

                await account.DeleteMail(i);
            }


            MailView.UpdateWorkingItems(items);
        }
示例#8
0
        public void Init()
        {
            InfoCache = new UserInfoCache(this);
            mAccountDB.Load();


            foreach (var i in mAccountDB.Accounts)
            {
                Account account = new Account(this, i);
                mAccounts.Add(account);
                mViewAccounts.Add(account.ViewAccount);
                if (account.DBAccount.Permissions.HasFlag(Auth.AccessFlag.MailSend))
                {
                    mSendAccounts.Add(account.ViewAccount);
                }
            }

            List <DraftMessageSource> loaded_drafts = new List <DraftMessageSource>();

            foreach (var i in mAccountDB.Drafts)
            {
                DraftMessageSource source = new DraftMessageSource(this, i);

                if (source.Account == null)
                {
                    continue;
                }

                mDrafts.Add(source);
                loaded_drafts.Add(source);
            }

            TaskChainHandler load_draft_ids = async delegate()
            {
                foreach (var i in loaded_drafts)
                {
                    await EntityLookupAsync.LookupIDs(i.Recipients);
                }
            };

            AddTaskToChain(load_draft_ids);
        }
示例#9
0
 public void CloseDraft(DraftMessageSource draft)
 {
     mDraftWindows.Remove(draft.DraftId);
 }