EncryptionStatusPanel.cs
author Dean Looyengoed
Tue, 29 Dec 2015 21:24:53 +0100
changeset 169 c7d9b7ad0639
parent 166 e830996006c2
child 170 07911d16b012
permissions -rw-r--r--
Comment and refactor MailItem event handlers
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@169
   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@169
   462
                            omi.Open += MailItem_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@169
   487
        /// <summary>
Dean@169
   488
        /// Event handler for when a mail item is being opened in an inspector.
Dean@169
   489
        /// </summary>
Dean@169
   490
        /// <param name="cancel">Whether to cancel the event: Value is False when the event occurs. 
Dean@169
   491
        /// If the event procedure sets this argument to True, the open operation is not completed 
Dean@169
   492
        /// and the inspector is not displayed.</param>
Dean@169
   493
        private void MailItem_Open(ref bool cancel)
Dean@159
   494
        {
Dean@169
   495
            // Cancel opening the if the mirror is displayed instead
Dean@159
   496
            if (mailItem != null && _mailItem.MirrorDisplay())
Dean@169
   497
            {
Dean@169
   498
                cancel = true;
Dean@169
   499
            }
Dean@169
   500
Dean@169
   501
            return;
Dean@159
   502
        }
Dean@159
   503
Dean@169
   504
        /// <summary>
Dean@169
   505
        /// Event handler for when a mail item property is changed.
Dean@169
   506
        /// See: https://msdn.microsoft.com/en-us/library/office/ff866739.aspx
Dean@169
   507
        /// </summary>
Dean@169
   508
        /// <param name="propertyName">The name of the property that was changed.</param>
Dean@169
   509
        private void MailItem_PropertyChange(string propertyName)
Dean@159
   510
        {
Dean@169
   511
            switch (propertyName)
Dean@159
   512
            {
Dean@159
   513
                case "To":
Dean@159
   514
                    timerRefresh.Enabled = true;
Dean@159
   515
                    break;
Dean@159
   516
                // Outlook bug: there are always both events, so one is enough
Dean@159
   517
                //case "CC":
Dean@159
   518
                //    reset_enc_status();
Dean@159
   519
                //    break;
Dean@159
   520
            }
Dean@169
   521
Dean@169
   522
            return;
Dean@159
   523
        }
Dean@159
   524
Dean@159
   525
        private void secure_strip_Opening(object sender, System.ComponentModel.CancelEventArgs e)
Dean@159
   526
        {
Dean@159
   527
            enc_status_data.strip.Items.Clear();
Dean@159
   528
Dean@159
   529
            if (mailItem.IsIncoming)
Dean@159
   530
            {
Dean@159
   531
                pEp_identity_s ident = new pEp_identity_s();
Dean@159
   532
                ident.address = mailItem.FromAddress;
Dean@159
   533
                ident.username = mailItem.FromUsername;
Dean@159
   534
                ident.user_id = CryptableMailItem.GetUserIDFromAddress(ident.address, ident.username);
Dean@159
   535
                ident = ThisAddIn.pEp.update_identity(ident);
Dean@159
   536
                string text = pEp.Properties.Resources.IdentityTrustText + ident.username + " <" + ident.address + ">";
Dean@159
   537
                enc_status_data.strip.Items.Add(text, null, (x, y) => { undoHandshake(ident); });
Dean@159
   538
            }
Dean@159
   539
            else
Dean@159
   540
            {
Dean@159
   541
                foreach (pEp_identity_s ident in mailItem.Addresses)
Dean@159
   542
                {
Dean@159
   543
                    pEp_identity_s identityPartner = ThisAddIn.pEp.update_identity(ident);
Dean@159
   544
                    if (identityPartner.comm_type >= _pEp_comm_type.pEp_ct_confirmed_encryption)
Dean@159
   545
                    {
Dean@159
   546
                        string text = pEp.Properties.Resources.IdentityTrustText + ident.username + " <" + ident.address + ">";
Dean@159
   547
                        enc_status_data.strip.Items.Add(text, null, (x, y) => { undoHandshake(ident); });
Dean@159
   548
                    }
Dean@159
   549
                }
Dean@159
   550
            }
Dean@159
   551
        }
