UI/FormRegionPrivacyStatus.cs
author Dean Looyengoed
Thu, 17 Mar 2016 17:01:04 +0100
changeset 680 c3c99a2d9403
parent 678 8cee539fcc3d
child 682 f6025a3d4062
permissions -rw-r--r--
Use a background process to decrypt and calculate color ratings. This helps performance in some situations.
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>
6153b54a5c32 Rename 'EncryptionStatusPanel' to 'FormRegionEncryptionStatus' in line with other controls.
Dean Looyengoed
parents: 194
diff changeset
   412
        /// Makes the unencrypted preview form.
6153b54a5c32 Rename 'EncryptionStatusPanel' to 'FormRegionEncryptionStatus' in line with other controls.
Dean Looyengoed
parents: 194
diff changeset
   413
        /// This gets the active form region then fills it's content.
6153b54a5c32 Rename 'EncryptionStatusPanel' to 'FormRegionEncryptionStatus' in line with other controls.
Dean Looyengoed
parents: 194
diff changeset
   414
        /// </summary>
198
ca1b6e20f1a6 Make mirror methods in CryptableMailItem report when they fail.
Dean Looyengoed
parents: 197
diff changeset
   415
        /// <returns>True if successful, otherwise false.</returns>
ca1b6e20f1a6 Make mirror methods in CryptableMailItem report when they fail.
Dean Looyengoed
parents: 197
diff changeset
   416
        private bool MakePreview()
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   417
        {
620
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   418
            bool success = false;
198
ca1b6e20f1a6 Make mirror methods in CryptableMailItem report when they fail.
Dean Looyengoed
parents: 197
diff changeset
   419
            bool isSuccessful;
ca1b6e20f1a6 Make mirror methods in CryptableMailItem report when they fail.
Dean Looyengoed
parents: 197
diff changeset
   420
            byte[] rtfBody;
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   421
            WindowFormRegionCollection formRegions;
620
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   422
            PEPMessage mirror;
198
ca1b6e20f1a6 Make mirror methods in CryptableMailItem report when they fail.
Dean Looyengoed
parents: 197
diff changeset
   423
            formRegions = Globals.FormRegions[Globals.ThisAddIn.Application.ActiveExplorer()];
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   424
198
ca1b6e20f1a6 Make mirror methods in CryptableMailItem report when they fail.
Dean Looyengoed
parents: 197
diff changeset
   425
            if ((formRegions != null) &&
ca1b6e20f1a6 Make mirror methods in CryptableMailItem report when they fail.
Dean Looyengoed
parents: 197
diff changeset
   426
                (formRegions.FormRegionPreviewUnencrypted != null) &&
620
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   427
                (formRegions.FormRegionPreviewUnencrypted.Visible))
198
ca1b6e20f1a6 Make mirror methods in CryptableMailItem report when they fail.
Dean Looyengoed
parents: 197
diff changeset
   428
            {
620
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   429
                formRegions.FormRegionPreviewUnencrypted.ClearMessage();
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   430
                mirror = this.associatedMailItem.MirrorGet();
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   431
                
620
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   432
                if (mirror != null)
198
ca1b6e20f1a6 Make mirror methods in CryptableMailItem report when they fail.
Dean Looyengoed
parents: 197
diff changeset
   433
                {
620
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   434
                    // Attempt to the the RTF body
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   435
                    isSuccessful = this.associatedMailItem.MirrorTryGetRTFBody(out rtfBody);
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   436
                    if (isSuccessful == false)
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   437
                    {
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   438
                        return (false);
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   439
                    }
198
ca1b6e20f1a6 Make mirror methods in CryptableMailItem report when they fail.
Dean Looyengoed
parents: 197
diff changeset
   440
620
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   441
                    formRegions.FormRegionPreviewUnencrypted.SetMessage(mirror);
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   442
                    formRegions.FormRegionPreviewUnencrypted.SetRTFBody(System.Text.Encoding.ASCII.GetString(rtfBody, 0, rtfBody.Length));
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   443
                    success = true;
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   444
                }
198
ca1b6e20f1a6 Make mirror methods in CryptableMailItem report when they fail.
Dean Looyengoed
parents: 197
diff changeset
   445
            }
ca1b6e20f1a6 Make mirror methods in CryptableMailItem report when they fail.
Dean Looyengoed
parents: 197
diff changeset
   446
ca1b6e20f1a6 Make mirror methods in CryptableMailItem report when they fail.
Dean Looyengoed
parents: 197
diff changeset
   447
            return (success);
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   448
        }
