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