Dean@159
   552
vb@133
   553
        private void EncryptionStatus_Click(object sender, EventArgs e)
vb@133
   554
        {
vb@133
   555
            switch (enc_status)
vb@133
   556
            {
vb@133
   557
                case _pEp_color.pEp_rating_green:
vb@133
   558
                    try
vb@133
   559
                    {
dean@144
   560
                        string[] key_list = mailItem.Keylist;
vb@133
   561
                        if (key_list.Length > 0)
vb@133
   562
                        {
vb@133
   563
                            string msg;
vb@133
   564
                            if (key_list.Length > 1)
vb@133
   565
                                msg = String.Format(pEp.Properties.Resources.EncryptionStatusClickMessageMultiple + " {0}.", String.Join(", ", key_list));
vb@133
   566
                            else
vb@133
   567
                                msg = String.Format(pEp.Properties.Resources.EncryptionStatusClickMessageSingle + " {0}.", key_list[0]);
vb@133
   568
                            MessageBox.Show(msg, pEp.Properties.Resources.EncryptionStatusClickMessageBox, MessageBoxButtons.OK, MessageBoxIcon.Information);
vb@133
   569
                        }
vb@133
   570
                    }
vb@133
   571
                    catch (Exception ex)
vb@133
   572
                    {
vb@133
   573
                        StopHere(ex.ToString());
vb@133
   574
                    }
vb@133
   575
                    break;
vb@133
   576
vb@133
   577
                case _pEp_color.pEp_rating_yellow:
vb@133
   578
                    try
vb@133
   579
                    {
dean@144
   580
                        if (mailItem.IsIncoming)
vb@133
   581
                        {
vb@133
   582
                            pEp_identity_s identityPartner = new pEp_identity_s();
dean@144
   583
                            identityPartner.address = mailItem.FromAddress;
dean@144
   584
                            identityPartner.username = mailItem.FromUsername;
dean@144
   585
                            identityPartner.user_id = CryptableMailItem.GetUserIDFromAddress(identityPartner.address, identityPartner.username);
vb@139
   586
vb@133
   587
                            try
vb@133
   588
                            {
vb@133
   589
                                identityPartner = ThisAddIn.pEp.update_identity(identityPartner);
vb@133
   590
                            }
vb@133
   591
                            catch
vb@133
   592
                            {
vb@133
   593
                                enc_status = _pEp_color.pEp_rating_undefined;
vb@133
   594
                                return;
vb@133
   595
                            }
vb@133
   596
                            doHandshake(identityPartner);
vb@133
   597
                        }
vb@133
   598
                        else // outgoing
vb@133
   599
                        {
vb@139
   600
                            ThisAddIn.verbose("yellow, handshake initiated");
vb@139
   601
vb@133
   602
                            List<pEp_identity_s> partnersToCheck = new List<pEp_identity_s>();
vb@133
   603
dean@144
   604
                            foreach (pEp_identity_s identity in mailItem.Addresses)
vb@133
   605
                            {
vb@139
   606
                                ThisAddIn.verbose("adding " + identity.username + " <" + identity.address + ">");
vb@139
   607
vb@133
   608
                                try
vb@133
   609
                                {
vb@133
   610
                                    pEp_identity_s identityPartner = ThisAddIn.pEp.update_identity(identity);
vb@133
   611
                                    if (identityPartner.comm_type >= _pEp_comm_type.pEp_ct_unconfirmed_encryption
vb@133
   612
                                        && identityPartner.comm_type < _pEp_comm_type.pEp_ct_confirmed_encryption)
vb@133
   613
                                    {
vb@133
   614
                                        partnersToCheck.Add(identityPartner);
vb@133
   615
                                    }
vb@133
   616
                                }
vb@133
   617
                                catch
vb@133
   618
                                {
vb@133
   619
                                }
vb@133
   620
                            }
vb@133
   621
vb@133
   622
                            if (partnersToCheck.Count == 0)
vb@133
   623
                            {
vb@133
   624
                                enc_status = _pEp_color.pEp_rating_undefined;
vb@133
   625
                                return;
vb@133
   626
                            }
vb@133
   627
dean@144
   628
                            pEp_identity_s[] addresses = mailItem.Addresses;
vb@133
   629
vb@133
   630
                            if (addresses.Length == 1)
vb@133
   631
                            {
vb@133
   632
                                doHandshake(partnersToCheck[0]);
vb@133
   633
                            }
vb@133
   634
                            else if (addresses.Length > 1)
vb@133
   635
                            {
vb@133
   636
                                contextMenuHandshake.Items.Clear();
vb@133
   637
                                foreach (pEp_identity_s identity in partnersToCheck) {
vb@133
   638
                                    string text = identity.username + " <" + identity.address + ">";
vb@133
   639
                                    contextMenuHandshake.Items.Add(text, null, (x, y) => { doHandshake(identity); });
vb@133
   640
                                }
vb@133
   641
                                contextMenuHandshake.Show(EncryptionStatus, 10, 10);
vb@133
   642
                            }
vb@133
   643
                        }
vb@133
   644
                    }
vb@133
   645
                    catch (COMException ex)
vb@133
   646
                    {
vb@133
   647
                        StopHere(ex.ToString());
vb@133
   648
                    }
vb@133
   649
                    catch (Exception ex)
vb@133
   650
                    {
vb@133
   651
                        StopHere(ex.ToString());
vb@133
   652
                    }
vb@133
   653
                    break;
vb@133
   654
vb@133
   655
                case _pEp_color.pEp_rating_unencrypted:
dean@144
   656
                    if (mailItem.IsIncoming)
vb@133
   657
                    {
vb@133
   658
                        MessageBox.Show(pEp.Properties.Resources.RatingUnencryptedMessageboxReasonBody, pEp.Properties.Resources.RatingUnencryptedMessageboxReasonTitle);
vb@133
   659
                    }
vb@133
   660
                    else
vb@133
   661
                    {
vb@133
   662
                        try
vb@133
   663
                        {
vb@133
   664
                            string reason = "";
dean@144
   665
                            foreach (pEp_identity_s identity in mailItem.Addresses)
vb@133
   666
                            {
vb@133
   667
                                if (identity.comm_type < _pEp_comm_type.pEp_ct_security_by_obscurity)
vb@133
   668
                                {
vb@133
   669
                                    if (reason != "")
vb@133
   670
                                        reason += "\n";
vb@133
   671
                                    // BUG: reason string in English language only and trivial
vb@133
   672
                                    string ct = identity.comm_type.ToString();
vb@133
   673
                                    ct = new string(ct.Skip(7).ToArray());
vb@133
   674
                                    ct = ct.Replace("_", " ");
vb@133
   675
                                    reason += identity.username + " <" + identity.address + ">: " + ct;
vb@133
   676
                                }
vb@133
   677
                            }
vb@133
   678
                            if (reason != "")
vb@133
   679
                                MessageBox.Show(reason, pEp.Properties.Resources.RatingUnencryptedMessageboxReasonTitle);
vb@133
   680
                        }
vb@133
   681
                        catch (COMException ex)
vb@133
   682
                        {
vb@133
   683
                            StopHere(ex.ToString());
vb@133
   684
                        }
vb@133
   685
                    }
vb@133
   686
                    break;
vb@133
   687
vb@133
   688
                case _pEp_color.pEp_rating_cannot_decrypt:
vb@133
   689
                case _pEp_color.pEp_rating_have_no_key:
vb@133
   690
                    try
vb@133
   691
                    {
dean@144
   692
                        string[] keys = mailItem.Keylist;
vb@133
   693
vb@133
   694
                        if (keys.Length > 1)
vb@133
   695
                        {
vb@133
   696
                            string reason;
vb@133
   697
vb@133
   698
                            if (keys.Length == 2)
vb@133
   699
                                reason = pEp.Properties.Resources.RatingHavenokeyMessageboxReasonBodyNokey;
vb@133
   700
                            else
vb@133
   701
                                reason = string.Format(pEp.Properties.Resources.RatingHavenokeyMessageboxReasonBodySomekey, keys.Length - 1);
vb@133
   702
vb@133
   703
                            string keyinfo = "";
vb@133
   704
vb@133
   705
                            foreach (string key in keys)
vb@133
   706
                            {
vb@133
   707
                                if (key.Length >= 8)
vb@133
   708
                                    keyinfo += "\n" + key;
vb@133
   709
                            }
vb@133
   710
vb@133
   711
                            reason += keyinfo;
vb@133
   712
vb@133
   713
                            MessageBox.Show(reason, pEp.Properties.Resources.RatingHavenokeyTitle);
vb@133
   714
                        }
vb@133
   715
                        else if (keys.Length == 1)
vb@133
   716
                        {
vb@133
   717
                            MessageBox.Show(pEp.Properties.Resources.RatingHavenokeyMessageboxReasonError + keys[0], pEp.Properties.Resources.RatingHavenokeyTitle);
vb@133
   718
                        }
vb@133
   719
                        else
vb@133
   720
                        {
vb@133
   721
                            MessageBox.Show(pEp.Properties.Resources.RatingHavenokeyMessageboxReasonUnknownformat, pEp.Properties.Resources.RatingHavenokeyTitle);
vb@133
   722
                        }
vb@133
   723
                    }
vb@133
   724
                    catch (COMException ex)
vb@133
   725
                    {
vb@133
   726
                        StopHere(ex.ToString());
vb@133
   727
                    }
vb@133
   728
                    break;
vb@133
   729
                    
vb@133
   730
                case _pEp_color.pEp_rating_undefined:
vb@133
   731
                    if (mailItem != null)
vb@133
   732
                    {
dean@144
   733
                        enc_status = mailItem.ColorRating;
vb@133
   734
                    }
vb@133
   735
                    break;
vb@133
   736
            }
vb@133
   737
        }
