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