EncryptionStatusPanel.cs
author Dean Looyengoed
Tue, 29 Dec 2015 21:26:17 +0100
changeset 170 07911d16b012
parent 169 c7d9b7ad0639
child 171 897440376f2d
permissions -rw-r--r--
Add method to determine then set the associated mail item for the encryption status panel.
Dean@159
     1
´╗┐using pEpCOMServerAdapterLib;
Dean@159
     2
using System;
vb@133
     3
using System.Collections.Generic;
Dean@159
     4
using System.Diagnostics;
vb@133
     5
using System.Linq;
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@159
    14
    /// Partial class for the encryption status panel that is displayed below every outlook message.
Dean@159
    15
    /// </summary>
vb@133
    16
    partial class EncryptionStatusPanel
vb@133
    17
    {
Dean@164
    18
        private static readonly Color COLOR_RED        = Color.Red;
Dean@164
    19
        private static readonly Color COLOR_YELLOW     = Color.Gold;
Dean@164
    20
        private static readonly Color COLOR_GREEN      = Color.Green;
Dean@164
    21
        private static readonly Color COLOR_GREY       = Color.Gainsboro;
Dean@164
    22
        private static readonly Color TEXT_COLOR_BLACK = Color.Black;
Dean@164
    23
        private static readonly Color TEXT_COLOR_WHITE = Color.White;
Dean@162
    24
vb@133
    25
        #region Form Region Factory
vb@133
    26
vb@133
    27
        [Microsoft.Office.Tools.Outlook.FormRegionMessageClass(Microsoft.Office.Tools.Outlook.FormRegionMessageClassAttribute.Note)]
vb@133
    28
        [Microsoft.Office.Tools.Outlook.FormRegionName("pEp.FormRegion1")]
vb@133
    29
        public partial class FormRegion1Factory
vb@133
    30
        {
vb@133
    31
            // Occurs before the form region is initialized.
vb@133
    32
            // To prevent the form region from appearing, set e.Cancel to true.
vb@133
    33
            // Use e.OutlookItem to get a reference to the current Outlook item.
vb@133
    34
            private void FormRegion1Factory_FormRegionInitializing(object sender, Microsoft.Office.Tools.Outlook.FormRegionInitializingEventArgs e)
vb@133
    35
            {
vb@133
    36
            }
vb@133
    37
        }
vb@133
    38
vb@133
    39
        #endregion
vb@133
    40
Dean@159
    41
        private struct EncStatusData
vb@133
    42
        {
Dean@159
    43
            public string title;
Dean@159
    44
            public string explanation;
Dean@159
    45
            public string suggestion;
Dean@159
    46
            public Color background;
Dean@159
    47
            public Color foreground;
Dean@159
    48
            public string button_text;
Dean@159
    49
            public ContextMenuStrip strip;
Dean@159
    50
        };
Dean@159
    51
Dean@159
    52
        /* Notes:
Dean@159
    53
         * Use this.OutlookItem to get a reference to the current Outlook item.
Dean@159
    54
         * Use this.OutlookFormRegion to get a reference to the form region.
Dean@159
    55
         */
vb@133
    56
vb@133
    57
        private CryptableMailItem _mailItem = null;
Dean@163
    58
        private bool resetOngoing = false;
Dean@159
    59
        private EncStatusData enc_status_data;
Dean@159
    60
        private _pEp_color _enc_status;
Dean@159
    61
Dean@170
    62
Dean@170
    63
        private bool eventsAreConnected = false;
Dean@170
    64
        private CryptableMailItem associatedMailItem = null;
Dean@170
    65
Dean@170
    66
        // UI data or controls not stored in the UI
Dean@170
    67
        private ContextMenuStrip buttonContextMenuStrip;
Dean@170
    68
Dean@159
    69
        /**************************************************************
Dean@159
    70
         * 
Dean@159
    71
         * Property Accessors
Dean@159
    72
         * 
Dean@159
    73
         *************************************************************/
vb@133
    74
vb@133
    75
        CryptableMailItem mailItem
vb@133
    76
        {
vb@133
    77
            get
vb@133
    78
            {
vb@133
    79
                try
vb@133
    80
                {
vb@133
    81
                    if (this.OutlookItem == null)
vb@133
    82
                    {
vb@133
    83
                        _mailItem = null;
vb@133
    84
                        return null;
vb@133
    85
                    }
vb@133
    86
                }
vb@133
    87
                catch (COMException)
vb@133
    88
                {
vb@133
    89
                    return null;
vb@133
    90
                }
vb@133
    91
vb@133
    92
                Outlook.MailItem omi = null;
vb@133
    93
vb@133
    94
                try
vb@133
    95
                {
vb@133
    96
                    omi = (Outlook.MailItem)this.OutlookItem;
vb@133
    97
                }
vb@133
    98
                catch
vb@133
    99
                {
vb@133
   100
                    _mailItem = null;
vb@133
   101
                    return null;
vb@133
   102
                }
vb@133
   103
vb@133
   104
                Outlook.MAPIFolder folder = omi.Parent;
vb@136
   105
                Outlook.MAPIFolder deleted = folder.Store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDeletedItems);
vb@136
   106
                if (deleted != null && folder.EntryID == deleted.EntryID)
vb@133
   107
                {
vb@133
   108
                    _mailItem = null;
vb@133
   109
                    return null;
vb@133
   110
                }
vb@133
   111
vb@133
   112
                if (_mailItem == null) {
vb@133
   113
                    _mailItem = new CryptableMailItem(omi);
vb@133
   114
                }
vb@133
   115
                else
vb@133
   116
                {
vb@133
   117
                    if (_mailItem.EntryID != omi.EntryID)
vb@133
   118
                    {
vb@133
   119
                        _mailItem = new CryptableMailItem(omi);
vb@133
   120
                    }
vb@133
   121
                }
vb@133
   122
vb@133
   123
                return _mailItem;
vb@133
   124
            }
vb@133
   125
        }
vb@133
   126
