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