UI/FormRegionPrivacyStatus.cs
author Dean Looyengoed
Fri, 11 Mar 2016 22:30:25 +0100
changeset 653 0e46e5c08f5b
parent 652 44bf944fcc83
child 660 e5346cda03ff
permissions -rw-r--r--
Only show the force unencrypted icon by identies in privacy status for outgoing messages.
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
170
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
    79
        private CryptableMailItem associatedMailItem = null;
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
    80
        private bool              refreshOngoing     = false;
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
    81
        private bool              eventsAreConnected = false;
170
07911d16b012 Add method to determine then set the associated mail item for the encryption status panel.
Dean Looyengoed
parents: 169
diff changeset
    82
313
619529633b8c Rename 'FormManageEncryptionStatus' to 'FormManagePrivacyStatus' everywhere.
Dean Looyengoed
parents: 312
diff changeset
    83
        private FormManagePrivacyStatus managerForm = null;
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>
290
a96add597d4c Spelling correction.
Dean Looyengoed
parents: 289
diff changeset
   191
        /// Completes the handshake process when the identity of a partner was previously marked as compromised.
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>
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   195
        private void DoHandshakeForCompromisedKey(PEPIdentity myself,
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
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,
378
e20e56a3d3a9 Rename and organize existing translations.
Dean Looyengoed
parents: 375
diff changeset
   201
                                     pEp.Properties.Resources.Message_WarningCompromisedKey,
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
652
44bf944fcc83 Stop calling the engine log and instead use the GlobalErrorHandler log.
Dean Looyengoed
parents: 648
diff changeset
   230
            GlobalExceptionHandler.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
                    {
290
a96add597d4c Spelling correction.
Dean Looyengoed
parents: 289
diff changeset
   289
                        // Check if key was previously compromised -- warning for this must be displayed earlier
281
4040d2e488b6 Add handshake procedure for keys that were previously marked as compromised.
Dean Looyengoed
parents: 280
diff changeset
   290
                        if (identityPartner.comm_type == _pEp_comm_type.pEp_ct_compromized)
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);
293
82d68d3863ba Add back manual setting of color rating for decrypted emails on trusted servers.
Dean Looyengoed
parents: 292
diff changeset
   296
                        this.associatedMailItem.ColorRating = _pEp_color.pEp_rating_trusted;
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   297
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   298
                        this.UpdateUIFromMailItem();
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   299
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   300
                        // 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
   301
                        if (this.managerForm != null)
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   302
                        {
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   303
                            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
   304
                        }
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   305
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   306
                        break;
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   307
                    }
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   308
                case DialogResult.No:
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   309
                    {
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   310
                        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
   311
                        identityPartner.comm_type = _pEp_comm_type.pEp_ct_compromized;
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   312
                        identityPartner = ThisAddIn.pEp.update_identity(identityPartner);
293
82d68d3863ba Add back manual setting of color rating for decrypted emails on trusted servers.
Dean Looyengoed
parents: 292
diff changeset
   313
                        this.associatedMailItem.ColorRating = _pEp_color.pEp_rating_red;
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   314
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   315
                        this.UpdateUIFromMailItem();
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   316
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   317
                        // 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
   318
                        if (this.managerForm != null)
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   319
                        {
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   320
                            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
   321
                        }
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
                        break;
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   324
                    }
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   325
            }
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   326
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   327
            return;
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   328
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   329
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   330
        /// <summary>
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   331
        /// 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
   332
        /// </summary>