vb@133
   127
        public _pEp_color enc_status {
vb@133
   128
            get
vb@133
   129
            {
vb@133
   130
                return _enc_status;
vb@133
   131
            }
vb@133
   132
            set
vb@133
   133
            {
vb@133
   134
                if (value != _enc_status)
vb@133
   135
                {
vb@133
   136
                    _enc_status = value;
vb@133
   137
vb@133
   138
                    switch (value)
vb@133
   139
                    {
vb@133
   140
                        case _pEp_color.pEp_rating_trusted:
vb@133
   141
                        case _pEp_color.pEp_rating_trusted_and_anonymized:
vb@133
   142
                            enc_status_data.explanation = pEp.Properties.Resources.RatingTrustedExplanation;
vb@133
   143
                            enc_status_data.suggestion = pEp.Properties.Resources.RatingTrustedSuggestion;
vb@133
   144
                            enc_status_data.title = pEp.Properties.Resources.RatingTrustedTitle;
Dean@162
   145
                            enc_status_data.background = COLOR_GREEN;
Dean@162
   146
                            enc_status_data.foreground = TEXT_COLOR_WHITE;
vb@133
   147
                            enc_status_data.button_text = pEp.Properties.Resources.RatingTrustedButtontext;
vb@133
   148
                            enc_status_data.strip = new ContextMenuStrip();
vb@133
   149
                            enc_status_data.strip.Items.Add("");
vb@133
   150
                            enc_status_data.strip.Opening += secure_strip_Opening;
vb@133
   151
                            break;
vb@133
   152
vb@133
   153
                        case _pEp_color.pEp_rating_reliable:
vb@133
   154
                            enc_status_data.explanation = pEp.Properties.Resources.RatingReliableExplaination;
vb@133
   155
                            enc_status_data.suggestion = pEp.Properties.Resources.RatingReliableSuggestion;
vb@133
   156
                            enc_status_data.title = pEp.Properties.Resources.RatingReliableTitle;
Dean@162
   157
                            enc_status_data.background = COLOR_YELLOW;
Dean@162
   158
                            enc_status_data.foreground = TEXT_COLOR_BLACK;
vb@133
   159
                            enc_status_data.button_text = pEp.Properties.Resources.RatingReliableButtontext;
vb@133
   160
                            enc_status_data.strip = null;
vb@133
   161
                            break;
vb@133
   162
vb@133
   163
                        case _pEp_color.pEp_rating_unreliable:
vb@133
   164
                            enc_status_data.explanation = pEp.Properties.Resources.RatingUnreliableExplanation;
vb@133
   165
                            enc_status_data.suggestion = pEp.Properties.Resources.RatingUnreliableSuggestion;
vb@133
   166
                            enc_status_data.title = pEp.Properties.Resources.RatingUnreliableTitle;
Dean@162
   167
                            enc_status_data.background = COLOR_GREY;
Dean@162
   168
                            enc_status_data.foreground = TEXT_COLOR_BLACK;
vb@133
   169
                            enc_status_data.button_text = pEp.Properties.Resources.RatingUnreliableButtontext;
vb@133
   170
                            enc_status_data.strip = null;
vb@133
   171
                            break;
vb@133
   172
vb@133
   173
                        case _pEp_color.pEp_rating_unencrypted:
vb@133
   174
                            enc_status_data.explanation = pEp.Properties.Resources.RatingUnencryptedExplanation;
vb@133
   175
                            enc_status_data.suggestion = pEp.Properties.Resources.RatingUnencryptedSuggestion;
vb@133
   176
                            enc_status_data.title = pEp.Properties.Resources.RatingUnencryptedTitle;
Dean@162
   177
                            enc_status_data.background = COLOR_GREY;
Dean@162
   178
                            enc_status_data.foreground = TEXT_COLOR_BLACK;
vb@133
   179
                            enc_status_data.button_text = pEp.Properties.Resources.RatingUnencryptedButtontext;
vb@133
   180
                            enc_status_data.strip = null;
vb@133
   181
                            break;
vb@133
   182
vb@133
   183
                        case _pEp_color.pEp_rating_under_attack:
vb@133
   184
                            enc_status_data.explanation = pEp.Properties.Resources.RatingUnderattackExplanation;
vb@133
   185
                            enc_status_data.suggestion = pEp.Properties.Resources.RatingUnderattackSuggestion;
vb@133
   186
                            enc_status_data.title = pEp.Properties.Resources.RatingUnderattackTitle;
Dean@162
   187
                            enc_status_data.background = COLOR_RED;
Dean@162
   188
                            enc_status_data.foreground = TEXT_COLOR_WHITE;
vb@133
   189
                            enc_status_data.button_text = pEp.Properties.Resources.RatingUnderattackButtontext;
vb@133
   190
                            enc_status_data.strip = null;
vb@133
   191
                            break;
vb@133
   192
vb@133
   193
                        case _pEp_color.pEp_rating_undefined:
vb@133
   194
                            // will not happen
vb@133
   195
                            enc_status_data.explanation = pEp.Properties.Resources.RatingUndefinedExplanation;
vb@133
   196
                            enc_status_data.suggestion = pEp.Properties.Resources.RatingUndefinedSuggestion;
vb@133
   197
                            enc_status_data.title = pEp.Properties.Resources.RatingUndefinedTitle;
Dean@162
   198
                            enc_status_data.background = COLOR_GREY;
Dean@162
   199
                            enc_status_data.foreground = TEXT_COLOR_BLACK;
vb@133
   200
                            enc_status_data.button_text = pEp.Properties.Resources.RatingUndefinedButtontext;
vb@133
   201
                            enc_status_data.strip = null;
vb@133
   202
                            break;
vb@133
   203
vb@133
   204
                        case _pEp_color.pEp_rating_cannot_decrypt:
vb@133
   205
                        case _pEp_color.pEp_rating_have_no_key:
vb@133
   206
                            enc_status_data.explanation = pEp.Properties.Resources.RatingHavenokeyExplanation;
vb@133
   207
                            enc_status_data.suggestion = pEp.Properties.Resources.RatingHavenokeySuggestion;
vb@133
   208
                            enc_status_data.title = pEp.Properties.Resources.RatingHavenokeyTitle;
Dean@162
   209
                            enc_status_data.background = COLOR_GREY;
Dean@162
   210
                            enc_status_data.foreground = TEXT_COLOR_BLACK;
vb@133
   211
                            enc_status_data.button_text = pEp.Properties.Resources.RatingHavenokeyButtontext;
vb@133
   212
                            enc_status_data.strip = null;
vb@133
   213
                            break;
vb@133
   214
                    }
vb@133
   215
vb@133
   216
                    linkExplanation.Text = enc_status_data.title;
vb@133
   217
                    EncryptionStatus.BackColor = enc_status_data.background;
vb@133
   218
                    EncryptionStatus.ForeColor = enc_status_data.foreground;
vb@133
   219
                    EncryptionStatus.Text = enc_status_data.button_text;
vb@133
   220
                    EncryptionStatus.ContextMenuStrip = enc_status_data.strip;
vb@133
   221
                }
vb@133
   222
            }
vb@133
   223
        }
vb@133
   224
Dean@159
   225
        /**************************************************************
Dean@159
   226
         * 
Dean@159
   227
         * Methods
Dean@159
   228
         * 
Dean@159
   229
         *************************************************************/
Dean@159
   230
Dean@159
   231
        static void StopHere(string reason)
vb@133
   232
        {
Dean@159
   233
#if DEBUG
Dean@159
   234
            MessageBox.Show(reason);
Dean@159
   235
#else
Dean@159
   236
            try
vb@133
   237
            {
Dean@159
   238
                ThisAddIn.pEp.log("internal error", "pEp for Outlook", reason, "in EncryptionStatusPanel.cs");
vb@133
   239
            }
Dean@159
   240
            catch (COMException) { }
Dean@159
   241
            catch (Exception) { }
Dean@159
   242
#endif
vb@133
   243
        }
vb@133
   244
Dean@170
   245
        /// <summary>
Dean@170
   246
        /// Sets the cryptable mail item associated with this encryption status panel.
Dean@170
   247
        /// The associated mail item can then be accessed through its local variable.
Dean@170
   248
        /// </summary>
Dean@170
   249
        private void SetAssociatedMailItem()
Dean@170
   250
        {
Dean@170
   251
            bool errorOccurred = false;
Dean@170
   252
            Outlook.MailItem omi = null;
Dean@170
   253
            Outlook.MAPIFolder omiFolder;
Dean@170
   254
            Outlook.MAPIFolder deletedFolder;
Dean@170
   255
Dean@170
   256
            // Null check
Dean@170
   257
            if (!errorOccurred)
Dean@170
   258
            {
Dean@170
   259
                try
Dean@170
   260
                {
Dean@170
   261
                    if (this.OutlookItem == null)
Dean@170
   262
                    {
Dean@170
   263
                        errorOccurred = true;
Dean@170
   264
                    }
Dean@170
   265
                }
Dean@170
   266
                catch (COMException)
Dean@170
   267
                {
Dean@170
   268
                    errorOccurred = true;
Dean@170
   269
                }
Dean@170
   270
            }
Dean@170
   271
Dean@170
   272
            // Attempt to get and cast the outlook mail item
Dean@170
   273
            if (!errorOccurred)
Dean@170
   274
            {
Dean@170
   275
                try
Dean@170
   276
                {
Dean@170
   277
                    omi = (Outlook.MailItem)this.OutlookItem;
Dean@170
   278
                }
Dean@170
   279
                catch
Dean@170
   280
                {
Dean@170
   281
                    errorOccurred = true;
Dean@170
   282
                }
Dean@170
   283
            }
Dean@170
   284
Dean@170
   285
            // Ensure the mail item is not in the deleted folder
Dean@170
   286
            if (!errorOccurred)
Dean@170
   287
            {
Dean@170
   288
                try
Dean@170
   289
                {
Dean@170
   290
                    omiFolder = omi.Parent;
Dean@170
   291
Dean@170
   292
                    if (omiFolder != null)
Dean@170
   293
                    {
Dean@170
   294
                        deletedFolder = omiFolder.Store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDeletedItems);
Dean@170
   295
Dean@170
   296
                        if ((deletedFolder != null) && 
Dean@170
   297
                            (omiFolder.EntryID == deletedFolder.EntryID))
Dean@170
   298
                        {
Dean@170
   299
                            errorOccurred = true;
Dean@170
   300
                        }
Dean@170
   301
                    }
Dean@170
   302
                    else
Dean@170
   303
                    {
Dean@170
   304
                        errorOccurred = true;
Dean@170
   305
                    }
Dean@170
   306
                }
Dean@170
   307
                catch
Dean@170
   308
                {
Dean@170
   309
                    errorOccurred = true;
Dean@170
   310
                }
Dean@170
   311
            }
