Example #1
0
        //Delete inbox mail by client
        private void DeleteInboxMail(object o)
        {
            var mail = o as MailMsgBase;

            if (mail != null && !string.IsNullOrEmpty(mail.UID))
            {
                Messenger.Default.Send(new DisplayMessage("Are you sure?", "The mail will delete and not exist.Ensure delete this mail.")
                {
                    OnOk = async() =>
                    {
                        System.Diagnostics.Debug.WriteLine("On ok click.");
                        IsRequesting = true;
                        await Task.Run(() =>
                        {
                            try
                            {
                                System.Diagnostics.Debug.WriteLine("Delete mail action invoked.");
                                if (EnsureLoginFetchMessage() && globalClient.DeleteMessage(mail.UID))
                                {
                                    Messenger.Default.Send(new DisplayMessage("Delete Successful!", DisplayType.Toast));
                                    Application.Current.Dispatcher.Invoke(() =>
                                    {
                                        InboxList.Remove(mail);
                                    });
                                }
                            }
                            catch (Exception e)
                            {
                                Messenger.Default.Send(new DisplayMessage("Delete Fail!", e.Message));
                            }
                        });
                        IsRequesting = false;
                    }
                });
            }
        }
Example #2
0
        //Ensure login and fetch new messages
        private bool EnsureLoginFetchMessage()
        {
            bool isSuccessful = false;

            try
            {
                var newMsgs = new List <MailMsgBase>();
                //Login
                EnsureLogin(msg =>
                {
                    newMsgs.Add(msg);
                });
                System.Diagnostics.Debug.WriteLine("Get new mail message succuessed.");
                System.Diagnostics.Debug.WriteLine($"newMsgs.Count : {newMsgs.Count}");
                var addList    = new List <MailMsgBase>();
                var removeList = new List <MailMsgBase>();
                //Remove messages not exist from InboxList
                //Remove messages exist in InboxList from NewMsgs
                for (int i = 0; i < InboxList.Count; i++)
                {
                    var msg   = InboxList[i];
                    var index = newMsgs.FindIndex(obj => obj.UID == msg.UID);
                    if (index < 0)
                    {
                        removeList.Add(msg);
                    }
                    else
                    {
                        var newer = newMsgs[index];
                        msg.UpdateOrigin(newer);
                        newMsgs.RemoveAt(index);
                    }
                }
                //Update it
                Application.Current.Dispatcher.Invoke(() =>
                {
                    for (int i = 0; i < removeList.Count; i++)
                    {
                        InboxList.Remove(removeList[i]);
                        if (removeList[i] == null)
                        {
                            continue;
                        }
                        System.Diagnostics.Debug.WriteLine($"Remvoe {removeList[i].UID}");
                    }
                    for (int i = 0; i < newMsgs.Count; i++)
                    {
                        if (newMsgs[i] == null)
                        {
                            continue;
                        }
                        InboxList.Insert(0, newMsgs[i]);
                        Messenger.Default.Send(new DisplayMessage("New Mail",
                                                                  newMsgs[i].From[i].ToString() + "\n" + newMsgs[i].Subject,
                                                                  DisplayType.Toast));
                        System.Diagnostics.Debug.WriteLine($"Add {newMsgs[i].UID}");
                    }
                });
                isSuccessful = true;
            }
            catch (Exception e)
            {
                Messenger.Default.Send(new DisplayMessage("Error on get mail.", e.Message));
                isSuccessful = false;
            }
            return(isSuccessful);
        }