vb@133
   738
vb@133
   739
        private void linkExplanation_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
vb@133
   740
        {
vb@133
   741
            if (enc_status == _pEp_color.pEp_rating_undefined)
vb@133
   742
            {
vb@133
   743
                enc_status_data.explanation = pEp.Properties.Resources.RatingUndefinedExplanation;
vb@133
   744
                enc_status_data.suggestion = pEp.Properties.Resources.RatingUndefinedSuggestion;
vb@133
   745
                enc_status_data.title = pEp.Properties.Resources.RatingUndefinedTitle;
Dean@162
   746
                enc_status_data.background = COLOR_GREY;
Dean@162
   747
                enc_status_data.foreground = TEXT_COLOR_BLACK;
vb@133
   748
                enc_status_data.button_text = pEp.Properties.Resources.RatingUndefinedButtontext;
vb@133
   749
                enc_status_data.strip = null;
vb@133
   750
            }
vb@133
   751
vb@133
   752
            var result = MessageBox.Show(
vb@133
   753
                            enc_status_data.explanation + "\n\n" + enc_status_data.suggestion,
vb@133
   754
                            enc_status_data.title,
vb@133
   755
                            MessageBoxButtons.OK,
vb@133
   756
                            enc_status == _pEp_color.pEp_rating_under_attack
vb@133
   757
                                ? MessageBoxIcon.Stop
vb@133
   758
                                : MessageBoxIcon.Information
vb@133
   759
                        );
vb@133
   760
        }