Dean@170
   312
Dean@170
   313
            // Finally set the associated mail item
Dean@170
   314
            if ((errorOccurred) ||
Dean@170
   315
                (omi == null))
Dean@170
   316
            {
Dean@170
   317
                this.associatedMailItem = null;
Dean@170
   318
            }
Dean@170
   319
            else
Dean@170
   320
            {
Dean@170
   321
                // Check if the associated mail item has already been set
Dean@170
   322
                if (this.associatedMailItem != null)
Dean@170
   323
                {
Dean@170
   324
                    // Only re-set the mail item if the EntryID has changed
Dean@170
   325
                    if (this.associatedMailItem.EntryID != omi.EntryID)
Dean@170
   326
                    {
Dean@170
   327
                        this.associatedMailItem = new CryptableMailItem(omi);
Dean@170
   328
                    }
Dean@170
   329
                }
Dean@170
   330
                else
Dean@170
   331
                {
Dean@170
   332
                    this.associatedMailItem = new CryptableMailItem(omi);
Dean@170
   333
                }
Dean@170
   334
            }
Dean@170
   335
Dean@170
   336
            return;
Dean@170
   337
        }
Dean@170
   338
vb@133
   339
        private void doHandshake(pEp_identity_s identityPartner)
vb@133
   340
        {
Dean@155
   341
            string ownShort;
Dean@155
   342
            string ownLong;
Dean@155
   343
            string ownFpr;
Dean@155
   344
            string partnerShort;
Dean@155
   345
            string partnerLong;
Dean@155
   346
            string partnerFpr;
Dean@155
   347
            string[] lines;
Dean@155
   348
            pEp_identity_s me;
Dean@155
   349
            FormHandshake handshakeDialog;
Dean@155
   350
            FormHandshake.State state = new FormHandshake.State();
Dean@155
   351
dean@144
   352
            Debug.Assert(mailItem.ColorRating == _pEp_color.pEp_rating_yellow);
vb@132
   353
vb@139
   354
            ThisAddIn.verbose("doHandshake");
vb@139
   355
            ThisAddIn.verbose(identityPartner.address);
vb@139
   356
vb@132
   357
            if (identityPartner.username == "")
vb@133
   358
                identityPartner.username = identityPartner.address;
vb@139
   359
            ThisAddIn.verbose(identityPartner.username);
vb@133
   360
dean@144
   361
            identityPartner.user_id = CryptableMailItem.GetUserIDFromAddress(identityPartner.address, identityPartner.username);
vb@139
   362
            ThisAddIn.verbose(identityPartner.user_id);
vb@133
   363
dean@144
   364
            if (mailItem.IsIncoming)
vb@133
   365
            {
dean@144
   366
                string entryID = mailItem.ReceivedByEntryID;
vb@133
   367
                string address = "";
vb@133
   368
vb@133
   369
                foreach (Outlook.Account a in ThisAddIn.addIn.Application.Session.Accounts){
vb@133
   370
                    if (a.CurrentUser.EntryID == entryID) {
vb@133
   371
                        address = a.SmtpAddress;
vb@133
   372
                        break;
vb@133
   373
                    }
vb@133
   374
                }
vb@133
   375
vb@133
   376
                if (address == "")
vb@133
   377
                    address = ThisAddIn.addIn.Application.Session.Accounts[1].SmtpAddress;
vb@133
   378
vb@133
   379
                me = ThisAddIn.addIn.mySelf(address);
vb@133
   380
            }
vb@133
   381
            else // outgoing
vb@133
   382
            {
dean@144
   383
                ThisAddIn.verbose("mailItem.from_address: " + mailItem.FromAddress);
dean@144
   384
                me = ThisAddIn.addIn.mySelf(mailItem.FromAddress);
vb@133
   385
            }
vb@133
   386
vb@139
   387
            ThisAddIn.verbose(me.fpr);
vb@139
   388
Dean@155
   389
            ownShort = ThisAddIn.pEp.trustwords(me.fpr, max_words: 5).ToLower();
Dean@155
   390
            ownLong  = ThisAddIn.pEp.trustwords(me.fpr).ToLower();
Dean@161
   391
            ownFpr   = this.ToQuadruple(me.fpr);
vb@133
   392
vb@139
   393
            ThisAddIn.verbose(identityPartner.fpr);
vb@139
   394
Dean@155
   395
            partnerShort = ThisAddIn.pEp.trustwords(identityPartner.fpr, max_words: 5).ToLower();
Dean@155
   396
            partnerLong  = ThisAddIn.pEp.trustwords(identityPartner.fpr).ToLower();
Dean@161
   397
            partnerFpr   = this.ToQuadruple(identityPartner.fpr);
vb@133
   398
Dean@155
   399
            if (ownFpr.CompareTo(partnerFpr) > 0)
vb@133
   400
            {
Dean@155
   401
                state.TrustwordsShort = partnerShort + ownShort;
Dean@155
   402
                state.TrustwordsFull  = partnerLong  + ownLong;
Dean@155
   403
Dean@155
   404
                lines = new string[3];
Dean@155
   405
                lines[0] = pEp.Properties.Resources.TrustwordsPartnershortPartner + partnerFpr;
Dean@155
   406
                lines[2] = pEp.Properties.Resources.TrustwordsPartnershortMyself + ownFpr;
Dean@155
   407
                state.Fingerprint = lines;
vb@133
   408
            }
vb@133
   409
            else
vb@133
   410
            {
Dean@155
   411
                state.TrustwordsShort = ownShort + " " + partnerShort;
Dean@155
   412
                state.TrustwordsFull  = ownLong  + " " + partnerLong;
Dean@155
   413
Dean@155
   414
                lines = new string[3];
Dean@155
   415
                lines[0] = pEp.Properties.Resources.TrustwordsOwnshortMyself + ownFpr;
Dean@155
   416
                lines[2] = pEp.Properties.Resources.TrustwordsOwnshortPartner + partnerFpr;
Dean@155
   417
                state.Fingerprint = lines;
vb@133
   418
            }
vb@133
   419
vb@139
   420
            ThisAddIn.verbose("try to show dialog");
vb@139
   421
Dean@155
   422
            // Create and show handshake dialog
Dean@155
   423
            handshakeDialog = new FormHandshake(state);
Dean@155
   424
vb@132
   425
            DialogResult result = handshakeDialog.ShowDialog(this);
vb@133
   426
            ThisAddIn.verbose("handshakeDialog.ShowDialog(this) => " + result.ToString());
vb@133
   427
vb@133
   428
            switch (result)
vb@133
   429
            {
vb@133
   430
                case DialogResult.Yes:
dean@144
   431
                    mailItem.ColorRating = _pEp_color.pEp_rating_trusted;
vb@132
   432
                    identityPartner = ThisAddIn.pEp.trust_personal_key(identityPartner);
vb@133
   433
                    reset_enc_status(); 
vb@133
   434
                    break;
vb@133
   435
                case DialogResult.No:
vb@133
   436
                    ThisAddIn.pEp.key_compromized(identityPartner);
vb@133
   437
                    identityPartner.comm_type = _pEp_comm_type.pEp_ct_compromized;
dean@144
   438
                    mailItem.ColorRating = _pEp_color.pEp_rating_red;
vb@133
   439
                    reset_enc_status(); 
vb@133
   440
                    break;
vb@133
   441
            }
vb@133
   442
        }
