public List <MyOutlookItem> GetAllItemsInSpecificFolder(MAPIFolder folder, bool unreadOnly = false)
        {
            Items relevantItems = folder.Items;

            if (unreadOnly && folder.UnReadItemCount == 0)
            {
                return(new List <MyOutlookItem>(0));
            }
            else
            if (unreadOnly)
            {
                relevantItems = folder.Items.Restrict("[Unread]=true");
            }

            List <MyOutlookItem> items = new List <MyOutlookItem>(folder.Items.Count);

            for (int i = 1; i <= relevantItems.Count; i++)
            {
                {
                    var item = relevantItems[i];
                    // ((ItemEvents_10_Event)item).Close += Item_Close;


                    MyOutlookItem itm = new MyOutlookItem(item, i, folder.Name);
                    items.Add(itm);
                }
            }
            return(items);
        }
 private void btnMarkAllMailsAsRead_Click(object sender, EventArgs e)
 {
     tmrRefreshOutlook.Enabled = false;
     foreach (DataGridViewRow row in dgvUnreadMails.Rows)
     {
         MyOutlookItem currentitem = (MyOutlookItem)row.DataBoundItem;
         var           outlookmail = currentitem.OutlookMailItem as dynamic;
         if (outlookmail != null)
         {
             try
             {
                 outlookmail.UnRead = false;
             }
             catch (System.Exception ex)
             {
                 MessageShow.ShowException(this, ex, false);
             }
         }
     }
     if (!bwRefreshMail.IsBusy)
     {
         bwRefreshMail.RunWorkerAsync();
     }
     tmrRefreshOutlook.Enabled = true;
 }
 private void dgvAllItems_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
 {
     if (dgvAllItems.CurrentRow != null)
     {
         MyOutlookItem currentitem = (MyOutlookItem)dgvAllItems.CurrentRow.DataBoundItem;
         dynamic       item        = currentitem.OutlookMailItem;
         item.Display();
     }
 }
 private void btnMailReply_Click(object sender, EventArgs e)
 {
     if (dgvUnreadMails.CurrentRow != null)
     {
         try
         {
             MyOutlookItem currentitem = (MyOutlookItem)dgvUnreadMails.CurrentRow.DataBoundItem;
             currentitem.RunMethod("Reply");
         }
         catch (System.Exception ex)
         {
             MessageShow.ShowException(this, ex);
         }
     }
 }
 private void dgvUnreadMails_CellDoubleClick(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
 {
     if (dgvUnreadMails.CurrentRow != null)
     {
         try
         {
             MyOutlookItem currentitem = (MyOutlookItem)dgvUnreadMails.CurrentRow.DataBoundItem;
             currentitem.RunMethod("Display");
         }
         catch (System.Exception ex)
         {
             MessageShow.ShowException(this, ex);
         }
     }
 }
 private void btnMailDelete_Click(object sender, EventArgs e)
 {
     if (dgvUnreadMails.CurrentRow != null)
     {
         try
         {
             MyOutlookItem currentitem = (MyOutlookItem)dgvUnreadMails.CurrentRow.DataBoundItem;
             currentitem.SetProperty("Unread", false);
             currentitem.RunMethod("Delete");
             RefreshMails();
         }
         catch (System.Exception ex)
         {
             MessageShow.ShowException(this, ex);
         }
     }
 }