201
9e0548fa3942 Code reformatting.
Markus Schaber <markus@pep-security.net>
parents: 199
diff changeset
   449
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   450
        /// <summary>
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   451
        /// 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
   452
        /// </summary>
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   453
        /// <returns>A new manager form state.</returns>
313
619529633b8c Rename 'FormManageEncryptionStatus' to 'FormManagePrivacyStatus' everywhere.
Dean Looyengoed
parents: 312
diff changeset
   454
        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
   455
        {
527
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   456
            bool isMyself;
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   457
            bool forceUnencrypted;
364
b3291efce20b Complete initial implementation of the expanded region (in-line handshake) in the selection list.
Dean Looyengoed
parents: 363
diff changeset
   458
            string trustwordsShort;
b3291efce20b Complete initial implementation of the expanded region (in-line handshake) in the selection list.
Dean Looyengoed
parents: 363
diff changeset
   459
            string trustwordsFull;
384
a0aa034cb7f3 Create and implement new classes for PEPAttachment, PEPIdentity and PEPMessage.
Dean Looyengoed
parents: 378
diff changeset
   460
            List<PEPIdentity> identities;
a0aa034cb7f3 Create and implement new classes for PEPAttachment, PEPIdentity and PEPMessage.
Dean Looyengoed
parents: 378
diff changeset
   461
            PEPIdentity myIdentity;
a0aa034cb7f3 Create and implement new classes for PEPAttachment, PEPIdentity and PEPMessage.
Dean Looyengoed
parents: 378
diff changeset
   462
            PEPIdentity incomingIdent;
527
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   463
            PEPIdentity[] myIdentities;
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   464
            _pEp_color identityPartnerColor;
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   465
            SelectionItem item;
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   466
            PrivacyState state = this.CopyUIToState();
313
619529633b8c Rename 'FormManageEncryptionStatus' to 'FormManagePrivacyStatus' everywhere.
Dean Looyengoed
parents: 312
diff changeset
   467
            FormManagePrivacyStatus.State managerState = new FormManagePrivacyStatus.State();
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   468
332
4221c5b34348 Do not show both user name and address in identities list if they are the same.
Dean Looyengoed
parents: 331
diff changeset
   469
            // 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
   470
            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
   471
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   472
            managerState.VisualState = state.Copy();
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   473
            managerState.IsIncoming = this.associatedMailItem.IsIncoming;
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   474
653
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   475
            if (managerState.IsIncoming)
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   476
            {
384
a0aa034cb7f3 Create and implement new classes for PEPAttachment, PEPIdentity and PEPMessage.
Dean Looyengoed
parents: 378
diff changeset
   477
                identities = new List<PEPIdentity>();
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   478
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   479
                // Add only one identity
638
5d99a596d5b5 Check for null From in CryptableMailItem before use.
Dean Looyengoed
parents: 633
diff changeset
   480
                if (this.associatedMailItem.From != null)
5d99a596d5b5 Check for null From in CryptableMailItem before use.
Dean Looyengoed
parents: 633
diff changeset
   481
                {
5d99a596d5b5 Check for null From in CryptableMailItem before use.
Dean Looyengoed
parents: 633
diff changeset
   482
                    incomingIdent = new PEPIdentity();
5d99a596d5b5 Check for null From in CryptableMailItem before use.
Dean Looyengoed
parents: 633
diff changeset
   483
                    incomingIdent.Address = this.associatedMailItem.From.Address;
5d99a596d5b5 Check for null From in CryptableMailItem before use.
Dean Looyengoed
parents: 633
diff changeset
   484
                    incomingIdent.Username = this.associatedMailItem.From.Username;
5d99a596d5b5 Check for null From in CryptableMailItem before use.
Dean Looyengoed
parents: 633
diff changeset
   485
                    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
   486
638
5d99a596d5b5 Check for null From in CryptableMailItem before use.
Dean Looyengoed
parents: 633
diff changeset
   487
                    identities.Add(incomingIdent);
5d99a596d5b5 Check for null From in CryptableMailItem before use.
Dean Looyengoed
parents: 633
diff changeset
   488
                }
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   489
            }
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   490
            else
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   491
            {
395
ba088d922a94 Rename Addresses property to Recipients in the CryptableMailItem.
Dean Looyengoed
parents: 394
diff changeset
   492
                identities = this.associatedMailItem.Recipients;
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   493
            }
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   494
366
1bb0df0e9970 Don't show an action button if the partner fingerprint is the same as myself.
Dean Looyengoed
parents: 364
diff changeset
   495
            // Get my identity
633
c65f81929528 Rewrite GetMyIdentity methods to work in more situations.
Dean Looyengoed
parents: 631
diff changeset
   496
            myIdentity = this.associatedMailItem.Myself;
527
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   497
            myIdentities = PEPIdentity.GetMyIdentities();
366
1bb0df0e9970 Don't show an action button if the partner fingerprint is the same as myself.
Dean Looyengoed
parents: 364
diff changeset
   498
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   499
            // 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
   500
            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
   501
            managerState.Identities.Clear();
384
a0aa034cb7f3 Create and implement new classes for PEPAttachment, PEPIdentity and PEPMessage.
Dean Looyengoed
parents: 378
diff changeset
   502
            foreach (PEPIdentity ident in identities)
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   503
            {
648
28f89d1e3c5b Make IsValid a property of PEPIdentity and remove empty check of Username.
Dean Looyengoed
parents: 646
diff changeset
   504
                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
   505
                {
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   506
                    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
   507
                    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
   508
                    identityPartnerColor = ThisAddIn.pEp.identity_color(partnerIdentity_s);
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   509
                    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
   510
527
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   511
                    // Check if identity is myself
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   512
                    isMyself = false;
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   513
                    foreach (PEPIdentity me in myIdentities)
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   514
                    {
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   515
                        if (partnerIdentity.EqualsByAddress(me))
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   516
                        {
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   517
                            isMyself = true;
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   518
                            break;
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   519
                        }
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   520
                    }
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   521
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   522
                    item = new SelectionItem();
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   523
                    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
   524
                    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
   525
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   526
                    // 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
   527
                    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
   528
                        (item.TextLine2 != null) &&
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   529
                        (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
   530
                    {
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   531
                        item.IsTwoTextLinesVisible = false;
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   532
                    }
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   533
527
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   534
                    // Calculate trustwords
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   535
                    this.CalcTrustwords(myIdentity,
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   536
                                        partnerIdentity,
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   537
                                        out trustwordsShort,
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   538
                                        out trustwordsFull);
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   539
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   540
                    // Set image
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   541
                    if ((forceUnencrypted) &&
653
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   542
                        (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
   543
                    {
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   544
                        // 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
   545
                        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
   546
                    }
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   547
                    else
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   548
                    {
641
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   549
                        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
   550
                        {
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   551
                            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
   552
                                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
   553
                                break;
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   554
                            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
   555
                                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
   556
                                break;
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   557
                            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
   558
                                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
   559
                                break;
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   560
                            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
   561
                                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
   562
                                break;
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   563
                            default:
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   564
                                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
   565
                                break;
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   566
                        }
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   567
                    }
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   568
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   569
                    // Set button
653
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   570
                    if ((isMyself) ||
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   571
                        ((forceUnencrypted) &&
653
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   572
                         (managerState.IsIncoming == false)))
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   573
                    {
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   574
                        item.IsButtonVisible = false;
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   575
                        item.IsExpandable = false;
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   576
                    }
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   577
                    else
366
1bb0df0e9970 Don't show an action button if the partner fingerprint is the same as myself.
Dean Looyengoed
parents: 364
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
                        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
   580
                        {
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   581
                            // Undo handshake
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   582
                            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
   583
                            item.IsButtonVisible = true;
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   584
                            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
   585
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   586
                            item.IsExpandable = false;
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   587
                        }
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   588
                        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
   589
                                 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
   590
                        {
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   591
                            // Do handshake
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   592
                            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
   593
                            item.IsButtonVisible = true;
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   594
                            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
   595
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   596
                            item.IsExpandable = true;
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   597
                            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
   598
                                                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
   599
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   600
                            item.ExpandedButton1Text = Properties.Resources.PrivacyStatus_SelectTrust;
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   601
                            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
   602
                            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
   603
                            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
   604
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   605
                            item.ExpandedButton2Text = Properties.Resources.PrivacyStatus_SelectMistrust;
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   606
                            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
   607
                            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
   608
                            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
   609
                        }
672
98bec5884763 Rename compromised to mistrustred throughout code. Updated to match the engine also.
Dean Looyengoed
parents: 670
diff changeset
   610
                        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
   611
                        {
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   612
                            // 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
   613
                            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
   614
                            item.IsButtonVisible = true;
672
98bec5884763 Rename compromised to mistrustred throughout code. Updated to match the engine also.
Dean Looyengoed
parents: 670
diff changeset
   615
                            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
   616
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   617
                            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
   618
                        }
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   619
                        else
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   620
                        {
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   621
                            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
   622
                            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
   623
                        }
366
1bb0df0e9970 Don't show an action button if the partner fingerprint is the same as myself.
Dean Looyengoed
parents: 364
diff changeset
   624
                    }
281
4040d2e488b6 Add handshake procedure for keys that were previously marked as compromised.
Dean Looyengoed
parents: 280
diff changeset
   625
                }
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   626
                else // Invalid identity
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   627
                {
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   628
                    item = new SelectionItem();
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   629
                    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
   630
                    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
   631
                    item.ItemImage = null;
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   632
                    item.IsTwoTextLinesVisible = true;
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   633
                    item.IsButtonVisible = false;
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   634
                }
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   635
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   636
                managerState.Identities.Add(item);
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   637
            }
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   638
375
98df9e57270b Automatically select the first identity requiring a handshake in the privacy status form.
Dean Looyengoed
parents: 366
diff changeset
   639
            // 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
   640
            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
   641
            {
98df9e57270b Automatically select the first identity requiring a handshake in the privacy status form.
Dean Looyengoed
parents: 366
diff changeset
   642
                // 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
   643
                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
   644
                {
98df9e57270b Automatically select the first identity requiring a handshake in the privacy status form.
Dean Looyengoed
parents: 366
diff changeset
   645
                    managerState.SelectedIdentityIndex = i;
98df9e57270b Automatically select the first identity requiring a handshake in the privacy status form.
Dean Looyengoed
parents: 366
diff changeset
   646
                    break;
98df9e57270b Automatically select the first identity requiring a handshake in the privacy status form.
Dean Looyengoed
parents: 366
diff changeset
   647
                }
98df9e57270b Automatically select the first identity requiring a handshake in the privacy status form.
Dean Looyengoed
parents: 366
diff changeset
   648
            }
98df9e57270b Automatically select the first identity requiring a handshake in the privacy status form.
Dean Looyengoed
parents: 366
diff changeset
   649
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   650
            return (managerState);
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   651
        }
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   652
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   653
        /// <summary>
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   654
        /// 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
   655
        /// </summary>
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   656
        private void BuildAndShowManager()
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   657
        {
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   658
            DialogResult result;
313
619529633b8c Rename 'FormManageEncryptionStatus' to 'FormManagePrivacyStatus' everywhere.
Dean Looyengoed
parents: 312
diff changeset
   659
            FormManagePrivacyStatus form;
619529633b8c Rename 'FormManageEncryptionStatus' to 'FormManagePrivacyStatus' everywhere.
Dean Looyengoed
parents: 312
diff changeset
   660
            FormManagePrivacyStatus.State stateOut;
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   661
483
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   662
            try
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   663
            {
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   664
                // Show the form
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   665
                form = new FormManagePrivacyStatus();
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   666
                form.StartPosition = FormStartPosition.CenterScreen;
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   667
483
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   668
                this.managerForm = form;
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   669
                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
   670
            }
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   671
            catch (Exception ex)
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   672
            {
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 653
diff changeset
   673
                Global.StopAndSendCrashReport(ex);
483
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   674
            }
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   675
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   676
            return;
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   677
        }
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   678
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   679
        /// <summary>
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   680
        /// 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
   681
        /// Any previous state changes in the UI are preserved.
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   682
        /// </summary>
622
7647f3056282 Use MailItem directly when get/set SendUnencrypted is called in a MailItem inspector.
Dean Looyengoed
parents: 620
diff changeset
   683
        public void UpdateUIFromMailItem()
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   684
        {
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   685
            PrivacyState state;
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   686
            bool? forceUnencryptedProperty;
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   687
173
cf2c9c426576 Remove the mailItem property and replace with single associatedMailItem variable.
Dean Looyengoed
parents: 172
diff changeset
   688
            if (this.associatedMailItem != null)
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   689
            {
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   690
                forceUnencryptedProperty = this.associatedMailItem.ForceUnencrypted;
342
bbc68931d60e Stop using CheckState and instead use bool? for SendUnencrypted property.
Dean Looyengoed
parents: 341
diff changeset
   691
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   692
                if ((forceUnencryptedProperty != null) &&
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   693
                    ((bool)forceUnencryptedProperty == true))
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   694
                {
342
bbc68931d60e Stop using CheckState and instead use bool? for SendUnencrypted property.
Dean Looyengoed
parents: 341
diff changeset
   695
                    // Force unencrypted
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   696
                    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
   697
                    this.CopyStateToUI(state);
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   698
                }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   699
                else
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   700
                {
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   701
                    // Start the color rating calculation/decryption process
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   702
                    this.associatedMailItem.StartDecryption();
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   703
                }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   704
            }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   705
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   706
            return;
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   707
        }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   708
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   709
        #region StateMethods
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   710
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   711
        /// <summary>
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   712
        /// Connects or disconnects all control events from the UI.
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   713
        /// </summary>
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   714
        /// <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
   715
        private void ConnectEvents(bool connect)
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
            // Connect events only if not already connected
201
9e0548fa3942 Code reformatting.
Markus Schaber <markus@pep-security.net>
parents: 199
diff changeset
   718
            if ((connect == true) &&
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   719
                (this.eventsAreConnected == false))
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   720
            {
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   721
                this.ButtonPrivacyStatus.Click += this.ButtonPrivacyStatus_Click;
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   722
                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
   723
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   724
                this.eventsAreConnected = true;
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   725
            }
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   726
            // Always attempt to disconnect
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   727
            else if (connect == false)
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   728
            {
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   729
                this.ButtonPrivacyStatus.Click -= this.ButtonPrivacyStatus_Click;
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   730
                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
   731
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   732
                this.eventsAreConnected = false;
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   733
            }
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
        /// Refreshes the UI by reloading the 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
        private void RefreshUI()
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   742
        {
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   743
            this.CopyStateToUI(this.CopyUIToState());
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   744
            return;
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
        /// <summary>
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   748
        /// Copies the given state to the UI.
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   749
        /// Events are turned off until the process is complete.
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   750
        /// </summary>
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   751
        /// <param name="state">The state to set to the UI.</param>
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   752
        private void CopyStateToUI(PrivacyState state)
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   753
        {
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   754
            this.ConnectEvents(false);
201
9e0548fa3942 Code reformatting.
Markus Schaber <markus@pep-security.net>
parents: 199
diff changeset
   755
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   756
            ///////////////////////////////////////////////////////////
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   757
            // Set UI data
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   758
            ///////////////////////////////////////////////////////////
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   759
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   760
            // Save UI state maintained outside of controls
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   761
            this.stateUIColorRating = state.PrivacyStatus;
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   762
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   763
            this.ButtonPrivacyStatus.BackColor = state.BackgroundColor;
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   764
            this.ButtonPrivacyStatus.ForeColor = state.ForegroundColor;
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   765
            this.ButtonPrivacyStatus.Text = state.ShortText;
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   766
670
821241386588 Update the manage privacy status form state when refreshing the form region.
Dean Looyengoed
parents: 664
diff changeset
   767
            // Update the manager form state
821241386588 Update the manage privacy status form state when refreshing the form region.
Dean Looyengoed
parents: 664
diff changeset
   768
            if (this.managerForm != null)
821241386588 Update the manage privacy status form state when refreshing the form region.
Dean Looyengoed
parents: 664
diff changeset
   769
            {
821241386588 Update the manage privacy status form state when refreshing the form region.
Dean Looyengoed
parents: 664
diff changeset
   770
                this.managerForm.CopyStateToUI(this.GetManagerState());
821241386588 Update the manage privacy status form state when refreshing the form region.
Dean Looyengoed
parents: 664
diff changeset
   771
            }
821241386588 Update the manage privacy status form state when refreshing the form region.
Dean Looyengoed
parents: 664
diff changeset
   772
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   773
            this.ConnectEvents(true);
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   774
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   775
            return;
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   776
        }
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   777
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   778
        /// <summary>
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   779
        /// Copies the UI to a new state.
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   780
        /// </summary>
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   781
        /// <returns>The state of the UI.</returns>
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   782
        private PrivacyState CopyUIToState()
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   783
        {
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   784
            return (new PrivacyState(this.stateUIColorRating));
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   785
        }
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   786
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   787
        #endregion
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   788
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   789
        /**************************************************************
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   790
         * 
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   791
         * Event Handling
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   792
         * 
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   793
         *************************************************************/
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   794
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   795
        /// <summary>
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   796
        /// 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
   797
        /// 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
   798
        /// (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
   799
        /// </summary>
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   800
        private void FormRegionPrivacyStatus_FormRegionShowing(object sender, System.EventArgs e)
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   801
        {
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   802
            // Do not allow initialization more than once
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   803
            if (initialized == false)
631
7d9cf2642434 Set background color of the FormRegionPrivacyStatus differently for Office 2013.
Dean Looyengoed
parents: 622
diff changeset
   804
            {
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   805
                this.SetAssociatedMailItem();
631
7d9cf2642434 Set background color of the FormRegionPrivacyStatus differently for Office 2013.
Dean Looyengoed
parents: 622
diff changeset
   806
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   807
                // Set background color for Office 2013
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   808
                try
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   809
                {
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   810
                    if (Globals.ThisAddIn.Application.Version.Substring(0, 2) == "15")
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   811
                    {
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   812
                        if (this.IsWithinInspector())
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   813
                        {
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   814
                            this.BackColor = SystemColors.ButtonFace;
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   815
                        }
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   816
                        else
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   817
                        {
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   818
                            this.BackColor = SystemColors.Window;
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   819
                        }
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   820
                    }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   821
                }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   822
                catch { }
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   823
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   824
                // Connect cryptable mail item events
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   825
                if (this.associatedMailItem != null)
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   826
                {
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   827
                    try
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   828
                    {
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   829
                        this.associatedMailItem.PropertyChanged += MailItem_PropertyChanged;
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   830
                        this.associatedMailItem.DecryptionComplete += MailItem_DecryptionComplete;
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   831
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   832
                        if (this.associatedMailItem.IsInEncryptedStore &&
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   833
                            this.associatedMailItem.IsPGPEncrypted)
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   834
                        {
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   835
                            this.associatedMailItem.Open += MailItem_Open;
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   836
                        }
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   837
                    }
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   838
                    catch { }
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   839
                }
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   840
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   841
                // Set the default UI state
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   842
                this.CopyStateToUI(new PrivacyState());
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   843
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   844
                this.initialized = true;
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   845
            }
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   846
199
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   847
            // Call the timer tick method manually to refresh data
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   848
            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
   849
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   850
            return;
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   851
        }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   852
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   853
        /// <summary>
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   854
        /// Event handler for when the form region is closed.
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   855
        /// </summary>
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   856
        private void FormRegionPrivacyStatus_FormRegionClosed(object sender, System.EventArgs e)
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   857
        {
199
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   858
            // Disconnect cryptable mail item events
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 189
diff changeset
   859
            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
   860
            {
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   861
                try
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   862
                {
445
499559d35fae Implement the INotifyPropertyChanged interface from System.ComponentModel.
Dean Looyengoed
parents: 438
diff changeset
   863
                    this.associatedMailItem.PropertyChanged -= MailItem_PropertyChanged;
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   864
                    this.associatedMailItem.DecryptionComplete -= MailItem_DecryptionComplete;
201
9e0548fa3942 Code reformatting.
Markus Schaber <markus@pep-security.net>
parents: 199
diff changeset
   865
                    this.associatedMailItem.Open -= MailItem_Open;
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   866
                }
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   867
                catch { }
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   868
            }
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   869
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   870
            return;
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   871
        }
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   872
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   873
        /// <summary>
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   874
        /// 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
   875
        /// </summary>
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   876
        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
   877
        {
199
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   878
            bool tryAgain = false;
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   879
            bool isSuccessful;
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   880
            this.TimerRefresh.Enabled = false; // Only once
201
9e0548fa3942 Code reformatting.
Markus Schaber <markus@pep-security.net>
parents: 199
diff changeset
   881
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   882
            // 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
   883
            if (refreshOngoing == false)
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   884
            {
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   885
                this.refreshOngoing = true;
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   886
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   887
                if (this.associatedMailItem != null)
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   888
                {
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   889
                    if (this.associatedMailItem.DownloadState == Outlook.OlDownloadState.olFullItem)
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   890
                    {
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   891
                        this.UpdateUIFromMailItem();
199
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   892
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   893
                        /* Create the unencrypted preview if the mail item is encrypted and
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   894
                         * it is in an encrypted (untrusted) store
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   895
                         * 
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   896
                         * This is done here because FormRegionPrivacyStatus has the cryptable mail item and
199
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   897
                         * it also is initialized after FormRegionPreviewUnencrypted.
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   898
                         */
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   899
                        if (this.associatedMailItem.IsInEncryptedStore &&
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   900
                            this.associatedMailItem.IsPGPEncrypted)
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   901
                        {
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   902
                            isSuccessful = this.MakePreview();
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   903
534
c38561b8a7e1 Disable try again if message preview fails.
Dean Looyengoed
parents: 527
diff changeset
   904
                            // Disable try again as it never seems to recover in real-world testing
c38561b8a7e1 Disable try again if message preview fails.
Dean Looyengoed
parents: 527
diff changeset
   905
                            /*if (isSuccessful == false)
199
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   906
                            {
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   907
                                tryAgain = true;
534
c38561b8a7e1 Disable try again if message preview fails.
Dean Looyengoed
parents: 527
diff changeset
   908
                            }*/
199
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   909
                        }
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   910
                    }
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   911
                    else
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   912
                    {
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   913
                        this.associatedMailItem.MarkForDownload = Outlook.OlRemoteStatus.olMarkedForDownload;
199
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   914
                        tryAgain = true;
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   915
                    }
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   916
                }
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   917
199
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   918
                // 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
   919
                if (tryAgain)
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   920
                {
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   921
                    this.TimerRefresh.Interval = 100;
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   922
                    this.TimerRefresh.Enabled = true;
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   923
                }
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   924
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   925
                this.refreshOngoing = false;
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   926
            }
175
48628e74ace0 Add a comment to remove event handlers
Dean Looyengoed
parents: 174
diff changeset
   927
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   928
            return;
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   929
        }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   930
169
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   931
        /// <summary>
680
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   932
        /// Event handler for when the decryption process is completed in the associated mail item.
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   933
        /// </summary>
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   934
        private void MailItem_DecryptionComplete(CryptableMailItem sender, CryptableMailItem.DecryptionEventArgs e)
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   935
        {
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   936
            try
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   937
            {
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   938
                // 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
   939
                this.Invoke(new Action(() =>
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   940
                    {
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   941
                        this.CopyStateToUI(new PrivacyState(e.ColorRating));
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   942
                    }));
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   943
            }
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   944
            catch (Exception ex)
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   945
            {
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   946
                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
   947
            }
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   948
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   949
            return;
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   950
        }
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   951
c3c99a2d9403 Use a background process to decrypt and calculate color ratings.
Dean Looyengoed
parents: 678
diff changeset
   952
        /// <summary>
169
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   953
        /// Event handler for when a mail item is being opened in an inspector.
180
1602b0e8fdd6 Add some comments
Dean Looyengoed
parents: 179
diff changeset
   954
        /// 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
   955
        /// </summary>
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   956
        /// <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
   957
        /// 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
   958
        /// and the inspector is not displayed.</param>
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   959
        private void MailItem_Open(ref bool cancel)
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   960
        {
173
cf2c9c426576 Remove the mailItem property and replace with single associatedMailItem variable.
Dean Looyengoed
parents: 172
diff changeset
   961
            if (this.associatedMailItem != null && this.associatedMailItem.MirrorDisplay())
169
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   962
            {
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   963
                cancel = true;
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   964
            }
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   965
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   966
            return;
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   967
        }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   968
169
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   969
        /// <summary>
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   970
        /// Event handler for when a mail item property is changed.
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   971
        /// See: https://msdn.microsoft.com/en-us/library/office/ff866739.aspx
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   972
        /// </summary>
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   973
        /// <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
   974
        private void MailItem_PropertyChanged(object sender, PropertyChangedEventArgs e)
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   975
        {
445
499559d35fae Implement the INotifyPropertyChanged interface from System.ComponentModel.
Dean Looyengoed
parents: 438
diff changeset
   976
            switch (e.PropertyName.ToUpper())
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   977
            {
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   978
                case "TO":
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   979
                    // Start the refresh timer
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   980
                    this.TimerRefresh.Enabled = true;
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   981
                    break;
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   982
                // 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
   983
                //case "CC":
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   984
                //    // Start the refresh timer
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   985
                //    this.TimerRefresh.Enabled = true;
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   986
                //    break;
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   987
            }
169
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   988
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   989
            return;
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   990
        }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   991
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   992
        /// <summary>
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   993
        /// 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
   994
        /// </summary>
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   995
        private void ButtonPrivacyStatus_Click(object sender, EventArgs e)
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   996
        {
310
ccf59b512bbd Remove right-click from encryption status button.
Dean Looyengoed
parents: 293
diff changeset
   997
            this.BuildAndShowManager();
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   998
            return;
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   999
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
  1000
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
  1001
        /// <summary>
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
  1002
        /// 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
  1003
        /// </summary>
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
  1004
        private void ButtonPrivacyStatus_MouseUp(object sender, MouseEventArgs e)
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
  1005
        {
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
  1006
            return;
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
  1007
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
  1008
    }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
  1009
}