vb@133
   443
vb@133
   444
        private void undoHandshake(pEp_identity_s identityPartner)
vb@133
   445
        {
vb@133
   446
            ThisAddIn.pEp.update_identity(identityPartner);
vb@133
   447
//            Debug.Assert((identityPartner.comm_type & _pEp_comm_type.pEp_ct_confirmed) != _pEp_comm_type.pEp_ct_unknown);
vb@133
   448
            identityPartner.comm_type ^= _pEp_comm_type.pEp_ct_confirmed;
vb@133
   449
            ThisAddIn.pEp.update_identity(identityPartner);
vb@133
   450
            reset_enc_status();
vb@133
   451
        }
vb@133
   452
Dean@161
   453
        /// <summary>
Dean@161
   454
        /// Formats the given text string as separated 4-character groups.
Dean@161
   455
        /// Example: 49422235FC99585B891C --> 4942 2235 FC99 585B 891C
Dean@161
   456
        /// </summary>
Dean@161
   457
        /// <param name="text">The text to format in 4-character groups.</param>
Dean@161
   458
        /// <returns>The re-formatted string.</returns>
Dean@161
   459
        private string ToQuadruple(string text)
Dean@159
   460
        {
Dean@159
   461
            List<string> result = new List<string>();
Dean@159
   462
Dean@161
   463
            if (text != null)
Dean@159
   464
            {
Dean@161
   465
                for (int i = 0; i < text.Length; i += 4)
Dean@159
   466
                {
Dean@161
   467
                    try
Dean@161
   468
                    {
Dean@161
   469
                        result.Add(text.Substring(i, 4));
Dean@161
   470
                    }
Dean@161
   471
                    catch (ArgumentOutOfRangeException)
Dean@161
   472
                    {
Dean@161
   473
                        result.Add(text.Substring(i));
Dean@161
   474
                        break;
Dean@161
   475
                    }
Dean@159
   476
                }
Dean@159
   477
            }
Dean@159
   478
Dean@159
   479
            return String.Join(" ", result);
Dean@159
   480
        }
Dean@159
   481
Dean@159
   482
        protected void makePreview()
Dean@159
   483
        {
Dean@159
   484
            WindowFormRegionCollection formRegions;
Dean@159
   485
Dean@159
   486
            if (Globals.ThisAddIn.Application.ActiveInspector() != null)
Dean@159
   487
                return;
Dean@159
   488
            else if (Globals.ThisAddIn.Application.ActiveExplorer() != null)
Dean@159
   489
                formRegions = Globals.FormRegions[Globals.ThisAddIn.Application.ActiveExplorer()];
Dean@159
   490
            else
Dean@159
   491
                return;
Dean@159
   492
Dean@159
   493
            try
Dean@159
   494
            {
Dean@159
   495
                if (formRegions.PreviewUnencrypted.Visible)
Dean@159
   496
                {
Dean@159
   497
                    byte[] rtf = mailItem.MirrorGetRTFBody();
Dean@159
   498
                    formRegions.PreviewUnencrypted.textPreview.Rtf = System.Text.Encoding.ASCII.GetString(rtf, 0, rtf.Length);
Dean@159
   499
                    formRegions.PreviewUnencrypted.textSubject.Text = mailItem.MirrorGetSubject();
Dean@159
   500
                    formRegions.PreviewUnencrypted.textFrom.Text = mailItem.FromUsername + " <" + mailItem.FromAddress + ">";
Dean@159
   501
                }
Dean@159
   502
            }
Dean@159
   503
            catch { }
Dean@159
   504
        }
Dean@159
   505
Dean@159
   506
        protected void reset_enc_status()
Dean@159
   507
        {
Dean@163
   508
            if (resetOngoing)
Dean@159
   509
                return;
Dean@159
   510
Dean@163
   511
            this.resetOngoing = true;
Dean@159
   512
Dean@159
   513
            if (mailItem != null)
Dean@159
   514
            {
Dean@159
   515
                if (_mailItem.DownloadState == Outlook.OlDownloadState.olFullItem)
Dean@159
   516
                {
Dean@159
   517
                    if (_mailItem.SendUnencrypted == CheckState.Checked)
Dean@159
   518
                    {
Dean@159
   519
                        enc_status = _pEp_color.pEp_rating_unencrypted;
Dean@159
   520
                    }
Dean@159
   521
                    else
Dean@159
   522
                    {
Dean@159
   523
                        ThisAddIn.verbose("get_color in reset_enc_status");
Dean@159
   524
                        enc_status = _mailItem.ColorRating;
Dean@159
   525
                    }
Dean@159
   526
                }
Dean@159
   527
                else
Dean@159
   528
                {
Dean@159
   529
                    _mailItem.MarkForDownload = Outlook.OlRemoteStatus.olMarkedForDownload;
Dean@159
   530
                    timerRefresh.Interval = 500;
Dean@159
   531
                    timerRefresh.Enabled = true;
Dean@159
   532
                }
Dean@159
   533
            }
Dean@159
   534
Dean@163
   535
            this.resetOngoing = false;
Dean@159
   536
        }
Dean@159
   537
Dean@159
   538
        /**************************************************************
Dean@159
   539
         * 
Dean@159
   540
         * Event Handling
Dean@159
   541
         * 
Dean@159
   542
         *************************************************************/
Dean@159
   543
Dean@159
   544
        /// <summary>
Dean@159
   545
        /// Event handler that is called before the form region is displayed.
Dean@159
   546
        /// </summary>
Dean@159
   547
        private void FormRegion1_FormRegionShowing(object sender, System.EventArgs e)
Dean@159
   548
        {
Dean@159
   549
            if (this.OutlookItem == null)
Dean@159
   550
            {
Dean@159
   551
                enc_status = _pEp_color.pEp_rating_undefined;
Dean@159
   552
            }
Dean@159
   553
            else
Dean@159
   554
            {
Dean@159
   555
                Outlook.MailItem omi = (Outlook.MailItem)this.OutlookItem;
Dean@159
   556
                try
Dean@159
   557
                {
Dean@169
   558
                    omi.PropertyChange += MailItem_PropertyChange;
Dean@159
   559
                    if (CryptableMailItem.IsEncryptedStore(omi))
Dean@159
   560
                    {
Dean@159
   561
                        if (PreviewUnencrypted.isPGPEncrypted(omi) && omi.Sender != null)
Dean@159
   562
                        {
Dean@169
   563
                            omi.Open += MailItem_Open;
Dean@159
   564
                        }
Dean@159
   565
                    }
Dean@159
   566
                }
Dean@159
   567
                catch { }
Dean@159
   568
Dean@159
   569
                if (ThisAddIn.addIn.enabled)
Dean@159
   570
                {
Dean@159
   571
                    reset_enc_status();
Dean@159
   572
                }
Dean@159
   573
                else
Dean@159
   574
                {
Dean@159
   575
                    timerRefresh.Enabled = true;
Dean@159
   576
                }
Dean@159
   577
            }
Dean@159
   578
        }
Dean@159
   579
Dean@159
   580
        /// <summary>
Dean@159
   581
        /// Event handler for when the form region is closed.
Dean@159
   582
        /// </summary>
Dean@159
   583
        private void FormRegion1_FormRegionClosed(object sender, System.EventArgs e)
Dean@159
   584
        {
Dean@159
   585
            return;
Dean@159
   586
        }
Dean@159
   587
