UI/FormRegionPrivacyStatus.cs
author Dean Looyengoed
Wed, 24 Feb 2016 17:39:42 +0100
changeset 527 a60b87842287
parent 501 158c070826dd
child 534 c38561b8a7e1
permissions -rw-r--r--
Check all 'my' identities before showing handshake button.
Also rename Equals to EqualsByAddress to be more clear and stop comparing by fingerprint.
Dean@159
     1
´╗┐using pEpCOMServerAdapterLib;
Dean@159
     2
using System;
vb@133
     3
using System.Collections.Generic;
Dean@445
     4
using System.ComponentModel;
Dean@438
     5
using System.Drawing;
Dean@159
     6
using System.Runtime.InteropServices;
vb@133
     7
using System.Windows.Forms;
Dean@159
     8
using Color = System.Drawing.Color;
vb@133
     9
using Outlook = Microsoft.Office.Interop.Outlook;
vb@133
    10
vb@133
    11
namespace pEp
vb@133
    12
{
Dean@159
    13
    /// <summary>
Dean@312
    14
    /// Partial class for the privacy status form region that is displayed below every outlook message.
Dean@159
    15
    /// </summary>
Dean@312
    16
    partial class FormRegionPrivacyStatus
vb@133
    17
    {
vb@133
    18
        #region Form Region Factory
vb@133
    19
vb@133
    20
        [Microsoft.Office.Tools.Outlook.FormRegionMessageClass(Microsoft.Office.Tools.Outlook.FormRegionMessageClassAttribute.Note)]
Dean@312
    21
        [Microsoft.Office.Tools.Outlook.FormRegionName("pEp.FormRegionPrivacyStatus")]
Dean@312
    22
        public partial class FormRegionPrivacyStatusFactory
vb@133
    23
        {
vb@133
    24
            // Occurs before the form region is initialized.
vb@133
    25
            // To prevent the form region from appearing, set e.Cancel to true.
vb@133
    26
            // Use e.OutlookItem to get a reference to the current Outlook item.
Dean@312
    27
            private void FormRegionPrivacyStatus_FormRegionInitializing(object sender, Microsoft.Office.Tools.Outlook.FormRegionInitializingEventArgs e)
vb@133
    28
            {
Dean@327
    29
                WindowFormRegionCollection formRegions;
Dean@327
    30
Dean@327
    31
                /* There is a Microsoft bug at least in Outlook 2013 and Windows 8.1
Dean@327
    32
                 * This bug causes multiple PrivacyStatus form regions to appear stacked on top of each other.
Dean@327
    33
                 * To trigger this bug, on an unencrypted server, click reply to compose an in-line response.
Dean@327
    34
                 * Then click to another tab such as People or Tasks. Then click back on the mail tab to view 
Dean@327
    35
                 * the original email again. Two form regions will be visible: 
Dean@327
    36
                 * (1) for the status during the in-line reply and 
Dean@327
    37
                 * (2) for the status of only the received message.
Dean@327
    38
                 * 
Dean@327
    39
                 * To fix this bug, any existing form regions are found and closed when initializing a new privacy status
Dean@327
    40
                 * form region.
Dean@327
    41
                 */
Dean@327
    42
Dean@327
    43
                try
Dean@327
    44
                {
Dean@327
    45
                    formRegions = Globals.FormRegions[Globals.ThisAddIn.Application.ActiveExplorer()];
Dean@327
    46
                    if (formRegions.FormRegionPrivacyStatus != null)
Dean@327
    47
                    {
Dean@327
    48
                        /* Note: there seems to be no way to actually close the form region.
Dean@327
    49
                         * Therefore, this is as close as possible to actually closing it.
Dean@327
    50
                         * The actual form regions will be cleaned up as soon as another email is selected.
Dean@327
    51
                         */
Dean@327
    52
                        formRegions.FormRegionPrivacyStatus.OutlookFormRegion.Visible = false;
Dean@327
    53
                    }
Dean@327
    54
                }
Dean@327
    55
                catch { }
Dean@327
    56
Dean@327
    57
                return;
vb@133
    58
            }
vb@133
    59
        }
vb@133
    60
vb@133
    61
        #endregion
vb@133
    62
Dean@159
    63
        /* Notes:
Dean@179
    64
         * 
Dean@159
    65
         * Use this.OutlookItem to get a reference to the current Outlook item.
Dean@159
    66
         * Use this.OutlookFormRegion to get a reference to the form region.
Dean@179
    67
         * 
Dean@179
    68
         * UI State Managment:
Dean@179
    69
         * 
Dean@179
    70
         * The UI state is almost entirely set from the associated mail item data.
Dean@179
    71
         * However, a separate state class is maintained to represent the UI as some separation is needed.
Dean@179
    72
         * This logical separation MUST be maintained throughout the code.
Dean@179
    73
         * Specific cases are noted where possible.
Dean@179
    74
         * 
Dean@356
    75
         * The separate privacy status manager form state is also managed here.
Dean@259
    76
         * 
Dean@159
    77
         */
Dean@159
    78
Dean@170
    79
        private CryptableMailItem associatedMailItem = null;
Dean@179
    80
        private bool              refreshOngoing     = false;
Dean@179
    81
        private bool              eventsAreConnected = false;
Dean@170
    82
Dean@313
    83
        private FormManagePrivacyStatus managerForm = null;
Dean@259
    84
Dean@250
    85
        // Data or controls not stored in the UI
Dean@179
    86
        private _pEp_color stateUIColorRating; // WARNING: Do NOT use this directly
vb@133
    87
Dean@159
    88
        /**************************************************************
Dean@159
    89
         * 
Dean@340
    90
         * Property Accessors
Dean@340
    91
         * 
Dean@340
    92
         *************************************************************/
Dean@340
    93
Dean@340
    94
        /// <summary>
Dean@340
    95
        /// Gets or sets whether to send the associated cryptable mail item as unencrypted.
Dean@342
    96
        /// This forwards the call to the cryptable mail item but also refreshes the UI.
Dean@340
    97
        /// </summary>
Dean@342
    98
        public bool? SendUnencrypted
Dean@340
    99
        {
Dean@340
   100
            get
Dean@340
   101
            {
Dean@340
   102
                if (this.associatedMailItem != null)
Dean@340
   103
                {
Dean@340
   104
                    return (this.associatedMailItem.SendUnencrypted);
Dean@340
   105
                }
Dean@340
   106
                else
Dean@340
   107
                {
Dean@342
   108
                    return (null);
Dean@340
   109
                }
Dean@340
   110
            }
Dean@340
   111
            set
Dean@340
   112
            {
Dean@340
   113
                if (this.associatedMailItem != null)
Dean@340
   114
                {
Dean@340
   115
                    this.associatedMailItem.SendUnencrypted = value;
Dean@340
   116
                    this.UpdateUIFromMailItem();
Dean@340
   117
                }
Dean@340
   118
            }
Dean@340
   119
        }
Dean@340
   120
Dean@340
   121
        /**************************************************************
Dean@340
   122
         * 
Dean@159
   123
         * Methods
Dean@159
   124
         * 
Dean@159
   125
         *************************************************************/
Dean@159
   126
Dean@171
   127
        /// <summary>
Dean@438
   128
        /// Determines if this form region is running in an inspector window.
Dean@438
   129
        /// If not true, it is assumed to be within an explorer window.
Dean@438
   130
        /// </summary>
Dean@438
   131
        /// <returns>True if an inspector window, false if within an explorer.</returns>
Dean@438
   132
        private bool IsWithinInspector()
Dean@438
   133
        {
Dean@438
   134
            bool isWithinInspector = false;
Dean@438
   135
            Outlook.Explorer temp = null;
Dean@438
   136
Dean@438
   137
            try
Dean@438
   138
            {
Dean@438
   139
                // Just try to cast to an explorer class
Dean@438
   140
                temp = (Outlook.Explorer)this.OutlookFormRegion.Parent;
Dean@438
   141
                isWithinInspector = false;
Dean@438
   142
            }
Dean@438
   143
            catch
Dean@438
   144
            {
Dean@438
   145
                isWithinInspector = true;
Dean@438
   146
            }
Dean@438
   147
            finally
Dean@438
   148
            {
Dean@438
   149
                if (temp != null)
Dean@438
   150
                {
Dean@438
   151
                    Marshal.ReleaseComObject(temp);
Dean@438
   152
                    temp = null;
Dean@438
   153
                }
Dean@438
   154
            }
Dean@438
   155
Dean@438
   156
            return (isWithinInspector);
Dean@438
   157
        }
Dean@438
   158
Dean@438
   159
        /// <summary>
Dean@170
   160
        /// Sets the cryptable mail item associated with this encryption status panel.
Dean@170
   161
        /// The associated mail item can then be accessed through its local variable.
Dean@170
   162
        /// </summary>
Dean@170
   163
        private void SetAssociatedMailItem()
Dean@170
   164
        {
Dean@170
   165
            bool errorOccurred = false;
Dean@170
   166
            Outlook.MailItem omi = null;
Dean@170
   167
Dean@170
   168
            // Null check
Dean@170
   169
            if (!errorOccurred)
Dean@170
   170
            {
Dean@170
   171
                try
Dean@170
   172
                {
Dean@170
   173
                    if (this.OutlookItem == null)
Dean@170
   174
                    {
Dean@170
   175
                        errorOccurred = true;
Dean@170
   176
                    }
Dean@170
   177
                }
Dean@170
   178
                catch (COMException)
Dean@170
   179
                {
Dean@170
   180
                    errorOccurred = true;
Dean@170
   181
                }
Dean@170
   182
            }
Dean@170
   183
Dean@170
   184
            // Attempt to get and cast the outlook mail item
Dean@170
   185
            if (!errorOccurred)
Dean@170
   186
            {
Dean@170
   187
                try
Dean@170
   188
                {
Dean@170
   189
                    omi = (Outlook.MailItem)this.OutlookItem;
Dean@170
   190
                }
Dean@170
   191
                catch
Dean@170
   192
                {
Dean@170
   193
                    errorOccurred = true;
Dean@170
   194
                }
Dean@170
   195
            }
Dean@170
   196
Dean@170
   197
            // Finally set the associated mail item
Dean@170
   198
            if ((errorOccurred) ||
Dean@170
   199
                (omi == null))
Dean@170
   200
            {
Dean@170
   201
                this.associatedMailItem = null;
Dean@170
   202
            }
Dean@170
   203
            else
Dean@170
   204
            {
Dean@170
   205
                // Check if the associated mail item has already been set
Dean@170
   206
                if (this.associatedMailItem != null)
Dean@170
   207
                {
Dean@170
   208
                    // Only re-set the mail item if the EntryID has changed
Dean@170
   209
                    if (this.associatedMailItem.EntryID != omi.EntryID)
Dean@170
   210
                    {
Dean@170
   211
                        this.associatedMailItem = new CryptableMailItem(omi);
Dean@170
   212
                    }
Dean@170
   213
                }
Dean@170
   214
                else
Dean@170
   215
                {
Dean@170
   216
                    this.associatedMailItem = new CryptableMailItem(omi);
Dean@170
   217
                }
Dean@170
   218
            }
Dean@170
   219
Dean@170
   220
            return;
Dean@170
   221
        }
Dean@170
   222
Dean@179
   223
        /// <summary>
Dean@290
   224
        /// Completes the handshake process when the identity of a partner was previously marked as compromised.
Dean@281
   225
        /// </summary>
Dean@281
   226
        /// <param name="identityPartner">The identity of the partner to complete the handshake with.</param>
Dean@384
   227
        private void DoHandshakeForCompromisedKey(PEPIdentity identityPartner)
Dean@281
   228
        {
Dean@281
   229
            DialogResult result;
Dean@281
   230
Dean@281
   231
            result = MessageBox.Show(this.ParentForm,
Dean@378
   232
                                     pEp.Properties.Resources.Message_WarningCompromisedKey,
Dean@378
   233
                                     pEp.Properties.Resources.Message_TitleConfirmOperation,
Dean@423
   234
                                     MessageBoxButtons.YesNo);
Dean@281
   235
Dean@423
   236
            if (result == DialogResult.Yes)
Dean@281
   237
            {
Dean@281
   238
                this.DoHandshake(identityPartner);
Dean@281
   239
            }
Dean@281
   240
Dean@281
   241
            return;
Dean@281
   242
        }
Dean@281
   243
Dean@281
   244
        /// <summary>
Dean@281
   245
        /// Completes the handshake process where the identity of a partner is confirmed.
Dean@179
   246
        /// </summary>
Dean@179
   247
        /// <param name="identityPartner">The identity of the partner to complete the handshake with.</param>
Dean@384
   248
        private void DoHandshake(PEPIdentity identityPartner)
vb@133
   249
        {
Dean@155
   250
            string ownFpr;
Dean@155
   251
            string partnerFpr;
Dean@363
   252
            string trustwordsShort;
Dean@363
   253
            string trustwordsFull;
Dean@155
   254
            string[] lines;
Dean@179
   255
            DialogResult result;
Dean@384
   256
            PEPIdentity me;
Dean@155
   257
            FormHandshake handshakeDialog;
Dean@155
   258
            FormHandshake.State state = new FormHandshake.State();
markus@201
   259
Dean@190
   260
            Globals.ThisAddIn.LogVerbose("doHandshake");
Dean@384
   261
            Globals.ThisAddIn.LogVerbose(identityPartner.Address);
vb@139
   262
Dean@363
   263
            // Process identities
Dean@384
   264
            if (identityPartner.Username == "")
Dean@363
   265
            {
Dean@384
   266
                identityPartner.Username = identityPartner.Address;
vb@133
   267
            }
vb@133
   268
Dean@501
   269
            identityPartner.UserID = Globals.ThisAddIn.GetUserID(identityPartner.Address);
vb@139
   270
Dean@384
   271
            me = PEPIdentity.GetMyIdentity(this.associatedMailItem);
Dean@363
   272
Dean@363
   273
            // Calculate and add trustwords
Dean@363
   274
            this.CalcTrustwords(me, identityPartner, out trustwordsShort, out trustwordsFull);
Dean@363
   275
            state.TrustwordsShort = trustwordsShort;
Dean@363
   276
            state.TrustwordsFull = trustwordsFull;
Dean@363
   277
Dean@363
   278
            // Calculate and add fingerprint
Dean@384
   279
            ownFpr = this.ToQuadruple(me.Fingerprint);
Dean@384
   280
            partnerFpr = this.ToQuadruple(identityPartner.Fingerprint);
vb@133
   281
Dean@384
   282
            if (me.Fingerprint.CompareTo(identityPartner.Fingerprint) > 0)
vb@133
   283
            {
Dean@155
   284
                lines = new string[3];
Dean@378
   285
                lines[0] = pEp.Properties.Resources.PrivacyStatus_TrustwordsPartnerShortPartner + partnerFpr;
Dean@378
   286
                lines[2] = pEp.Properties.Resources.PrivacyStatus_TrustwordsPartnerShortMyself + ownFpr;
Dean@155
   287
                state.Fingerprint = lines;
vb@133
   288
            }
vb@133
   289
            else
vb@133
   290
            {
Dean@155
   291
                lines = new string[3];
Dean@378
   292
                lines[0] = pEp.Properties.Resources.PrivacyStatus_TrustwordsOwnShortMyself + ownFpr;
Dean@378
   293
                lines[2] = pEp.Properties.Resources.PrivacyStatus_TrustwordsOwnShortPartner + partnerFpr;
Dean@155
   294
                state.Fingerprint = lines;
vb@133
   295
            }
vb@133
   296
Dean@155
   297
            // Create and show handshake dialog
Dean@155
   298
            handshakeDialog = new FormHandshake(state);
Dean@179
   299
            handshakeDialog.StartPosition = FormStartPosition.CenterScreen;
Dean@179
   300
            result = handshakeDialog.ShowDialog(this);
Dean@155
   301
Dean@356
   302
            this.ProcessDoHandshakeResult(result, identityPartner);
Dean@356
   303
Dean@356
   304
            return;
Dean@356
   305
        }
Dean@356
   306
Dean@356
   307
        /// <summary>
Dean@356
   308
        /// Processes the result of the do handshake dialog after a user makes a selection.
Dean@356
   309
        /// </summary>
Dean@356
   310
        /// <param name="result">The result of the handshake dialog selection.</param>
Dean@356
   311
        /// <param name="partner">The identity of the partner to handshake with.</param>
Dean@356
   312
        private void ProcessDoHandshakeResult(DialogResult result,
Dean@384
   313
                                              PEPIdentity partner)
Dean@356
   314
        {
Dean@384
   315
            pEp_identity_s identityPartner = ThisAddIn.pEp.update_identity(partner.ToCOMType());
vb@133
   316
vb@133
   317
            switch (result)
vb@133
   318
            {
vb@133
   319
                case DialogResult.Yes:
Dean@279
   320
                    {
Dean@290
   321
                        // Check if key was previously compromised -- warning for this must be displayed earlier
Dean@281
   322
                        if (identityPartner.comm_type == _pEp_comm_type.pEp_ct_compromized)
Dean@281
   323
                        {
Dean@281
   324
                            ThisAddIn.pEp.key_reset_trust(ref identityPartner);
Dean@281
   325
                        }
Dean@281
   326
Dean@279
   327
                        identityPartner = ThisAddIn.pEp.trust_personal_key(ref identityPartner);
Dean@293
   328
                        this.associatedMailItem.ColorRating = _pEp_color.pEp_rating_trusted;
Dean@279
   329
Dean@279
   330
                        this.UpdateUIFromMailItem();
Dean@279
   331
Dean@279
   332
                        // Update the manager form state
Dean@279
   333
                        if (this.managerForm != null)
Dean@279
   334
                        {
Dean@279
   335
                            this.managerForm.CopyStateToUI(this.GetManagerState());
Dean@279
   336
                        }
Dean@279
   337
Dean@279
   338
                        break;
Dean@279
   339
                    }
vb@133
   340
                case DialogResult.No:
Dean@279
   341
                    {
Dean@279
   342
                        ThisAddIn.pEp.key_compromized(ref identityPartner);
Dean@279
   343
                        identityPartner.comm_type = _pEp_comm_type.pEp_ct_compromized;
Dean@279
   344
                        identityPartner = ThisAddIn.pEp.update_identity(identityPartner);
Dean@293
   345
                        this.associatedMailItem.ColorRating = _pEp_color.pEp_rating_red;
Dean@279
   346
Dean@279
   347
                        this.UpdateUIFromMailItem();
Dean@279
   348
Dean@279
   349
                        // Update the manager form state
Dean@279
   350
                        if (this.managerForm != null)
Dean@279
   351
                        {
Dean@279
   352
                            this.managerForm.CopyStateToUI(this.GetManagerState());
Dean@279
   353
                        }
Dean@279
   354
Dean@279
   355
                        break;
Dean@279
   356
                    }
vb@133
   357
            }
Dean@279
   358
Dean@279
   359
            return;
vb@133
   360
        }
vb@133
   361
Dean@179
   362
        /// <summary>
Dean@179
   363
        /// Reverses any past handshake confirmation by unconfirming the given identity partner.
Dean@179
   364
        /// </summary>
Dean@384
   365
        /// <param name="partner">The identity of the partner to unconfirm.</param>
Dean@384
   366
        private void UndoHandshake(PEPIdentity partner)
vb@133
   367
        {
Dean@384
   368
            pEp_identity_s identityPartner = ThisAddIn.pEp.update_identity(partner.ToCOMType());
Dean@280
   369
            ThisAddIn.pEp.key_reset_trust(ref identityPartner);
Dean@279
   370
Dean@179
   371
            this.UpdateUIFromMailItem();
Dean@279
   372
Dean@279
   373
            // Update the manager form state
Dean@279
   374
            if (this.managerForm != null)
Dean@279
   375
            {
Dean@279
   376
                this.managerForm.CopyStateToUI(this.GetManagerState());
Dean@279
   377
            }
Dean@279
   378
Dean@279
   379
            return;
vb@133
   380
        }
vb@133
   381
Dean@161
   382
        /// <summary>
Dean@363
   383
        /// Calculates both the short and full trustwords between the given personal identity and the identity partner.
Dean@363
   384
        /// </summary>
Dean@363
   385
        /// <param name="myIdentity">The personal identity.</param>
Dean@363
   386
        /// <param name="partnerIdentity">The identity of the partner.</param>
Dean@363
   387
        /// <param name="trustwordsShort">The short version of trustwords.</param>
Dean@363
   388
        /// <param name="trustwordsFull">The full/long version of trustwords.</param>
Dean@384
   389
        private void CalcTrustwords(PEPIdentity myIdentity,
Dean@384
   390
                                    PEPIdentity partnerIdentity,
Dean@363
   391
                                    out string trustwordsShort,
Dean@363
   392
                                    out string trustwordsFull)
Dean@363
   393
        {
Dean@363
   394
            string myShort;
Dean@363
   395
            string myLong;
Dean@363
   396
            string partnerShort;
Dean@363
   397
            string partnerLong;
Dean@363
   398
Dean@384
   399
            myShort = ThisAddIn.pEp.trustwords(myIdentity.Fingerprint, max_words: 5).ToLower();
Dean@384
   400
            myLong = ThisAddIn.pEp.trustwords(myIdentity.Fingerprint).ToLower();
Dean@384
   401
            partnerShort = ThisAddIn.pEp.trustwords(partnerIdentity.Fingerprint, max_words: 5).ToLower();
Dean@384
   402
            partnerLong = ThisAddIn.pEp.trustwords(partnerIdentity.Fingerprint).ToLower();
Dean@363
   403
Dean@384
   404
            if (myIdentity.Fingerprint.CompareTo(partnerIdentity.Fingerprint) > 0)
Dean@363
   405
            {
Dean@363
   406
                trustwordsShort = partnerShort + myShort;
Dean@363
   407
                trustwordsFull = partnerLong + myLong;
Dean@363
   408
            }
Dean@363
   409
            else
Dean@363
   410
            {
Dean@363
   411
                trustwordsShort = myShort + " " + partnerShort;
Dean@363
   412
                trustwordsFull = myLong + " " + partnerLong;
Dean@363
   413
            }
Dean@363
   414
Dean@363
   415
            return;
Dean@363
   416
        }
Dean@363
   417
Dean@363
   418
        /// <summary>
Dean@161
   419
        /// Formats the given text string as separated 4-character groups.
Dean@161
   420
        /// Example: 49422235FC99585B891C --> 4942 2235 FC99 585B 891C
Dean@161
   421
        /// </summary>
Dean@161
   422
        /// <param name="text">The text to format in 4-character groups.</param>
Dean@161
   423
        /// <returns>The re-formatted string.</returns>
Dean@161
   424
        private string ToQuadruple(string text)
Dean@159
   425
        {
Dean@159
   426
            List<string> result = new List<string>();
Dean@159
   427
Dean@161
   428
            if (text != null)
Dean@159
   429
            {
Dean@161
   430
                for (int i = 0; i < text.Length; i += 4)
Dean@159
   431
                {
Dean@161
   432
                    try
Dean@161
   433
                    {
Dean@161
   434
                        result.Add(text.Substring(i, 4));
Dean@161
   435
                    }
Dean@161
   436
                    catch (ArgumentOutOfRangeException)
Dean@161
   437
                    {
Dean@161
   438
                        result.Add(text.Substring(i));
Dean@161
   439
                        break;
Dean@161
   440
                    }
Dean@159
   441
                }
Dean@159
   442
            }
Dean@159
   443
Dean@159
   444
            return String.Join(" ", result);
Dean@159
   445
        }
markus@201
   446
Dean@196
   447
        /// <summary>
Dean@196
   448
        /// Makes the unencrypted preview form.
Dean@196
   449
        /// This gets the active form region then fills it's content.
Dean@196
   450
        /// </summary>
Dean@198
   451
        /// <returns>True if successful, otherwise false.</returns>
Dean@198
   452
        private bool MakePreview()
Dean@159
   453
        {
Dean@198
   454
            bool success = true;
Dean@198
   455
            bool isSuccessful;
Dean@198
   456
            byte[] rtfBody;
Dean@198
   457
            string subject;
Dean@159
   458
            WindowFormRegionCollection formRegions;
markus@201
   459
Dean@198
   460
            formRegions = Globals.FormRegions[Globals.ThisAddIn.Application.ActiveExplorer()];
Dean@159
   461
Dean@198
   462
            if ((formRegions != null) &&
Dean@198
   463
                (formRegions.FormRegionPreviewUnencrypted != null) &&
Dean@198
   464
                (formRegions.FormRegionPreviewUnencrypted.Visible))
Dean@198
   465
            {
Dean@198
   466
                // Attempt to the the RTF body
Dean@198
   467
                isSuccessful = this.associatedMailItem.MirrorTryGetRTFBody(out rtfBody);
Dean@198
   468
                if (isSuccessful == false)
Dean@198
   469
                {
Dean@198
   470
                    return (false);
Dean@198
   471
                }
Dean@159
   472
Dean@198
   473
                // Attempt to get the subject
Dean@198
   474
                isSuccessful = this.associatedMailItem.MirrorTryGetSubject(out subject);
Dean@198
   475
                if (isSuccessful == false)
Dean@159
   476
                {
Dean@198
   477
                    return (false);
Dean@159
   478
                }
Dean@196
   479
Dean@198
   480
                // Add data to the form
markus@201
   481
                formRegions.FormRegionPreviewUnencrypted.RichTextBoxPreview.Rtf = System.Text.Encoding.ASCII.GetString(rtfBody, 0, rtfBody.Length);
markus@201
   482
                formRegions.FormRegionPreviewUnencrypted.TextBoxSubject.Text = subject;
Dean@412
   483
                formRegions.FormRegionPreviewUnencrypted.TextBoxFrom.Text = this.associatedMailItem.From.Username + " <" + this.associatedMailItem.From.Address + ">";
Dean@198
   484
            }
Dean@198
   485
            else
Dean@198
   486
            {
Dean@198
   487
                success = false;
Dean@198
   488
            }
Dean@198
   489
Dean@198
   490
            return (success);
Dean@159
   491
        }
markus@201
   492
Dean@179
   493
        /// <summary>
Dean@279
   494
        /// Builds a new manager form state using this encryption state/mail item current state.
Dean@279
   495
        /// </summary>
Dean@279
   496
        /// <returns>A new manager form state.</returns>
Dean@313
   497
        private FormManagePrivacyStatus.State GetManagerState()
Dean@279
   498
        {
Dean@527
   499
            bool isMyself;
Dean@364
   500
            string trustwordsShort;
Dean@364
   501
            string trustwordsFull;
Dean@384
   502
            List<PEPIdentity> identities;
Dean@384
   503
            PEPIdentity myIdentity;
Dean@384
   504
            PEPIdentity incomingIdent;
Dean@527
   505
            PEPIdentity[] myIdentities;
Dean@259
   506
            _pEp_color identityPartnerColor;
Dean@259
   507
            SelectionItem item;
Dean@312
   508
            PrivacyState state = this.CopyUIToState();
Dean@313
   509
            FormManagePrivacyStatus.State managerState = new FormManagePrivacyStatus.State();
Dean@259
   510
Dean@332
   511
            // Resolve all recipients -- this ensures the identities list is correctly populated
Dean@332
   512
            this.associatedMailItem.ResolveAllRecipients();
Dean@332
   513
Dean@279
   514
            managerState.VisualState = state.Copy();
Dean@279
   515
            managerState.IsIncoming = this.associatedMailItem.IsIncoming;
Dean@259
   516
Dean@259
   517
            if (this.associatedMailItem.IsIncoming)
Dean@259
   518
            {
Dean@384
   519
                identities = new List<PEPIdentity>();
Dean@259
   520
Dean@259
   521
                // Add only one identity
Dean@384
   522
                incomingIdent = new PEPIdentity();
Dean@412
   523
                incomingIdent.Address = this.associatedMailItem.From.Address;
Dean@412
   524
                incomingIdent.Username = this.associatedMailItem.From.Username;
Dean@501
   525
                incomingIdent.UserID = Globals.ThisAddIn.GetUserID(incomingIdent.Address);
Dean@259
   526
Dean@384
   527
                identities.Add(incomingIdent);
Dean@259
   528
            }
Dean@259
   529
            else
Dean@259
   530
            {
Dean@395
   531
                identities = this.associatedMailItem.Recipients;
Dean@259
   532
            }
Dean@259
   533
Dean@366
   534
            // Get my identity
Dean@384
   535
            myIdentity = PEPIdentity.GetMyIdentity(this.associatedMailItem);
Dean@527
   536
            myIdentities = PEPIdentity.GetMyIdentities();
Dean@366
   537
Dean@279
   538
            // Add identities
Dean@394
   539
            identities = PEPIdentity.ToFlatList(identities);
Dean@279
   540
            managerState.Identities.Clear();
Dean@384
   541
            foreach (PEPIdentity ident in identities)
Dean@259
   542
            {
Dean@485
   543
                if (ident.IsValid())
Dean@485
   544
                {
Dean@485
   545
                    pEp_identity_s partnerIdentity_s = ThisAddIn.pEp.update_identity(ident.ToCOMType());
Dean@485
   546
                    PEPIdentity partnerIdentity = new PEPIdentity(partnerIdentity_s);
Dean@485
   547
                    identityPartnerColor = ThisAddIn.pEp.identity_color(partnerIdentity_s);
Dean@259
   548
Dean@527
   549
                    // Check if identity is myself
Dean@527
   550
                    isMyself = false;
Dean@527
   551
                    foreach (PEPIdentity me in myIdentities)
Dean@527
   552
                    {
Dean@527
   553
                        if (partnerIdentity.EqualsByAddress(me))
Dean@527
   554
                        {
Dean@527
   555
                            isMyself = true;
Dean@527
   556
                            break;
Dean@527
   557
                        }
Dean@527
   558
                    }
Dean@527
   559
Dean@485
   560
                    item = new SelectionItem();
Dean@485
   561
                    item.TextLine1 = partnerIdentity.Username;
Dean@485
   562
                    item.TextLine2 = partnerIdentity.Address;
Dean@259
   563
Dean@485
   564
                    // Don't show both the user name and address if they are the same
Dean@485
   565
                    if ((item.TextLine1 != null) &&
Dean@485
   566
                        (item.TextLine2 != null) &&
Dean@485
   567
                        (item.TextLine1 == item.TextLine2))
Dean@485
   568
                    {
Dean@485
   569
                        item.IsTwoTextLinesVisible = false;
Dean@485
   570
                    }
Dean@332
   571
Dean@527
   572
                    // Calculate trustwords
Dean@527
   573
                    this.CalcTrustwords(myIdentity,
Dean@527
   574
                                        partnerIdentity,
Dean@527
   575
                                        out trustwordsShort,
Dean@527
   576
                                        out trustwordsFull);
Dean@527
   577
Dean@485
   578
                    // Set image
Dean@485
   579
                    switch (PrivacyState.ConvertRatingToPrivacyColor(identityPartnerColor))
Dean@485
   580
                    {
Dean@485
   581
                        case PrivacyState.PrivacyColor.Green:
Dean@485
   582
                            item.ItemImage = pEp.Properties.Resources.ImagePrivacyStatusGreen;
Dean@485
   583
                            break;
Dean@485
   584
                        case PrivacyState.PrivacyColor.Yellow:
Dean@485
   585
                            item.ItemImage = pEp.Properties.Resources.ImagePrivacyStatusYellow;
Dean@485
   586
                            break;
Dean@485
   587
                        case PrivacyState.PrivacyColor.Red:
Dean@485
   588
                            item.ItemImage = pEp.Properties.Resources.ImagePrivacyStatusRed;
Dean@485
   589
                            break;
Dean@485
   590
                        case PrivacyState.PrivacyColor.NoColor:
Dean@485
   591
                            item.ItemImage = pEp.Properties.Resources.ImagePrivacyStatusNoColor;
Dean@485
   592
                            break;
Dean@485
   593
                        default:
Dean@485
   594
                            item.ItemImage = null;
Dean@485
   595
                            break;
Dean@485
   596
                    }
Dean@259
   597
Dean@485
   598
                    // Set button
Dean@527
   599
                    if (isMyself == false)
Dean@366
   600
                    {
Dean@485
   601
                        if (partnerIdentity.CommunicationType >= _pEp_comm_type.pEp_ct_confirmed_encryption)
Dean@485
   602
                        {
Dean@485
   603
                            // Undo handshake
Dean@485
   604
                            item.TextButton = pEp.Properties.Resources.PrivacyStatus_StopTrusting;
Dean@485
   605
                            item.IsButtonVisible = true;
Dean@485
   606
                            item.ButtonOnClick = (x, y) => { this.UndoHandshake(partnerIdentity); };
Dean@356
   607
Dean@485
   608
                            item.IsExpandable = false;
Dean@485
   609
                        }
Dean@485
   610
                        else if (partnerIdentity.CommunicationType >= _pEp_comm_type.pEp_ct_unconfirmed_encryption &&
Dean@485
   611
                                 partnerIdentity.CommunicationType < _pEp_comm_type.pEp_ct_confirmed_encryption)
Dean@485
   612
                        {
Dean@485
   613
                            // Do handshake
Dean@485
   614
                            item.TextButton = pEp.Properties.Resources.PrivacyStatus_HandshakeAdvanced;
Dean@485
   615
                            item.IsButtonVisible = true;
Dean@485
   616
                            item.ButtonOnClick = (x, y) => { this.DoHandshake(partnerIdentity); };
Dean@356
   617
Dean@485
   618
                            item.IsExpandable = true;
Dean@485
   619
                            item.ExpandedText = Properties.Resources.PrivacyStatus_TrustwordDesc + "\n\n" +
Dean@485
   620
                                                trustwordsShort;
Dean@447
   621
Dean@485
   622
                            item.ExpandedButton1Text = Properties.Resources.PrivacyStatus_SelectTrust;
Dean@485
   623
                            item.ExpandedButton1OnClick = (x, y) => { this.ProcessDoHandshakeResult(DialogResult.Yes, partnerIdentity); };
Dean@485
   624
                            item.ExpandedButton1BackColor = PrivacyState.COLOR_GREEN;
Dean@485
   625
                            item.ExpandedButton1ForeColor = Color.White;
Dean@447
   626
Dean@485
   627
                            item.ExpandedButton2Text = Properties.Resources.PrivacyStatus_SelectMistrust;
Dean@485
   628
                            item.ExpandedButton2OnClick = (x, y) => { this.ProcessDoHandshakeResult(DialogResult.No, partnerIdentity); };
Dean@485
   629
                            item.ExpandedButton2BackColor = PrivacyState.COLOR_RED;
Dean@485
   630
                            item.ExpandedButton2ForeColor = Color.White;
Dean@485
   631
                        }
Dean@485
   632
                        else if (partnerIdentity.CommunicationType == _pEp_comm_type.pEp_ct_compromized)
Dean@485
   633
                        {
Dean@485
   634
                            // Redo handshake with confirmation
Dean@485
   635
                            item.TextButton = pEp.Properties.Resources.PrivacyStatus_Handshake;
Dean@485
   636
                            item.IsButtonVisible = true;
Dean@485
   637
                            item.ButtonOnClick = (x, y) => { this.DoHandshakeForCompromisedKey(partnerIdentity); };
Dean@485
   638
                        }
Dean@485
   639
                        else
Dean@485
   640
                        {
Dean@485
   641
                            item.IsButtonVisible = false;
Dean@485
   642
                        }
Dean@366
   643
                    }
Dean@366
   644
                    else
Dean@366
   645
                    {
Dean@366
   646
                        item.IsButtonVisible = false;
Dean@366
   647
                    }
Dean@281
   648
                }
Dean@485
   649
                else // Invalid identity
Dean@259
   650
                {
Dean@485
   651
                    item = new SelectionItem();
Dean@485
   652
                    item.TextLine1 = ident.Username;
Dean@485
   653
                    item.TextLine2 = ident.Address;
Dean@485
   654
                    item.ItemImage = null;
Dean@485
   655
                    item.IsTwoTextLinesVisible = true;
Dean@259
   656
                    item.IsButtonVisible = false;
Dean@259
   657
                }
Dean@259
   658
Dean@279
   659
                managerState.Identities.Add(item);
Dean@259
   660
            }
Dean@259
   661
Dean@375
   662
            // Attempt to select the first identity requiring a handshake
Dean@375
   663
            for (int i = 0; i < managerState.Identities.Count; i++)
Dean@375
   664
            {
Dean@375
   665
                // Determine if it's a handshake identity by simply seeing if it's expandable
Dean@375
   666
                if (managerState.Identities[i].IsExpandable)
Dean@375
   667
                {
Dean@375
   668
                    managerState.SelectedIdentityIndex = i;
Dean@375
   669
                    break;
Dean@375
   670
                }
Dean@375
   671
            }
Dean@375
   672
Dean@279
   673
            return (managerState);
Dean@279
   674
        }
Dean@279
   675
Dean@279
   676
        /// <summary>
Dean@279
   677
        /// Builds the latest state of the encryption status manager then shows the UI.
Dean@279
   678
        /// </summary>
Dean@279
   679
        private void BuildAndShowManager()
Dean@279
   680
        {
Dean@279
   681
            DialogResult result;
Dean@313
   682
            FormManagePrivacyStatus form;
Dean@313
   683
            FormManagePrivacyStatus.State stateOut;
Dean@279
   684
Dean@483
   685
            try
Dean@483
   686
            {
Dean@483
   687
                // Show the form
Dean@483
   688
                form = new FormManagePrivacyStatus();
Dean@483
   689
                form.StartPosition = FormStartPosition.CenterScreen;
Dean@259
   690
Dean@483
   691
                this.managerForm = form;
Dean@483
   692
                result = form.ShowDialog(this.ParentForm, this.GetManagerState(), out stateOut); // Must show as dialog to block code
Dean@483
   693
            }
Dean@483
   694
            catch (Exception ex)
Dean@483
   695
            {
Dean@483
   696
                GlobalExceptionHandler.StopAndSendCrashReport(ex);
Dean@483
   697
            }
Dean@259
   698
Dean@259
   699
            return;
Dean@259
   700
        }
Dean@259
   701
Dean@259
   702
        /// <summary>
Dean@179
   703
        /// Updates the status of the UI state based on the associated mail item.
Dean@179
   704
        /// Any previous state changes in the UI are preserved.
Dean@179
   705
        /// </summary>
Dean@179
   706
        private void UpdateUIFromMailItem()
Dean@159
   707
        {
Dean@312
   708
            PrivacyState state;
Dean@342
   709
            bool? sendUnencryptedProperty;
Dean@159
   710
Dean@173
   711
            if (this.associatedMailItem != null)
Dean@159
   712
            {
Dean@342
   713
                sendUnencryptedProperty = this.associatedMailItem.SendUnencrypted;
Dean@342
   714
Dean@342
   715
                if ((sendUnencryptedProperty != null) &&
Dean@342
   716
                    ((bool)sendUnencryptedProperty == true))
Dean@159
   717
                {
Dean@342
   718
                    // Force unencrypted
Dean@312
   719
                    state = new PrivacyState(_pEp_color.pEp_rating_unencrypted);
Dean@159
   720
                }
Dean@159
   721
                else
Dean@159
   722
                {
Dean@312
   723
                    state = new PrivacyState(this.associatedMailItem.ColorRating);
Dean@159
   724
                }
Dean@179
   725
Dean@179
   726
                this.CopyStateToUI(state);
Dean@159
   727
            }
Dean@159
   728
Dean@179
   729
            return;
Dean@159
   730
        }
Dean@159
   731
Dean@172
   732
        #region StateMethods
Dean@172
   733
Dean@172
   734
        /// <summary>
Dean@172
   735
        /// Connects or disconnects all control events from the UI.
Dean@172
   736
        /// </summary>
Dean@172
   737
        /// <param name="connect">True to connect events, false to disconnect.</param>
Dean@172
   738
        private void ConnectEvents(bool connect)
Dean@172
   739
        {
Dean@172
   740
            // Connect events only if not already connected
markus@201
   741
            if ((connect == true) &&
Dean@172
   742
                (this.eventsAreConnected == false))
Dean@172
   743
            {
Dean@312
   744
                this.ButtonPrivacyStatus.Click += this.ButtonPrivacyStatus_Click;
Dean@312
   745
                this.ButtonPrivacyStatus.MouseUp += this.ButtonPrivacyStatus_MouseUp;
Dean@179
   746
Dean@172
   747
                this.eventsAreConnected = true;
Dean@172
   748
            }
Dean@172
   749
            // Always attempt to disconnect
Dean@172
   750
            else if (connect == false)
Dean@172
   751
            {
Dean@312
   752
                this.ButtonPrivacyStatus.Click -= this.ButtonPrivacyStatus_Click;
Dean@312
   753
                this.ButtonPrivacyStatus.MouseUp -= this.ButtonPrivacyStatus_MouseUp;
Dean@179
   754
Dean@172
   755
                this.eventsAreConnected = false;
Dean@172
   756
            }
Dean@172
   757
Dean@172
   758
            return;
Dean@172
   759
        }
Dean@172
   760
Dean@172
   761
        /// <summary>
Dean@172
   762
        /// Refreshes the UI by reloading the state.
Dean@172
   763
        /// </summary>
Dean@172
   764
        private void RefreshUI()
Dean@172
   765
        {
Dean@172
   766
            this.CopyStateToUI(this.CopyUIToState());
Dean@172
   767
            return;
Dean@172
   768
        }
Dean@172
   769
Dean@172
   770
        /// <summary>
Dean@172
   771
        /// Copies the given state to the UI.
Dean@172
   772
        /// Events are turned off until the process is complete.
Dean@172
   773
        /// </summary>
Dean@172
   774
        /// <param name="state">The state to set to the UI.</param>
Dean@312
   775
        private void CopyStateToUI(PrivacyState state)
Dean@172
   776
        {
Dean@172
   777
            this.ConnectEvents(false);
markus@201
   778
Dean@172
   779
            ///////////////////////////////////////////////////////////
Dean@172
   780
            // Set UI data
Dean@172
   781
            ///////////////////////////////////////////////////////////
Dean@172
   782
Dean@179
   783
            // Save UI state maintained outside of controls
Dean@312
   784
            this.stateUIColorRating = state.PrivacyStatus;
Dean@179
   785
Dean@312
   786
            this.ButtonPrivacyStatus.BackColor = state.BackgroundColor;
Dean@312
   787
            this.ButtonPrivacyStatus.ForeColor = state.ForegroundColor;
Dean@312
   788
            this.ButtonPrivacyStatus.Text = state.ShortText;
Dean@172
   789
Dean@172
   790
            this.ConnectEvents(true);
Dean@172
   791
Dean@172
   792
            return;
Dean@172
   793
        }
Dean@172
   794
Dean@172
   795
        /// <summary>
Dean@172
   796
        /// Copies the UI to a new state.
Dean@172
   797
        /// </summary>
Dean@172
   798
        /// <returns>The state of the UI.</returns>
Dean@312
   799
        private PrivacyState CopyUIToState()
Dean@172
   800
        {
Dean@312
   801
            return (new PrivacyState(this.stateUIColorRating));
Dean@172
   802
        }
Dean@172
   803
Dean@172
   804
        #endregion
Dean@172
   805
Dean@159
   806
        /**************************************************************
Dean@159
   807
         * 
Dean@159
   808
         * Event Handling
Dean@159
   809
         * 
Dean@159
   810
         *************************************************************/
Dean@159
   811
Dean@159
   812
        /// <summary>
Dean@159
   813
        /// Event handler that is called before the form region is displayed.
Dean@159
   814
        /// </summary>
Dean@312
   815
        private void FormRegionPrivacyStatus_FormRegionShowing(object sender, System.EventArgs e)
Dean@159
   816
        {
Dean@173
   817
            this.SetAssociatedMailItem();
Dean@173
   818
Dean@438
   819
            // Set background color
Dean@438
   820
            if (this.IsWithinInspector())
Dean@438
   821
            {
Dean@438
   822
                this.BackColor = SystemColors.ButtonFace;
Dean@438
   823
            }
Dean@438
   824
            else
Dean@438
   825
            {
Dean@438
   826
                this.BackColor = SystemColors.Window;
Dean@438
   827
            }
Dean@438
   828
Dean@199
   829
            // Connect cryptable mail item events
Dean@189
   830
            if (this.associatedMailItem != null)
Dean@159
   831
            {
Dean@159
   832
                try
Dean@159
   833
                {
Dean@445
   834
                    this.associatedMailItem.PropertyChanged += MailItem_PropertyChanged;
Dean@179
   835
Dean@189
   836
                    if (this.associatedMailItem.IsInEncryptedStore &&
Dean@198
   837
                        this.associatedMailItem.IsPGPEncrypted)
Dean@159
   838
                    {
Dean@189
   839
                        this.associatedMailItem.Open += MailItem_Open;
Dean@159
   840
                    }
Dean@159
   841
                }
Dean@159
   842
                catch { }
Dean@179
   843
            }
Dean@159
   844
Dean@179
   845
            // Set the default UI state
Dean@312
   846
            this.CopyStateToUI(new PrivacyState());
Dean@179
   847
Dean@199
   848
            // Call the timer tick method manually to refresh data
Dean@199
   849
            this.TimerRefresh_Tick(null, new EventArgs());
Dean@179
   850
Dean@179
   851
            return;
Dean@159
   852
        }
Dean@159
   853
Dean@159
   854
        /// <summary>
Dean@159
   855
        /// Event handler for when the form region is closed.
Dean@159
   856
        /// </summary>
Dean@312
   857
        private void FormRegionPrivacyStatus_FormRegionClosed(object sender, System.EventArgs e)
Dean@159
   858
        {
Dean@199
   859
            // Disconnect cryptable mail item events
Dean@190
   860
            if (this.associatedMailItem != null)
Dean@179
   861
            {
Dean@179
   862
                try
Dean@179
   863
                {
Dean@445
   864
                    this.associatedMailItem.PropertyChanged -= MailItem_PropertyChanged;
markus@201
   865
                    this.associatedMailItem.Open -= MailItem_Open;
Dean@179
   866
                }
Dean@179
   867
                catch { }
Dean@179
   868
            }
Dean@179
   869
Dean@179
   870
            return;
Dean@179
   871
        }
Dean@179
   872
Dean@179
   873
        /// <summary>
Dean@179
   874
        /// Event handler called after the refresh timer has elapsed.
Dean@179
   875
        /// </summary>
Dean@179
   876
        private void TimerRefresh_Tick(object sender, EventArgs e)
Dean@179
   877
        {
Dean@199
   878
            bool tryAgain = false;
Dean@199
   879
            bool isSuccessful;
Dean@179
   880
            this.TimerRefresh.Enabled = false; // Only once
markus@201
   881
Dean@179
   882
            // Ensure the tick method is not called more than once
Dean@179
   883
            if (refreshOngoing == false)
Dean@179
   884
            {
Dean@179
   885
                this.refreshOngoing = true;
Dean@179
   886
Dean@179
   887
                if (this.associatedMailItem != null)
Dean@179
   888
                {
Dean@179
   889
                    if (this.associatedMailItem.DownloadState == Outlook.OlDownloadState.olFullItem)
Dean@179
   890
                    {
Dean@179
   891
                        this.UpdateUIFromMailItem();
Dean@199
   892
Dean@199
   893
                        /* Create the unencrypted preview if the mail item is encrypted and
Dean@199
   894
                         * it is in an encrypted (untrusted) store
Dean@199
   895
                         * 
Dean@312
   896
                         * This is done here because FormRegionPrivacyStatus has the cryptable mail item and
Dean@199
   897
                         * it also is initialized after FormRegionPreviewUnencrypted.
Dean@199
   898
                         */
Dean@199
   899
                        if (this.associatedMailItem.IsInEncryptedStore &&
Dean@199
   900
                            this.associatedMailItem.IsPGPEncrypted)
Dean@199
   901
                        {
Dean@199
   902
                            isSuccessful = this.MakePreview();
Dean@199
   903
Dean@199
   904
                            if (isSuccessful == false)
Dean@199
   905
                            {
Dean@199
   906
                                tryAgain = true;
Dean@199
   907
                            }
Dean@199
   908
                        }
Dean@179
   909
                    }
Dean@179
   910
                    else
Dean@179
   911
                    {
Dean@179
   912
                        this.associatedMailItem.MarkForDownload = Outlook.OlRemoteStatus.olMarkedForDownload;
Dean@199
   913
                        tryAgain = true;
Dean@179
   914
                    }
Dean@179
   915
                }
Dean@179
   916
Dean@199
   917
                // Set the timer to refresh again later automatically
Dean@199
   918
                if (tryAgain)
Dean@199
   919
                {
Dean@199
   920
                    this.TimerRefresh.Interval = 100;
Dean@199
   921
                    this.TimerRefresh.Enabled = true;
Dean@199
   922
                }
Dean@199
   923
Dean@179
   924
                this.refreshOngoing = false;
Dean@179
   925
            }
Dean@175
   926
Dean@159
   927
            return;
Dean@159
   928
        }
Dean@159
   929
Dean@169
   930
        /// <summary>
Dean@169
   931
        /// Event handler for when a mail item is being opened in an inspector.
Dean@180
   932
        /// See: https://msdn.microsoft.com/en-us/library/office/ff865989.aspx
Dean@169
   933
        /// </summary>
Dean@169
   934
        /// <param name="cancel">Whether to cancel the event: Value is False when the event occurs. 
Dean@169
   935
        /// If the event procedure sets this argument to True, the open operation is not completed 
Dean@169
   936
        /// and the inspector is not displayed.</param>
Dean@169
   937
        private void MailItem_Open(ref bool cancel)
Dean@159
   938
        {
Dean@173
   939
            if (this.associatedMailItem != null && this.associatedMailItem.MirrorDisplay())
Dean@169
   940
            {
Dean@169
   941
                cancel = true;
Dean@169
   942
            }
Dean@169
   943
Dean@169
   944
            return;
Dean@159
   945
        }
Dean@159
   946
Dean@169
   947
        /// <summary>
Dean@169
   948
        /// Event handler for when a mail item property is changed.
Dean@169
   949
        /// See: https://msdn.microsoft.com/en-us/library/office/ff866739.aspx
Dean@169
   950
        /// </summary>
Dean@169
   951
        /// <param name="propertyName">The name of the property that was changed.</param>
Dean@445
   952
        private void MailItem_PropertyChanged(object sender, PropertyChangedEventArgs e)
Dean@159
   953
        {
Dean@445
   954
            switch (e.PropertyName.ToUpper())
Dean@159
   955
            {
Dean@179
   956
                case "TO":
Dean@179
   957
                    // Start the refresh timer
Dean@179
   958
                    this.TimerRefresh.Enabled = true;
Dean@159
   959
                    break;
Dean@159
   960
                // Outlook bug: there are always both events, so one is enough
Dean@159
   961
                //case "CC":
Dean@179
   962
                //    // Start the refresh timer
Dean@179
   963
                //    this.TimerRefresh.Enabled = true;
Dean@159
   964
                //    break;
Dean@159
   965
            }
Dean@169
   966
Dean@169
   967
            return;
Dean@159
   968
        }
Dean@159
   969
Dean@179
   970
        /// <summary>
Dean@312
   971
        /// Event handler for when the privacy status button is clicked.
Dean@179
   972
        /// </summary>
Dean@312
   973
        private void ButtonPrivacyStatus_Click(object sender, EventArgs e)
vb@133
   974
        {
Dean@310
   975
            this.BuildAndShowManager();
Dean@179
   976
            return;
vb@133
   977
        }
vb@133
   978
Dean@179
   979
        /// <summary>
Dean@312
   980
        /// Event handler for when a mouse button is released over the privacy status button.
Dean@179
   981
        /// </summary>
Dean@312
   982
        private void ButtonPrivacyStatus_MouseUp(object sender, MouseEventArgs e)
vb@133
   983
        {
Dean@179
   984
            return;
vb@133
   985
        }
vb@133
   986
    }
vb@133
   987
}