384
a0aa034cb7f3 Create and implement new classes for PEPAttachment, PEPIdentity and PEPMessage.
Dean Looyengoed
parents: 378
diff changeset
   333
        /// <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
   334
        private void UndoHandshake(PEPIdentity partner)
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   335
        {
384
a0aa034cb7f3 Create and implement new classes for PEPAttachment, PEPIdentity and PEPMessage.
Dean Looyengoed
parents: 378
diff changeset
   336
            pEp_identity_s identityPartner = ThisAddIn.pEp.update_identity(partner.ToCOMType());
280
dd7ed070e7d0 API change from the COM adapter.
Dean Looyengoed
parents: 279
diff changeset
   337
            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
   338
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   339
            this.UpdateUIFromMailItem();
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   340
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   341
            // 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
   342
            if (this.managerForm != null)
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   343
            {
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   344
                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
   345
            }
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   346
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   347
            return;
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   348
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   349
161
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   350
        /// <summary>
363
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   351
        /// 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
   352
        /// </summary>
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   353
        /// <param name="myself">The personal identity.</param>
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   354
        /// <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
   355
        /// <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
   356
        /// <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
   357
        private void CalcTrustwords(PEPIdentity myself,
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   358
                                    PEPIdentity partner,
363
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   359
                                    out string trustwordsShort,
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   360
                                    out string trustwordsFull)
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   361
        {
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   362
            string myShort;
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   363
            string myLong;
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   364
            string partnerShort;
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   365
            string partnerLong;
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   366
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   367
            myShort = ThisAddIn.pEp.trustwords(myself.Fingerprint, max_words: 5).ToLower();
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   368
            myLong = ThisAddIn.pEp.trustwords(myself.Fingerprint).ToLower();
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   369
            partnerShort = ThisAddIn.pEp.trustwords(partner.Fingerprint, max_words: 5).ToLower();
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   370
            partnerLong = ThisAddIn.pEp.trustwords(partner.Fingerprint).ToLower();
363
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   371
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   372
            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
   373
            {
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   374
                trustwordsShort = partnerShort + myShort;
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   375
                trustwordsFull = partnerLong + myLong;
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   376
            }
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   377
            else
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
                trustwordsShort = myShort + " " + partnerShort;
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   380
                trustwordsFull = myLong + " " + partnerLong;
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
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   383
            return;
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   384
        }
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   385
27c3ca00e69c Separate the DoHandshake method into smaller parts using other methods.
Dean Looyengoed
parents: 359
diff changeset
   386
        /// <summary>
161
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   387
        /// 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
   388
        /// 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
   389
        /// </summary>
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   390
        /// <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
   391
        /// <returns>The re-formatted string.</returns>
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   392
        private string ToQuadruple(string text)
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   393
        {
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   394
            List<string> result = new List<string>();
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
            if (text != null)
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   397
            {
161
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   398
                for (int i = 0; i < text.Length; i += 4)
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   399
                {
161
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   400
                    try
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, 4));
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   403
                    }
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   404
                    catch (ArgumentOutOfRangeException)
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   405
                    {
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   406
                        result.Add(text.Substring(i));
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   407
                        break;
2b6b485152c5 Comment and rename quadruple method. Add null check just in case.
Dean Looyengoed
parents: 159
diff changeset
   408
                    }
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   409
                }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   410
            }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   411
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   412
            return String.Join(" ", result);
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   413
        }
201
9e0548fa3942 Code reformatting.
Markus Schaber <markus@pep-security.net>
parents: 199
diff changeset
   414
196
6153b54a5c32 Rename 'EncryptionStatusPanel' to 'FormRegionEncryptionStatus' in line with other controls.
Dean Looyengoed
parents: 194
diff changeset
   415
        /// <summary>
6153b54a5c32 Rename 'EncryptionStatusPanel' to 'FormRegionEncryptionStatus' in line with other controls.
Dean Looyengoed
parents: 194
diff changeset
   416
        /// Makes the unencrypted preview form.
6153b54a5c32 Rename 'EncryptionStatusPanel' to 'FormRegionEncryptionStatus' in line with other controls.
Dean Looyengoed
parents: 194
diff changeset
   417
        /// 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
   418
        /// </summary>
198
ca1b6e20f1a6 Make mirror methods in CryptableMailItem report when they fail.
Dean Looyengoed
parents: 197
diff changeset
   419
        /// <returns>True if successful, otherwise false.</returns>
ca1b6e20f1a6 Make mirror methods in CryptableMailItem report when they fail.
Dean Looyengoed
parents: 197
diff changeset
   420
        private bool MakePreview()
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   421
        {
620
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   422
            bool success = false;
198
ca1b6e20f1a6 Make mirror methods in CryptableMailItem report when they fail.
Dean Looyengoed
parents: 197
diff changeset
   423
            bool isSuccessful;
ca1b6e20f1a6 Make mirror methods in CryptableMailItem report when they fail.
Dean Looyengoed
parents: 197
diff changeset
   424
            byte[] rtfBody;
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   425
            WindowFormRegionCollection formRegions;
620
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   426
            PEPMessage mirror;
198
ca1b6e20f1a6 Make mirror methods in CryptableMailItem report when they fail.
Dean Looyengoed
parents: 197
diff changeset
   427
            formRegions = Globals.FormRegions[Globals.ThisAddIn.Application.ActiveExplorer()];
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   428
198
ca1b6e20f1a6 Make mirror methods in CryptableMailItem report when they fail.
Dean Looyengoed
parents: 197
diff changeset
   429
            if ((formRegions != null) &&
ca1b6e20f1a6 Make mirror methods in CryptableMailItem report when they fail.
Dean Looyengoed
parents: 197
diff changeset
   430
                (formRegions.FormRegionPreviewUnencrypted != null) &&
620
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   431
                (formRegions.FormRegionPreviewUnencrypted.Visible))
198
ca1b6e20f1a6 Make mirror methods in CryptableMailItem report when they fail.
Dean Looyengoed
parents: 197
diff changeset
   432
            {
620
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   433
                formRegions.FormRegionPreviewUnencrypted.ClearMessage();
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   434
                mirror = this.associatedMailItem.MirrorGet();
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   435
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   436
                if (mirror != null)
198
ca1b6e20f1a6 Make mirror methods in CryptableMailItem report when they fail.
Dean Looyengoed
parents: 197
diff changeset
   437
                {
620
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   438
                    // Attempt to the the RTF body
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   439
                    isSuccessful = this.associatedMailItem.MirrorTryGetRTFBody(out rtfBody);
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   440
                    if (isSuccessful == false)
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   441
                    {
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   442
                        return (false);
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   443
                    }
198
ca1b6e20f1a6 Make mirror methods in CryptableMailItem report when they fail.
Dean Looyengoed
parents: 197
diff changeset
   444
620
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   445
                    formRegions.FormRegionPreviewUnencrypted.SetMessage(mirror);
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   446
                    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
   447
                    success = true;
7c01eca90a5f Clear unencrypted preview before showing the decrypted message.
Dean Looyengoed
parents: 605
diff changeset
   448
                }
198
ca1b6e20f1a6 Make mirror methods in CryptableMailItem report when they fail.
Dean Looyengoed
parents: 197
diff changeset
   449
            }
ca1b6e20f1a6 Make mirror methods in CryptableMailItem report when they fail.
Dean Looyengoed
parents: 197
diff changeset
   450
ca1b6e20f1a6 Make mirror methods in CryptableMailItem report when they fail.
Dean Looyengoed
parents: 197
diff changeset
   451
            return (success);
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   452
        }