Dean@169
   588
        /// <summary>
Dean@169
   589
        /// Event handler for when a mail item is being opened in an inspector.
Dean@169
   590
        /// </summary>
Dean@169
   591
        /// <param name="cancel">Whether to cancel the event: Value is False when the event occurs. 
Dean@169
   592
        /// If the event procedure sets this argument to True, the open operation is not completed 
Dean@169
   593
        /// and the inspector is not displayed.</param>
Dean@169
   594
        private void MailItem_Open(ref bool cancel)
Dean@159
   595
        {
Dean@169
   596
            // Cancel opening the if the mirror is displayed instead
Dean@159
   597
            if (mailItem != null && _mailItem.MirrorDisplay())
Dean@169
   598
            {
Dean@169
   599
                cancel = true;
Dean@169
   600
            }
Dean@169
   601
Dean@169
   602
            return;
Dean@159
   603
        }
Dean@159
   604
Dean@169
   605
        /// <summary>
Dean@169
   606
        /// Event handler for when a mail item property is changed.
Dean@169
   607
        /// See: https://msdn.microsoft.com/en-us/library/office/ff866739.aspx
Dean@169
   608
        /// </summary>
Dean@169
   609
        /// <param name="propertyName">The name of the property that was changed.</param>
Dean@169
   610
        private void MailItem_PropertyChange(string propertyName)
Dean@159
   611
        {
Dean@169
   612
            switch (propertyName)
Dean@159
   613
            {
Dean@159
   614
                case "To":
Dean@159
   615
                    timerRefresh.Enabled = true;
Dean@159
   616
                    break;
Dean@159
   617
                // Outlook bug: there are always both events, so one is enough
Dean@159
   618
                //case "CC":
Dean@159
   619
                //    reset_enc_status();
Dean@159
   620
                //    break;
Dean@159
   621
            }
Dean@169
   622
Dean@169
   623
            return;
Dean@159
   624
        }
Dean@159
   625
Dean@159
   626
        private void secure_strip_Opening(object sender, System.ComponentModel.CancelEventArgs e)
Dean@159
   627
        {
Dean@159
   628
            enc_status_data.strip.Items.Clear();
Dean@159
   629
Dean@159
   630
            if (mailItem.IsIncoming)
Dean@159
   631
            {
Dean@159
   632
                pEp_identity_s ident = new pEp_identity_s();
Dean@159
   633
                ident.address = mailItem.FromAddress;
Dean@159
   634
                ident.username = mailItem.FromUsername;
Dean@159
   635
                ident.user_id = CryptableMailItem.GetUserIDFromAddress(ident.address, ident.username);
Dean@159
   636
                ident = ThisAddIn.pEp.update_identity(ident);
Dean@159
   637
                string text = pEp.Properties.Resources.IdentityTrustText + ident.username + " <" + ident.address + ">";
Dean@159
   638
                enc_status_data.strip.Items.Add(text, null, (x, y) => { undoHandshake(ident); });
Dean@159
   639
            }
Dean@159
   640
            else
Dean@159
   641
            {
Dean@159
   642
                foreach (pEp_identity_s ident in mailItem.Addresses)
Dean@159
   643
                {
Dean@159
   644
                    pEp_identity_s identityPartner = ThisAddIn.pEp.update_identity(ident);
Dean@159
   645
                    if (identityPartner.comm_type >= _pEp_comm_type.pEp_ct_confirmed_encryption)
Dean@159
   646
                    {
Dean@159
   647
                        string text = pEp.Properties.Resources.IdentityTrustText + ident.username + " <" + ident.address + ">";
Dean@159
   648
                        enc_status_data.strip.Items.Add(text, null, (x, y) => { undoHandshake(ident); });
Dean@159
   649
                    }
Dean@159
   650
                }
Dean@159
   651
            }
Dean@159
   652
        }
Dean@159
   653
vb@133
   654
        private void EncryptionStatus_Click(object sender, EventArgs e)