vb@133
   761
vb@133
   762
        private void timerRefresh_Tick(object sender, EventArgs e)
vb@133
   763
        {
vb@133
   764
            timerRefresh.Interval = 100;
vb@133
   765
            timerRefresh.Enabled = false; // only once
vb@133
   766
vb@133
   767
            if (!ThisAddIn.addIn.enabled)
vb@133
   768
                ThisAddIn.addIn.enable();
vb@133
   769
vb@133
   770
            makePreview();
vb@133
   771
vb@133
   772
            reset_enc_status();
vb@133
   773
        }
vb@133
   774
vb@133
   775
        private void EncryptionStatus_MouseUp(object sender, MouseEventArgs e)
vb@133
   776
        {
vb@133
   777
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
vb@133
   778
            {
vb@133
   779
                CryptableMailItem cmi = mailItem;
vb@133
   780
dean@144
   781
                if (cmi != null && !cmi.IsIncoming && !cmi.IsInSentFolder && cmi.OutgoingColor > _pEp_color.pEp_rating_unencrypted)
vb@133
   782
                {
dean@144
   783
                    if (cmi.SendUnencrypted == CheckState.Indeterminate)
vb@133
   784
                    {
vb@133
   785
                        sendUnencryptedToolStripMenuItem.CheckState = CheckState.Unchecked;
vb@133
   786
                    }
vb@133
   787
                    else {
dean@144
   788
                        sendUnencryptedToolStripMenuItem.CheckState = cmi.SendUnencrypted;
vb@133
   789
                    }
vb@133
   790
vb@133
   791
                    Control _sender = (Control)sender;
vb@133
   792
                    contextMenuEdit.Show(_sender.PointToScreen(e.Location));
vb@133
   793
                }
vb@133
   794
            }
vb@133
   795
        }
