UI/FormRegionPrivacyStatus.cs
author Dean Looyengoed
Thu, 24 Mar 2016 14:39:48 +0100
changeset 719 e2f2fd67fb84
parent 713 0035e6809ef2
child 720 17c2278b0af6
permissions -rw-r--r--
Clear the unencrypted preview even if it should not be shown.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
     1
´╗┐using pEpCOMServerAdapterLib;
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
     2
using System;
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
     3
using System.Collections.Generic;
445
499559d35fae Implement the INotifyPropertyChanged interface from System.ComponentModel.
Dean Looyengoed
parents: 438
diff changeset
     4
using System.ComponentModel;
438
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
     5
using System.Drawing;
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
     6
using System.Runtime.InteropServices;
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
     7
using System.Windows.Forms;
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
     8
using Color = System.Drawing.Color;
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
     9
using Outlook = Microsoft.Office.Interop.Outlook;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    10
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    11
namespace pEp
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    12
{
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
    13
    /// <summary>
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
    14
    /// Partial class for the privacy status form region that is displayed below every outlook message.
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
    15
    /// </summary>
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
    16
    partial class FormRegionPrivacyStatus
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    17
    {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    18
        #region Form Region Factory
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    19
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    20
        [Microsoft.Office.Tools.Outlook.FormRegionMessageClass(Microsoft.Office.Tools.Outlook.FormRegionMessageClassAttribute.Note)]
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
    21
        [Microsoft.Office.Tools.Outlook.FormRegionName("pEp.FormRegionPrivacyStatus")]
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
    22
        public partial class FormRegionPrivacyStatusFactory
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    23
        {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    24
            // Occurs before the form region is initialized.
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    25
            // To prevent the form region from appearing, set e.Cancel to true.
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    26
            // Use e.OutlookItem to get a reference to the current Outlook item.
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
    27
            private void FormRegionPrivacyStatus_FormRegionInitializing(object sender, Microsoft.Office.Tools.Outlook.FormRegionInitializingEventArgs e)
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    28
            {
327
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    29
                WindowFormRegionCollection formRegions;
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    30
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    31
                /* There is a Microsoft bug at least in Outlook 2013 and Windows 8.1
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    32
                 * This bug causes multiple PrivacyStatus form regions to appear stacked on top of each other.
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    33
                 * To trigger this bug, on an unencrypted server, click reply to compose an in-line response.
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    34
                 * Then click to another tab such as People or Tasks. Then click back on the mail tab to view 
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    35
                 * the original email again. Two form regions will be visible: 
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    36
                 * (1) for the status during the in-line reply and 
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    37
                 * (2) for the status of only the received message.
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    38
                 * 
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    39
                 * To fix this bug, any existing form regions are found and closed when initializing a new privacy status
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    40
                 * form region.
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    41
                 */
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    42
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    43
                try
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    44
                {
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    45
                    formRegions = Globals.FormRegions[Globals.ThisAddIn.Application.ActiveExplorer()];
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    46
                    if (formRegions.FormRegionPrivacyStatus != null)
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    47
                    {
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    48
                        /* Note: there seems to be no way to actually close the form region.
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    49
                         * Therefore, this is as close as possible to actually closing it.
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    50
                         * The actual form regions will be cleaned up as soon as another email is selected.
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    51
                         */
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    52
                        formRegions.FormRegionPrivacyStatus.OutlookFormRegion.Visible = false;
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    53
                    }
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    54
                }
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    55
                catch { }
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    56
776d10c3d587 Work around an Outlook bug that causes multiple privacy status form regions to be shown.
Dean Looyengoed
parents: 325
diff changeset
    57
                return;
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    58
            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    59
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    60
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    61
        #endregion
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    62
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
    63
        /* Notes:
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
    64
         * 
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
    65
         * Use this.OutlookItem to get a reference to the current Outlook item.
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
    66
         * Use this.OutlookFormRegion to get a reference to the form region.
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
    67
         * 
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
    68
         * UI State Managment:
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
    69
         * 
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
    70
         * The UI state is almost entirely set from the associated mail item data.
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
    71
         * However, a separate state class is maintained to represent the UI as some separation is needed.
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
    72
         * This logical separation MUST be maintained throughout the code.
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
    73
         * Specific cases are noted where possible.
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
    74
         * 
356
919bcfd67cc6 Populate expanded properties/data in the selection item for in-line handshake.
Dean Looyengoed
parents: 355
diff changeset
    75
         * The separate privacy status manager form state is also managed here.
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
    76
         * 
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
    77
         */
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
    78
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
    79
        private CryptableMailItem       associatedMailItem = null;
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
    80
        private bool                    eventsAreConnected = false;
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
    81
        private bool                    initialized        = false;
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
    82
        private FormManagePrivacyStatus managerForm        = null;
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
    83
        private bool                    refreshOngoing     = false;
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
    84
250
3b6d98cbfc20 Finish initial implementation of the selection list in the UI.
Dean Looyengoed
parents: 244
diff changeset
    85
        // Data or controls not stored in the UI
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
    86
        private _pEp_color stateUIColorRating; // WARNING: Do NOT use this directly
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    87
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
    88
        /**************************************************************
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
    89
         * 
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
    90
         * Methods
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
    91
         * 
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
    92
         *************************************************************/
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    93
171
897440376f2d Comment the StopHere method
Dean Looyengoed
parents: 170
diff changeset
    94
        /// <summary>
438
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
    95
        /// Determines if this form region is running in an inspector window.
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
    96
        /// If not true, it is assumed to be within an explorer window.
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
    97
        /// </summary>
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
    98
        /// <returns>True if an inspector window, false if within an explorer.</returns>
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
    99
        private bool IsWithinInspector()
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
   100
        {
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
   101
            bool isWithinInspector = false;
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
   102
            Outlook.Explorer temp = null;
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
   103
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
   104
            try
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
   105
            {
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
   106
                // Just try to cast to an explorer class
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
   107
                temp = (Outlook.Explorer)this.OutlookFormRegion.Parent;
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
   108
                isWithinInspector = false;
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
   109
            }
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
   110
            catch
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
   111
            {
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
   112
                isWithinInspector = true;
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
   113
            }
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
   114
            finally
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
   115
            {
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
   116
                if (temp != null)
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
   117
                {
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
   118
                    Marshal.ReleaseComObject(temp);
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
   119
                    temp = null;
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
   120
                }
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
   121
            }
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
   122
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
   123
            return (isWithinInspector);
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
   124
        }
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
   125
ac133be97883 Add method to determine if the privacy status form region is displayed in an inspector.
Dean Looyengoed
parents: 434
diff changeset
   126
        /// <summary>
170
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   127
        /// Sets the cryptable mail item associated with this encryption status panel.
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   128
        /// The associated mail item can then be accessed through its local variable.
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   129
        /// </summary>
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   130
        private void SetAssociatedMailItem()
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   131
        {
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   132
            bool errorOccurred = false;
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   133
            Outlook.MailItem omi = null;
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   134
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   135
            // Null check
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   136
            if (!errorOccurred)
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   137
            {
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   138
                try
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   139
                {
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   140
                    if (this.OutlookItem == null)
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   141
                    {
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   142
                        errorOccurred = true;
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   143
                    }
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   144
                }
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   145
                catch (COMException)
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   146
                {
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   147
                    errorOccurred = true;
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   148
                }
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   149
            }
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   150
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   151
            // Attempt to get and cast the outlook mail item
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   152
            if (!errorOccurred)
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   153
            {
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   154
                try
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   155
                {
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   156
                    omi = (Outlook.MailItem)this.OutlookItem;
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   157
                }
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   158
                catch
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   159
                {
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   160
                    errorOccurred = true;
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   161
                }
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   162
            }
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   163
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   164
            // Finally set the associated mail item
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   165
            if ((errorOccurred) ||
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   166
                (omi == null))
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   167
            {
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   168
                this.associatedMailItem = null;
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   169
            }
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   170
            else
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   171
            {
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   172
                // Check if the associated mail item has already been set
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   173
                if (this.associatedMailItem != null)
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   174
                {
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   175
                    // Only re-set the mail item if the EntryID has changed
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   176
                    if (this.associatedMailItem.EntryID != omi.EntryID)
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   177
                    {
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   178
                        this.associatedMailItem = new CryptableMailItem(omi);
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   179
                    }
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   180
                }
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   181
                else
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   182
                {
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   183
                    this.associatedMailItem = new CryptableMailItem(omi);
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   184
                }
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   185
            }
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   186
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   187
            return;
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   188
        }
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
   189
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   190
        /// <summary>
672
98bec5884763 Rename compromised to mistrustred throughout code. Updated to match the engine also.
Dean Looyengoed
parents: 670
diff changeset
   191
        /// Completes the handshake process when the identity of a partner was previously marked as mistrusted.
281
4040d2e488b6 Add handshake procedure for keys that were previously marked as compromised.
Dean Looyengoed
parents: 280
diff changeset
   192
        /// </summary>
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   193
        /// <param name="myself">The personal identity to complete the handshake with.</param>
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   194
        /// <param name="partner">The identity of the partner to complete the handshake with.</param>
672
98bec5884763 Rename compromised to mistrustred throughout code. Updated to match the engine also.
Dean Looyengoed
parents: 670
diff changeset
   195
        private void DoHandshakeForMistrustedKey(PEPIdentity myself,
98bec5884763 Rename compromised to mistrustred throughout code. Updated to match the engine also.
Dean Looyengoed
parents: 670
diff changeset
   196
                                                 PEPIdentity partner)
281
4040d2e488b6 Add handshake procedure for keys that were previously marked as compromised.
Dean Looyengoed
parents: 280
diff changeset
   197
        {
4040d2e488b6 Add handshake procedure for keys that were previously marked as compromised.
Dean Looyengoed
parents: 280
diff changeset
   198
            DialogResult result;
4040d2e488b6 Add handshake procedure for keys that were previously marked as compromised.
Dean Looyengoed
parents: 280
diff changeset
   199
4040d2e488b6 Add handshake procedure for keys that were previously marked as compromised.
Dean Looyengoed
parents: 280
diff changeset
   200
            result = MessageBox.Show(this.ParentForm,
672
98bec5884763 Rename compromised to mistrustred throughout code. Updated to match the engine also.
Dean Looyengoed
parents: 670
diff changeset
   201
                                     pEp.Properties.Resources.Message_WarningMistrustedKey,
378
e20e56a3d3a9 Rename and organize existing translations.
Dean Looyengoed
parents: 375
diff changeset
   202
                                     pEp.Properties.Resources.Message_TitleConfirmOperation,
423
713d5baee692 Change warning dialog for handshake with mistrusted key to Yes/No.
Dean Looyengoed
parents: 417
diff changeset
   203
                                     MessageBoxButtons.YesNo);
281
4040d2e488b6 Add handshake procedure for keys that were previously marked as compromised.
Dean Looyengoed
parents: 280
diff changeset
   204
423
713d5baee692 Change warning dialog for handshake with mistrusted key to Yes/No.
Dean Looyengoed
parents: 417
diff changeset
   205
            if (result == DialogResult.Yes)
281
4040d2e488b6 Add handshake procedure for keys that were previously marked as compromised.
Dean Looyengoed
parents: 280
diff changeset
   206
            {
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   207
                this.DoHandshake(myself, partner);
281
4040d2e488b6 Add handshake procedure for keys that were previously marked as compromised.
Dean Looyengoed
parents: 280
diff changeset
   208
            }
4040d2e488b6 Add handshake procedure for keys that were previously marked as compromised.
Dean Looyengoed
parents: 280
diff changeset
   209
4040d2e488b6 Add handshake procedure for keys that were previously marked as compromised.
Dean Looyengoed
parents: 280
diff changeset
   210
            return;
4040d2e488b6 Add handshake procedure for keys that were previously marked as compromised.
Dean Looyengoed
parents: 280
diff changeset
   211
        }
4040d2e488b6 Add handshake procedure for keys that were previously marked as compromised.
Dean Looyengoed
parents: 280
diff changeset
   212
4040d2e488b6 Add handshake procedure for keys that were previously marked as compromised.
Dean Looyengoed
parents: 280
diff changeset
   213
        /// <summary>
4040d2e488b6 Add handshake procedure for keys that were previously marked as compromised.
Dean Looyengoed
parents: 280
diff changeset
   214
        /// Completes the handshake process where the identity of a partner is confirmed.
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   215
        /// </summary>
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   216
        /// <param name="myself">The personal identity to complete the handshake with.</param>
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   217
        /// <param name="partner">The identity of the partner to complete the handshake with.</param>
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   218
        private void DoHandshake(PEPIdentity myself,
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   219
                                 PEPIdentity partner)
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   220
        {
155
cda43d18bcd3 Add state to handshake form and decouple it from the encryption status panel
Dean Looyengoed
parents: 154
diff changeset
   221
            string ownFpr;
cda43d18bcd3 Add state to handshake form and decouple it from the encryption status panel
Dean Looyengoed
parents: 154
diff changeset
   222
            string partnerFpr;
363
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   223
            string trustwordsShort;
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   224
            string trustwordsFull;
155
cda43d18bcd3 Add state to handshake form and decouple it from the encryption status panel
Dean Looyengoed
parents: 154
diff changeset
   225
            string[] lines;
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   226
            DialogResult result;
155
cda43d18bcd3 Add state to handshake form and decouple it from the encryption status panel
Dean Looyengoed
parents: 154
diff changeset
   227
            FormHandshake handshakeDialog;
cda43d18bcd3 Add state to handshake form and decouple it from the encryption status panel
Dean Looyengoed
parents: 154
diff changeset
   228
            FormHandshake.State state = new FormHandshake.State();
201
9e0548fa3942 Code reformatting.
Markus Schaber <markus@pep-security.net>
parents: 199
diff changeset
   229
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 653
diff changeset
   230
            Global.AddToLog("DoHandshake: handshake started.");
139
5fba0600b7a2 user_id everywhere
Volker Birk <vb@pep-project.org>
parents: 137
diff changeset
   231
363
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   232
            // Process identities
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   233
            if (partner.Username == "")
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   234
            {
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   235
                partner.Username = partner.Address;
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   236
            }
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   237
            partner.UserID = Globals.ThisAddIn.GetUserID(partner.Address);
139
5fba0600b7a2 user_id everywhere
Volker Birk <vb@pep-project.org>
parents: 137
diff changeset
   238
363
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   239
            // Calculate and add trustwords
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   240
            this.CalcTrustwords(myself, partner, out trustwordsShort, out trustwordsFull);
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   241
            state.Myself = myself.Copy();
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   242
            state.Partner = partner.Copy();
363
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   243
            state.TrustwordsShort = trustwordsShort;
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   244
            state.TrustwordsFull = trustwordsFull;
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   245
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   246
            // Calculate and add fingerprint
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   247
            ownFpr = this.ToQuadruple(myself.Fingerprint);
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   248
            partnerFpr = this.ToQuadruple(partner.Fingerprint);
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   249
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   250
            if (myself.Fingerprint.CompareTo(partner.Fingerprint) > 0)
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   251
            {
155
cda43d18bcd3 Add state to handshake form and decouple it from the encryption status panel
Dean Looyengoed
parents: 154
diff changeset
   252
                lines = new string[3];
378
e20e56a3d3a9 Rename and organize existing translations.
Dean Looyengoed
parents: 375
diff changeset
   253
                lines[0] = pEp.Properties.Resources.PrivacyStatus_TrustwordsPartnerShortPartner + partnerFpr;
e20e56a3d3a9 Rename and organize existing translations.
Dean Looyengoed
parents: 375
diff changeset
   254
                lines[2] = pEp.Properties.Resources.PrivacyStatus_TrustwordsPartnerShortMyself + ownFpr;
155
cda43d18bcd3 Add state to handshake form and decouple it from the encryption status panel
Dean Looyengoed
parents: 154
diff changeset
   255
                state.Fingerprint = lines;
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   256
            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   257
            else
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   258
            {
155
cda43d18bcd3 Add state to handshake form and decouple it from the encryption status panel
Dean Looyengoed
parents: 154
diff changeset
   259
                lines = new string[3];
378
e20e56a3d3a9 Rename and organize existing translations.
Dean Looyengoed
parents: 375
diff changeset
   260
                lines[0] = pEp.Properties.Resources.PrivacyStatus_TrustwordsOwnShortMyself + ownFpr;
e20e56a3d3a9 Rename and organize existing translations.
Dean Looyengoed
parents: 375
diff changeset
   261
                lines[2] = pEp.Properties.Resources.PrivacyStatus_TrustwordsOwnShortPartner + partnerFpr;
155
cda43d18bcd3 Add state to handshake form and decouple it from the encryption status panel
Dean Looyengoed
parents: 154
diff changeset
   262
                state.Fingerprint = lines;
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   263
            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   264
155
cda43d18bcd3 Add state to handshake form and decouple it from the encryption status panel
Dean Looyengoed
parents: 154
diff changeset
   265
            // Create and show handshake dialog
cda43d18bcd3 Add state to handshake form and decouple it from the encryption status panel
Dean Looyengoed
parents: 154
diff changeset
   266
            handshakeDialog = new FormHandshake(state);
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   267
            handshakeDialog.StartPosition = FormStartPosition.CenterScreen;
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   268
            result = handshakeDialog.ShowDialog(this);
155
cda43d18bcd3 Add state to handshake form and decouple it from the encryption status panel
Dean Looyengoed
parents: 154
diff changeset
   269
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   270
            this.ProcessDoHandshakeResult(result, partner);
356
919bcfd67cc6 Populate expanded properties/data in the selection item for in-line handshake.
Dean Looyengoed
parents: 355
diff changeset
   271
919bcfd67cc6 Populate expanded properties/data in the selection item for in-line handshake.
Dean Looyengoed
parents: 355
diff changeset
   272
            return;
919bcfd67cc6 Populate expanded properties/data in the selection item for in-line handshake.
Dean Looyengoed
parents: 355
diff changeset
   273
        }
919bcfd67cc6 Populate expanded properties/data in the selection item for in-line handshake.
Dean Looyengoed
parents: 355
diff changeset
   274
919bcfd67cc6 Populate expanded properties/data in the selection item for in-line handshake.
Dean Looyengoed
parents: 355
diff changeset
   275
        /// <summary>
919bcfd67cc6 Populate expanded properties/data in the selection item for in-line handshake.
Dean Looyengoed
parents: 355
diff changeset
   276
        /// Processes the result of the do handshake dialog after a user makes a selection.
919bcfd67cc6 Populate expanded properties/data in the selection item for in-line handshake.
Dean Looyengoed
parents: 355
diff changeset
   277
        /// </summary>
919bcfd67cc6 Populate expanded properties/data in the selection item for in-line handshake.
Dean Looyengoed
parents: 355
diff changeset
   278
        /// <param name="result">The result of the handshake dialog selection.</param>
919bcfd67cc6 Populate expanded properties/data in the selection item for in-line handshake.
Dean Looyengoed
parents: 355
diff changeset
   279
        /// <param name="partner">The identity of the partner to handshake with.</param>
919bcfd67cc6 Populate expanded properties/data in the selection item for in-line handshake.
Dean Looyengoed
parents: 355
diff changeset
   280
        private void ProcessDoHandshakeResult(DialogResult result,
384
a0aa034cb7f3 Create and implement new classes for PEPAttachment, PEPIdentity and PEPMessage.
Dean Looyengoed
parents: 378
diff changeset
   281
                                              PEPIdentity partner)
356
919bcfd67cc6 Populate expanded properties/data in the selection item for in-line handshake.
Dean Looyengoed
parents: 355
diff changeset
   282
        {
384
a0aa034cb7f3 Create and implement new classes for PEPAttachment, PEPIdentity and PEPMessage.
Dean Looyengoed
parents: 378
diff changeset
   283
            pEp_identity_s identityPartner = ThisAddIn.pEp.update_identity(partner.ToCOMType());
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   284
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   285
            switch (result)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   286
            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   287
                case DialogResult.Yes:
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   288
                    {
672
98bec5884763 Rename compromised to mistrustred throughout code. Updated to match the engine also.
Dean Looyengoed
parents: 670
diff changeset
   289
                        // Check if key was previously mistrusted -- warning to user must be displayed earlier
98bec5884763 Rename compromised to mistrustred throughout code. Updated to match the engine also.
Dean Looyengoed
parents: 670
diff changeset
   290
                        if (identityPartner.comm_type == _pEp_comm_type.pEp_ct_mistrusted)
281
4040d2e488b6 Add handshake procedure for keys that were previously marked as compromised.
Dean Looyengoed
parents: 280
diff changeset
   291
                        {
4040d2e488b6 Add handshake procedure for keys that were previously marked as compromised.
Dean Looyengoed
parents: 280
diff changeset
   292
                            ThisAddIn.pEp.key_reset_trust(ref identityPartner);
4040d2e488b6 Add handshake procedure for keys that were previously marked as compromised.
Dean Looyengoed
parents: 280
diff changeset
   293
                        }
4040d2e488b6 Add handshake procedure for keys that were previously marked as compromised.
Dean Looyengoed
parents: 280
diff changeset
   294
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   295
                        identityPartner = ThisAddIn.pEp.trust_personal_key(ref identityPartner);
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   296
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   297
                        this.UpdateUIFromMailItem();
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   298
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   299
                        // Update the manager form state
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   300
                        if (this.managerForm != null)
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   301
                        {
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   302
                            this.managerForm.CopyStateToUI(this.GetManagerState());
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   303
                        }
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   304
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   305
                        break;
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   306
                    }
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   307
                case DialogResult.No:
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   308
                    {
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   309
                        ThisAddIn.pEp.key_compromized(ref identityPartner);
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   310
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   311
                        this.UpdateUIFromMailItem();
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   312
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   313
                        // Update the manager form state
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   314
                        if (this.managerForm != null)
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   315
                        {
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   316
                            this.managerForm.CopyStateToUI(this.GetManagerState());
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   317
                        }
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   318
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   319
                        break;
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   320
                    }
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   321
            }
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   322
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   323
            return;
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   324
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   325
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   326
        /// <summary>
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   327
        /// Reverses any past handshake confirmation by unconfirming the given identity partner.
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   328
        /// </summary>
384
a0aa034cb7f3 Create and implement new classes for PEPAttachment, PEPIdentity and PEPMessage.
Dean Looyengoed
parents: 378
diff changeset
   329
        /// <param name="partner">The identity of the partner to unconfirm.</param>
a0aa034cb7f3 Create and implement new classes for PEPAttachment, PEPIdentity and PEPMessage.
Dean Looyengoed
parents: 378
diff changeset
   330
        private void UndoHandshake(PEPIdentity partner)
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   331
        {
384
a0aa034cb7f3 Create and implement new classes for PEPAttachment, PEPIdentity and PEPMessage.
Dean Looyengoed
parents: 378
diff changeset
   332
            pEp_identity_s identityPartner = ThisAddIn.pEp.update_identity(partner.ToCOMType());
280
dd7ed070e7d0 API change from the COM adapter.
Dean Looyengoed
parents: 279
diff changeset
   333
            ThisAddIn.pEp.key_reset_trust(ref identityPartner);
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   334
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   335
            this.UpdateUIFromMailItem();
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   336
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   337
            // Update the manager form state
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   338
            if (this.managerForm != null)
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   339
            {
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   340
                this.managerForm.CopyStateToUI(this.GetManagerState());
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   341
            }
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   342
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   343
            return;
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   344
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   345
161
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   346
        /// <summary>
363
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   347
        /// Calculates both the short and full trustwords between the given personal identity and the identity partner.
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   348
        /// </summary>
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   349
        /// <param name="myself">The personal identity.</param>
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   350
        /// <param name="partner">The identity of the partner.</param>
363
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   351
        /// <param name="trustwordsShort">The short version of trustwords.</param>
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   352
        /// <param name="trustwordsFull">The full/long version of trustwords.</param>
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   353
        private void CalcTrustwords(PEPIdentity myself,
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   354
                                    PEPIdentity partner,
363
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   355
                                    out string trustwordsShort,
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   356
                                    out string trustwordsFull)
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   357
        {
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   358
            string myShort;
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   359
            string myLong;
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   360
            string partnerShort;
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   361
            string partnerLong;
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   362
674
f849cd99d2d7 Remove .ToLower() conversion of trustwords.
Dean Looyengoed
parents: 673
diff changeset
   363
            myShort = ThisAddIn.pEp.trustwords(myself.Fingerprint, max_words: 5);
f849cd99d2d7 Remove .ToLower() conversion of trustwords.
Dean Looyengoed
parents: 673
diff changeset
   364
            myLong = ThisAddIn.pEp.trustwords(myself.Fingerprint);
f849cd99d2d7 Remove .ToLower() conversion of trustwords.
Dean Looyengoed
parents: 673
diff changeset
   365
            partnerShort = ThisAddIn.pEp.trustwords(partner.Fingerprint, max_words: 5);
f849cd99d2d7 Remove .ToLower() conversion of trustwords.
Dean Looyengoed
parents: 673
diff changeset
   366
            partnerLong = ThisAddIn.pEp.trustwords(partner.Fingerprint);
363
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   367
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   368
            if (myself.Fingerprint.CompareTo(partner.Fingerprint) > 0)
363
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   369
            {
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   370
                trustwordsShort = partnerShort + myShort;
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   371
                trustwordsFull = partnerLong + myLong;
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   372
            }
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   373
            else
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   374
            {
673
de55c344da2e Stop adding extra space in trustwords calculation.
Dean Looyengoed
parents: 672
diff changeset
   375
                trustwordsShort = myShort + partnerShort;
de55c344da2e Stop adding extra space in trustwords calculation.
Dean Looyengoed
parents: 672
diff changeset
   376
                trustwordsFull = myLong + partnerLong;
363
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   377
            }
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   378
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   379
            return;
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   380
        }
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   381
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   382
        /// <summary>
161
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   383
        /// Formats the given text string as separated 4-character groups.
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   384
        /// Example: 49422235FC99585B891C --> 4942 2235 FC99 585B 891C
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   385
        /// </summary>
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   386
        /// <param name="text">The text to format in 4-character groups.</param>
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   387
        /// <returns>The re-formatted string.</returns>
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   388
        private string ToQuadruple(string text)
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   389
        {
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   390
            List<string> result = new List<string>();
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   391
161
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   392
            if (text != null)
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   393
            {
161
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   394
                for (int i = 0; i < text.Length; i += 4)
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   395
                {
161
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   396
                    try
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   397
                    {
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   398
                        result.Add(text.Substring(i, 4));
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   399
                    }
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   400
                    catch (ArgumentOutOfRangeException)
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   401
                    {
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   402
                        result.Add(text.Substring(i));
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   403
                        break;
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   404
                    }
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   405
                }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   406
            }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   407
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   408
            return String.Join(" ", result);
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   409
        }
201
9e0548fa3942 Code reformatting.
Markus Schaber <markus@pep-security.net>
parents: 199
diff changeset
   410
196
6153b54a5c32 Rename 'EncryptionStatusPanel' to 'FormRegionEncryptionStatus' in line with other controls.
Dean Looyengoed
parents: 194
diff changeset
   411
        /// <summary>
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   412
        /// Builds a new manager form state using this encryption state/mail item current state.
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   413
        /// </summary>
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   414
        /// <returns>A new manager form state.</returns>
313
619529633b8c Rename 'FormManageEncryptionStatus' to 'FormManagePrivacyStatus' everywhere.
Dean Looyengoed
parents: 312
diff changeset
   415
        private FormManagePrivacyStatus.State GetManagerState()
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   416
        {
527
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   417
            bool isMyself;
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   418
            bool forceUnencrypted;
364
b3291efce20b Complete initial implementation of the expanded region (in-line handshake) in the selection list.
Dean Looyengoed
parents: 363
diff changeset
   419
            string trustwordsShort;
b3291efce20b Complete initial implementation of the expanded region (in-line handshake) in the selection list.
Dean Looyengoed
parents: 363
diff changeset
   420
            string trustwordsFull;
384
a0aa034cb7f3 Create and implement new classes for PEPAttachment, PEPIdentity and PEPMessage.
Dean Looyengoed
parents: 378
diff changeset
   421
            List<PEPIdentity> identities;
a0aa034cb7f3 Create and implement new classes for PEPAttachment, PEPIdentity and PEPMessage.
Dean Looyengoed
parents: 378
diff changeset
   422
            PEPIdentity myIdentity;
a0aa034cb7f3 Create and implement new classes for PEPAttachment, PEPIdentity and PEPMessage.
Dean Looyengoed
parents: 378
diff changeset
   423
            PEPIdentity incomingIdent;
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   424
            _pEp_color identityPartnerColor;
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   425
            SelectionItem item;
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   426
            PrivacyState state = this.CopyUIToState();
313
619529633b8c Rename 'FormManageEncryptionStatus' to 'FormManagePrivacyStatus' everywhere.
Dean Looyengoed
parents: 312
diff changeset
   427
            FormManagePrivacyStatus.State managerState = new FormManagePrivacyStatus.State();
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   428
332
4221c5b34348 Do not show both user name and address in identities list if they are the same.
Dean Looyengoed
parents: 331
diff changeset
   429
            // Resolve all recipients -- this ensures the identities list is correctly populated
4221c5b34348 Do not show both user name and address in identities list if they are the same.
Dean Looyengoed
parents: 331
diff changeset
   430
            this.associatedMailItem.ResolveAllRecipients();
4221c5b34348 Do not show both user name and address in identities list if they are the same.
Dean Looyengoed
parents: 331
diff changeset
   431
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   432
            managerState.VisualState = state.Copy();
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   433
            managerState.IsIncoming = this.associatedMailItem.IsIncoming;
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   434
653
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   435
            if (managerState.IsIncoming)
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   436
            {
384
a0aa034cb7f3 Create and implement new classes for PEPAttachment, PEPIdentity and PEPMessage.
Dean Looyengoed
parents: 378
diff changeset
   437
                identities = new List<PEPIdentity>();
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   438
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   439
                // Add only one identity
638
5d99a596d5b5 Check for null From in CryptableMailItem before use.
Dean Looyengoed
parents: 633
diff changeset
   440
                if (this.associatedMailItem.From != null)
5d99a596d5b5 Check for null From in CryptableMailItem before use.
Dean Looyengoed
parents: 633
diff changeset
   441
                {
5d99a596d5b5 Check for null From in CryptableMailItem before use.
Dean Looyengoed
parents: 633
diff changeset
   442
                    incomingIdent = new PEPIdentity();
5d99a596d5b5 Check for null From in CryptableMailItem before use.
Dean Looyengoed
parents: 633
diff changeset
   443
                    incomingIdent.Address = this.associatedMailItem.From.Address;
5d99a596d5b5 Check for null From in CryptableMailItem before use.
Dean Looyengoed
parents: 633
diff changeset
   444
                    incomingIdent.Username = this.associatedMailItem.From.Username;
5d99a596d5b5 Check for null From in CryptableMailItem before use.
Dean Looyengoed
parents: 633
diff changeset
   445
                    incomingIdent.UserID = Globals.ThisAddIn.GetUserID(incomingIdent.Address);
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   446
638
5d99a596d5b5 Check for null From in CryptableMailItem before use.
Dean Looyengoed
parents: 633
diff changeset
   447
                    identities.Add(incomingIdent);
5d99a596d5b5 Check for null From in CryptableMailItem before use.
Dean Looyengoed
parents: 633
diff changeset
   448
                }
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   449
            }
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   450
            else
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   451
            {
395
ba088d922a94 Rename Addresses property to Recipients in the CryptableMailItem.
Dean Looyengoed
parents: 394
diff changeset
   452
                identities = this.associatedMailItem.Recipients;
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   453
            }
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   454
366
1bb0df0e9970 Don't show an action button if the partner fingerprint is the same as myself.
Dean Looyengoed
parents: 364
diff changeset
   455
            // Get my identity
633
c65f81929528 Rewrite GetMyIdentity methods to work in more situations.
Dean Looyengoed
parents: 631
diff changeset
   456
            myIdentity = this.associatedMailItem.Myself;
366
1bb0df0e9970 Don't show an action button if the partner fingerprint is the same as myself.
Dean Looyengoed
parents: 364
diff changeset
   457
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   458
            // Add identities
394
a04b30dd83ab Make PEPIdentity support local contact groups (as well as full hierarchy) and implement in privacy status UI.
Dean Looyengoed
parents: 384
diff changeset
   459
            identities = PEPIdentity.ToFlatList(identities);
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   460
            managerState.Identities.Clear();
384
a0aa034cb7f3 Create and implement new classes for PEPAttachment, PEPIdentity and PEPMessage.
Dean Looyengoed
parents: 378
diff changeset
   461
            foreach (PEPIdentity ident in identities)
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   462
            {
648
28f89d1e3c5b Make IsValid a property of PEPIdentity and remove empty check of Username.
Dean Looyengoed
parents: 646
diff changeset
   463
                if (ident.IsValid)
332
4221c5b34348 Do not show both user name and address in identities list if they are the same.
Dean Looyengoed
parents: 331
diff changeset
   464
                {
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   465
                    pEp_identity_s partnerIdentity_s = ThisAddIn.pEp.update_identity(ident.ToCOMType());
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   466
                    PEPIdentity partnerIdentity = new PEPIdentity(partnerIdentity_s);
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   467
                    identityPartnerColor = ThisAddIn.pEp.identity_color(partnerIdentity_s);
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   468
                    forceUnencrypted = Globals.ThisAddIn.ContactIsForceUnencrypted(partnerIdentity.Address);
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   469
527
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   470
                    // Check if identity is myself
713
0035e6809ef2 Add GetIsMyIdentity method to PEPIdentity and remove GetMyIdentities.
Dean Looyengoed
parents: 709
diff changeset
   471
                    isMyself = PEPIdentity.GetIsMyIdentity(partnerIdentity.Address);
0035e6809ef2 Add GetIsMyIdentity method to PEPIdentity and remove GetMyIdentities.
Dean Looyengoed
parents: 709
diff changeset
   472
                    
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   473
                    item = new SelectionItem();
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   474
                    item.TextLine1 = partnerIdentity.Username;
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   475
                    item.TextLine2 = partnerIdentity.Address;
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   476
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   477
                    // Don't show both the user name and address if they are the same
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   478
                    if ((item.TextLine1 != null) &&
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   479
                        (item.TextLine2 != null) &&
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   480
                        (item.TextLine1 == item.TextLine2))
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   481
                    {
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   482
                        item.IsTwoTextLinesVisible = false;
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   483
                    }
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   484
527
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   485
                    // Calculate trustwords
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   486
                    this.CalcTrustwords(myIdentity,
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   487
                                        partnerIdentity,
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   488
                                        out trustwordsShort,
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   489
                                        out trustwordsFull);
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   490
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   491
                    // Set image
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   492
                    if ((forceUnencrypted) &&
653
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   493
                        (managerState.IsIncoming == false))
641
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   494
                    {
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   495
                        // Show the force unencrypted image indicating this is set by the user not the engine
642
1a59435a585c Rename force unencrypted images to ImageForceUnencOn/Off.
Dean Looyengoed
parents: 641
diff changeset
   496
                        item.ItemImage = pEp.Properties.Resources.ImageForceUnencOn;
641
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   497
                    }
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   498
                    else
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   499
                    {
641
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   500
                        switch (PrivacyState.ConvertRatingToPrivacyColor(identityPartnerColor))
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   501
                        {
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   502
                            case PrivacyState.PrivacyColor.Green:
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   503
                                item.ItemImage = pEp.Properties.Resources.ImagePrivacyStatusGreen;
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   504
                                break;
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   505
                            case PrivacyState.PrivacyColor.Yellow:
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   506
                                item.ItemImage = pEp.Properties.Resources.ImagePrivacyStatusYellow;
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   507
                                break;
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   508
                            case PrivacyState.PrivacyColor.Red:
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   509
                                item.ItemImage = pEp.Properties.Resources.ImagePrivacyStatusRed;
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   510
                                break;
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   511
                            case PrivacyState.PrivacyColor.NoColor:
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   512
                                item.ItemImage = pEp.Properties.Resources.ImagePrivacyStatusNoColor;
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   513
                                break;
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   514
                            default:
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   515
                                item.ItemImage = null;
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   516
                                break;
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   517
                        }
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   518
                    }
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   519
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   520
                    // Set button
653
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   521
                    if ((isMyself) ||
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   522
                        ((forceUnencrypted) &&
653
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   523
                         (managerState.IsIncoming == false)))
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   524
                    {
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   525
                        item.IsButtonVisible = false;
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   526
                        item.IsExpandable = false;
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   527
                    }
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   528
                    else
366
1bb0df0e9970 Don't show an action button if the partner fingerprint is the same as myself.
Dean Looyengoed
parents: 364
diff changeset
   529
                    {
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   530
                        if (partnerIdentity.CommunicationType >= _pEp_comm_type.pEp_ct_confirmed_encryption)
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   531
                        {
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   532
                            // Undo handshake
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   533
                            item.TextButton = pEp.Properties.Resources.PrivacyStatus_StopTrusting;
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   534
                            item.IsButtonVisible = true;
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   535
                            item.ButtonOnClick = (x, y) => { this.UndoHandshake(partnerIdentity.Copy()); };
356
919bcfd67cc6 Populate expanded properties/data in the selection item for in-line handshake.
Dean Looyengoed
parents: 355
diff changeset
   536
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   537
                            item.IsExpandable = false;
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   538
                        }
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   539
                        else if (partnerIdentity.CommunicationType >= _pEp_comm_type.pEp_ct_unconfirmed_encryption &&
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   540
                                 partnerIdentity.CommunicationType < _pEp_comm_type.pEp_ct_confirmed_encryption)
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   541
                        {
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   542
                            // Do handshake
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   543
                            item.TextButton = pEp.Properties.Resources.PrivacyStatus_HandshakeAdvanced;
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   544
                            item.IsButtonVisible = true;
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   545
                            item.ButtonOnClick = (x, y) => { this.DoHandshake(myIdentity.Copy(), partnerIdentity.Copy()); };
356
919bcfd67cc6 Populate expanded properties/data in the selection item for in-line handshake.
Dean Looyengoed
parents: 355
diff changeset
   546
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   547
                            item.IsExpandable = true;
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   548
                            item.ExpandedText = Properties.Resources.PrivacyStatus_TrustwordDesc + "\n\n" +
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   549
                                                trustwordsShort;
447
e4cb391f3b77 Make Confirm/Wrong buttons in the expanded region of the identites list have a colored background.
Dean Looyengoed
parents: 445
diff changeset
   550
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   551
                            item.ExpandedButton1Text = Properties.Resources.PrivacyStatus_SelectTrust;
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   552
                            item.ExpandedButton1OnClick = (x, y) => { this.ProcessDoHandshakeResult(DialogResult.Yes, partnerIdentity.Copy()); };
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   553
                            item.ExpandedButton1BackColor = PrivacyState.COLOR_GREEN;
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   554
                            item.ExpandedButton1ForeColor = Color.White;
447
e4cb391f3b77 Make Confirm/Wrong buttons in the expanded region of the identites list have a colored background.
Dean Looyengoed
parents: 445
diff changeset
   555
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   556
                            item.ExpandedButton2Text = Properties.Resources.PrivacyStatus_SelectMistrust;
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   557
                            item.ExpandedButton2OnClick = (x, y) => { this.ProcessDoHandshakeResult(DialogResult.No, partnerIdentity.Copy()); };
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   558
                            item.ExpandedButton2BackColor = PrivacyState.COLOR_RED;
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   559
                            item.ExpandedButton2ForeColor = Color.White;
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   560
                        }
672
98bec5884763 Rename compromised to mistrustred throughout code. Updated to match the engine also.
Dean Looyengoed
parents: 670
diff changeset
   561
                        else if (partnerIdentity.CommunicationType == _pEp_comm_type.pEp_ct_mistrusted)
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   562
                        {
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   563
                            // Redo handshake with confirmation
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   564
                            item.TextButton = pEp.Properties.Resources.PrivacyStatus_Handshake;
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   565
                            item.IsButtonVisible = true;
672
98bec5884763 Rename compromised to mistrustred throughout code. Updated to match the engine also.
Dean Looyengoed
parents: 670
diff changeset
   566
                            item.ButtonOnClick = (x, y) => { this.DoHandshakeForMistrustedKey(myIdentity.Copy(), partnerIdentity.Copy()); };
641
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   567
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   568
                            item.IsExpandable = false;
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   569
                        }
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   570
                        else
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   571
                        {
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   572
                            item.IsButtonVisible = false;
641
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   573
                            item.IsExpandable = false;
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   574
                        }
366
1bb0df0e9970 Don't show an action button if the partner fingerprint is the same as myself.
Dean Looyengoed
parents: 364
diff changeset
   575
                    }
281
4040d2e488b6 Add handshake procedure for keys that were previously marked as compromised.
Dean Looyengoed
parents: 280
diff changeset
   576
                }
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   577
                else // Invalid identity
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   578
                {
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   579
                    item = new SelectionItem();
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   580
                    item.TextLine1 = ident.Username;
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   581
                    item.TextLine2 = ident.Address;
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   582
                    item.ItemImage = null;
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   583
                    item.IsTwoTextLinesVisible = true;
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   584
                    item.IsButtonVisible = false;
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   585
                }
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   586
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   587
                managerState.Identities.Add(item);
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   588
            }
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   589
375
98df9e57270b Automatically select the first identity requiring a handshake in the privacy status form.
Dean Looyengoed
parents: 366
diff changeset
   590
            // Attempt to select the first identity requiring a handshake
98df9e57270b Automatically select the first identity requiring a handshake in the privacy status form.
Dean Looyengoed
parents: 366
diff changeset
   591
            for (int i = 0; i < managerState.Identities.Count; i++)
98df9e57270b Automatically select the first identity requiring a handshake in the privacy status form.
Dean Looyengoed
parents: 366
diff changeset
   592
            {
98df9e57270b Automatically select the first identity requiring a handshake in the privacy status form.
Dean Looyengoed
parents: 366
diff changeset
   593
                // Determine if it's a handshake identity by simply seeing if it's expandable
98df9e57270b Automatically select the first identity requiring a handshake in the privacy status form.
Dean Looyengoed
parents: 366
diff changeset
   594
                if (managerState.Identities[i].IsExpandable)
98df9e57270b Automatically select the first identity requiring a handshake in the privacy status form.
Dean Looyengoed
parents: 366
diff changeset
   595
                {
98df9e57270b Automatically select the first identity requiring a handshake in the privacy status form.
Dean Looyengoed
parents: 366
diff changeset
   596
                    managerState.SelectedIdentityIndex = i;
98df9e57270b Automatically select the first identity requiring a handshake in the privacy status form.
Dean Looyengoed
parents: 366
diff changeset
   597
                    break;
98df9e57270b Automatically select the first identity requiring a handshake in the privacy status form.
Dean Looyengoed
parents: 366
diff changeset
   598
                }
98df9e57270b Automatically select the first identity requiring a handshake in the privacy status form.
Dean Looyengoed
parents: 366
diff changeset
   599
            }
98df9e57270b Automatically select the first identity requiring a handshake in the privacy status form.
Dean Looyengoed
parents: 366
diff changeset
   600
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   601
            return (managerState);
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   602
        }
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   603
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   604
        /// <summary>
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   605
        /// Builds the latest state of the encryption status manager then shows the UI.
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   606
        /// </summary>
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   607
        private void BuildAndShowManager()
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   608
        {
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   609
            DialogResult result;
313
619529633b8c Rename 'FormManageEncryptionStatus' to 'FormManagePrivacyStatus' everywhere.
Dean Looyengoed
parents: 312
diff changeset
   610
            FormManagePrivacyStatus form;
619529633b8c Rename 'FormManageEncryptionStatus' to 'FormManagePrivacyStatus' everywhere.
Dean Looyengoed
parents: 312
diff changeset
   611
            FormManagePrivacyStatus.State stateOut;
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   612
483
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   613
            try
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   614
            {
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   615
                // Show the form
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   616
                form = new FormManagePrivacyStatus();
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   617
                form.StartPosition = FormStartPosition.CenterScreen;
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   618
483
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   619
                this.managerForm = form;
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   620
                result = form.ShowDialog(this.ParentForm, this.GetManagerState(), out stateOut); // Must show as dialog to block code
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   621
            }
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   622
            catch (Exception ex)
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   623
            {
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 653
diff changeset
   624
                Global.StopAndSendCrashReport(ex);
483
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   625
            }
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   626
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   627
            return;
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   628
        }
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   629
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   630
        /// <summary>
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   631
        /// Updates the status of the UI state based on the associated mail item.
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   632
        /// </summary>
622
7647f3056282 Use MailItem directly when get/set SendUnencrypted is called in a MailItem inspector.
Dean Looyengoed
parents: 620
diff changeset
   633
        public void UpdateUIFromMailItem()
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   634
        {
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   635
            PrivacyState state;
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   636
            bool? forceUnencryptedProperty;
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   637
173
cf2c9c426576 Remove the mailItem property and replace with single associatedMailItem variable.
Dean Looyengoed
parents: 172
diff changeset
   638
            if (this.associatedMailItem != null)
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   639
            {
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   640
                forceUnencryptedProperty = this.associatedMailItem.ForceUnencrypted;
342
bbc68931d60e Stop using CheckState and instead use bool? for SendUnencrypted property.
Dean Looyengoed
parents: 341
diff changeset
   641
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   642
                if ((forceUnencryptedProperty != null) &&
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   643
                    ((bool)forceUnencryptedProperty == true))
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   644
                {
342
bbc68931d60e Stop using CheckState and instead use bool? for SendUnencrypted property.
Dean Looyengoed
parents: 341
diff changeset
   645
                    // Force unencrypted
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   646
                    state = new PrivacyState(_pEp_color.pEp_rating_unencrypted);
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   647
                    this.CopyStateToUI(state);
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   648
                }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   649
                else
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   650
                {
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   651
                    // Start the color rating calculation/decryption process
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   652
                    this.associatedMailItem.StartDecryption();
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   653
                }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   654
            }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   655
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   656
            return;
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   657
        }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   658
709
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   659
        /// <summary>
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   660
        /// Clears the associated unencrypted preview and displays the given note (if any).
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   661
        /// </summary>
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   662
        /// <param name="note">The note to diplsay.</param>
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   663
        private void ClearPreview(string note = null)
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   664
        {
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   665
            WindowFormRegionCollection formRegions = Globals.FormRegions[Globals.ThisAddIn.Application.ActiveExplorer()];
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   666
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   667
            if ((formRegions != null) &&
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   668
                (formRegions.FormRegionPreviewUnencrypted != null) &&
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   669
                (formRegions.FormRegionPreviewUnencrypted.Visible))
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   670
            {
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   671
                formRegions.FormRegionPreviewUnencrypted.ClearMessage();
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   672
                formRegions.FormRegionPreviewUnencrypted.SetNote(note);
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   673
            }
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   674
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   675
            return;
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   676
        }
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   677
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   678
        #region StateMethods
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   679
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   680
        /// <summary>
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   681
        /// Connects or disconnects all control events from the UI.
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   682
        /// </summary>
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   683
        /// <param name="connect">True to connect events, false to disconnect.</param>
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   684
        private void ConnectEvents(bool connect)
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   685
        {
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   686
            // Connect events only if not already connected
201
9e0548fa3942 Code reformatting.
Markus Schaber <markus@pep-security.net>
parents: 199
diff changeset
   687
            if ((connect == true) &&
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   688
                (this.eventsAreConnected == false))
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   689
            {
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   690
                this.ButtonPrivacyStatus.Click += this.ButtonPrivacyStatus_Click;
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   691
                this.ButtonPrivacyStatus.MouseUp += this.ButtonPrivacyStatus_MouseUp;
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   692
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   693
                this.eventsAreConnected = true;
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   694
            }
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   695
            // Always attempt to disconnect
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   696
            else if (connect == false)
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   697
            {
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   698
                this.ButtonPrivacyStatus.Click -= this.ButtonPrivacyStatus_Click;
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   699
                this.ButtonPrivacyStatus.MouseUp -= this.ButtonPrivacyStatus_MouseUp;
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   700
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   701
                this.eventsAreConnected = false;
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   702
            }
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   703
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   704
            return;
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   705
        }
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   706
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   707
        /// <summary>
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   708
        /// Copies the given state to the UI.
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   709
        /// Events are turned off until the process is complete.
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   710
        /// </summary>
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   711
        /// <param name="state">The state to set to the UI.</param>
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   712
        private void CopyStateToUI(PrivacyState state)
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   713
        {
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   714
            this.ConnectEvents(false);
201
9e0548fa3942 Code reformatting.
Markus Schaber <markus@pep-security.net>
parents: 199
diff changeset
   715
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   716
            ///////////////////////////////////////////////////////////
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   717
            // Set UI data
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   718
            ///////////////////////////////////////////////////////////
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   719
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   720
            // Save UI state maintained outside of controls
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   721
            this.stateUIColorRating = state.PrivacyStatus;
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   722
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   723
            this.ButtonPrivacyStatus.BackColor = state.BackgroundColor;
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   724
            this.ButtonPrivacyStatus.ForeColor = state.ForegroundColor;
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   725
            this.ButtonPrivacyStatus.Text = state.ShortText;
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   726
670
821241386588 Update the manage privacy status form state when refreshing the form region.
Dean Looyengoed
parents: 664
diff changeset
   727
            // Update the manager form state
821241386588 Update the manage privacy status form state when refreshing the form region.
Dean Looyengoed
parents: 664
diff changeset
   728
            if (this.managerForm != null)
821241386588 Update the manage privacy status form state when refreshing the form region.
Dean Looyengoed
parents: 664
diff changeset
   729
            {
821241386588 Update the manage privacy status form state when refreshing the form region.
Dean Looyengoed
parents: 664
diff changeset
   730
                this.managerForm.CopyStateToUI(this.GetManagerState());
821241386588 Update the manage privacy status form state when refreshing the form region.
Dean Looyengoed
parents: 664
diff changeset
   731
            }
821241386588 Update the manage privacy status form state when refreshing the form region.
Dean Looyengoed
parents: 664
diff changeset
   732
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   733
            this.ConnectEvents(true);
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   734
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   735
            return;
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   736
        }
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   737
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   738
        /// <summary>
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   739
        /// Copies the UI to a new state.
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   740
        /// </summary>
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   741
        /// <returns>The state of the UI.</returns>
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   742
        private PrivacyState CopyUIToState()
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   743
        {
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   744
            return (new PrivacyState(this.stateUIColorRating));
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   745
        }
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   746
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   747
        #endregion
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   748
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   749
        /**************************************************************
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   750
         * 
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   751
         * Event Handling
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   752
         * 
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   753
         *************************************************************/
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   754
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   755
        /// <summary>
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   756
        /// Event handler that is called when the form region is displayed.
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   757
        /// This is called each time the form region looses then regains visiblity 
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   758
        /// (for example an other email is selected then back to this one).
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   759
        /// </summary>
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   760
        private void FormRegionPrivacyStatus_FormRegionShowing(object sender, System.EventArgs e)
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   761
        {
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   762
            // Do not allow initialization more than once
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   763
            if (initialized == false)
631
7d9cf2642434 Set background color of the FormRegionPrivacyStatus differently for Office 2013.
Dean Looyengoed
parents: 622
diff changeset
   764
            {
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   765
                this.SetAssociatedMailItem();
631
7d9cf2642434 Set background color of the FormRegionPrivacyStatus differently for Office 2013.
Dean Looyengoed
parents: 622
diff changeset
   766
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   767
                // Set background color for Office 2013
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   768
                try
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   769
                {
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   770
                    if (Globals.ThisAddIn.Application.Version.Substring(0, 2) == "15")
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   771
                    {
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   772
                        if (this.IsWithinInspector())
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   773
                        {
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   774
                            this.BackColor = SystemColors.ButtonFace;
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   775
                        }
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   776
                        else
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   777
                        {
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   778
                            this.BackColor = SystemColors.Window;
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   779
                        }
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   780
                    }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   781
                }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   782
                catch { }
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   783
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   784
                // Connect cryptable mail item events
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   785
                if (this.associatedMailItem != null)
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   786
                {
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   787
                    try
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   788
                    {
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   789
                        this.associatedMailItem.PropertyChanged += MailItem_PropertyChanged;
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   790
                        this.associatedMailItem.DecryptionComplete += MailItem_DecryptionComplete;
709
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   791
                        this.associatedMailItem.GetMirrorComplete += MailItem_GetMirrorComplete;
682
f6025a3d4062 Shutdown the refresh timer on form region close AND item Send event.
Dean Looyengoed
parents: 680
diff changeset
   792
                        this.associatedMailItem.Send += MailItem_Send;
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   793
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   794
                        if (this.associatedMailItem.IsInEncryptedStore &&
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   795
                            this.associatedMailItem.IsPGPEncrypted)
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   796
                        {
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   797
                            this.associatedMailItem.Open += MailItem_Open;
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   798
                        }
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   799
                    }
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   800
                    catch { }
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   801
                }
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   802
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   803
                this.CopyStateToUI(new PrivacyState());
683
21bad2819cf8 Specifically connect timer event when the form region is shown.
Dean Looyengoed
parents: 682
diff changeset
   804
                this.TimerRefresh.Tick += TimerRefresh_Tick;
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   805
                this.initialized = true;
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   806
            }
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   807
683
21bad2819cf8 Specifically connect timer event when the form region is shown.
Dean Looyengoed
parents: 682
diff changeset
   808
            // Call the timer tick method manually to refresh data with no delay
199
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   809
            this.TimerRefresh_Tick(null, new EventArgs());
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   810
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   811
            return;
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   812
        }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   813
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   814
        /// <summary>
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   815
        /// Event handler for when the form region is closed.
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   816
        /// </summary>
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   817
        private void FormRegionPrivacyStatus_FormRegionClosed(object sender, System.EventArgs e)
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   818
        {
199
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   819
            // Disconnect cryptable mail item events
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 189
diff changeset
   820
            if (this.associatedMailItem != null)
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   821
            {
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   822
                try
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   823
                {
445
499559d35fae Implement the INotifyPropertyChanged interface from System.ComponentModel.
Dean Looyengoed
parents: 438
diff changeset
   824
                    this.associatedMailItem.PropertyChanged -= MailItem_PropertyChanged;
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   825
                    this.associatedMailItem.DecryptionComplete -= MailItem_DecryptionComplete;
709
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   826
                    this.associatedMailItem.GetMirrorComplete -= MailItem_GetMirrorComplete;
201
9e0548fa3942 Code reformatting.
Markus Schaber <markus@pep-security.net>
parents: 199
diff changeset
   827
                    this.associatedMailItem.Open -= MailItem_Open;
682
f6025a3d4062 Shutdown the refresh timer on form region close AND item Send event.
Dean Looyengoed
parents: 680
diff changeset
   828
                    this.associatedMailItem.Send -= MailItem_Send;
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   829
                }
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   830
                catch { }
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   831
            }
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   832
682
f6025a3d4062 Shutdown the refresh timer on form region close AND item Send event.
Dean Looyengoed
parents: 680
diff changeset
   833
            // Stop and disconnect the refresh timer
f6025a3d4062 Shutdown the refresh timer on form region close AND item Send event.
Dean Looyengoed
parents: 680
diff changeset
   834
            this.TimerRefresh.Stop();
f6025a3d4062 Shutdown the refresh timer on form region close AND item Send event.
Dean Looyengoed
parents: 680
diff changeset
   835
            this.TimerRefresh.Enabled = false;
f6025a3d4062 Shutdown the refresh timer on form region close AND item Send event.
Dean Looyengoed
parents: 680
diff changeset
   836
            this.TimerRefresh.Tick -= TimerRefresh_Tick;
f6025a3d4062 Shutdown the refresh timer on form region close AND item Send event.
Dean Looyengoed
parents: 680
diff changeset
   837
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   838
            return;
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   839
        }
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   840
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   841
        /// <summary>
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   842
        /// Event handler called after the refresh timer has elapsed.
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   843
        /// </summary>
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   844
        private void TimerRefresh_Tick(object sender, EventArgs e)
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   845
        {
199
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   846
            bool tryAgain = false;
684
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   847
            bool markForDownload = false;
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   848
            this.TimerRefresh.Enabled = false; // Only once
684
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   849
            Outlook.OlDownloadState dlState;
201
9e0548fa3942 Code reformatting.
Markus Schaber <markus@pep-security.net>
parents: 199
diff changeset
   850
709
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   851
            /* The Refresh/UI_Update process is a little more complicated here than other forms.
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   852
             * There are the following components:
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   853
             *   1. TimerRefresh_Tick
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   854
             *        This is the main timer tick event handler called any time
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   855
             *        a refresh was requested and hasn't been run yet. A refresh
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   856
             *        is requested either at initialization or when a property changes
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   857
             *        (such as MailItem_PropertyChanged). It is on a timer as many 
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   858
             *        property change events could occur rapidy, but only one refresh should
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   859
             *        occur for performance reasons.
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   860
             * 
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   861
             *   2. UpdateUIFromMailItem
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   862
             *        This will re-calculate the mail item's color rating and then update the UI.
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   863
             *        However, if a mail item is not forcefully unencrypted, it will just call StartDecryption.
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   864
             * 
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   865
             *   3. MailItem_DecryptionComplete
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   866
             *        When decryption of the mail item is complete, this even handler will be called.
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   867
             *        This will update the UI with the latest color rating then call StartGetMirror.
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   868
             *        The CopyStateToUI method is used which means any open privacy status form will also
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   869
             *        be updated.
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   870
             * 
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   871
             *   4. MailItem_GetMirrorComplete
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   872
             *        This is the final step in updating the UI, after a mirror is located, it's contents
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   873
             *        will be shown to the unencrypted preview.
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   874
             * 
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   875
             * The general calling sequence is as shown above 1->4 with each component calling the next.
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   876
             * However, for methods that update the mail item directly, commonly only 2->4 is needed.
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   877
             */
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   878
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   879
            // Ensure the tick method is not called more than once
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   880
            if (refreshOngoing == false)
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   881
            {
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   882
                this.refreshOngoing = true;
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   883
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   884
                if (this.associatedMailItem != null)
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   885
                {
684
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   886
                    // Attempt to get the download state
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   887
                    try
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   888
                    {
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   889
                        dlState = this.associatedMailItem.DownloadState;
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   890
                    }
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   891
                    catch (Exception ex)
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   892
                    {
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   893
                        Global.AddToLog("TimerRefresh_Tick: Get DownloadState failed, " + ex.ToString());
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   894
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   895
                        // Assume everything is downloaded, but try to download again as well
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   896
                        dlState = Outlook.OlDownloadState.olFullItem;
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   897
                        markForDownload = true;
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   898
                    }
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   899
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   900
                    if (dlState == Outlook.OlDownloadState.olFullItem)
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   901
                    {
709
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   902
                        // Clear any existing preview and update
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   903
                        this.ClearPreview(Properties.Resources.Message_Opening);
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   904
                        this.UpdateUIFromMailItem();
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   905
                    }
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   906
                    else
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   907
                    {
684
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   908
                        markForDownload = true;
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   909
                    }
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   910
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   911
                    if (markForDownload)
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   912
                    {
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   913
                        // Try to mark the message for full download
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   914
                        try
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   915
                        {
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   916
                            this.associatedMailItem.MarkForDownload = Outlook.OlRemoteStatus.olMarkedForDownload;
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   917
                            tryAgain = true;
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   918
                        }
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   919
                        catch (Exception ex)
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   920
                        {
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   921
                            Global.AddToLog("TimerRefresh_Tick: MarkForDownload failed, " + ex.ToString());
7d761e28bdbc Log errors when getting DownloadState or setting MarkForDownload of a mail item.
Dean Looyengoed
parents: 683
diff changeset
   922
                        }
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   923
                    }
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   924
                }
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   925
199
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   926
                // Set the timer to refresh again later automatically
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   927
                if (tryAgain)
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   928
                {
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   929
                    this.TimerRefresh.Interval = 100;
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   930
                    this.TimerRefresh.Enabled = true;
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   931
                }
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   932
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   933
                this.refreshOngoing = false;
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   934
            }
175
48628e74ace0 Add a comment to remove event handlers
Dean Looyengoed
parents: 174
diff changeset
   935
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   936
            return;
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   937
        }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   938
169
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   939
        /// <summary>
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   940
        /// Event handler for when the decryption process is completed in the associated mail item.
709
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   941
        /// This will then update the form region UI and the privacy status window as needed.
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   942
        /// </summary>
704
0218918dda31 Add GetMirrorComplete event to the cryptable mail item.
Dean Looyengoed
parents: 699
diff changeset
   943
        private void MailItem_DecryptionComplete(object sender, CryptableMailItem.DecryptionEventArgs e)
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   944
        {
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   945
            try
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   946
            {
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   947
                // Marshal code back to UI thread as necessary
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   948
                this.Invoke(new Action(() =>
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   949
                    {
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   950
                        this.CopyStateToUI(new PrivacyState(e.ColorRating));
709
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   951
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   952
                        /* Create the unencrypted preview if the mail item is encrypted and
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   953
                         * it is in an encrypted (untrusted) store
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   954
                         * 
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   955
                         * This is done here because FormRegionPrivacyStatus has the cryptable mail item and
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   956
                         * it also is initialized after FormRegionPreviewUnencrypted.
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   957
                         */
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   958
                        if (this.associatedMailItem.IsInEncryptedStore &&
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   959
                            this.associatedMailItem.IsPGPEncrypted)
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   960
                        {
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   961
                            this.associatedMailItem.StartGetMirror();
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   962
                        }
719
e2f2fd67fb84 Clear the unencrypted preview even if it should not be shown.
Dean Looyengoed
parents: 713
diff changeset
   963
                        else
e2f2fd67fb84 Clear the unencrypted preview even if it should not be shown.
Dean Looyengoed
parents: 713
diff changeset
   964
                        {
e2f2fd67fb84 Clear the unencrypted preview even if it should not be shown.
Dean Looyengoed
parents: 713
diff changeset
   965
                            this.ClearPreview();
e2f2fd67fb84 Clear the unencrypted preview even if it should not be shown.
Dean Looyengoed
parents: 713
diff changeset
   966
                        }
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   967
                    }));
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   968
            }
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   969
            catch (Exception ex)
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   970
            {
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   971
                Global.AddToLog("MailItem_DecryptionComplete: Error setting UI state, " + ex.ToString());
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   972
            }
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   973
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   974
            return;
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   975
        }
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   976
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   977
        /// <summary>
709
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   978
        /// Event handler for when the get mirror locating process is complete for the associated mail item.
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   979
        /// This will then update the unencrypted preview in the UI.
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   980
        /// </summary>
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   981
        private void MailItem_GetMirrorComplete(object sender, CryptableMailItem.GetMirrorEventArgs e)
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   982
        {
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   983
            try
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   984
            {
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   985
                // Marshal code back to UI thread as necessary
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   986
                this.Invoke(new Action(() =>
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   987
                    {
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   988
                        WindowFormRegionCollection formRegions = Globals.FormRegions[Globals.ThisAddIn.Application.ActiveExplorer()];
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   989
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   990
                        if ((formRegions != null) &&
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   991
                            (formRegions.FormRegionPreviewUnencrypted != null) &&
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   992
                            (formRegions.FormRegionPreviewUnencrypted.Visible))
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   993
                        {
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   994
                            formRegions.FormRegionPreviewUnencrypted.SetMessage(e.Mirror);
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   995
                        }
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   996
                    }));
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   997
            }
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   998
            catch (Exception ex)
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
   999
            {
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
  1000
                Global.AddToLog("MailItem_GetMirrorComplete: Error displaying preview, " + ex.ToString());
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
  1001
            }
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
  1002
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
  1003
            return;
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
  1004
        }
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
  1005
beb17ca67621 Revise the UI update process for the FormRegionPrivacyStatus.
Dean Looyengoed
parents: 704
diff changeset
  1006
        /// <summary>
169
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
  1007
        /// Event handler for when a mail item is being opened in an inspector.
180
1602b0e8fdd6 Add some comments
Dean Looyengoed
parents: 179
diff changeset
  1008
        /// See: https://msdn.microsoft.com/en-us/library/office/ff865989.aspx
169
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
  1009
        /// </summary>
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
  1010
        /// <param name="cancel">Whether to cancel the event: Value is False when the event occurs. 
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
  1011
        /// If the event procedure sets this argument to True, the open operation is not completed 
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
  1012
        /// and the inspector is not displayed.</param>
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
  1013
        private void MailItem_Open(ref bool cancel)
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
  1014
        {
173
cf2c9c426576 Remove the mailItem property and replace with single associatedMailItem variable.
Dean Looyengoed
parents: 172
diff changeset
  1015
            if (this.associatedMailItem != null && this.associatedMailItem.MirrorDisplay())
169
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
  1016
            {
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
  1017
                cancel = true;
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
  1018
            }
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
  1019
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
  1020
            return;
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
  1021
        }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
  1022
169
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
  1023
        /// <summary>
682
f6025a3d4062 Shutdown the refresh timer on form region close AND item Send event.
Dean Looyengoed
parents: 680
diff changeset
  1024
        /// Event handler for when a mail item is sent.
f6025a3d4062 Shutdown the refresh timer on form region close AND item Send event.
Dean Looyengoed
parents: 680
diff changeset
  1025
        /// See: https://msdn.microsoft.com/en-us/library/office/ff865379.aspx
f6025a3d4062 Shutdown the refresh timer on form region close AND item Send event.
Dean Looyengoed
parents: 680
diff changeset
  1026
        /// </summary>
f6025a3d4062 Shutdown the refresh timer on form region close AND item Send event.
Dean Looyengoed
parents: 680
diff changeset
  1027
        /// <param name="cancel">Whether to cancel the event: Value is False when the event occurs. 
f6025a3d4062 Shutdown the refresh timer on form region close AND item Send event.
Dean Looyengoed
parents: 680
diff changeset
  1028
        /// If the event procedure sets this argument to True, the send operation is not completed 
f6025a3d4062 Shutdown the refresh timer on form region close AND item Send event.
Dean Looyengoed
parents: 680
diff changeset
  1029
        /// and the inspector is left open.</param>
f6025a3d4062 Shutdown the refresh timer on form region close AND item Send event.
Dean Looyengoed
parents: 680
diff changeset
  1030
        private void MailItem_Send(ref bool cancel)
f6025a3d4062 Shutdown the refresh timer on form region close AND item Send event.
Dean Looyengoed
parents: 680
diff changeset
  1031
        {
f6025a3d4062 Shutdown the refresh timer on form region close AND item Send event.
Dean Looyengoed
parents: 680
diff changeset
  1032
            // Stop and disconnect the refresh timer
f6025a3d4062 Shutdown the refresh timer on form region close AND item Send event.
Dean Looyengoed
parents: 680
diff changeset
  1033
            // This is necessary so an ongoing refresh doesn't try to access a mail item as it's being moved
f6025a3d4062 Shutdown the refresh timer on form region close AND item Send event.
Dean Looyengoed
parents: 680
diff changeset
  1034
            this.TimerRefresh.Stop();
f6025a3d4062 Shutdown the refresh timer on form region close AND item Send event.
Dean Looyengoed
parents: 680
diff changeset
  1035
            this.TimerRefresh.Enabled = false;
f6025a3d4062 Shutdown the refresh timer on form region close AND item Send event.
Dean Looyengoed
parents: 680
diff changeset
  1036
            this.TimerRefresh.Tick -= TimerRefresh_Tick;
f6025a3d4062 Shutdown the refresh timer on form region close AND item Send event.
Dean Looyengoed
parents: 680
diff changeset
  1037
f6025a3d4062 Shutdown the refresh timer on form region close AND item Send event.
Dean Looyengoed
parents: 680
diff changeset
  1038
            return;
f6025a3d4062 Shutdown the refresh timer on form region close AND item Send event.
Dean Looyengoed
parents: 680
diff changeset
  1039
        }
f6025a3d4062 Shutdown the refresh timer on form region close AND item Send event.
Dean Looyengoed
parents: 680
diff changeset
  1040
f6025a3d4062 Shutdown the refresh timer on form region close AND item Send event.
Dean Looyengoed
parents: 680
diff changeset
  1041
        /// <summary>
169
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
  1042
        /// Event handler for when a mail item property is changed.
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
  1043
        /// See: https://msdn.microsoft.com/en-us/library/office/ff866739.aspx
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
  1044
        /// </summary>
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
  1045
        /// <param name="propertyName">The name of the property that was changed.</param>
445
499559d35fae Implement the INotifyPropertyChanged interface from System.ComponentModel.
Dean Looyengoed
parents: 438
diff changeset
  1046
        private void MailItem_PropertyChanged(object sender, PropertyChangedEventArgs e)
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
  1047
        {
445
499559d35fae Implement the INotifyPropertyChanged interface from System.ComponentModel.
Dean Looyengoed
parents: 438
diff changeset
  1048
            switch (e.PropertyName.ToUpper())
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
  1049
            {
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
  1050
                case "TO":
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
  1051
                    // Start the refresh timer
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
  1052
                    this.TimerRefresh.Enabled = true;
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
  1053
                    break;
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
  1054
                // Outlook bug: there are always both events, so one is enough
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
  1055
                //case "CC":
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
  1056
                //    // Start the refresh timer
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
  1057
                //    this.TimerRefresh.Enabled = true;
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
  1058
                //    break;
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
  1059
            }
169
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
  1060
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
  1061
            return;
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
  1062
        }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
  1063
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
  1064
        /// <summary>
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
  1065
        /// Event handler for when the privacy status button is clicked.
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
  1066
        /// </summary>
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
  1067
        private void ButtonPrivacyStatus_Click(object sender, EventArgs e)
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
  1068
        {
310
ccf59b512bbd Remove right-click from encryption status button.
Dean Looyengoed
parents: 293
diff changeset
  1069
            this.BuildAndShowManager();
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
  1070
            return;
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
  1071
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
  1072
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
  1073
        /// <summary>
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
  1074
        /// Event handler for when a mouse button is released over the privacy status button.
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
  1075
        /// </summary>
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
  1076
        private void ButtonPrivacyStatus_MouseUp(object sender, MouseEventArgs e)
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
  1077
        {
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
  1078
            return;
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
  1079
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
  1080
    }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
  1081
}