vb@133
   655
        {
vb@133
   656
            switch (enc_status)
vb@133
   657
            {
vb@133
   658
                case _pEp_color.pEp_rating_green:
vb@133
   659
                    try
vb@133
   660
                    {
dean@144
   661
                        string[] key_list = mailItem.Keylist;
vb@133
   662
                        if (key_list.Length > 0)
vb@133
   663
                        {
vb@133
   664
                            string msg;
vb@133
   665
                            if (key_list.Length > 1)
vb@133
   666
                                msg = String.Format(pEp.Properties.Resources.EncryptionStatusClickMessageMultiple + " {0}.", String.Join(", ", key_list));
vb@133
   667
                            else
vb@133
   668
                                msg = String.Format(pEp.Properties.Resources.EncryptionStatusClickMessageSingle + " {0}.", key_list[0]);
vb@133
   669
                            MessageBox.Show(msg, pEp.Properties.Resources.EncryptionStatusClickMessageBox, MessageBoxButtons.OK, MessageBoxIcon.Information);
vb@133
   670
                        }
vb@133
   671
                    }
vb@133
   672
                    catch (Exception ex)
vb@133
   673
                    {
vb@133
   674
                        StopHere(ex.ToString());
vb@133
   675
                    }
vb@133
   676
                    break;
vb@133
   677
vb@133
   678
                case _pEp_color.pEp_rating_yellow:
vb@133
   679
                    try
vb@133
   680
                    {
dean@144
   681
                        if (mailItem.IsIncoming)
vb@133
   682
                        {
vb@133
   683
                            pEp_identity_s identityPartner = new pEp_identity_s();
dean@144
   684
                            identityPartner.address = mailItem.FromAddress;
dean@144
   685
                            identityPartner.username = mailItem.FromUsername;
dean@144
   686
                            identityPartner.user_id = CryptableMailItem.GetUserIDFromAddress(identityPartner.address, identityPartner.username);
vb@139
   687
vb@133
   688
                            try
vb@133
   689
                            {
vb@133
   690
                                identityPartner = ThisAddIn.pEp.update_identity(identityPartner);
vb@133
   691
                            }
vb@133
   692
                            catch
vb@133
   693
                            {
vb@133
   694
                                enc_status = _pEp_color.pEp_rating_undefined;
vb@133
   695
                                return;
vb@133
   696
                            }
vb@133
   697
                            doHandshake(identityPartner);
vb@133
   698
                        }
vb@133
   699
                        else // outgoing
vb@133
   700
                        {
vb@139
   701
                            ThisAddIn.verbose("yellow, handshake initiated");
vb@139
   702
vb@133
   703
                            List<pEp_identity_s> partnersToCheck = new List<pEp_identity_s>();
vb@133
   704
dean@144
   705
                            foreach (pEp_identity_s identity in mailItem.Addresses)
vb@133
   706
                            {
vb@139
   707
                                ThisAddIn.verbose("adding " + identity.username + " <" + identity.address + ">");
vb@139
   708
vb@133
   709
                                try
vb@133
   710
                                {
vb@133
   711
                                    pEp_identity_s identityPartner = ThisAddIn.pEp.update_identity(identity);
vb@133
   712
                                    if (identityPartner.comm_type >= _pEp_comm_type.pEp_ct_unconfirmed_encryption
vb@133
   713
                                        && identityPartner.comm_type < _pEp_comm_type.pEp_ct_confirmed_encryption)
vb@133
   714
                                    {
vb@133
   715
                                        partnersToCheck.Add(identityPartner);
vb@133
   716
                                    }
vb@133
   717
                                }
vb@133
   718
                                catch
vb@133
   719
                                {
vb@133
   720
                                }
vb@133
   721
                            }
vb@133
   722
vb@133
   723
                            if (partnersToCheck.Count == 0)
vb@133
   724
                            {
vb@133
   725
                                enc_status = _pEp_color.pEp_rating_undefined;
vb@133
   726
                                return;
vb@133
   727
                            }
vb@133
   728
dean@144
   729
                            pEp_identity_s[] addresses = mailItem.Addresses;
vb@133
   730
vb@133
   731
                            if (addresses.Length == 1)
vb@133
   732
                            {
vb@133
   733
                                doHandshake(partnersToCheck[0]);
vb@133
   734
                            }
vb@133
   735
                            else if (addresses.Length > 1)
vb@133
   736
                            {
vb@133
   737
                                contextMenuHandshake.Items.Clear();
vb@133
   738
                                foreach (pEp_identity_s identity in partnersToCheck) {
vb@133
   739
                                    string text = identity.username + " <" + identity.address + ">";
vb@133
   740
                                    contextMenuHandshake.Items.Add(text, null, (x, y) => { doHandshake(identity); });
vb@133
   741
                                }
vb@133
   742
                                contextMenuHandshake.Show(EncryptionStatus, 10, 10);
vb@133
   743
                            }
vb@133
   744
                        }
vb@133
   745
                    }
vb@133
   746
                    catch (COMException ex)
vb@133
   747
                    {
vb@133
   748
                        StopHere(ex.ToString());
vb@133
   749
                    }
vb@133
   750
                    catch (Exception ex)
vb@133
   751
                    {
vb@133
   752
                        StopHere(ex.ToString());
vb@133
   753
                    }
vb@133
   754
                    break;
vb@133
   755
vb@133
   756
                case _pEp_color.pEp_rating_unencrypted:
dean@144
   757
                    if (mailItem.IsIncoming)
vb@133
   758
                    {
vb@133
   759
                        MessageBox.Show(pEp.Properties.Resources.RatingUnencryptedMessageboxReasonBody, pEp.Properties.Resources.RatingUnencryptedMessageboxReasonTitle);
vb@133
   760
                    }
vb@133
   761
                    else
vb@133
   762
                    {
vb@133
   763
                        try
vb@133
   764
                        {
vb@133
   765
                            string reason = "";
dean@144
   766
                            foreach (pEp_identity_s identity in mailItem.Addresses)
vb@133
   767
                            {
vb@133
   768
                                if (identity.comm_type < _pEp_comm_type.pEp_ct_security_by_obscurity)
vb@133
   769
                                {
vb@133
   770
                                    if (reason != "")
vb@133
   771
                                        reason += "\n";
vb@133
   772
                                    // BUG: reason string in English language only and trivial
vb@133
   773
                                    string ct = identity.comm_type.ToString();
vb@133
   774
                                    ct = new string(ct.Skip(7).ToArray());
vb@133
   775
                                    ct = ct.Replace("_", " ");
vb@133
   776
                                    reason += identity.username + " <" + identity.address + ">: " + ct;
vb@133
   777
                                }
vb@133
   778
                            }
vb@133
   779
                            if (reason != "")
vb@133
   780
                                MessageBox.Show(reason, pEp.Properties.Resources.RatingUnencryptedMessageboxReasonTitle);
vb@133
   781
                        }
vb@133
   782
                        catch (COMException ex)
vb@133
   783
                        {
vb@133
   784
                            StopHere(ex.ToString());
vb@133
   785
                        }
vb@133
   786
                    }
vb@133
   787
                    break;
vb@133
   788
vb@133
   789
                case _pEp_color.pEp_rating_cannot_decrypt:
vb@133
   790
                case _pEp_color.pEp_rating_have_no_key:
vb@133
   791
                    try
vb@133
   792
                    {
dean@144
   793
                        string[] keys = mailItem.Keylist;
vb@133
   794
vb@133
   795
                        if (keys.Length > 1)
vb@133
   796
                        {
vb@133
   797
                            string reason;
vb@133
   798
vb@133
   799
                            if (keys.Length == 2)
vb@133
   800
                                reason = pEp.Properties.Resources.RatingHavenokeyMessageboxReasonBodyNokey;
vb@133
   801
                            else
vb@133
   802
                                reason = string.Format(pEp.Properties.Resources.RatingHavenokeyMessageboxReasonBodySomekey, keys.Length - 1);
vb@133
   803
vb@133
   804
                            string keyinfo = "";
vb@133
   805
vb@133
   806
                            foreach (string key in keys)
vb@133
   807
                            {
vb@133
   808
                                if (key.Length >= 8)
vb@133
   809
                                    keyinfo += "\n" + key;
vb@133
   810
                            }
vb@133
   811
vb@133
   812
                            reason += keyinfo;
vb@133
   813
vb@133
   814
                            MessageBox.Show(reason, pEp.Properties.Resources.RatingHavenokeyTitle);
vb@133
   815
                        }
vb@133
   816
                        else if (keys.Length == 1)
vb@133
   817
                        {
vb@133
   818
                            MessageBox.Show(pEp.Properties.Resources.RatingHavenokeyMessageboxReasonError + keys[0], pEp.Properties.Resources.RatingHavenokeyTitle);
vb@133
   819
                        }
vb@133
   820
                        else
vb@133
   821
                        {
vb@133
   822
                            MessageBox.Show(pEp.Properties.Resources.RatingHavenokeyMessageboxReasonUnknownformat, pEp.Properties.Resources.RatingHavenokeyTitle);
vb@133
   823
                        }
vb@133
   824
                    }
vb@133
   825
                    catch (COMException ex)
vb@133
   826
                    {
vb@133
   827
                        StopHere(ex.ToString());
vb@133
   828
                    }
vb@133
   829
                    break;
vb@133
   830
                    
vb@133
   831
                case _pEp_color.pEp_rating_undefined:
vb@133
   832
                    if (mailItem != null)
vb@133
   833
                    {
dean@144
   834
                        enc_status = mailItem.ColorRating;
vb@133
   835
                    }
vb@133
   836
                    break;
vb@133
   837
            }
vb@133
   838
        }
vb@133
   839
vb@133
   840
        private void linkExplanation_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
vb@133
   841
        {
vb@133
   842
            if (enc_status == _pEp_color.pEp_rating_undefined)
vb@133
   843
            {
vb@133
   844
                enc_status_data.explanation = pEp.Properties.Resources.RatingUndefinedExplanation;
vb@133
   845
                enc_status_data.suggestion = pEp.Properties.Resources.RatingUndefinedSuggestion;
vb@133
   846
                enc_status_data.title = pEp.Properties.Resources.RatingUndefinedTitle;
Dean@162
   847
                enc_status_data.background = COLOR_GREY;
Dean@162
   848
                enc_status_data.foreground = TEXT_COLOR_BLACK;
vb@133
   849
                enc_status_data.button_text = pEp.Properties.Resources.RatingUndefinedButtontext;
vb@133
   850
                enc_status_data.strip = null;
vb@133
   851
            }
vb@133
   852
vb@133
   853
            var result = MessageBox.Show(
vb@133
   854
                            enc_status_data.explanation + "\n\n" + enc_status_data.suggestion,
vb@133
   855
                            enc_status_data.title,
vb@133
   856
                            MessageBoxButtons.OK,
vb@133
   857
                            enc_status == _pEp_color.pEp_rating_under_attack
vb@133
   858
                                ? MessageBoxIcon.Stop
vb@133
   859
                                : MessageBoxIcon.Information
vb@133
   860
                        );
vb@133
   861
        }
vb@133
   862
vb@133
   863
        private void timerRefresh_Tick(object sender, EventArgs e)
vb@133
   864
        {
vb@133
   865
            timerRefresh.Interval = 100;
vb@133
   866
            timerRefresh.Enabled = false; // only once
vb@133
   867
vb@133
   868
            if (!ThisAddIn.addIn.enabled)
vb@133
   869
                ThisAddIn.addIn.enable();
vb@133
   870
vb@133
   871
            makePreview();
vb@133
   872
vb@133
   873
            reset_enc_status();
vb@133
   874
        }
vb@133
   875
vb@133
   876
        private void EncryptionStatus_MouseUp(object sender, MouseEventArgs e)