vb@133
   796
vb@133
   797
        private void sendUnencryptedToolStripMenuItem_Click(object sender, EventArgs e)
vb@133
   798
        {
vb@133
   799
            sendUnencryptedToolStripMenuItem.Checked = !sendUnencryptedToolStripMenuItem.Checked;
dean@144
   800
            mailItem.SendUnencrypted = sendUnencryptedToolStripMenuItem.CheckState;
vb@133
   801
            timerRefresh.Enabled = true;
vb@133
   802
        }
Dean@151
   803
Dean@151
   804
        /// <summary>
Dean@151
   805
        /// Event handler for when the options picture box is clicked.
Dean@151
   806
        /// This will open the options form for user editing.
Dean@151
   807
        /// </summary>
Dean@151
   808
        private void PictureBoxOptions_Click(object sender, EventArgs e)
Dean@151
   809
        {
Dean@159
   810
            DialogResult result;
Dean@152
   811
            FormOptions frm = new FormOptions();
Dean@154
   812
            frm.StartPosition = FormStartPosition.CenterScreen;
Dean@159
   813
            result = frm.ShowDialog(this.ParentForm); // Must show as dialog to block code
Dean@151
   814
Dean@154
   815
            if (ThisAddIn.addIn.use_keyserver)
Dean@154
   816
                ThisAddIn.pEp.start_keyserver_lookup();
Dean@154
   817
            else
Dean@154
   818
                ThisAddIn.pEp.stop_keyserver_lookup();
Dean@151
   819
Dean@151
   820
            return;
Dean@151
   821
        }
Dean@151
   822
Dean@151
   823
        /// <summary>
Dean@151
   824
        /// Event handler for when the mouse hovers over the options picture box.
Dean@151
   825
        /// This is a work-around to show a tool tip.
Dean@151
   826
        /// </summary>
Dean@151
   827
        private void PictureBoxOptions_MouseHover(object sender, EventArgs e)
Dean@151
   828
        {
Dean@151
   829
            ToolTip toolTip = new ToolTip();
Dean@151
   830
            toolTip.SetToolTip(this.PictureBoxOptions, "Click to open options");
Dean@151
   831
            return;
Dean@151
   832
        }
Dean@166
   833
Dean@166
   834
        /**************************************************************
Dean@166
   835
         * 
Dean@166
   836
         * Sub-classes
Dean@166
   837
         * 
Dean@166
   838
         *************************************************************/
Dean@166
   839
Dean@166
   840
        /// <summary>
Dean@166
   841
        /// Class used to store the state of the encryption status panel.
Dean@166
   842
        /// </summary>