201
9e0548fa3942 Code reformatting.
Markus Schaber <markus@pep-security.net>
parents: 199
diff changeset
   453
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   454
        /// <summary>
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   455
        /// 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
   456
        /// </summary>
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   457
        /// <returns>A new manager form state.</returns>
313
619529633b8c Rename 'FormManageEncryptionStatus' to 'FormManagePrivacyStatus' everywhere.
Dean Looyengoed
parents: 312
diff changeset
   458
        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
   459
        {
527
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   460
            bool isMyself;
641
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   461
            bool isContactSendUnencrypted;
364
b3291efce20b Complete initial implementation of the expanded region (in-line handshake) in the selection list.
Dean Looyengoed
parents: 363
diff changeset
   462
            string trustwordsShort;
b3291efce20b Complete initial implementation of the expanded region (in-line handshake) in the selection list.
Dean Looyengoed
parents: 363
diff changeset
   463
            string trustwordsFull;
384
a0aa034cb7f3 Create and implement new classes for PEPAttachment, PEPIdentity and PEPMessage.
Dean Looyengoed
parents: 378
diff changeset
   464
            List<PEPIdentity> identities;
a0aa034cb7f3 Create and implement new classes for PEPAttachment, PEPIdentity and PEPMessage.
Dean Looyengoed
parents: 378
diff changeset
   465
            PEPIdentity myIdentity;
a0aa034cb7f3 Create and implement new classes for PEPAttachment, PEPIdentity and PEPMessage.
Dean Looyengoed
parents: 378
diff changeset
   466
            PEPIdentity incomingIdent;
527
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   467
            PEPIdentity[] myIdentities;
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   468
            _pEp_color identityPartnerColor;
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   469
            SelectionItem item;
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   470
            PrivacyState state = this.CopyUIToState();
313
619529633b8c Rename 'FormManageEncryptionStatus' to 'FormManagePrivacyStatus' everywhere.
Dean Looyengoed
parents: 312
diff changeset
   471
            FormManagePrivacyStatus.State managerState = new FormManagePrivacyStatus.State();
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   472
332
4221c5b34348 Do not show both user name and address in identities list if they are the same.
Dean Looyengoed
parents: 331
diff changeset
   473
            // 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
   474
            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
   475
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   476
            managerState.VisualState = state.Copy();
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   477
            managerState.IsIncoming = this.associatedMailItem.IsIncoming;
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   478
653
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   479
            if (managerState.IsIncoming)
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   480
            {
384
a0aa034cb7f3 Create and implement new classes for PEPAttachment, PEPIdentity and PEPMessage.
Dean Looyengoed
parents: 378
diff changeset
   481
                identities = new List<PEPIdentity>();
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   482
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   483
                // Add only one identity
638
5d99a596d5b5 Check for null From in CryptableMailItem before use.
Dean Looyengoed
parents: 633
diff changeset
   484
                if (this.associatedMailItem.From != null)
5d99a596d5b5 Check for null From in CryptableMailItem before use.
Dean Looyengoed
parents: 633
diff changeset
   485
                {
5d99a596d5b5 Check for null From in CryptableMailItem before use.
Dean Looyengoed
parents: 633
diff changeset
   486
                    incomingIdent = new PEPIdentity();
5d99a596d5b5 Check for null From in CryptableMailItem before use.
Dean Looyengoed
parents: 633
diff changeset
   487
                    incomingIdent.Address = this.associatedMailItem.From.Address;
5d99a596d5b5 Check for null From in CryptableMailItem before use.
Dean Looyengoed
parents: 633
diff changeset
   488
                    incomingIdent.Username = this.associatedMailItem.From.Username;
5d99a596d5b5 Check for null From in CryptableMailItem before use.
Dean Looyengoed
parents: 633
diff changeset
   489
                    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
   490
638
5d99a596d5b5 Check for null From in CryptableMailItem before use.
Dean Looyengoed
parents: 633
diff changeset
   491
                    identities.Add(incomingIdent);
5d99a596d5b5 Check for null From in CryptableMailItem before use.
Dean Looyengoed
parents: 633
diff changeset
   492
                }
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
            else
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   495
            {
395
ba088d922a94 Rename Addresses property to Recipients in the CryptableMailItem.
Dean Looyengoed
parents: 394
diff changeset
   496
                identities = this.associatedMailItem.Recipients;
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   497
            }
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   498
366
1bb0df0e9970 Don't show an action button if the partner fingerprint is the same as myself.
Dean Looyengoed
parents: 364
diff changeset
   499
            // Get my identity
633
c65f81929528 Rewrite GetMyIdentity methods to work in more situations.
Dean Looyengoed
parents: 631
diff changeset
   500
            myIdentity = this.associatedMailItem.Myself;
527
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   501
            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
   502
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   503
            // 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
   504
            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
   505
            managerState.Identities.Clear();
384
a0aa034cb7f3 Create and implement new classes for PEPAttachment, PEPIdentity and PEPMessage.
Dean Looyengoed
parents: 378
diff changeset
   506
            foreach (PEPIdentity ident in identities)
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   507
            {
648
28f89d1e3c5b Make IsValid a property of PEPIdentity and remove empty check of Username.
Dean Looyengoed
parents: 646
diff changeset
   508
                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
   509
                {
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   510
                    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
   511
                    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
   512
                    identityPartnerColor = ThisAddIn.pEp.identity_color(partnerIdentity_s);
641
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   513
                    isContactSendUnencrypted = Globals.ThisAddIn.ContactIsSendUnencryptedForced(partnerIdentity.Address);
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   514
527
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   515
                    // Check if identity is myself
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   516
                    isMyself = false;
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   517
                    foreach (PEPIdentity me in myIdentities)
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   518
                    {
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   519
                        if (partnerIdentity.EqualsByAddress(me))
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
                            isMyself = true;
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   522
                            break;
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   523
                        }
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   524
                    }
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   525
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   526
                    item = new SelectionItem();
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   527
                    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
   528
                    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
   529
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   530
                    // 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
   531
                    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
   532
                        (item.TextLine2 != null) &&
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   533
                        (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
   534
                    {
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   535
                        item.IsTwoTextLinesVisible = false;
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   536
                    }
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   537
527
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   538
                    // Calculate trustwords
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   539
                    this.CalcTrustwords(myIdentity,
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   540
                                        partnerIdentity,
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   541
                                        out trustwordsShort,
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   542
                                        out trustwordsFull);
a60b87842287 Check all 'my' identities before showing handshake button.
Dean Looyengoed
parents: 501
diff changeset
   543
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   544
                    // Set image
653
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   545
                    if ((isContactSendUnencrypted) &&
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   546
                        (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
   547
                    {
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   548
                        // 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
   549
                        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
   550
                    }
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   551
                    else
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   552
                    {
641
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   553
                        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
   554
                        {
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   555
                            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
   556
                                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
   557
                                break;
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   558
                            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
   559
                                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
   560
                                break;
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   561
                            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
   562
                                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
   563
                                break;
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   564
                            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
   565
                                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
   566
                                break;
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   567
                            default:
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   568
                                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
   569
                                break;
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   570
                        }
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   571
                    }
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   572
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   573
                    // Set button
653
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   574
                    if ((isMyself) ||
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   575
                        ((isContactSendUnencrypted) &&
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   576
                         (managerState.IsIncoming == false)))
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   577
                    {
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   578
                        item.IsButtonVisible = false;
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   579
                        item.IsExpandable = false;
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   580
                    }
0e46e5c08f5b Only show the force unencrypted icon by identies in privacy status for outgoing messages.
Dean Looyengoed
parents: 652
diff changeset
   581
                    else
366
1bb0df0e9970 Don't show an action button if the partner fingerprint is the same as myself.
Dean Looyengoed
parents: 364
diff changeset
   582
                    {
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   583
                        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
   584
                        {
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   585
                            // Undo handshake
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   586
                            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
   587
                            item.IsButtonVisible = true;
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   588
                            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
   589
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   590
                            item.IsExpandable = false;
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   591
                        }
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   592
                        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
   593
                                 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
   594
                        {
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   595
                            // Do handshake
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   596
                            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
   597
                            item.IsButtonVisible = true;
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   598
                            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
   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.IsExpandable = true;
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   601
                            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
   602
                                                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
   603
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   604
                            item.ExpandedButton1Text = Properties.Resources.PrivacyStatus_SelectTrust;
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   605
                            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
   606
                            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
   607
                            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
   608
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   609
                            item.ExpandedButton2Text = Properties.Resources.PrivacyStatus_SelectMistrust;
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   610
                            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
   611
                            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
   612
                            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
   613
                        }
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   614
                        else if (partnerIdentity.CommunicationType == _pEp_comm_type.pEp_ct_compromized)
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   615
                        {
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   616
                            // 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
   617
                            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
   618
                            item.IsButtonVisible = true;
646
c5ba1646f90d Pass my identity to DoHandshake instead of recalculating it.
Dean Looyengoed
parents: 642
diff changeset
   619
                            item.ButtonOnClick = (x, y) => { this.DoHandshakeForCompromisedKey(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
   620
58d9dbf575bb Show force unencrypted image next to identities whose Outlook contact is set to force unencrypted.
Dean Looyengoed
parents: 638
diff changeset
   621
                            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
   622
                        }
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   623
                        else
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   624
                        {
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   625
                            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
   626
                            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
   627
                        }
366
1bb0df0e9970 Don't show an action button if the partner fingerprint is the same as myself.
Dean Looyengoed
parents: 364
diff changeset
   628
                    }
281
4040d2e488b6 Add handshake procedure for keys that were previously marked as compromised.
Dean Looyengoed
parents: 280
diff changeset
   629
                }
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   630
                else // Invalid identity
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   631
                {
485
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   632
                    item = new SelectionItem();
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   633
                    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
   634
                    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
   635
                    item.ItemImage = null;
486b81348e82 Add and implement method to determine if a PEPIdentity is valid for further processing.
Dean Looyengoed
parents: 483
diff changeset
   636
                    item.IsTwoTextLinesVisible = true;
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   637
                    item.IsButtonVisible = false;
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   638
                }
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   639
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   640
                managerState.Identities.Add(item);
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   641
            }
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   642
375
98df9e57270b Automatically select the first identity requiring a handshake in the privacy status form.
Dean Looyengoed
parents: 366
diff changeset
   643
            // 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
   644
            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
   645
            {
98df9e57270b Automatically select the first identity requiring a handshake in the privacy status form.
Dean Looyengoed
parents: 366
diff changeset
   646
                // 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
   647
                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
   648
                {
98df9e57270b Automatically select the first identity requiring a handshake in the privacy status form.
Dean Looyengoed
parents: 366
diff changeset
   649
                    managerState.SelectedIdentityIndex = i;
98df9e57270b Automatically select the first identity requiring a handshake in the privacy status form.
Dean Looyengoed
parents: 366
diff changeset
   650
                    break;
98df9e57270b Automatically select the first identity requiring a handshake in the privacy status form.
Dean Looyengoed
parents: 366
diff changeset
   651
                }
98df9e57270b Automatically select the first identity requiring a handshake in the privacy status form.
Dean Looyengoed
parents: 366
diff changeset
   652
            }
98df9e57270b Automatically select the first identity requiring a handshake in the privacy status form.
Dean Looyengoed
parents: 366
diff changeset
   653
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   654
            return (managerState);
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   655
        }
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   656
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   657
        /// <summary>
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   658
        /// 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
   659
        /// </summary>
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   660
        private void BuildAndShowManager()
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   661
        {
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   662
            DialogResult result;
313
619529633b8c Rename 'FormManageEncryptionStatus' to 'FormManagePrivacyStatus' everywhere.
Dean Looyengoed
parents: 312
diff changeset
   663
            FormManagePrivacyStatus form;
619529633b8c Rename 'FormManageEncryptionStatus' to 'FormManagePrivacyStatus' everywhere.
Dean Looyengoed
parents: 312
diff changeset
   664
            FormManagePrivacyStatus.State stateOut;
279
93fa916f4bc9 Make the encryption status form region control the state of the encryption manager.
Dean Looyengoed
parents: 277
diff changeset
   665
483
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   666
            try
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   667
            {
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   668
                // Show the form
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   669
                form = new FormManagePrivacyStatus();
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   670
                form.StartPosition = FormStartPosition.CenterScreen;
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   671
483
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   672
                this.managerForm = form;
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   673
                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
   674
            }
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   675
            catch (Exception ex)
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   676
            {
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   677
                GlobalExceptionHandler.StopAndSendCrashReport(ex);
d0ec604f5f4e Add exception handling around FormManagePrivacyStatus.
Dean Looyengoed
parents: 471
diff changeset
   678
            }
259
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   679
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   680
            return;
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   681
        }
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   682
98b68d170427 Add a new manage encryption status form to the UI.
Dean Looyengoed
parents: 253
diff changeset
   683
        /// <summary>
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   684
        /// 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
   685
        /// 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
   686
        /// </summary>
622
7647f3056282 Use MailItem directly when get/set SendUnencrypted is called in a MailItem inspector.
Dean Looyengoed
parents: 620
diff changeset
   687
        public void UpdateUIFromMailItem()
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   688
        {
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   689
            PrivacyState state;
342
bbc68931d60e Stop using CheckState and instead use bool? for SendUnencrypted property.
Dean Looyengoed
parents: 341
diff changeset
   690
            bool? sendUnencryptedProperty;
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   691
173
cf2c9c426576 Remove the mailItem property and replace with single associatedMailItem variable.
Dean Looyengoed
parents: 172
diff changeset
   692
            if (this.associatedMailItem != null)
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   693
            {
342
bbc68931d60e Stop using CheckState and instead use bool? for SendUnencrypted property.
Dean Looyengoed
parents: 341
diff changeset
   694
                sendUnencryptedProperty = this.associatedMailItem.SendUnencrypted;
bbc68931d60e Stop using CheckState and instead use bool? for SendUnencrypted property.
Dean Looyengoed
parents: 341
diff changeset
   695
bbc68931d60e Stop using CheckState and instead use bool? for SendUnencrypted property.
Dean Looyengoed
parents: 341
diff changeset
   696
                if ((sendUnencryptedProperty != null) &&
bbc68931d60e Stop using CheckState and instead use bool? for SendUnencrypted property.
Dean Looyengoed
parents: 341
diff changeset
   697
                    ((bool)sendUnencryptedProperty == true))
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   698
                {
342
bbc68931d60e Stop using CheckState and instead use bool? for SendUnencrypted property.
Dean Looyengoed
parents: 341
diff changeset
   699
                    // Force unencrypted
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   700
                    state = new PrivacyState(_pEp_color.pEp_rating_unencrypted);
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   701
                }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   702
                else
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   703
                {
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   704
                    state = new PrivacyState(this.associatedMailItem.ColorRating);
159
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
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   707
                this.CopyStateToUI(state);
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   708
            }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   709
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   710
            return;
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   711
        }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   712
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   713
        #region StateMethods
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   714
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   715
        /// <summary>
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   716
        /// Connects or disconnects all control events from the UI.
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   717
        /// </summary>
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   718
        /// <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
   719
        private void ConnectEvents(bool connect)
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   720
        {
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   721
            // Connect events only if not already connected
201
9e0548fa3942 Code reformatting.
Markus Schaber <markus@pep-security.net>
parents: 199
diff changeset
   722
            if ((connect == true) &&
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   723
                (this.eventsAreConnected == false))
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   724
            {
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   725
                this.ButtonPrivacyStatus.Click += this.ButtonPrivacyStatus_Click;
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   726
                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
   727
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   728
                this.eventsAreConnected = true;
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   729
            }
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   730
            // Always attempt to disconnect
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   731
            else if (connect == false)
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   732
            {
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   733
                this.ButtonPrivacyStatus.Click -= this.ButtonPrivacyStatus_Click;
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   734
                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
   735
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   736
                this.eventsAreConnected = false;
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
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   739
            return;
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   740
        }
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   741
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   742
        /// <summary>
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   743
        /// Refreshes the UI by reloading the state.
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   744
        /// </summary>
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   745
        private void RefreshUI()
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
            this.CopyStateToUI(this.CopyUIToState());
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   748
            return;
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   749
        }
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   750
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   751
        /// <summary>
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   752
        /// Copies the given state to the UI.
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   753
        /// Events are turned off until the process is complete.
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   754
        /// </summary>
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   755
        /// <param name="state">The state to set to the UI.</param>
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   756
        private void CopyStateToUI(PrivacyState state)
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   757
        {
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   758
            this.ConnectEvents(false);
201
9e0548fa3942 Code reformatting.
Markus Schaber <markus@pep-security.net>
parents: 199
diff changeset
   759
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   760
            ///////////////////////////////////////////////////////////
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   761
            // Set UI data
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   762
            ///////////////////////////////////////////////////////////
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   763
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   764
            // Save UI state maintained outside of controls
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   765
            this.stateUIColorRating = state.PrivacyStatus;
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   766
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   767
            this.ButtonPrivacyStatus.BackColor = state.BackgroundColor;
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   768
            this.ButtonPrivacyStatus.ForeColor = state.ForegroundColor;
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   769
            this.ButtonPrivacyStatus.Text = state.ShortText;
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   770
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   771
            this.ConnectEvents(true);
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   772
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   773
            return;
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
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   776
        /// <summary>
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   777
        /// Copies the UI to a new state.
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
        /// <returns>The state of the UI.</returns>
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   780
        private PrivacyState CopyUIToState()
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   781
        {
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   782
            return (new PrivacyState(this.stateUIColorRating));
172
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   783
        }
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   784
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   785
        #endregion
60c6af7c94e5 Add state method framework (non-functional right now)
Dean Looyengoed
parents: 171
diff changeset
   786
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   787
        /**************************************************************
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   788
         * 
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   789
         * Event Handling
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
         *************************************************************/
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
        /// <summary>
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   794
        /// Event handler that is called before the form region is displayed.
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   795
        /// </summary>
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   796
        private void FormRegionPrivacyStatus_FormRegionShowing(object sender, System.EventArgs e)
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   797
        {
173
cf2c9c426576 Remove the mailItem property and replace with single associatedMailItem variable.
Dean Looyengoed
parents: 172
diff changeset
   798
            this.SetAssociatedMailItem();
cf2c9c426576 Remove the mailItem property and replace with single associatedMailItem variable.
Dean Looyengoed
parents: 172
diff changeset
   799
631
7d9cf2642434 Set background color of the FormRegionPrivacyStatus differently for Office 2013.
Dean Looyengoed
parents: 622
diff changeset
   800
            // Set background color for Office 2013
7d9cf2642434 Set background color of the FormRegionPrivacyStatus differently for Office 2013.
Dean Looyengoed
parents: 622
diff changeset
   801
            try
7d9cf2642434 Set background color of the FormRegionPrivacyStatus differently for Office 2013.
Dean Looyengoed
parents: 622
diff changeset
   802
            {
7d9cf2642434 Set background color of the FormRegionPrivacyStatus differently for Office 2013.
Dean Looyengoed
parents: 622
diff changeset
   803
                if (Globals.ThisAddIn.Application.Version.Substring(0, 2) == "15")
7d9cf2642434 Set background color of the FormRegionPrivacyStatus differently for Office 2013.
Dean Looyengoed
parents: 622
diff changeset
   804
                {
7d9cf2642434 Set background color of the FormRegionPrivacyStatus differently for Office 2013.
Dean Looyengoed
parents: 622
diff changeset
   805
                    if (this.IsWithinInspector())
7d9cf2642434 Set background color of the FormRegionPrivacyStatus differently for Office 2013.
Dean Looyengoed
parents: 622
diff changeset
   806
                    {
7d9cf2642434 Set background color of the FormRegionPrivacyStatus differently for Office 2013.
Dean Looyengoed
parents: 622
diff changeset
   807
                        this.BackColor = SystemColors.ButtonFace;
7d9cf2642434 Set background color of the FormRegionPrivacyStatus differently for Office 2013.
Dean Looyengoed
parents: 622
diff changeset
   808
                    }
7d9cf2642434 Set background color of the FormRegionPrivacyStatus differently for Office 2013.
Dean Looyengoed
parents: 622
diff changeset
   809
                    else
7d9cf2642434 Set background color of the FormRegionPrivacyStatus differently for Office 2013.
Dean Looyengoed
parents: 622
diff changeset
   810
                    {
7d9cf2642434 Set background color of the FormRegionPrivacyStatus differently for Office 2013.
Dean Looyengoed
parents: 622
diff changeset
   811
                        this.BackColor = SystemColors.Window;
7d9cf2642434 Set background color of the FormRegionPrivacyStatus differently for Office 2013.
Dean Looyengoed
parents: 622
diff changeset
   812
                    }
7d9cf2642434 Set background color of the FormRegionPrivacyStatus differently for Office 2013.
Dean Looyengoed
parents: 622
diff changeset
   813
                }
7d9cf2642434 Set background color of the FormRegionPrivacyStatus differently for Office 2013.
Dean Looyengoed
parents: 622
diff changeset
   814
            }
7d9cf2642434 Set background color of the FormRegionPrivacyStatus differently for Office 2013.
Dean Looyengoed
parents: 622
diff changeset
   815
            catch { }
7d9cf2642434 Set background color of the FormRegionPrivacyStatus differently for Office 2013.
Dean Looyengoed
parents: 622
diff changeset
   816
199
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   817
            // Connect cryptable mail item events
189
40f4e17a5744 Refactor some method names in CryptableMailItem. Use CryptableMailItem events in EncryptionStatusPanel.
Dean Looyengoed
parents: 186
diff changeset
   818
            if (this.associatedMailItem != null)
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   819
            {
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   820
                try
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   821
                {
445
499559d35fae Implement the INotifyPropertyChanged interface from System.ComponentModel.
Dean Looyengoed
parents: 438
diff changeset
   822
                    this.associatedMailItem.PropertyChanged += MailItem_PropertyChanged;
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   823
189
40f4e17a5744 Refactor some method names in CryptableMailItem. Use CryptableMailItem events in EncryptionStatusPanel.
Dean Looyengoed
parents: 186
diff changeset
   824
                    if (this.associatedMailItem.IsInEncryptedStore &&
198
ca1b6e20f1a6 Make mirror methods in CryptableMailItem report when they fail.
Dean Looyengoed
parents: 197
diff changeset
   825
                        this.associatedMailItem.IsPGPEncrypted)
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   826
                    {
189
40f4e17a5744 Refactor some method names in CryptableMailItem. Use CryptableMailItem events in EncryptionStatusPanel.
Dean Looyengoed
parents: 186
diff changeset
   827
                        this.associatedMailItem.Open += MailItem_Open;
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   828
                    }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   829
                }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   830
                catch { }
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   831
            }
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   832
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   833
            // Set the default UI state
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   834
            this.CopyStateToUI(new PrivacyState());
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   835
199
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   836
            // 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
   837
            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
   838
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   839
            return;
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   840
        }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   841
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   842
        /// <summary>
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   843
        /// Event handler for when the form region is closed.
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   844
        /// </summary>
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   845
        private void FormRegionPrivacyStatus_FormRegionClosed(object sender, System.EventArgs e)
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   846
        {
199
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   847
            // Disconnect cryptable mail item events
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 189
diff changeset
   848
            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
   849
            {
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   850
                try
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   851
                {
445
499559d35fae Implement the INotifyPropertyChanged interface from System.ComponentModel.
Dean Looyengoed
parents: 438
diff changeset
   852
                    this.associatedMailItem.PropertyChanged -= MailItem_PropertyChanged;
201
9e0548fa3942 Code reformatting.
Markus Schaber <markus@pep-security.net>
parents: 199
diff changeset
   853
                    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
   854
                }
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   855
                catch { }
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   856
            }
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   857
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   858
            return;
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   859
        }
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
        /// <summary>
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   862
        /// 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
   863
        /// </summary>
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   864
        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
   865
        {
199
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   866
            bool tryAgain = false;
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   867
            bool isSuccessful;
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   868
            this.TimerRefresh.Enabled = false; // Only once
201
9e0548fa3942 Code reformatting.
Markus Schaber <markus@pep-security.net>
parents: 199
diff changeset
   869
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   870
            // 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
   871
            if (refreshOngoing == false)
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
                this.refreshOngoing = true;
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   874
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   875
                if (this.associatedMailItem != null)
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   876
                {
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   877
                    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
   878
                    {
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   879
                        this.UpdateUIFromMailItem();
199
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   880
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   881
                        /* 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
   882
                         * 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
   883
                         * 
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   884
                         * 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
   885
                         * 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
   886
                         */
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   887
                        if (this.associatedMailItem.IsInEncryptedStore &&
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   888
                            this.associatedMailItem.IsPGPEncrypted)
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   889
                        {
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   890
                            isSuccessful = this.MakePreview();
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   891
534
c38561b8a7e1 Disable try again if message preview fails.
Dean Looyengoed
parents: 527
diff changeset
   892
                            // 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
   893
                            /*if (isSuccessful == false)
199
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   894
                            {
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   895
                                tryAgain = true;
534
c38561b8a7e1 Disable try again if message preview fails.
Dean Looyengoed
parents: 527
diff changeset
   896
                            }*/
199
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   897
                        }
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   898
                    }
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   899
                    else
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   900
                    {
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   901
                        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
   902
                        tryAgain = true;
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   903
                    }
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   904
                }
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   905
199
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   906
                // 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
   907
                if (tryAgain)
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   908
                {
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   909
                    this.TimerRefresh.Interval = 100;
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   910
                    this.TimerRefresh.Enabled = true;
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   911
                }
94f5017acda0 Detect when making the unencrypted preview fails and continuously attempt to refresh.
Dean Looyengoed
parents: 198
diff changeset
   912
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   913
                this.refreshOngoing = false;
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   914
            }
175
48628e74ace0 Add a comment to remove event handlers
Dean Looyengoed
parents: 174
diff changeset
   915
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   916
            return;
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   917
        }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   918
169
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   919
        /// <summary>
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   920
        /// Event handler for when a mail item is being opened in an inspector.
180
1602b0e8fdd6 Add some comments
Dean Looyengoed
parents: 179
diff changeset
   921
        /// 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
   922
        /// </summary>
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   923
        /// <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
   924
        /// 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
   925
        /// and the inspector is not displayed.</param>
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   926
        private void MailItem_Open(ref bool cancel)
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   927
        {
173
cf2c9c426576 Remove the mailItem property and replace with single associatedMailItem variable.
Dean Looyengoed
parents: 172
diff changeset
   928
            if (this.associatedMailItem != null && this.associatedMailItem.MirrorDisplay())
169
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   929
            {
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   930
                cancel = true;
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   931
            }
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   932
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   933
            return;
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   934
        }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   935
169
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   936
        /// <summary>
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   937
        /// Event handler for when a mail item property is changed.
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   938
        /// See: https://msdn.microsoft.com/en-us/library/office/ff866739.aspx
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   939
        /// </summary>
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   940
        /// <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
   941
        private void MailItem_PropertyChanged(object sender, PropertyChangedEventArgs e)
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   942
        {
445
499559d35fae Implement the INotifyPropertyChanged interface from System.ComponentModel.
Dean Looyengoed
parents: 438
diff changeset
   943
            switch (e.PropertyName.ToUpper())
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   944
            {
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   945
                case "TO":
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   946
                    // Start the refresh timer
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   947
                    this.TimerRefresh.Enabled = true;
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   948
                    break;
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   949
                // 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
   950
                //case "CC":
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   951
                //    // Start the refresh timer
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   952
                //    this.TimerRefresh.Enabled = true;
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   953
                //    break;
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   954
            }
169
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   955
c7d9b7ad0639 Comment and refactor MailItem event handlers
Dean Looyengoed
parents: 166
diff changeset
   956
            return;
159
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   957
        }
15d0050bc11a Initial refactoring of the encryption status panel
Dean Looyengoed
parents: 156
diff changeset
   958
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   959
        /// <summary>
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   960
        /// 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
   961
        /// </summary>
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   962
        private void ButtonPrivacyStatus_Click(object sender, EventArgs e)
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   963
        {
310
ccf59b512bbd Remove right-click from encryption status button.
Dean Looyengoed
parents: 293
diff changeset
   964
            this.BuildAndShowManager();
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   965
            return;
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   966
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   967
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   968
        /// <summary>
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   969
        /// 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
   970
        /// </summary>
312
ca6e4fb02692 Rename 'FormRegionEncryptionStatus' to 'FormRegionPrivacyStatus' everywhere.
Dean Looyengoed
parents: 311
diff changeset
   971
        private void ButtonPrivacyStatus_MouseUp(object sender, MouseEventArgs e)
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   972
        {
179
ff5101f87d35 Finish almost completely rewriting the encryption status panel... yes, it was very necessary.
Dean Looyengoed
parents: 178
diff changeset
   973
            return;
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   974
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   975
    }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   976
}