vb@133
   877
        {
vb@133
   878
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
vb@133
   879
            {
vb@133
   880
                CryptableMailItem cmi = mailItem;
vb@133
   881
dean@144
   882
                if (cmi != null && !cmi.IsIncoming && !cmi.IsInSentFolder && cmi.OutgoingColor > _pEp_color.pEp_rating_unencrypted)
vb@133
   883
                {
dean@144
   884
                    if (cmi.SendUnencrypted == CheckState.Indeterminate)
vb@133
   885
                    {
vb@133
   886
                        sendUnencryptedToolStripMenuItem.CheckState = CheckState.Unchecked;
vb@133
   887
                    }
vb@133
   888
                    else {
dean@144
   889
                        sendUnencryptedToolStripMenuItem.CheckState = cmi.SendUnencrypted;
vb@133
   890
                    }
vb@133
   891
vb@133
   892
                    Control _sender = (Control)sender;
vb@133
   893
                    contextMenuEdit.Show(_sender.PointToScreen(e.Location));
vb@133
   894
                }
vb@133
   895
            }
vb@133
   896
        }
vb@133
   897
vb@133
   898
        private void sendUnencryptedToolStripMenuItem_Click(object sender, EventArgs e)
vb@133
   899
        {
vb@133
   900
            sendUnencryptedToolStripMenuItem.Checked = !sendUnencryptedToolStripMenuItem.Checked;
dean@144
   901
            mailItem.SendUnencrypted = sendUnencryptedToolStripMenuItem.CheckState;
vb@133
   902
            timerRefresh.Enabled = true;
vb@133
   903
        }
Dean@151
   904
Dean@151
   905
        /// <summary>
Dean@151
   906
        /// Event handler for when the options picture box is clicked.
Dean@151
   907
        /// This will open the options form for user editing.
Dean@151
   908
        /// </summary>
Dean@151
   909
        private void PictureBoxOptions_Click(object sender, EventArgs e)
Dean@151
   910
        {
Dean@159
   911
            DialogResult result;
Dean@152
   912
            FormOptions frm = new FormOptions();
Dean@154
   913
            frm.StartPosition = FormStartPosition.CenterScreen;
Dean@159
   914
            result = frm.ShowDialog(this.ParentForm); // Must show as dialog to block code
Dean@151
   915
Dean@154
   916
            if (ThisAddIn.addIn.use_keyserver)
Dean@154
   917
                ThisAddIn.pEp.start_keyserver_lookup();
Dean@154
   918
            else
Dean@154
   919
                ThisAddIn.pEp.stop_keyserver_lookup();
Dean@151
   920
Dean@151
   921
            return;
Dean@151
   922
        }
Dean@151
   923
Dean@151
   924
        /// <summary>
Dean@151
   925
        /// Event handler for when the mouse hovers over the options picture box.
Dean@151
   926
        /// This is a work-around to show a tool tip.
Dean@151
   927
        /// </summary>
Dean@151
   928
        private void PictureBoxOptions_MouseHover(object sender, EventArgs e)
Dean@151
   929
        {
Dean@151
   930
            ToolTip toolTip = new ToolTip();
Dean@151
   931
            toolTip.SetToolTip(this.PictureBoxOptions, "Click to open options");
Dean@151
   932
            return;
Dean@151
   933
        }
Dean@166
   934
Dean@166
   935
        /**************************************************************
Dean@166
   936
         * 
Dean@166
   937
         * Sub-classes
Dean@166
   938
         * 
Dean@166
   939
         *************************************************************/
Dean@166
   940
Dean@166
   941
        /// <summary>
Dean@166
   942
        /// Class used to store the state of the encryption status panel.
Dean@166
   943
        /// </summary>
Dean@166
   944
        public class State
