EncryptionStatusPanel.cs
author Volker Birk <vb@pep-project.org>
Tue, 13 Oct 2015 20:31:26 +0200
changeset 133 214f4dc9e2c8
parent 132 f0c74e2c6dfb
child 136 34e41293d3b0
permissions -rw-r--r--
coloring new
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
     1
´╗┐using System;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
     2
using System.Collections;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
     3
using System.Collections.Generic;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
     4
using System.Linq;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
     5
using System.Text;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
     6
using System.IO;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
     7
using System.Windows.Forms;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
     8
using System.Threading;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
     9
using System.Runtime.InteropServices;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    10
using Office = Microsoft.Office.Core;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    11
using Outlook = Microsoft.Office.Interop.Outlook;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    12
using MessageBox = System.Windows.Forms.MessageBox;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    13
using MessageBoxButtons = System.Windows.Forms.MessageBoxButtons;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    14
using MessageBoxIcon = System.Windows.Forms.MessageBoxIcon;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    15
using Color = System.Drawing.Color;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    16
using pEpCOMServerAdapterLib;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    17
using System.Diagnostics;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    18
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    19
namespace pEp
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    20
{
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    21
    partial class EncryptionStatusPanel
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    22
    {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    23
        #region Form Region Factory
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    24
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    25
        [Microsoft.Office.Tools.Outlook.FormRegionMessageClass(Microsoft.Office.Tools.Outlook.FormRegionMessageClassAttribute.Note)]
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    26
        [Microsoft.Office.Tools.Outlook.FormRegionName("pEp.FormRegion1")]
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    27
        public partial class FormRegion1Factory
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    28
        {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    29
            // Occurs before the form region is initialized.
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    30
            // To prevent the form region from appearing, set e.Cancel to true.
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    31
            // Use e.OutlookItem to get a reference to the current Outlook item.
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    32
            private void FormRegion1Factory_FormRegionInitializing(object sender, Microsoft.Office.Tools.Outlook.FormRegionInitializingEventArgs e)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    33
            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    34
            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    35
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    36
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    37
        #endregion
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    38
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    39
        static void StopHere(string reason)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    40
        {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    41
#if DEBUG
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    42
            MessageBox.Show(reason);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    43
#else
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    44
            try
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    45
            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    46
                ThisAddIn.pEp.log("internal error", "pEp for Outlook", reason, "in EncryptionStatusPanel.cs");
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    47
            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    48
            catch (COMException) { }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    49
            catch (Exception) { }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    50
#endif
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    51
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    52
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    53
        private CryptableMailItem _mailItem = null;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    54
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    55
        CryptableMailItem mailItem
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    56
        {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    57
            get
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    58
            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    59
                try
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    60
                {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    61
                    if (this.OutlookItem == null)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    62
                    {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    63
                        _mailItem = null;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    64
                        return null;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    65
                    }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    66
                }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    67
                catch (COMException)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    68
                {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    69
                    return null;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    70
                }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    71
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    72
                Outlook.MailItem omi = null;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    73
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    74
                try
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    75
                {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    76
                    omi = (Outlook.MailItem)this.OutlookItem;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    77
                }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    78
                catch
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    79
                {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    80
                    _mailItem = null;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    81
                    return null;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    82
                }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    83
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    84
                Outlook.MAPIFolder folder = omi.Parent;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    85
                if (folder.EntryID == folder.Store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDeletedItems).EntryID)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    86
                {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    87
                    _mailItem = null;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    88
                    return null;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    89
                }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    90
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    91
                if (_mailItem == null) {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    92
                    _mailItem = new CryptableMailItem(omi);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    93
                }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    94
                else
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    95
                {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    96
                    if (_mailItem.EntryID != omi.EntryID)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    97
                    {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    98
                        _mailItem = new CryptableMailItem(omi);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
    99
                    }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   100
                }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   101
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   102
                return _mailItem;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   103
            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   104
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   105
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   106
        // Occurs before the form region is displayed.
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   107
        // Use this.OutlookItem to get a reference to the current Outlook item.
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   108
        // Use this.OutlookFormRegion to get a reference to the form region.
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   109
        private void FormRegion1_FormRegionShowing(object sender, System.EventArgs e)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   110
        {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   111
            if (this.OutlookItem == null)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   112
            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   113
                enc_status = _pEp_color.pEp_rating_undefined;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   114
            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   115
            else
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   116
            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   117
                Outlook.MailItem omi = (Outlook.MailItem)this.OutlookItem;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   118
                try
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   119
                {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   120
                    omi.PropertyChange += mailItem_PropertyChange;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   121
                    if (CryptableMailItem.is_encrypted_store(omi))
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   122
                    {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   123
                        if (PreviewUnencrypted.isPGPEncrypted(omi) && omi.Sender != null)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   124
                        {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   125
                            omi.Open += omi_Open;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   126
                        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   127
                    }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   128
                }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   129
                catch { }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   130
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   131
                if (ThisAddIn.addIn.enabled)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   132
                {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   133
                    reset_enc_status();
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   134
                }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   135
                else
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   136
                {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   137
                    timerRefresh.Enabled = true;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   138
                }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   139
            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   140
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   141
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   142
        void omi_Open(ref bool Cancel)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   143
        {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   144
            if (mailItem != null && _mailItem.DisplayMirror())
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   145
                Cancel = true;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   146
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   147
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   148
        private bool in_reset = false;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   149
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   150
        protected void makePreview()
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   151
        {
130
df48305bff34 crash prevention
Volker Birk <vb@pep-project.org>
parents: 126
diff changeset
   152
            WindowFormRegionCollection formRegions;
df48305bff34 crash prevention
Volker Birk <vb@pep-project.org>
parents: 126
diff changeset
   153
df48305bff34 crash prevention
Volker Birk <vb@pep-project.org>
parents: 126
diff changeset
   154
            if (Globals.ThisAddIn.Application.ActiveInspector() != null)
df48305bff34 crash prevention
Volker Birk <vb@pep-project.org>
parents: 126
diff changeset
   155
                return;
df48305bff34 crash prevention
Volker Birk <vb@pep-project.org>
parents: 126
diff changeset
   156
            else if (Globals.ThisAddIn.Application.ActiveExplorer() != null)
df48305bff34 crash prevention
Volker Birk <vb@pep-project.org>
parents: 126
diff changeset
   157
                formRegions = Globals.FormRegions[Globals.ThisAddIn.Application.ActiveExplorer()];
df48305bff34 crash prevention
Volker Birk <vb@pep-project.org>
parents: 126
diff changeset
   158
            else
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   159
                return;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   160
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   161
            try
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   162
            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   163
                if (formRegions.PreviewUnencrypted.Visible)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   164
                {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   165
                    byte[] rtf = mailItem.getMirrorRTFBody();
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   166
                    formRegions.PreviewUnencrypted.textPreview.Rtf = System.Text.Encoding.ASCII.GetString(rtf, 0, rtf.Length);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   167
                    formRegions.PreviewUnencrypted.textSubject.Text = mailItem.getMirrorSubject();
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   168
                    formRegions.PreviewUnencrypted.textFrom.Text = mailItem.from_username + " <" + mailItem.from_address + ">";
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   169
                }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   170
            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   171
            catch { }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   172
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   173
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   174
        protected void reset_enc_status()
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   175
        {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   176
            if (in_reset)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   177
                return;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   178
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   179
            in_reset = true;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   180
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   181
            if (mailItem != null)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   182
            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   183
                if (_mailItem.DownloadState == Outlook.OlDownloadState.olFullItem)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   184
                {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   185
                    if (_mailItem.send_unencrypted == CheckState.Checked)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   186
                    {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   187
                        enc_status = _pEp_color.pEp_rating_unencrypted;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   188
                    }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   189
                    else
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   190
                    {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   191
                        ThisAddIn.verbose("get_color in reset_enc_status");
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   192
                        enc_status = _mailItem.color;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   193
                    }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   194
                }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   195
                else
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   196
                {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   197
                    _mailItem.MarkForDownload = Outlook.OlRemoteStatus.olMarkedForDownload;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   198
                    timerRefresh.Interval = 500;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   199
                    timerRefresh.Enabled = true;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   200
                }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   201
            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   202
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   203
            in_reset = false;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   204
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   205
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   206
        void mailItem_PropertyChange(string Name)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   207
        {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   208
            switch (Name)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   209
            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   210
                case "To":
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   211
                    timerRefresh.Enabled = true;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   212
                    break;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   213
                // Outlook bug: there are always both events, so one is enough
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   214
                //case "CC":
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   215
                //    reset_enc_status();
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   216
                //    break;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   217
            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   218
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   219
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   220
        // Occurs when the form region is closed.
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   221
        // Use this.OutlookItem to get a reference to the current Outlook item.
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   222
        // Use this.OutlookFormRegion to get a reference to the form region.
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   223
        private void FormRegion1_FormRegionClosed(object sender, System.EventArgs e)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   224
        {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   225
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   226
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   227
        private struct EncStatusData
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   228
        {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   229
            public string title;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   230
            public string explanation;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   231
            public string suggestion;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   232
            public Color background;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   233
            public Color foreground;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   234
            public string button_text;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   235
            public ContextMenuStrip strip;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   236
        };
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   237
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   238
        private EncStatusData enc_status_data;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   239
        private _pEp_color _enc_status;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   240
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   241
        public _pEp_color enc_status {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   242
            get
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   243
            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   244
                return _enc_status;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   245
            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   246
            set
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   247
            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   248
                if (value != _enc_status)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   249
                {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   250
                    _enc_status = value;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   251
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   252
                    switch (value)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   253
                    {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   254
                        case _pEp_color.pEp_rating_trusted:
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   255
                        case _pEp_color.pEp_rating_trusted_and_anonymized:
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   256
                            enc_status_data.explanation = pEp.Properties.Resources.RatingTrustedExplanation;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   257
                            enc_status_data.suggestion = pEp.Properties.Resources.RatingTrustedSuggestion;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   258
                            enc_status_data.title = pEp.Properties.Resources.RatingTrustedTitle;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   259
                            enc_status_data.background = Color.Green;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   260
                            enc_status_data.foreground = Color.White;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   261
                            enc_status_data.button_text = pEp.Properties.Resources.RatingTrustedButtontext;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   262
                            enc_status_data.strip = new ContextMenuStrip();
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   263
                            enc_status_data.strip.Items.Add("");
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   264
                            enc_status_data.strip.Opening += secure_strip_Opening;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   265
                            break;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   266
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   267
                        case _pEp_color.pEp_rating_reliable:
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   268
                            enc_status_data.explanation = pEp.Properties.Resources.RatingReliableExplaination;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   269
                            enc_status_data.suggestion = pEp.Properties.Resources.RatingReliableSuggestion;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   270
                            enc_status_data.title = pEp.Properties.Resources.RatingReliableTitle;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   271
                            enc_status_data.background = Color.Gold;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   272
                            enc_status_data.foreground = Color.Black;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   273
                            enc_status_data.button_text = pEp.Properties.Resources.RatingReliableButtontext;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   274
                            enc_status_data.strip = null;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   275
                            break;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   276
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   277
                        case _pEp_color.pEp_rating_unreliable:
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   278
                            enc_status_data.explanation = pEp.Properties.Resources.RatingUnreliableExplanation;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   279
                            enc_status_data.suggestion = pEp.Properties.Resources.RatingUnreliableSuggestion;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   280
                            enc_status_data.title = pEp.Properties.Resources.RatingUnreliableTitle;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   281
                            enc_status_data.background = Color.Gainsboro;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   282
                            enc_status_data.foreground = Color.Black;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   283
                            enc_status_data.button_text = pEp.Properties.Resources.RatingUnreliableButtontext;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   284
                            enc_status_data.strip = null;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   285
                            break;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   286
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   287
                        case _pEp_color.pEp_rating_unencrypted:
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   288
                            enc_status_data.explanation = pEp.Properties.Resources.RatingUnencryptedExplanation;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   289
                            enc_status_data.suggestion = pEp.Properties.Resources.RatingUnencryptedSuggestion;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   290
                            enc_status_data.title = pEp.Properties.Resources.RatingUnencryptedTitle;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   291
                            enc_status_data.background = Color.Gainsboro;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   292
                            enc_status_data.foreground = Color.Black;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   293
                            enc_status_data.button_text = pEp.Properties.Resources.RatingUnencryptedButtontext;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   294
                            enc_status_data.strip = null;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   295
                            break;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   296
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   297
                        case _pEp_color.pEp_rating_under_attack:
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   298
                            enc_status_data.explanation = pEp.Properties.Resources.RatingUnderattackExplanation;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   299
                            enc_status_data.suggestion = pEp.Properties.Resources.RatingUnderattackSuggestion;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   300
                            enc_status_data.title = pEp.Properties.Resources.RatingUnderattackTitle;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   301
                            enc_status_data.background = Color.Red;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   302
                            enc_status_data.foreground = Color.White;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   303
                            enc_status_data.button_text = pEp.Properties.Resources.RatingUnderattackButtontext;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   304
                            enc_status_data.strip = null;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   305
                            break;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   306
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   307
                        case _pEp_color.pEp_rating_undefined:
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   308
                            // will not happen
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   309
                            enc_status_data.explanation = pEp.Properties.Resources.RatingUndefinedExplanation;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   310
                            enc_status_data.suggestion = pEp.Properties.Resources.RatingUndefinedSuggestion;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   311
                            enc_status_data.title = pEp.Properties.Resources.RatingUndefinedTitle;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   312
                            enc_status_data.background = Color.Gainsboro;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   313
                            enc_status_data.foreground = Color.Black;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   314
                            enc_status_data.button_text = pEp.Properties.Resources.RatingUndefinedButtontext;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   315
                            enc_status_data.strip = null;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   316
                            break;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   317
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   318
                        case _pEp_color.pEp_rating_cannot_decrypt:
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   319
                        case _pEp_color.pEp_rating_have_no_key:
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   320
                            enc_status_data.explanation = pEp.Properties.Resources.RatingHavenokeyExplanation;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   321
                            enc_status_data.suggestion = pEp.Properties.Resources.RatingHavenokeySuggestion;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   322
                            enc_status_data.title = pEp.Properties.Resources.RatingHavenokeyTitle;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   323
                            enc_status_data.background = Color.Gainsboro;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   324
                            enc_status_data.foreground = Color.Black;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   325
                            enc_status_data.button_text = pEp.Properties.Resources.RatingHavenokeyButtontext;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   326
                            enc_status_data.strip = null;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   327
                            break;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   328
                    }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   329
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   330
                    linkExplanation.Text = enc_status_data.title;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   331
                    EncryptionStatus.BackColor = enc_status_data.background;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   332
                    EncryptionStatus.ForeColor = enc_status_data.foreground;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   333
                    EncryptionStatus.Text = enc_status_data.button_text;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   334
                    EncryptionStatus.ContextMenuStrip = enc_status_data.strip;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   335
                }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   336
            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   337
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   338
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   339
        void secure_strip_Opening(object sender, System.ComponentModel.CancelEventArgs e)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   340
        {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   341
            enc_status_data.strip.Items.Clear();
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   342
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   343
            if (mailItem.incoming)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   344
            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   345
                pEp_identity_s ident = new pEp_identity_s();
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   346
                ident.address = mailItem.from_address;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   347
                ident = ThisAddIn.pEp.update_identity(ident);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   348
                string text = pEp.Properties.Resources.IdentityTrustText + ident.username + " <" + ident.address + ">";
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   349
                enc_status_data.strip.Items.Add(text, null, (x, y) => { undoHandshake(ident); });
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   350
            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   351
            else
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   352
            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   353
                foreach (pEp_identity_s ident in mailItem.addresses)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   354
                {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   355
                    pEp_identity_s identityPartner = ThisAddIn.pEp.update_identity(ident);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   356
                    if (identityPartner.comm_type >= _pEp_comm_type.pEp_ct_confirmed_encryption)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   357
                    {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   358
                        string text = pEp.Properties.Resources.IdentityTrustText + ident.username + " <" + ident.address + ">";
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   359
                        enc_status_data.strip.Items.Add(text, null, (x, y) => { undoHandshake(ident); });
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   360
                    }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   361
                }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   362
            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   363
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   364
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   365
        public static string quadruple(string text)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   366
        {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   367
            List<string> result = new List<string>();
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   368
            for (int i=0; i<text.Length; i+=4)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   369
            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   370
                try
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   371
                {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   372
                    result.Add(text.Substring(i, 4));
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   373
                }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   374
                catch (ArgumentOutOfRangeException)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   375
                {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   376
                    result.Add(text.Substring(i));
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   377
                    break;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   378
                }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   379
            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   380
            return String.Join(" ", result);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   381
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   382
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   383
        private void doHandshake(pEp_identity_s identityPartner)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   384
        {
132
f0c74e2c6dfb review of mailItem handling
Volker Birk <vb@pep-project.org>
parents: 131
diff changeset
   385
            Debug.Assert(mailItem.color == _pEp_color.pEp_rating_yellow);
f0c74e2c6dfb review of mailItem handling
Volker Birk <vb@pep-project.org>
parents: 131
diff changeset
   386
f0c74e2c6dfb review of mailItem handling
Volker Birk <vb@pep-project.org>
parents: 131
diff changeset
   387
            if (identityPartner.username == "")
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   388
                identityPartner.username = identityPartner.address;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   389
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   390
            identityPartner.user_id = CryptableMailItem.user_id_from_address(identityPartner.address, identityPartner.username);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   391
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   392
            Handshake handshakeDialog = new Handshake();
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   393
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   394
            TextBox txtOwnTrustwordsShort = (TextBox)handshakeDialog.Controls.Find("txtOwnTrustwordsShort", true).First();
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   395
            TextBox txtOwnTrustwordsFull = (TextBox)handshakeDialog.Controls.Find("txtOwnTrustwordsFull", true).First();
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   396
            TextBox txtOwnFpr = (TextBox)handshakeDialog.Controls.Find("txtOwnFpr", true).First();
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   397
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   398
            pEp_identity_s me;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   399
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   400
            if (mailItem.incoming)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   401
            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   402
                string entryID = mailItem.recieved_by;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   403
                string address = "";
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   404
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   405
                foreach (Outlook.Account a in ThisAddIn.addIn.Application.Session.Accounts){
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   406
                    if (a.CurrentUser.EntryID == entryID) {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   407
                        address = a.SmtpAddress;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   408
                        break;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   409
                    }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   410
                }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   411
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   412
                if (address == "")
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   413
                    address = ThisAddIn.addIn.Application.Session.Accounts[1].SmtpAddress;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   414
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   415
                me = ThisAddIn.addIn.mySelf(address);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   416
            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   417
            else // outgoing
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   418
            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   419
                me = ThisAddIn.addIn.mySelf(mailItem.from_address);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   420
            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   421
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   422
            string own_short = ThisAddIn.pEp.trustwords(me.fpr, max_words: 5).ToLower();
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   423
            string own_long = ThisAddIn.pEp.trustwords(me.fpr).ToLower();
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   424
            string own_fpr = quadruple(me.fpr);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   425
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   426
            string partner_short = ThisAddIn.pEp.trustwords(identityPartner.fpr, max_words: 5).ToLower();
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   427
            string partner_long = ThisAddIn.pEp.trustwords(identityPartner.fpr).ToLower();
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   428
            string partner_fpr = quadruple(identityPartner.fpr);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   429
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   430
            if (own_fpr.CompareTo(partner_fpr) > 0)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   431
            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   432
                txtOwnTrustwordsShort.Text = partner_short + own_short;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   433
                txtOwnTrustwordsFull.Text = partner_long + own_long;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   434
                string[] lines = new string[3];
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   435
                lines[0] = pEp.Properties.Resources.TrustwordsPartnershortPartner + partner_fpr;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   436
                lines[2] = pEp.Properties.Resources.TrustwordsPartnershortMyself + own_fpr;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   437
                txtOwnFpr.Lines = lines;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   438
            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   439
            else
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   440
            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   441
                txtOwnTrustwordsShort.Text = own_short + " " + partner_short;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   442
                txtOwnTrustwordsFull.Text = own_long + " " + partner_long;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   443
                string[] lines = new string[3];
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   444
                lines[0] = pEp.Properties.Resources.TrustwordsOwnshortMyself + own_fpr;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   445
                lines[2] = pEp.Properties.Resources.TrustwordsOwnshortPartner + partner_fpr;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   446
                txtOwnFpr.Lines = lines;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   447
            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   448
132
f0c74e2c6dfb review of mailItem handling
Volker Birk <vb@pep-project.org>
parents: 131
diff changeset
   449
            DialogResult result = handshakeDialog.ShowDialog(this);
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   450
            ThisAddIn.verbose("handshakeDialog.ShowDialog(this) => " + result.ToString());
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   451
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   452
            switch (result)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   453
            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   454
                case DialogResult.Yes:
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   455
                    mailItem.color = _pEp_color.pEp_rating_trusted;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   456
                    MessageBox.Show("user_id => " + identityPartner.user_id);
132
f0c74e2c6dfb review of mailItem handling
Volker Birk <vb@pep-project.org>
parents: 131
diff changeset
   457
                    identityPartner = ThisAddIn.pEp.trust_personal_key(identityPartner);
133
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   458
                    reset_enc_status(); 
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   459
                    break;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   460
                case DialogResult.No:
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   461
                    ThisAddIn.pEp.key_compromized(identityPartner);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   462
                    identityPartner.comm_type = _pEp_comm_type.pEp_ct_compromized;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   463
                    mailItem.color = _pEp_color.pEp_rating_red;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   464
                    reset_enc_status(); 
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   465
                    break;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   466
            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   467
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   468
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   469
        void btnConfirm_Click(object sender, EventArgs e)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   470
        {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   471
            Button btn = (Button)sender;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   472
            TabControl tc = (TabControl)btn.Parent.Parent.Parent;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   473
            tc.SelectedIndex = 1;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   474
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   475
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   476
        private void undoHandshake(pEp_identity_s identityPartner)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   477
        {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   478
            ThisAddIn.pEp.update_identity(identityPartner);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   479
//            Debug.Assert((identityPartner.comm_type & _pEp_comm_type.pEp_ct_confirmed) != _pEp_comm_type.pEp_ct_unknown);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   480
            identityPartner.comm_type ^= _pEp_comm_type.pEp_ct_confirmed;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   481
            ThisAddIn.pEp.update_identity(identityPartner);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   482
            reset_enc_status();
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   483
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   484
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   485
        private void EncryptionStatus_Click(object sender, EventArgs e)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   486
        {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   487
            switch (enc_status)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   488
            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   489
                case _pEp_color.pEp_rating_green:
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   490
                    try
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   491
                    {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   492
                        string[] key_list = mailItem.keylist;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   493
                        if (key_list.Length > 0)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   494
                        {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   495
                            string msg;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   496
                            if (key_list.Length > 1)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   497
                                msg = String.Format(pEp.Properties.Resources.EncryptionStatusClickMessageMultiple + " {0}.", String.Join(", ", key_list));
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   498
                            else
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   499
                                msg = String.Format(pEp.Properties.Resources.EncryptionStatusClickMessageSingle + " {0}.", key_list[0]);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   500
                            MessageBox.Show(msg, pEp.Properties.Resources.EncryptionStatusClickMessageBox, MessageBoxButtons.OK, MessageBoxIcon.Information);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   501
                        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   502
                    }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   503
                    catch (Exception ex)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   504
                    {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   505
                        StopHere(ex.ToString());
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   506
                    }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   507
                    break;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   508
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   509
                case _pEp_color.pEp_rating_yellow:
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   510
                    try
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   511
                    {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   512
                        if (mailItem.incoming)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   513
                        {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   514
                            pEp_identity_s identityPartner = new pEp_identity_s();
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   515
                            identityPartner.address = mailItem.from_address;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   516
                            identityPartner.username = mailItem.from_username;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   517
                            try
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   518
                            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   519
                                identityPartner = ThisAddIn.pEp.update_identity(identityPartner);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   520
                            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   521
                            catch
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   522
                            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   523
                                enc_status = _pEp_color.pEp_rating_undefined;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   524
                                return;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   525
                            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   526
                            doHandshake(identityPartner);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   527
                        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   528
                        else // outgoing
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   529
                        {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   530
                            List<pEp_identity_s> partnersToCheck = new List<pEp_identity_s>();
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   531
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   532
                            foreach (pEp_identity_s identity in mailItem.addresses)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   533
                            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   534
                                try
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   535
                                {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   536
                                    pEp_identity_s identityPartner = ThisAddIn.pEp.update_identity(identity);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   537
                                    if (identityPartner.comm_type >= _pEp_comm_type.pEp_ct_unconfirmed_encryption
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   538
                                        && identityPartner.comm_type < _pEp_comm_type.pEp_ct_confirmed_encryption)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   539
                                    {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   540
                                        partnersToCheck.Add(identityPartner);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   541
                                    }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   542
                                }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   543
                                catch
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   544
                                {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   545
                                }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   546
                            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   547
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   548
                            if (partnersToCheck.Count == 0)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   549
                            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   550
                                enc_status = _pEp_color.pEp_rating_undefined;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   551
                                return;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   552
                            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   553
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   554
                            pEp_identity_s[] addresses = mailItem.addresses;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   555
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   556
                            if (addresses.Length == 1)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   557
                            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   558
                                doHandshake(partnersToCheck[0]);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   559
                            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   560
                            else if (addresses.Length > 1)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   561
                            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   562
                                contextMenuHandshake.Items.Clear();
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   563
                                foreach (pEp_identity_s identity in partnersToCheck) {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   564
                                    string text = identity.username + " <" + identity.address + ">";
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   565
                                    contextMenuHandshake.Items.Add(text, null, (x, y) => { doHandshake(identity); });
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   566
                                }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   567
                                contextMenuHandshake.Show(EncryptionStatus, 10, 10);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   568
                            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   569
                        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   570
                    }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   571
                    catch (COMException ex)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   572
                    {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   573
                        StopHere(ex.ToString());
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   574
                    }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   575
                    catch (Exception ex)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   576
                    {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   577
                        StopHere(ex.ToString());
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   578
                    }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   579
                    break;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   580
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   581
                case _pEp_color.pEp_rating_unencrypted:
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   582
                    if (mailItem.incoming)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   583
                    {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   584
                        MessageBox.Show(pEp.Properties.Resources.RatingUnencryptedMessageboxReasonBody, pEp.Properties.Resources.RatingUnencryptedMessageboxReasonTitle);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   585
                    }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   586
                    else
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   587
                    {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   588
                        try
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   589
                        {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   590
                            string reason = "";
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   591
                            foreach (pEp_identity_s identity in mailItem.addresses)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   592
                            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   593
                                if (identity.comm_type < _pEp_comm_type.pEp_ct_security_by_obscurity)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   594
                                {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   595
                                    if (reason != "")
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   596
                                        reason += "\n";
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   597
                                    // BUG: reason string in English language only and trivial
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   598
                                    string ct = identity.comm_type.ToString();
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   599
                                    ct = new string(ct.Skip(7).ToArray());
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   600
                                    ct = ct.Replace("_", " ");
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   601
                                    reason += identity.username + " <" + identity.address + ">: " + ct;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   602
                                }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   603
                            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   604
                            if (reason != "")
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   605
                                MessageBox.Show(reason, pEp.Properties.Resources.RatingUnencryptedMessageboxReasonTitle);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   606
                        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   607
                        catch (COMException ex)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   608
                        {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   609
                            StopHere(ex.ToString());
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   610
                        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   611
                    }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   612
                    break;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   613
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   614
                case _pEp_color.pEp_rating_cannot_decrypt:
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   615
                case _pEp_color.pEp_rating_have_no_key:
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   616
                    try
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   617
                    {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   618
                        string[] keys = mailItem.keylist;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   619
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   620
                        if (keys.Length > 1)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   621
                        {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   622
                            string reason;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   623
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   624
                            if (keys.Length == 2)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   625
                                reason = pEp.Properties.Resources.RatingHavenokeyMessageboxReasonBodyNokey;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   626
                            else
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   627
                                reason = string.Format(pEp.Properties.Resources.RatingHavenokeyMessageboxReasonBodySomekey, keys.Length - 1);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   628
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   629
                            string keyinfo = "";
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   630
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   631
                            foreach (string key in keys)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   632
                            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   633
                                if (key.Length >= 8)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   634
                                    keyinfo += "\n" + key;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   635
                            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   636
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   637
                            reason += keyinfo;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   638
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   639
                            MessageBox.Show(reason, pEp.Properties.Resources.RatingHavenokeyTitle);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   640
                        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   641
                        else if (keys.Length == 1)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   642
                        {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   643
                            MessageBox.Show(pEp.Properties.Resources.RatingHavenokeyMessageboxReasonError + keys[0], pEp.Properties.Resources.RatingHavenokeyTitle);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   644
                        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   645
                        else
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   646
                        {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   647
                            MessageBox.Show(pEp.Properties.Resources.RatingHavenokeyMessageboxReasonUnknownformat, pEp.Properties.Resources.RatingHavenokeyTitle);
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   648
                        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   649
                    }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   650
                    catch (COMException ex)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   651
                    {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   652
                        StopHere(ex.ToString());
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   653
                    }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   654
                    break;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   655
                    
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   656
                case _pEp_color.pEp_rating_undefined:
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   657
                    if (mailItem != null)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   658
                    {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   659
                        enc_status = mailItem.color;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   660
                    }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   661
                    break;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   662
            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   663
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   664
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   665
        private void linkExplanation_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   666
        {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   667
            if (enc_status == _pEp_color.pEp_rating_undefined)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   668
            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   669
                enc_status_data.explanation = pEp.Properties.Resources.RatingUndefinedExplanation;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   670
                enc_status_data.suggestion = pEp.Properties.Resources.RatingUndefinedSuggestion;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   671
                enc_status_data.title = pEp.Properties.Resources.RatingUndefinedTitle;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   672
                enc_status_data.background = Color.Gainsboro;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   673
                enc_status_data.foreground = Color.Black;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   674
                enc_status_data.button_text = pEp.Properties.Resources.RatingUndefinedButtontext;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   675
                enc_status_data.strip = null;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   676
            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   677
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   678
            var result = MessageBox.Show(
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   679
                            enc_status_data.explanation + "\n\n" + enc_status_data.suggestion,
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   680
                            enc_status_data.title,
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   681
                            MessageBoxButtons.OK,
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   682
                            enc_status == _pEp_color.pEp_rating_under_attack
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   683
                                ? MessageBoxIcon.Stop
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   684
                                : MessageBoxIcon.Information
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   685
                        );
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   686
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   687
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   688
        private void timerRefresh_Tick(object sender, EventArgs e)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   689
        {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   690
            timerRefresh.Interval = 100;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   691
            timerRefresh.Enabled = false; // only once
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   692
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   693
            if (!ThisAddIn.addIn.enabled)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   694
                ThisAddIn.addIn.enable();
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   695
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   696
            makePreview();
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   697
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   698
            reset_enc_status();
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   699
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   700
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   701
        private void EncryptionStatus_MouseUp(object sender, MouseEventArgs e)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   702
        {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   703
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   704
            {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   705
                CryptableMailItem cmi = mailItem;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   706
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   707
                if (cmi != null && !cmi.incoming && !cmi.inSentFolder && cmi.outgoing_color > _pEp_color.pEp_rating_unencrypted)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   708
                {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   709
                    if (cmi.send_unencrypted == CheckState.Indeterminate)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   710
                    {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   711
                        sendUnencryptedToolStripMenuItem.CheckState = CheckState.Unchecked;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   712
                    }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   713
                    else {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   714
                        sendUnencryptedToolStripMenuItem.CheckState = cmi.send_unencrypted;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   715
                    }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   716
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   717
                    Control _sender = (Control)sender;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   718
                    contextMenuEdit.Show(_sender.PointToScreen(e.Location));
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   719
                }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   720
            }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   721
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   722
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   723
        private void sendUnencryptedToolStripMenuItem_Click(object sender, EventArgs e)
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   724
        {
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   725
            sendUnencryptedToolStripMenuItem.Checked = !sendUnencryptedToolStripMenuItem.Checked;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   726
            mailItem.send_unencrypted = sendUnencryptedToolStripMenuItem.CheckState;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   727
            timerRefresh.Enabled = true;
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   728
        }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   729
    }
214f4dc9e2c8 coloring new
Volker Birk <vb@pep-project.org>
parents: 132
diff changeset
   730
}