Dean@166
   843
        public class State
Dean@166
   844
        {
Dean@166
   845
            private _pEp_color _EncryptionStatus;
Dean@166
   846
Dean@166
   847
            private string _Title;
Dean@166
   848
            private string _Explanation;
Dean@166
   849
            private string _Suggestion;
Dean@166
   850
            private Color  _ButtonBackground;
Dean@166
   851
            private Color  _ButtonForeground;
Dean@166
   852
            private string _ButtonText;
Dean@166
   853
Dean@166
   854
            /**************************************************************
Dean@166
   855
             * 
Dean@166
   856
             * Constructors
Dean@166
   857
             * 
Dean@166
   858
             *************************************************************/
Dean@166
   859
Dean@166
   860
            /// <summary>
Dean@166
   861
            /// Default constructor.
Dean@166
   862
            /// </summary>
Dean@166
   863
            public State()
Dean@166
   864
            {
Dean@166
   865
                this.Reset();
Dean@166
   866
            }
Dean@166
   867
Dean@166
   868
            /**************************************************************
Dean@166
   869
             * 
Dean@166
   870
             * Property Accessors
Dean@166
   871
             * 
Dean@166
   872
             *************************************************************/
Dean@166
   873
Dean@166
   874
            /// <summary>
Dean@166
   875
            /// Gets or sets the encryption status as a pEp color rating.
Dean@166
   876
            /// </summary>
Dean@166
   877
            public _pEp_color EncryptionStatus
Dean@166
   878
            {
Dean@166
   879
                get { return (this._EncryptionStatus); }
Dean@166
   880
                set 
Dean@166
   881
                { 
Dean@166
   882
                    this._EncryptionStatus = value;
Dean@166
   883
                    this.UpdateProperties();
Dean@166
   884
                }
Dean@166
   885
            }
Dean@166
   886
Dean@166
   887
            /// <summary>
Dean@166
   888
            /// Gets the title of the encryption status.
Dean@166
   889
            /// This is dependent on EncryptionStatus and therefore automatically set.
Dean@166
   890
            /// </summary>
Dean@166
   891
            public string Title
Dean@166
   892
            {
Dean@166
   893
                get { return (this._Title); }
Dean@166
   894
            }
Dean@166
   895
Dean@166
   896
            /// <summary>
Dean@166
   897
            /// Gets the explanation for the encryption status.
Dean@166
   898
            /// This is dependent on EncryptionStatus and therefore automatically set.
Dean@166
   899
            /// </summary>
Dean@166
   900
            public string Explanation
Dean@166
   901
            {
Dean@166
   902
                get { return (this._Explanation); }
Dean@166
   903
            }
Dean@166
   904
Dean@166
   905
            /// <summary>
Dean@166
   906
            /// Gets the suggestion to improve the encryption status.
Dean@166
   907
            /// This is dependent on EncryptionStatus and therefore automatically set.
Dean@166
   908
            /// </summary>
Dean@166
   909
            public string Suggestion
Dean@166
   910
            {
Dean@166
   911
                get { return (this._Suggestion); }
Dean@166
   912
            }
Dean@166
   913
Dean@166
   914
            /// <summary>
Dean@166
   915
            /// Gets the background color of the encryption button.
Dean@166
   916
            /// This is dependent on EncryptionStatus and therefore automatically set.
Dean@166
   917
            /// </summary>
Dean@166
   918
            public Color ButtonBackground
Dean@166
   919
            {
Dean@166
   920
                get { return (this._ButtonBackground); }
Dean@166
   921
            }
Dean@166
   922
Dean@166
   923
            /// <summary>
Dean@166
   924
            /// Gets the foreground color of the encryption button.
Dean@166
   925
            /// This is dependent on EncryptionStatus and therefore automatically set.
Dean@166
   926
            /// </summary>
Dean@166
   927
            public Color ButtonForeground
Dean@166
   928
            {
Dean@166
   929
                get { return (this._ButtonForeground); }
Dean@166
   930
            }
Dean@166
   931
Dean@166
   932
            /// <summary>
Dean@166
   933
            /// Gets the text of the encryption button.
Dean@166
   934
            /// This is dependent on EncryptionStatus and therefore automatically set.
Dean@166
   935
            /// </summary>
Dean@166
   936
            public string ButtonText
Dean@166
   937
            {
Dean@166
   938
                get { return (this._ButtonText); }
Dean@166
   939
            }
Dean@166
   940
Dean@166
   941
            /**************************************************************
Dean@166
   942
             * 
Dean@166
   943
             * Methods
Dean@166
   944
             * 
Dean@166
   945
             *************************************************************/
Dean@166
   946
Dean@166
   947
            /// <summary>
Dean@166
   948
            /// Resets the object to it's default values.
Dean@166
   949
            /// </summary>
Dean@166
   950
            public void Reset()
Dean@166
   951
            {
Dean@166
   952
                this._EncryptionStatus = _pEp_color.pEp_rating_undefined;
Dean@166
   953
                this.UpdateProperties();
Dean@166
   954
Dean@166
   955
                return;
Dean@166
   956
            }
Dean@166
   957
Dean@166
   958
            /// <summary>
Dean@166
   959
            /// Updates any properties dependent on the encryption status.
Dean@166
   960
            /// </summary>
Dean@166
   961
            private void UpdateProperties()
Dean@166
   962
            {
Dean@166
   963
                switch (this._EncryptionStatus)
Dean@166
   964
                {
Dean@166
   965
                    case _pEp_color.pEp_rating_trusted:
Dean@166
   966
                    case _pEp_color.pEp_rating_trusted_and_anonymized:
Dean@166
   967
                        this._Title       = pEp.Properties.Resources.RatingTrustedTitle;
Dean@166
   968
                        this._Explanation = pEp.Properties.Resources.RatingTrustedExplanation;
Dean@166
   969
                        this._Suggestion  = pEp.Properties.Resources.RatingTrustedSuggestion;
Dean@166
   970
                        
Dean@166
   971
                        this._ButtonBackground = COLOR_GREEN;
Dean@166
   972
                        this._ButtonForeground = TEXT_COLOR_WHITE;
Dean@166
   973
                        this._ButtonText       = pEp.Properties.Resources.RatingTrustedButtontext;
Dean@166
   974
                        break;
Dean@166
   975
Dean@166
   976
                    case _pEp_color.pEp_rating_reliable:
Dean@166
   977
                        this._Title       = pEp.Properties.Resources.RatingReliableTitle;
Dean@166
   978
                        this._Explanation = pEp.Properties.Resources.RatingReliableExplaination;
Dean@166
   979
                        this._Suggestion  = pEp.Properties.Resources.RatingReliableSuggestion;
Dean@166
   980
                        
Dean@166
   981
                        this._ButtonBackground = COLOR_YELLOW;
Dean@166
   982
                        this._ButtonForeground = TEXT_COLOR_BLACK;
Dean@166
   983
                        this._ButtonText       = pEp.Properties.Resources.RatingReliableButtontext;
Dean@166
   984
                        break;
Dean@166
   985
Dean@166
   986
                    case _pEp_color.pEp_rating_unreliable:
Dean@166
   987
                        this._Title       = pEp.Properties.Resources.RatingUnreliableTitle;
Dean@166
   988
                        this._Explanation = pEp.Properties.Resources.RatingUnreliableExplanation;
Dean@166
   989
                        this._Suggestion  = pEp.Properties.Resources.RatingUnreliableSuggestion;
Dean@166
   990
                        
Dean@166
   991
                        this._ButtonBackground = COLOR_GREY;
Dean@166
   992
                        this._ButtonForeground = TEXT_COLOR_BLACK;
Dean@166
   993
                        this._ButtonText       = pEp.Properties.Resources.RatingUnreliableButtontext;
Dean@166
   994
                        break;
Dean@166
   995
Dean@166
   996
                    case _pEp_color.pEp_rating_unencrypted:
Dean@166
   997
                        this._Title       = pEp.Properties.Resources.RatingUnencryptedTitle;
Dean@166
   998
                        this._Explanation = pEp.Properties.Resources.RatingUnencryptedExplanation;
Dean@166
   999
                        this._Suggestion  = pEp.Properties.Resources.RatingUnencryptedSuggestion;
Dean@166
  1000
                        
Dean@166
  1001
                        this._ButtonBackground = COLOR_GREY;
Dean@166
  1002
                        this._ButtonForeground = TEXT_COLOR_BLACK;
Dean@166
  1003
                        this._ButtonText       = pEp.Properties.Resources.RatingUnencryptedButtontext;
Dean@166
  1004
                        break;
Dean@166
  1005
Dean@166
  1006
                    case _pEp_color.pEp_rating_under_attack:
Dean@166
  1007
                        this._Title       = pEp.Properties.Resources.RatingUnderattackTitle;
Dean@166
  1008
                        this._Explanation = pEp.Properties.Resources.RatingUnderattackExplanation;
Dean@166
  1009
                        this._Suggestion  = pEp.Properties.Resources.RatingUnderattackSuggestion;
Dean@166
  1010
                        
Dean@166
  1011
                        this._ButtonBackground = COLOR_RED;
Dean@166
  1012
                        this._ButtonForeground = TEXT_COLOR_WHITE;
Dean@166
  1013
                        this._ButtonText       = pEp.Properties.Resources.RatingUnderattackButtontext;
Dean@166
  1014
                        break;
Dean@166
  1015
Dean@166
  1016
                    case _pEp_color.pEp_rating_undefined:
Dean@166
  1017
                        this._Title       = pEp.Properties.Resources.RatingUndefinedTitle;
Dean@166
  1018
                        this._Explanation = pEp.Properties.Resources.RatingUndefinedExplanation;
Dean@166
  1019
                        this._Suggestion  = pEp.Properties.Resources.RatingUndefinedSuggestion;
Dean@166
  1020
                        
Dean@166
  1021
                        this._ButtonBackground = COLOR_GREY;
Dean@166
  1022
                        this._ButtonForeground = TEXT_COLOR_BLACK;
Dean@166
  1023
                        this._ButtonText       = pEp.Properties.Resources.RatingUndefinedButtontext;
Dean@166
  1024
                        break;
Dean@166
  1025
Dean@166
  1026
                    case _pEp_color.pEp_rating_cannot_decrypt:
Dean@166
  1027
                    case _pEp_color.pEp_rating_have_no_key:
Dean@166
  1028
                        this._Title       = pEp.Properties.Resources.RatingHavenokeyTitle;
Dean@166
  1029
                        this._Explanation = pEp.Properties.Resources.RatingHavenokeyExplanation;
Dean@166
  1030
                        this._Suggestion  = pEp.Properties.Resources.RatingHavenokeySuggestion;
Dean@166
  1031
                        
Dean@166
  1032
                        this._ButtonBackground = COLOR_GREY;
Dean@166
  1033
                        this._ButtonForeground = TEXT_COLOR_BLACK;
Dean@166
  1034
                        this._ButtonText       = pEp.Properties.Resources.RatingHavenokeyButtontext;
Dean@166
  1035
                        break;
Dean@166
  1036
Dean@166
  1037
                    default:
Dean@166
  1038
                        this._Title       = "";
Dean@166
  1039
                        this._Explanation = "";
Dean@166
  1040
                        this._Suggestion  = "";
Dean@166
  1041
                        
Dean@166
  1042
                        this._ButtonBackground = COLOR_GREY;
Dean@166
  1043
                        this._ButtonForeground = TEXT_COLOR_BLACK;
Dean@166
  1044
                        this._ButtonText       = "";
Dean@166
  1045
                        break;
Dean@166
  1046
                }
Dean@166
  1047
Dean@166
  1048
                return;
Dean@166
  1049
            }
Dean@166
  1050
Dean@166
  1051
        }
vb@133
  1052
    }
vb@133
  1053
}