Dean@166
   945
        {
Dean@166
   946
            private _pEp_color _EncryptionStatus;
Dean@166
   947
Dean@166
   948
            private string _Title;
Dean@166
   949
            private string _Explanation;
Dean@166
   950
            private string _Suggestion;
Dean@166
   951
            private Color  _ButtonBackground;
Dean@166
   952
            private Color  _ButtonForeground;
Dean@166
   953
            private string _ButtonText;
Dean@166
   954
Dean@166
   955
            /**************************************************************
Dean@166
   956
             * 
Dean@166
   957
             * Constructors
Dean@166
   958
             * 
Dean@166
   959
             *************************************************************/
Dean@166
   960
Dean@166
   961
            /// <summary>
Dean@166
   962
            /// Default constructor.
Dean@166
   963
            /// </summary>
Dean@166
   964
            public State()
Dean@166
   965
            {
Dean@166
   966
                this.Reset();
Dean@166
   967
            }
Dean@166
   968
Dean@166
   969
            /**************************************************************
Dean@166
   970
             * 
Dean@166
   971
             * Property Accessors
Dean@166
   972
             * 
Dean@166
   973
             *************************************************************/
Dean@166
   974
Dean@166
   975
            /// <summary>
Dean@166
   976
            /// Gets or sets the encryption status as a pEp color rating.
Dean@166
   977
            /// </summary>
Dean@166
   978
            public _pEp_color EncryptionStatus
Dean@166
   979
            {
Dean@166
   980
                get { return (this._EncryptionStatus); }
Dean@166
   981
                set 
Dean@166
   982
                { 
Dean@166
   983
                    this._EncryptionStatus = value;
Dean@166
   984
                    this.UpdateProperties();
Dean@166
   985
                }
Dean@166
   986
            }
Dean@166
   987
Dean@166
   988
            /// <summary>
Dean@166
   989
            /// Gets the title of the encryption status.
Dean@166
   990
            /// This is dependent on EncryptionStatus and therefore automatically set.
Dean@166
   991
            /// </summary>
Dean@166
   992
            public string Title
Dean@166
   993
            {
Dean@166
   994
                get { return (this._Title); }
Dean@166
   995
            }
Dean@166
   996
Dean@166
   997
            /// <summary>
Dean@166
   998
            /// Gets the explanation for the encryption status.
Dean@166
   999
            /// This is dependent on EncryptionStatus and therefore automatically set.
Dean@166
  1000
            /// </summary>
Dean@166
  1001
            public string Explanation
Dean@166
  1002
            {
Dean@166
  1003
                get { return (this._Explanation); }
Dean@166
  1004
            }
Dean@166
  1005
Dean@166
  1006
            /// <summary>
Dean@166
  1007
            /// Gets the suggestion to improve the encryption status.
Dean@166
  1008
            /// This is dependent on EncryptionStatus and therefore automatically set.
Dean@166
  1009
            /// </summary>
Dean@166
  1010
            public string Suggestion
Dean@166
  1011
            {
Dean@166
  1012
                get { return (this._Suggestion); }
Dean@166
  1013
            }
Dean@166
  1014
Dean@166
  1015
            /// <summary>
Dean@166
  1016
            /// Gets the background color of the encryption button.
Dean@166
  1017
            /// This is dependent on EncryptionStatus and therefore automatically set.
Dean@166
  1018
            /// </summary>
Dean@166
  1019
            public Color ButtonBackground
Dean@166
  1020
            {
Dean@166
  1021
                get { return (this._ButtonBackground); }
Dean@166
  1022
            }
Dean@166
  1023
Dean@166
  1024
            /// <summary>
Dean@166
  1025
            /// Gets the foreground color of the encryption button.
Dean@166
  1026
            /// This is dependent on EncryptionStatus and therefore automatically set.
Dean@166
  1027
            /// </summary>
Dean@166
  1028
            public Color ButtonForeground
Dean@166
  1029
            {
Dean@166
  1030
                get { return (this._ButtonForeground); }
Dean@166
  1031
            }
Dean@166
  1032
Dean@166
  1033
            /// <summary>
Dean@166
  1034
            /// Gets the text of the encryption button.
Dean@166
  1035
            /// This is dependent on EncryptionStatus and therefore automatically set.
Dean@166
  1036
            /// </summary>
Dean@166
  1037
            public string ButtonText
Dean@166
  1038
            {
Dean@166
  1039
                get { return (this._ButtonText); }
Dean@166
  1040
            }
Dean@166
  1041
Dean@166
  1042
            /**************************************************************
Dean@166
  1043
             * 
Dean@166
  1044
             * Methods
Dean@166
  1045
             * 
Dean@166
  1046
             *************************************************************/
Dean@166
  1047
Dean@166
  1048
            /// <summary>
Dean@166
  1049
            /// Resets the object to it's default values.
Dean@166
  1050
            /// </summary>
Dean@166
  1051
            public void Reset()
Dean@166
  1052
            {
Dean@166
  1053
                this._EncryptionStatus = _pEp_color.pEp_rating_undefined;
Dean@166
  1054
                this.UpdateProperties();
Dean@166
  1055
Dean@166
  1056
                return;
Dean@166
  1057
            }
Dean@166
  1058
Dean@166
  1059
            /// <summary>
Dean@166
  1060
            /// Updates any properties dependent on the encryption status.
Dean@166
  1061
            /// </summary>
Dean@166
  1062
            private void UpdateProperties()
Dean@166
  1063
            {
Dean@166
  1064
                switch (this._EncryptionStatus)
Dean@166
  1065
                {
Dean@166
  1066
                    case _pEp_color.pEp_rating_trusted:
Dean@166
  1067
                    case _pEp_color.pEp_rating_trusted_and_anonymized:
Dean@166
  1068
                        this._Title       = pEp.Properties.Resources.RatingTrustedTitle;
Dean@166
  1069
                        this._Explanation = pEp.Properties.Resources.RatingTrustedExplanation;
Dean@166
  1070
                        this._Suggestion  = pEp.Properties.Resources.RatingTrustedSuggestion;
Dean@166
  1071
                        
Dean@166
  1072
                        this._ButtonBackground = COLOR_GREEN;
Dean@166
  1073
                        this._ButtonForeground = TEXT_COLOR_WHITE;
Dean@166
  1074
                        this._ButtonText       = pEp.Properties.Resources.RatingTrustedButtontext;
Dean@166
  1075
                        break;
Dean@166
  1076
Dean@166
  1077
                    case _pEp_color.pEp_rating_reliable:
Dean@166
  1078
                        this._Title       = pEp.Properties.Resources.RatingReliableTitle;
Dean@166
  1079
                        this._Explanation = pEp.Properties.Resources.RatingReliableExplaination;
Dean@166
  1080
                        this._Suggestion  = pEp.Properties.Resources.RatingReliableSuggestion;
Dean@166
  1081
                        
Dean@166
  1082
                        this._ButtonBackground = COLOR_YELLOW;
Dean@166
  1083
                        this._ButtonForeground = TEXT_COLOR_BLACK;
Dean@166
  1084
                        this._ButtonText       = pEp.Properties.Resources.RatingReliableButtontext;
Dean@166
  1085
                        break;
Dean@166
  1086
Dean@166
  1087
                    case _pEp_color.pEp_rating_unreliable:
Dean@166
  1088
                        this._Title       = pEp.Properties.Resources.RatingUnreliableTitle;
Dean@166
  1089
                        this._Explanation = pEp.Properties.Resources.RatingUnreliableExplanation;
Dean@166
  1090
                        this._Suggestion  = pEp.Properties.Resources.RatingUnreliableSuggestion;
Dean@166
  1091
                        
Dean@166
  1092
                        this._ButtonBackground = COLOR_GREY;
Dean@166
  1093
                        this._ButtonForeground = TEXT_COLOR_BLACK;
Dean@166
  1094
                        this._ButtonText       = pEp.Properties.Resources.RatingUnreliableButtontext;
Dean@166
  1095
                        break;
Dean@166
  1096
Dean@166
  1097
                    case _pEp_color.pEp_rating_unencrypted:
Dean@166
  1098
                        this._Title       = pEp.Properties.Resources.RatingUnencryptedTitle;
Dean@166
  1099
                        this._Explanation = pEp.Properties.Resources.RatingUnencryptedExplanation;
Dean@166
  1100
                        this._Suggestion  = pEp.Properties.Resources.RatingUnencryptedSuggestion;
Dean@166
  1101
                        
Dean@166
  1102
                        this._ButtonBackground = COLOR_GREY;
Dean@166
  1103
                        this._ButtonForeground = TEXT_COLOR_BLACK;
Dean@166
  1104
                        this._ButtonText       = pEp.Properties.Resources.RatingUnencryptedButtontext;
Dean@166
  1105
                        break;
Dean@166
  1106
Dean@166
  1107
                    case _pEp_color.pEp_rating_under_attack:
Dean@166
  1108
                        this._Title       = pEp.Properties.Resources.RatingUnderattackTitle;
Dean@166
  1109
                        this._Explanation = pEp.Properties.Resources.RatingUnderattackExplanation;
Dean@166
  1110
                        this._Suggestion  = pEp.Properties.Resources.RatingUnderattackSuggestion;
Dean@166
  1111
                        
Dean@166
  1112
                        this._ButtonBackground = COLOR_RED;
Dean@166
  1113
                        this._ButtonForeground = TEXT_COLOR_WHITE;
Dean@166
  1114
                        this._ButtonText       = pEp.Properties.Resources.RatingUnderattackButtontext;
Dean@166
  1115
                        break;
Dean@166
  1116
Dean@166
  1117
                    case _pEp_color.pEp_rating_undefined:
Dean@166
  1118
                        this._Title       = pEp.Properties.Resources.RatingUndefinedTitle;
Dean@166
  1119
                        this._Explanation = pEp.Properties.Resources.RatingUndefinedExplanation;
Dean@166
  1120
                        this._Suggestion  = pEp.Properties.Resources.RatingUndefinedSuggestion;
Dean@166
  1121
                        
Dean@166
  1122
                        this._ButtonBackground = COLOR_GREY;
Dean@166
  1123
                        this._ButtonForeground = TEXT_COLOR_BLACK;
Dean@166
  1124
                        this._ButtonText       = pEp.Properties.Resources.RatingUndefinedButtontext;
Dean@166
  1125
                        break;
Dean@166
  1126
Dean@166
  1127
                    case _pEp_color.pEp_rating_cannot_decrypt:
Dean@166
  1128
                    case _pEp_color.pEp_rating_have_no_key:
Dean@166
  1129
                        this._Title       = pEp.Properties.Resources.RatingHavenokeyTitle;
Dean@166
  1130
                        this._Explanation = pEp.Properties.Resources.RatingHavenokeyExplanation;
Dean@166
  1131
                        this._Suggestion  = pEp.Properties.Resources.RatingHavenokeySuggestion;
Dean@166
  1132
                        
Dean@166
  1133
                        this._ButtonBackground = COLOR_GREY;
Dean@166
  1134
                        this._ButtonForeground = TEXT_COLOR_BLACK;
Dean@166
  1135
                        this._ButtonText       = pEp.Properties.Resources.RatingHavenokeyButtontext;
Dean@166
  1136
                        break;
Dean@166
  1137
Dean@166
  1138
                    default:
Dean@166
  1139
                        this._Title       = "";
Dean@166
  1140
                        this._Explanation = "";
Dean@166
  1141
                        this._Suggestion  = "";
Dean@166
  1142
                        
Dean@166
  1143
                        this._ButtonBackground = COLOR_GREY;
Dean@166
  1144
                        this._ButtonForeground = TEXT_COLOR_BLACK;
Dean@166
  1145
                        this._ButtonText       = "";
Dean@166
  1146
                        break;
Dean@166
  1147
                }
Dean@166
  1148
Dean@166
  1149
                return;
Dean@166
  1150
            }
Dean@166
  1151
Dean@166
  1152
        }
vb@133
  1153
    }
vb@133
  1154
}