ThisAddIn.cs
author Dean Looyengoed
Tue, 15 Mar 2016 21:25:29 +0100
changeset 671 57fdc1b20a02
parent 667 496791de8b69
child 675 b953e5d40837
permissions -rw-r--r--
Add method to get account trust by searching the whitelist.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
155
cda43d18bcd3 Add state to handshake form and decouple it from the encryption status panel
Dean Looyengoed
parents: 144
diff changeset
     1
using Microsoft.Win32;
cda43d18bcd3 Add state to handshake form and decouple it from the encryption status panel
Dean Looyengoed
parents: 144
diff changeset
     2
using pEpCOMServerAdapterLib;
cda43d18bcd3 Add state to handshake form and decouple it from the encryption status panel
Dean Looyengoed
parents: 144
diff changeset
     3
using System;
0
6dfec3b090d6 initial commit
vb
parents:
diff changeset
     4
using System.Collections.Generic;
155
cda43d18bcd3 Add state to handshake form and decouple it from the encryption status panel
Dean Looyengoed
parents: 144
diff changeset
     5
using System.Diagnostics;
cda43d18bcd3 Add state to handshake form and decouple it from the encryption status panel
Dean Looyengoed
parents: 144
diff changeset
     6
using System.Globalization;
0
6dfec3b090d6 initial commit
vb
parents:
diff changeset
     7
using System.Runtime.InteropServices;
6dfec3b090d6 initial commit
vb
parents:
diff changeset
     8
using System.Threading;
47
d3b5164cc922 read in extra keys
Volker Birk <vb@pep-project.org>
parents: 46
diff changeset
     9
using System.Windows.Forms;
0
6dfec3b090d6 initial commit
vb
parents:
diff changeset
    10
using Outlook = Microsoft.Office.Interop.Outlook;
626
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
    11
using Office = Microsoft.Office.Core;
0
6dfec3b090d6 initial commit
vb
parents:
diff changeset
    12
6dfec3b090d6 initial commit
vb
parents:
diff changeset
    13
namespace pEp
6dfec3b090d6 initial commit
vb
parents:
diff changeset
    14
{
6dfec3b090d6 initial commit
vb
parents:
diff changeset
    15
    public partial class ThisAddIn
6dfec3b090d6 initial commit
vb
parents:
diff changeset
    16
    {
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    17
        #region VSTO generated code
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    18
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    19
        /// <summary>
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    20
        /// Required method for Designer support - do not modify
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    21
        /// the contents of this method with the code editor.
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    22
        /// </summary>
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    23
        private void InternalStartup()
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    24
        {
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    25
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    26
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    27
        }
201
9e0548fa3942 Code reformatting.
Markus Schaber <markus@pep-security.net>
parents: 191
diff changeset
    28
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    29
        #endregion
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    30
451
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
    31
        private const string REG_KEY_SOFTWARE                         = "Software";
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
    32
        private const string REG_KEY_PEP                              = "pEp";
515
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
    33
        private const string REG_KEY_MICROSOFT_OFFICE                 = "Microsoft\\Office";
588
2d12fb5ee4fc Add developer mode to config and options state.
Dean Looyengoed
parents: 587
diff changeset
    34
        private const string REG_KEY_ENCRYPTED_ACCOUNTS_LIST          = "EncryptedAccountsList";
649
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
    35
        private const string REG_NAME_ACCOUNT_WHITELIST               = "AccountWhitelist";
453
4b8c31936610 Add crash report config options and read from registry.
Dean Looyengoed
parents: 452
diff changeset
    36
        private const string REG_NAME_CRASH_REPORT_SEND_ADDRESS       = "CrashReportSendAddress";
451
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
    37
        private const string REG_NAME_EXTRA_KEYS                      = "ExtraKeys";
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
    38
        private const string REG_NAME_IS_CRASH_REPORT_VISIBLE         = "IsCrashReportVisible";
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
    39
        private const string REG_NAME_IS_DEVELOPER_MODE_ENABLED       = "IsDeveloperModeEnabled";
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
    40
        private const string REG_NAME_IS_ENCRYPT_ALL_ACCOUNTS_ENABLED = "IsEncryptAllAccountsEnabled";
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
    41
        private const string REG_NAME_IS_KEY_SERVER_USED              = "IsKeyServerUsed";
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
    42
        private const string REG_NAME_IS_PASSIVE_MODE_ENABLED         = "IsPassiveModeEnabled";
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
    43
        private const string REG_NAME_IS_TNEF_DISABLED                = "DisableTNEF"; // Name defined by Microsoft
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
    44
        private const string REG_NAME_IS_UNENCRYPTED_SUBJECT_ENABLED  = "IsUnencryptedSubjectEnabled";
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
    45
        private const string REG_NAME_IS_VERBOSE_LOGGING_ENABLED      = "IsVerboseLoggingEnabled";
206
630f24c2cd54 Add constants for pEp registry entry names and keys.
Dean Looyengoed
parents: 203
diff changeset
    46
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
    47
        private string[]                 _AccountWhitelist            = Global.HARDCODED_ACCOUNT_WHITELIST;
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
    48
        private string                   _CrashReportSendAddress      = Global.CRASH_REPORT_SEND_ADDRESS_DEFAULT;
451
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
    49
        private Dictionary<string, bool> _EncryptedAccountsList       = new Dictionary<string, bool>();
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
    50
        private string[]                 _ExtraKeys                   = null;
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
    51
        private bool                     _IsCrashReportVisible        = Global.IS_CRASH_REPORT_VISIBLE_DEFAULT;
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
    52
        private bool                     _IsDeveloperModeEnabled      = Global.IS_DEVELOPER_MODE_ENABLED_DEFAULT;
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
    53
        private bool                     _IsEncryptAllAccountsEnabled = Global.IS_ENCRYPT_ALL_ACCOUNTS_ENABLED_DEFAULT;
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
    54
        private bool                     _IsKeyServerUsed             = Global.IS_KEY_SERVER_USED_DEFAULT;
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
    55
        private bool                     _IsPassiveModeEnabled        = Global.IS_PASSIVE_MODE_ENABLED_DEFAULT;
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
    56
        private bool                     _IsTNEFDisabled              = Global.IS_TNEF_DISABLED_DEFAULT;
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
    57
        private bool                     _IsUnencryptedSubjectEnabled = Global.IS_UNENCRYPTED_SUBJECT_ENABLED_DEFAULT;
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
    58
        private bool                     _IsVerboseLoggingEnabled     = Global.IS_VERBOSE_LOGGING_ENABLED_DEFAULT;
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
    59
        private static pEpEngine         _pEp                         = null;
451
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
    60
        private Outlook.Folder           _TempFolder                  = null;
64
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
    61
608
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
    62
        private bool                       initialized      = false;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
    63
        private FormOptions.State          lastOptionsState = null;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
    64
        private List<string>               doNotProcessList = new List<string>();
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
    65
        private Dictionary<string, string> userIDCache      = new Dictionary<string, string>();
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    66
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    67
        /**************************************************************
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    68
         * 
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    69
         * Property Accessors
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    70
         * 
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    71
         *************************************************************/
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    72
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    73
        /// <summary>
650
568a3a9c2d33 Add account whitelist property and trim when making the list.
Dean Looyengoed
parents: 649
diff changeset
    74
        /// Gets the account whitelist as the combination of hardcoded and registry values.
568a3a9c2d33 Add account whitelist property and trim when making the list.
Dean Looyengoed
parents: 649
diff changeset
    75
        /// </summary>
568a3a9c2d33 Add account whitelist property and trim when making the list.
Dean Looyengoed
parents: 649
diff changeset
    76
        public string[] AccountWhitelist
568a3a9c2d33 Add account whitelist property and trim when making the list.
Dean Looyengoed
parents: 649
diff changeset
    77
        {
568a3a9c2d33 Add account whitelist property and trim when making the list.
Dean Looyengoed
parents: 649
diff changeset
    78
            get { return (this._AccountWhitelist); }
568a3a9c2d33 Add account whitelist property and trim when making the list.
Dean Looyengoed
parents: 649
diff changeset
    79
        }
568a3a9c2d33 Add account whitelist property and trim when making the list.
Dean Looyengoed
parents: 649
diff changeset
    80
568a3a9c2d33 Add account whitelist property and trim when making the list.
Dean Looyengoed
parents: 649
diff changeset
    81
        /// <summary>
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
    82
        /// Gets the email address to send any crash report to.
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
    83
        /// Can only be set from the registry.
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
    84
        /// </summary>
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
    85
        public string CrashReportSendAddress
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
    86
        {
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
    87
            get { return (this._CrashReportSendAddress); }
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
    88
        }
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
    89
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
    90
        /// <summary>
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
    91
        /// Gets the encrypted accounts list (as a dictionary) used to show which accounts are encrypted.
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
    92
        /// This is only those accounts which existed already in the registry plus any added 
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
    93
        /// from saving the options form.
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
    94
        /// </summary>
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
    95
        public Dictionary<string, bool> EncryptedAccountsList
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
    96
        {
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
    97
            get { return (this._EncryptedAccountsList); }
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
    98
        }
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
    99
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   100
        /// <summary>
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   101
        /// Gets any extra encryption keys that were loaded from the registry.
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   102
        /// Can only be set from the registry.
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   103
        /// </summary>
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   104
        public string[] ExtraKeys
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   105
        {
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   106
            get { return (this._ExtraKeys); }
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   107
        }
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   108
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   109
        /// <summary>
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   110
        /// Gets whether the crash report window is visible to the user.
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   111
        /// Can only be set from the registry.
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   112
        /// </summary>
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   113
        public bool IsCrashReportVisible
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   114
        {
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   115
            get { return (this._IsCrashReportVisible); }
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   116
        }
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   117
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   118
        /// <summary>
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   119
        /// Gets whether developer mode is enabled.
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   120
        /// Can only be set from the registry.
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   121
        /// </summary>
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   122
        public bool IsDeveloperModeEnabled
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   123
        {
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   124
            get { return (this._IsDeveloperModeEnabled); }
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   125
        }
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   126
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   127
        /// <summary>
451
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   128
        /// Gets or sets whether data should be stored encrypted for all accounts.
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   129
        /// </summary>
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   130
        public bool IsEncryptAllAccountsEnabled
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   131
        {
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   132
            get { return (this._IsEncryptAllAccountsEnabled); }
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   133
            set { this._IsEncryptAllAccountsEnabled = value; }
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   134
        }
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   135
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   136
        /// <summary>
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   137
        /// Gets or sets whether to use a key server.
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   138
        /// When set, this also updates the pEp engine.
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   139
        /// </summary>
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   140
        public bool IsKeyServerUsed
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   141
        {
451
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   142
            get { return (this._IsKeyServerUsed); }
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   143
            set
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   144
            {
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   145
                this._IsKeyServerUsed = value;
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   146
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   147
                // Start/stop key server
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   148
                if (this._IsKeyServerUsed)
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   149
                {
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   150
                    ThisAddIn.pEp.start_keyserver_lookup();
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   151
                }
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   152
                else
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   153
                {
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   154
                    ThisAddIn.pEp.stop_keyserver_lookup();
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   155
                }
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   156
            }
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   157
        }
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   158
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   159
        /// <summary>
598
e1ff494dc53b Implement passive mode which can only be enabled from the registry.
Dean Looyengoed
parents: 597
diff changeset
   160
        /// Gets or sets whether passive mode is enabled.
e1ff494dc53b Implement passive mode which can only be enabled from the registry.
Dean Looyengoed
parents: 597
diff changeset
   161
        /// When set, this also updates the pEp engine.
e1ff494dc53b Implement passive mode which can only be enabled from the registry.
Dean Looyengoed
parents: 597
diff changeset
   162
        /// Passive mode will not attach keys unless keys are received.
452
9be34118b38f Add IsSendWithoutKeyEnabled config option and read from registry.
Dean Looyengoed
parents: 451
diff changeset
   163
        /// </summary>
598
e1ff494dc53b Implement passive mode which can only be enabled from the registry.
Dean Looyengoed
parents: 597
diff changeset
   164
        public bool IsPassiveModeEnabled
452
9be34118b38f Add IsSendWithoutKeyEnabled config option and read from registry.
Dean Looyengoed
parents: 451
diff changeset
   165
        {
598
e1ff494dc53b Implement passive mode which can only be enabled from the registry.
Dean Looyengoed
parents: 597
diff changeset
   166
            get { return (this._IsPassiveModeEnabled); }
e1ff494dc53b Implement passive mode which can only be enabled from the registry.
Dean Looyengoed
parents: 597
diff changeset
   167
            set
e1ff494dc53b Implement passive mode which can only be enabled from the registry.
Dean Looyengoed
parents: 597
diff changeset
   168
            {
e1ff494dc53b Implement passive mode which can only be enabled from the registry.
Dean Looyengoed
parents: 597
diff changeset
   169
                this._IsPassiveModeEnabled = value;
e1ff494dc53b Implement passive mode which can only be enabled from the registry.
Dean Looyengoed
parents: 597
diff changeset
   170
                ThisAddIn.pEp.passive_mode(this._IsPassiveModeEnabled);
e1ff494dc53b Implement passive mode which can only be enabled from the registry.
Dean Looyengoed
parents: 597
diff changeset
   171
            }
452
9be34118b38f Add IsSendWithoutKeyEnabled config option and read from registry.
Dean Looyengoed
parents: 451
diff changeset
   172
        }
9be34118b38f Add IsSendWithoutKeyEnabled config option and read from registry.
Dean Looyengoed
parents: 451
diff changeset
   173
9be34118b38f Add IsSendWithoutKeyEnabled config option and read from registry.
Dean Looyengoed
parents: 451
diff changeset
   174
        /// <summary>
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   175
        /// Gets or sets whether TNEF/RTF format is forcefully disabled in the registry.
588
2d12fb5ee4fc Add developer mode to config and options state.
Dean Looyengoed
parents: 587
diff changeset
   176
        /// </summary>
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   177
        public bool IsTNEFDisabled
588
2d12fb5ee4fc Add developer mode to config and options state.
Dean Looyengoed
parents: 587
diff changeset
   178
        {
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   179
            get { return (this._IsTNEFDisabled); }
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   180
            set { this._IsTNEFDisabled = value; }
453
4b8c31936610 Add crash report config options and read from registry.
Dean Looyengoed
parents: 452
diff changeset
   181
        }
4b8c31936610 Add crash report config options and read from registry.
Dean Looyengoed
parents: 452
diff changeset
   182
4b8c31936610 Add crash report config options and read from registry.
Dean Looyengoed
parents: 452
diff changeset
   183
        /// <summary>
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   184
        /// Gets or sets whether to enable encryption of message subjects.
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   185
        /// When set, this also updates the pEp engine.
453
4b8c31936610 Add crash report config options and read from registry.
Dean Looyengoed
parents: 452
diff changeset
   186
        /// </summary>
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   187
        public bool IsUnencryptedSubjectEnabled
453
4b8c31936610 Add crash report config options and read from registry.
Dean Looyengoed
parents: 452
diff changeset
   188
        {
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   189
            get { return (this._IsUnencryptedSubjectEnabled); }
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   190
            set
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   191
            {
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   192
                this._IsUnencryptedSubjectEnabled = value;
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   193
                ThisAddIn.pEp.unencrypted_subject(this._IsUnencryptedSubjectEnabled);
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   194
            }
453
4b8c31936610 Add crash report config options and read from registry.
Dean Looyengoed
parents: 452
diff changeset
   195
        }
4b8c31936610 Add crash report config options and read from registry.
Dean Looyengoed
parents: 452
diff changeset
   196
4b8c31936610 Add crash report config options and read from registry.
Dean Looyengoed
parents: 452
diff changeset
   197
        /// <summary>
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   198
        /// Gets or sets whether verbose logging is enabled.
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   199
        /// When set, this also updates the pEp engine.
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   200
        /// </summary>
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   201
        public bool IsVerboseLoggingEnabled
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   202
        {
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   203
            get { return (this._IsVerboseLoggingEnabled); }
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   204
            set
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   205
            {
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   206
                this._IsVerboseLoggingEnabled = value;
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   207
                ThisAddIn.pEp.verbose_logging(this._IsVerboseLoggingEnabled);
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   208
            }
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   209
        }
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   210
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   211
        /// <summary>
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   212
        /// Gets the pEp engine which is static.
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   213
        /// </summary>
64
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   214
        public static pEpEngine pEp
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   215
        {
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   216
            get
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   217
            {
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   218
                if (_pEp == null)
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   219
                {
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   220
                    try
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   221
                    {
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   222
                        _pEp = new pEpEngine();
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   223
                    }
467
aeb05f7b2704 Finish initial implementation of global exception handler and sending crash report.
Dean Looyengoed
parents: 465
diff changeset
   224
                    catch (Exception ex)
64
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   225
                    {
467
aeb05f7b2704 Finish initial implementation of global exception handler and sending crash report.
Dean Looyengoed
parents: 465
diff changeset
   226
                        string summaryMessage = Properties.Resources.Message_InitError + " " +
aeb05f7b2704 Finish initial implementation of global exception handler and sending crash report.
Dean Looyengoed
parents: 465
diff changeset
   227
                                                Properties.Resources.Message_Reinstall;
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
   228
                        Global.StopAndSendCrashReport(ex, summaryMessage, false, true);
460
690f8853d7ae Start to implement the global exception handler in ThisAddIn.
Dean Looyengoed
parents: 455
diff changeset
   229
64
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   230
                        return null;
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   231
                    }
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   232
                }
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   233
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   234
                return _pEp;
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   235
            }
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   236
        }
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   237
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   238
        /// <summary>
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   239
        /// Gets the temporary outlook folder used to save unencrypted outlook mail items.
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   240
        /// </summary>
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   241
        public Outlook.Folder TempFolder
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   242
        {
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   243
            get { return (this._TempFolder); }
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   244
        }
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   245
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   246
        /**************************************************************
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   247
         * 
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   248
         * Methods
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   249
         * 
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   250
         *************************************************************/
335
6411b6eb2638 Add initial backstage menu for options.
Dean Looyengoed
parents: 330
diff changeset
   251
361
bbe04f85ac03 Updates to the get my identity methods adding the ability to get my identity from a mail item.
Dean Looyengoed
parents: 342
diff changeset
   252
        /// <summary>
bbe04f85ac03 Updates to the get my identity methods adding the ability to get my identity from a mail item.
Dean Looyengoed
parents: 342
diff changeset
   253
        /// Required override to add ribbon extensions.
bbe04f85ac03 Updates to the get my identity methods adding the ability to get my identity from a mail item.
Dean Looyengoed
parents: 342
diff changeset
   254
        /// </summary>
326
2acfe22efee4 Remove pEp ribbon tab and add ribbon for backstage options (disabled for now).
Dean Looyengoed
parents: 307
diff changeset
   255
        protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
2acfe22efee4 Remove pEp ribbon tab and add ribbon for backstage options (disabled for now).
Dean Looyengoed
parents: 307
diff changeset
   256
        {
340
ded73ac01f51 Implement the send unencrypted option in the ribbon.
Dean Looyengoed
parents: 335
diff changeset
   257
            return new RibbonCustomizations();
335
6411b6eb2638 Add initial backstage menu for options.
Dean Looyengoed
parents: 330
diff changeset
   258
        }
0
6dfec3b090d6 initial commit
vb
parents:
diff changeset
   259
361
bbe04f85ac03 Updates to the get my identity methods adding the ability to get my identity from a mail item.
Dean Looyengoed
parents: 342
diff changeset
   260
        /// <summary>
626
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   261
        /// Detects and disables GPG for Windows GpgOL Outlook add-in.
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   262
        /// </summary>
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   263
        /// <returns>True if the GpgOL add-in was disabled.</returns>
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   264
        private bool DisableGpgOL()
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   265
        {
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   266
            bool wasDisabled = false;
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   267
            Office.COMAddIns comAddIns;
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   268
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   269
            comAddIns = Globals.ThisAddIn.Application.COMAddIns;
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   270
            foreach (Office.COMAddIn addin in comAddIns)
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   271
            {
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   272
                if (string.Equals(addin.Description, "GpgOL - The GnuPG Outlook Plugin", StringComparison.OrdinalIgnoreCase))
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   273
                {
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   274
                    addin.Connect = false;
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   275
                    wasDisabled = true;
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   276
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
   277
                    Global.AddToLog("DisableGpgOL: GpgOL was detected and disabled.");
626
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   278
                }
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   279
            }
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   280
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   281
            return (wasDisabled);
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   282
        }
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   283
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   284
        /// <summary>
384
a0aa034cb7f3 Create and implement new classes for PEPAttachment, PEPIdentity and PEPMessage.
Dean Looyengoed
parents: 378
diff changeset
   285
        /// Registers each personal identity in the pEp engine.
a0aa034cb7f3 Create and implement new classes for PEPAttachment, PEPIdentity and PEPMessage.
Dean Looyengoed
parents: 378
diff changeset
   286
        /// An identity is determined by each account in Outlook.
361
bbe04f85ac03 Updates to the get my identity methods adding the ability to get my identity from a mail item.
Dean Looyengoed
parents: 342
diff changeset
   287
        /// </summary>
384
a0aa034cb7f3 Create and implement new classes for PEPAttachment, PEPIdentity and PEPMessage.
Dean Looyengoed
parents: 378
diff changeset
   288
        public void RegisterMyself()
0
6dfec3b090d6 initial commit
vb
parents:
diff changeset
   289
        {
575
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   290
            Outlook.NameSpace ns = Application.Session;
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   291
            Outlook.Account acct = null;
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   292
            Outlook.Accounts accounts = ns.Accounts;
576
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   293
            Outlook.Recipient currUser = null;
575
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   294
            pEp_identity_s me;
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   295
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   296
            for (int i = 1; i <= accounts.Count; i++)
0
6dfec3b090d6 initial commit
vb
parents:
diff changeset
   297
            {
575
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   298
                acct = accounts[i];
576
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   299
                currUser = acct.CurrentUser;
575
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   300
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   301
                me = new pEp_identity_s();
14
84089e08d01c bugfix for Exchange account(s)
vb
parents: 13
diff changeset
   302
                me.address = acct.SmtpAddress;
576
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   303
                me.username = (currUser != null ? currUser.Name : null);
525
69ca517635c4 Change UserID to standard calculation when finding Myself.
Dean Looyengoed
parents: 523
diff changeset
   304
                me.user_id = Globals.ThisAddIn.GetUserID(me.address); // Previously: acct.CurrentUser.EntryID
12
7dce2af80337 first key will be used to sign a message
vb
parents: 0
diff changeset
   305
575
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   306
                // Log information if invalid
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   307
                if (string.IsNullOrWhiteSpace(me.address))
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   308
                {
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
   309
                    Global.AddToLog("RegisterMyself: Myself[" + i.ToString() + "] doesn't have an address.");
575
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   310
                }
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   311
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   312
                if (string.IsNullOrWhiteSpace(me.username))
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   313
                {
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
   314
                    Global.AddToLog("RegisterMyself: Myself[" + i.ToString() + "] doesn't have a username.");
575
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   315
                }
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   316
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   317
                if (string.IsNullOrWhiteSpace(me.user_id))
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   318
                {
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
   319
                    Global.AddToLog("RegisterMyself: Myself[" + i.ToString() + "] doesn't have a user ID.");
575
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   320
                }
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   321
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   322
                // Call engine
12
7dce2af80337 first key will be used to sign a message
vb
parents: 0
diff changeset
   323
                try
7dce2af80337 first key will be used to sign a message
vb
parents: 0
diff changeset
   324
                {
59
Volker Birk <vb@pep-project.org>
parents: 55
diff changeset
   325
                    pEp.myself(me);
12
7dce2af80337 first key will be used to sign a message
vb
parents: 0
diff changeset
   326
                }
7dce2af80337 first key will be used to sign a message
vb
parents: 0
diff changeset
   327
                catch (COMException ex)
7dce2af80337 first key will be used to sign a message
vb
parents: 0
diff changeset
   328
                {
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
   329
                    Global.StopAndSendCrashReport(ex);
12
7dce2af80337 first key will be used to sign a message
vb
parents: 0
diff changeset
   330
                }
575
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   331
576
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   332
                // Release objects
575
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   333
                if (acct != null)
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   334
                {
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   335
                    Marshal.ReleaseComObject(acct);
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   336
                    acct = null;
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   337
                }
576
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   338
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   339
                if (currUser != null)
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   340
                {
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   341
                    Marshal.ReleaseComObject(currUser);
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   342
                    currUser = null;
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   343
                }
575
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   344
            }
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   345
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   346
            // Release objects
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   347
            if (ns != null)
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   348
            {
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   349
                Marshal.ReleaseComObject(ns);
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   350
                ns = null;
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   351
            }
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   352
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   353
            if (acct != null)
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   354
            {
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   355
                Marshal.ReleaseComObject(acct);
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   356
                acct = null;
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   357
            }
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   358
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   359
            if (accounts != null)
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   360
            {
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   361
                Marshal.ReleaseComObject(accounts);
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   362
                accounts = null;
0
6dfec3b090d6 initial commit
vb
parents:
diff changeset
   363
            }
588
2d12fb5ee4fc Add developer mode to config and options state.
Dean Looyengoed
parents: 587
diff changeset
   364
576
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   365
            if (currUser != null)
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   366
            {
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   367
                Marshal.ReleaseComObject(currUser);
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   368
                currUser = null;
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   369
            }
0
6dfec3b090d6 initial commit
vb
parents:
diff changeset
   370
384
a0aa034cb7f3 Create and implement new classes for PEPAttachment, PEPIdentity and PEPMessage.
Dean Looyengoed
parents: 378
diff changeset
   371
            return;
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   372
        }
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   373
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   374
        /// <summary>
624
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   375
        /// Gets whether the given contact should be forcefully sent unencrypted messages.
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   376
        /// This will read the value of the user property.
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   377
        /// </summary>
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   378
        /// <param name="contact">The contact to get the force unencrypted status from.</param>
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   379
        /// <returns>True if the mail item is force unencrypted, otherwise false or null.</returns>
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   380
        public bool? GetForceUnencrypted(Outlook.ContactItem contact)
624
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   381
        {
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   382
            bool? value = false;
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   383
            Outlook.UserProperties properties = contact.UserProperties;
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   384
            Outlook.UserProperty up = properties.Find(CryptableMailItem.USER_PROPERTY_KEY_FORCE_UNENCRYPTED);
624
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   385
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   386
            if (up == null)
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   387
            {
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   388
                value = null;
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   389
            }
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   390
            else
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   391
            {
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   392
                value = up.Value;
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   393
            }
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   394
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   395
            // Release objects
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   396
            if (properties != null)
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   397
            {
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   398
                Marshal.ReleaseComObject(properties);
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   399
                properties = null;
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   400
            }
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   401
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   402
            if (up != null)
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   403
            {
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   404
                Marshal.ReleaseComObject(up);
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   405
                up = null;
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   406
            }
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   407
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   408
            return (value);
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   409
        }
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   410
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   411
        /// <summary>
487
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   412
        /// Sets whether the given contact should be forcefully sent unencrypted messages.
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   413
        /// This will set the value of the user property.
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   414
        /// </summary>
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   415
        /// <param name="contact">The contact to set force unencrypted status for.</param>
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   416
        /// <param name="forceUnencrypted">The force unencrypted status to set.</param>
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   417
        public void SetForceUnencrypted(Outlook.ContactItem contact,
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   418
                                        bool forceUnencrypted)
487
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   419
        {
624
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   420
            Outlook.UserProperties properties = contact.UserProperties;
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   421
            Outlook.UserProperty up = properties.Find(CryptableMailItem.USER_PROPERTY_KEY_FORCE_UNENCRYPTED);
487
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   422
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   423
            if (up == null)
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   424
            {
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   425
                up = contact.UserProperties.Add(CryptableMailItem.USER_PROPERTY_KEY_FORCE_UNENCRYPTED,
487
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   426
                                                Outlook.OlUserPropertyType.olYesNo, false);
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   427
            }
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   428
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   429
            up.Value = forceUnencrypted;
487
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   430
624
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   431
            // Release objects
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   432
            if (properties != null)
487
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   433
            {
624
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   434
                Marshal.ReleaseComObject(properties);
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   435
                properties = null;
487
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   436
            }
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   437
488
c654979e27ac Fix so release isn't done on null objects...
Dean Looyengoed
parents: 487
diff changeset
   438
            if (up != null)
c654979e27ac Fix so release isn't done on null objects...
Dean Looyengoed
parents: 487
diff changeset
   439
            {
c654979e27ac Fix so release isn't done on null objects...
Dean Looyengoed
parents: 487
diff changeset
   440
                Marshal.ReleaseComObject(up);
c654979e27ac Fix so release isn't done on null objects...
Dean Looyengoed
parents: 487
diff changeset
   441
                up = null;
c654979e27ac Fix so release isn't done on null objects...
Dean Looyengoed
parents: 487
diff changeset
   442
            }
487
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   443
624
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   444
            return;
487
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   445
        }
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   446
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   447
        /// <summary>
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   448
        /// Determines if the contact associated with the given address is to be forcefully sent unencrypted messages.
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   449
        /// This will match the address to a contact then check the force unencrypted user property of the contact.
487
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   450
        /// </summary>
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   451
        /// <param name="address">The address to determine whether it should be forcefully sent unencrypted messages.</param>
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   452
        /// <returns>True if the given address should be sent unencrypted messages based on its contact, otherwise false.</returns>
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   453
        public bool ContactIsForceUnencrypted(string address)
487
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   454
        {
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   455
            bool forceUnencrypted = false;
625
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   456
            bool? propertyValue;
487
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   457
            Outlook.MAPIFolder contactFolder = null;
625
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   458
            Outlook.NameSpace ns = Application.Session;
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   459
            Outlook.Store store = null;
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   460
            Outlook.Stores stores = ns.Stores;
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   461
            Outlook.ContactItem item = null;
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   462
            Outlook.Items items = null;
487
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   463
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   464
            try
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   465
            {
625
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   466
                if (string.IsNullOrEmpty(address) == false)
487
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   467
                {
625
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   468
                    for (int i = 1; i <= stores.Count; i++)
487
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   469
                    {
625
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   470
                        store = stores[i];
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   471
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   472
                        try
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   473
                        {
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   474
                            contactFolder = store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   475
                        }
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   476
                        catch
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   477
                        {
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   478
                            contactFolder = null;
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   479
                        }
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   480
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   481
                        // Go through each contact item in the default contacts folder
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   482
                        if (contactFolder != null)
487
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   483
                        {
625
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   484
                            items = contactFolder.Items;
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   485
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   486
                            for (int j = 0; j < items.Count; j++)
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   487
                            {
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   488
                                try
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   489
                                {
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   490
                                    item = (Outlook.ContactItem)items[j];
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   491
                                }
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   492
                                catch
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   493
                                {
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   494
                                    item = null;
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   495
                                }
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   496
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   497
                                if (item != null)
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   498
                                {
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   499
                                    propertyValue = this.GetForceUnencrypted(item);
625
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   500
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   501
                                    // Check property and address for a match
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   502
                                    if ((propertyValue != null) &&
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   503
                                        ((bool)propertyValue == true))
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   504
                                    {
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   505
                                        if (((item.Email1Address != null) &&
632
ee26f2b9771b Change string comparison type.
Dean Looyengoed
parents: 627
diff changeset
   506
                                             string.Equals(item.Email1Address, address, StringComparison.OrdinalIgnoreCase)) ||
625
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   507
                                            ((item.Email2Address != null) &&
632
ee26f2b9771b Change string comparison type.
Dean Looyengoed
parents: 627
diff changeset
   508
                                             string.Equals(item.Email2Address, address, StringComparison.OrdinalIgnoreCase)) ||
625
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   509
                                            ((item.Email3Address != null) &&
632
ee26f2b9771b Change string comparison type.
Dean Looyengoed
parents: 627
diff changeset
   510
                                             string.Equals(item.Email3Address, address, StringComparison.OrdinalIgnoreCase)))
625
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   511
                                        {
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   512
                                            forceUnencrypted = true;
625
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   513
                                            break;
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   514
                                        }
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   515
                                    }
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   516
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   517
                                    // Release objects
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   518
                                    Marshal.ReleaseComObject(item);
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   519
                                    item = null;
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   520
                                }
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   521
                            }
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   522
                        }
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   523
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   524
                        // Break if 
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   525
                        if (forceUnencrypted)
625
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   526
                        {
487
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   527
                            break;
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   528
                        }
625
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   529
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   530
                        // Release objects
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   531
                        if (store != null)
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   532
                        {
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   533
                            Marshal.ReleaseComObject(store);
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   534
                            store = null;
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   535
                        }
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   536
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   537
                        if (contactFolder != null)
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   538
                        {
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   539
                            Marshal.ReleaseComObject(contactFolder);
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   540
                            contactFolder = null;
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   541
                        }
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   542
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   543
                        if (item != null)
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   544
                        {
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   545
                            Marshal.ReleaseComObject(item);
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   546
                            item = null;
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   547
                        }
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   548
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   549
                        if (items != null)
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   550
                        {
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   551
                            Marshal.ReleaseComObject(items);
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   552
                            items = null;
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   553
                        }
487
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   554
                    }
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   555
                }
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   556
            }
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   557
            catch (Exception ex)
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   558
            {
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
   559
                Global.StopAndSendCrashReport(ex);
487
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   560
            }
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   561
            finally
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   562
            {
625
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   563
                // Release objects
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   564
                if (store != null)
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   565
                {
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   566
                    Marshal.ReleaseComObject(store);
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   567
                    store = null;
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   568
                }
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   569
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   570
                if (stores != null)
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   571
                {
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   572
                    Marshal.ReleaseComObject(stores);
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   573
                    stores = null;
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   574
                }
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   575
487
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   576
                if (contactFolder != null)
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   577
                {
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   578
                    Marshal.ReleaseComObject(contactFolder);
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   579
                    contactFolder = null;
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   580
                }
625
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   581
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   582
                if (item != null)
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   583
                {
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   584
                    Marshal.ReleaseComObject(item);
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   585
                    item = null;
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   586
                }
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   587
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   588
                if (items != null)
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   589
                {
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   590
                    Marshal.ReleaseComObject(items);
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   591
                    items = null;
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   592
                }
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   593
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   594
                if (ns != null)
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   595
                {
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   596
                    Marshal.ReleaseComObject(ns);
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   597
                    ns = null;
d4af7230450f Implement contact-based send unencrypted in the message processor.
Dean Looyengoed
parents: 624
diff changeset
   598
                }
487
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   599
            }
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   600
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   601
            return (forceUnencrypted);
487
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   602
        }
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   603
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   604
        /// <summary>
413
6a780cc16111 Move all get from/sender methods to the PEPMessage.
Dean Looyengoed
parents: 384
diff changeset
   605
        /// Gets the pEp user ID (Outlook EntryID) for the given address.
362
867beb89ee19 Move GetUserIDFromAddress from the CryptableMailItem to ThisAddIn.
Dean Looyengoed
parents: 361
diff changeset
   606
        /// </summary>
867beb89ee19 Move GetUserIDFromAddress from the CryptableMailItem to ThisAddIn.
Dean Looyengoed
parents: 361
diff changeset
   607
        /// <param name="address">The address to get the user ID for.</param>
867beb89ee19 Move GetUserIDFromAddress from the CryptableMailItem to ThisAddIn.
Dean Looyengoed
parents: 361
diff changeset
   608
        /// <returns>The user ID (Outlook EntryID) for the given address</returns>
501
158c070826dd Remove username parameter from GetUserID calculation.
Dean Looyengoed
parents: 500
diff changeset
   609
        public string GetUserID(string address)
362
867beb89ee19 Move GetUserIDFromAddress from the CryptableMailItem to ThisAddIn.
Dean Looyengoed
parents: 361
diff changeset
   610
        {
511
4a970a30be20 Get rid of unnecessary null/empty check as the structure of the method has changed.
Dean Looyengoed
parents: 510
diff changeset
   611
            string id = null;
608
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   612
            bool existingFound;
569
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   613
            Outlook.AddressList al = null;
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   614
            Outlook.AddressLists addressLists = null;
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   615
            Outlook.AddressEntry entry = null;
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   616
            Outlook.AddressEntry addressEntry = null;
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   617
            Outlook.AddressEntries entries = null;
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   618
            Outlook.NameSpace ns = null;
608
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   619
            Outlook.Folder contacts = null;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   620
            Outlook.Folders contactsFolders = null;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   621
            Outlook.Store tempStore = null;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   622
            Outlook.Folder addressBook = null;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   623
            Outlook.ContactItem newContact = null;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   624
            Outlook.Items addressBookItems = null;
507
d0b1586c5235 Add fallback to GetUserID that searches address book entry-by-entry.
Dean Looyengoed
parents: 502
diff changeset
   625
474
a27dbbb2dd88 Add try/catch and error handling around several ThisAddIn methods.
Dean Looyengoed
parents: 473
diff changeset
   626
            try
362
867beb89ee19 Move GetUserIDFromAddress from the CryptableMailItem to ThisAddIn.
Dean Looyengoed
parents: 361
diff changeset
   627
            {
608
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   628
                if (string.IsNullOrEmpty(address) == false)
569
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   629
                {
608
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   630
                    // Search cache
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   631
                    if (id == null)
511
4a970a30be20 Get rid of unnecessary null/empty check as the structure of the method has changed.
Dean Looyengoed
parents: 510
diff changeset
   632
                    {
569
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   633
                        try
474
a27dbbb2dd88 Add try/catch and error handling around several ThisAddIn methods.
Dean Looyengoed
parents: 473
diff changeset
   634
                        {
608
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   635
                            id = this.userIDCache[address];
569
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   636
                        }
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   637
                        catch
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   638
                        {
608
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   639
                            id = null;
510
500cb064737d Remove try/catch around GetUserID that could hide errors.
Dean Looyengoed
parents: 508
diff changeset
   640
                        }
511
4a970a30be20 Get rid of unnecessary null/empty check as the structure of the method has changed.
Dean Looyengoed
parents: 510
diff changeset
   641
                    }
477
23462dc9e619 Release COM objects in GetUserID.
Dean Looyengoed
parents: 475
diff changeset
   642
608
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   643
                    // Search all existing address lists
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   644
                    if (id == null)
511
4a970a30be20 Get rid of unnecessary null/empty check as the structure of the method has changed.
Dean Looyengoed
parents: 510
diff changeset
   645
                    {
608
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   646
                        ns = Globals.ThisAddIn.Application.Session;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   647
                        addressLists = ns.AddressLists;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   648
                        for (int i = 1; i <= addressLists.Count; i++)
569
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   649
                        {
608
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   650
                            addressEntry = null;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   651
                            al = addressLists[i];
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   652
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   653
                            // Skip exchange which is too slow
570
21d996cd35e8 Stop searching through Exchange AddressLists due to performance.
Dean Looyengoed
parents: 569
diff changeset
   654
                            if ((al.AddressListType != Outlook.OlAddressListType.olExchangeContainer) &&
21d996cd35e8 Stop searching through Exchange AddressLists due to performance.
Dean Looyengoed
parents: 569
diff changeset
   655
                                (al.AddressListType != Outlook.OlAddressListType.olExchangeGlobalAddressList))
21d996cd35e8 Stop searching through Exchange AddressLists due to performance.
Dean Looyengoed
parents: 569
diff changeset
   656
                            {
608
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   657
                                // Method 1
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   658
                                if (addressEntry == null)
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   659
                                {
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   660
                                    try
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   661
                                    {
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   662
                                        addressEntry = al.AddressEntries[address];
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   663
                                    }
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   664
                                    catch
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   665
                                    {
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   666
                                        addressEntry = null;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   667
                                    }
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   668
                                }
569
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   669
608
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   670
                                // Method 2
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   671
                                if (addressEntry == null)
570
21d996cd35e8 Stop searching through Exchange AddressLists due to performance.
Dean Looyengoed
parents: 569
diff changeset
   672
                                {
608
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   673
                                    try
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   674
                                    {
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   675
                                        entries = al.AddressEntries;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   676
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   677
                                        // Note: index starts at 1
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   678
                                        for (int j = 1; j <= entries.Count; j++)
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   679
                                        {
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   680
                                            entry = al.AddressEntries[j];
569
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   681
608
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   682
                                            if ((entry.Address != null) &&
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   683
                                                (entry.Address == address))
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   684
                                            {
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   685
                                                addressEntry = entry;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   686
                                                break;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   687
                                            }
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   688
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   689
                                            Marshal.ReleaseComObject(entry);
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   690
                                            entry = null;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   691
                                        }
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   692
                                    }
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   693
                                    catch
570
21d996cd35e8 Stop searching through Exchange AddressLists due to performance.
Dean Looyengoed
parents: 569
diff changeset
   694
                                    {
608
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   695
                                        addressEntry = null;
570
21d996cd35e8 Stop searching through Exchange AddressLists due to performance.
Dean Looyengoed
parents: 569
diff changeset
   696
                                    }
608
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   697
                                }
570
21d996cd35e8 Stop searching through Exchange AddressLists due to performance.
Dean Looyengoed
parents: 569
diff changeset
   698
608
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   699
                                if (addressEntry != null)
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   700
                                {
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   701
                                    id = al.ID + "_" + addressEntry.ID;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   702
                                    this.userIDCache[address] = id;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   703
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   704
                                    Marshal.ReleaseComObject(al);
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   705
                                    al = null;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   706
                                    Marshal.ReleaseComObject(addressEntry);
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   707
                                    addressEntry = null;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   708
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   709
                                    break;
569
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   710
                                }
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   711
                            }
608
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   712
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   713
                            // Release objects
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   714
                            if (al != null)
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   715
                            {
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   716
                                Marshal.ReleaseComObject(al);
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   717
                                al = null;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   718
                            }
569
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   719
                        }
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   720
                    }
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   721
608
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   722
                    // Create new entry with an ID
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   723
                    if (id == null)
569
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   724
                    {
608
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   725
                        tempStore = this.TempFolder.Store;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   726
                        contacts = (Outlook.Folder)tempStore.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   727
                        contactsFolders = contacts.Folders;
521
24b0f54a71e5 Don't try to release null objects in GetUserID.
Dean Looyengoed
parents: 520
diff changeset
   728
608
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   729
                        // Search for existing 'pEp Contacts' folder
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   730
                        existingFound = false;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   731
                        for (int i = 1; i <= contactsFolders.Count; i++)
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   732
                        {
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   733
                            addressBook = (Outlook.Folder)contactsFolders[i];
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   734
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   735
                            if ((addressBook != null) &&
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   736
                                (addressBook.ShowAsOutlookAB == true) &&
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   737
                                (addressBook.Name == "pEp Contacts"))
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   738
                            {
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   739
                                existingFound = true;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   740
                                break;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   741
                            }
521
24b0f54a71e5 Don't try to release null objects in GetUserID.
Dean Looyengoed
parents: 520
diff changeset
   742
608
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   743
                            if (addressBook != null)
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   744
                            {
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   745
                                Marshal.ReleaseComObject(addressBook);
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   746
                                addressBook = null;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   747
                            }
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   748
                        }
510
500cb064737d Remove try/catch around GetUserID that could hide errors.
Dean Looyengoed
parents: 508
diff changeset
   749
608
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   750
                        // Create new address book
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   751
                        if ((existingFound == false) ||
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   752
                            (addressBook == null))
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   753
                        {
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   754
                            addressBook = (Outlook.Folder)contactsFolders.Add("pEp Contacts", Outlook.OlDefaultFolders.olFolderContacts);
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   755
                            addressBook.ShowAsOutlookAB = true;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   756
                        }
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   757
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   758
                        // Create new contact
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   759
                        addressBookItems = addressBook.Items;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   760
                        newContact = addressBookItems.Add();
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   761
                        newContact.Email1Address = address;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   762
                        newContact.Save();
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   763
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   764
                        id = addressBook.StoreID + "_" + newContact.EntryID;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   765
                        this.userIDCache[address] = id;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   766
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
   767
                        Global.AddToLog("GetUserID: created new contact for EntryID.");
521
24b0f54a71e5 Don't try to release null objects in GetUserID.
Dean Looyengoed
parents: 520
diff changeset
   768
                    }
362
867beb89ee19 Move GetUserIDFromAddress from the CryptableMailItem to ThisAddIn.
Dean Looyengoed
parents: 361
diff changeset
   769
                }
474
a27dbbb2dd88 Add try/catch and error handling around several ThisAddIn methods.
Dean Looyengoed
parents: 473
diff changeset
   770
            }
a27dbbb2dd88 Add try/catch and error handling around several ThisAddIn methods.
Dean Looyengoed
parents: 473
diff changeset
   771
            catch (Exception ex)
a27dbbb2dd88 Add try/catch and error handling around several ThisAddIn methods.
Dean Looyengoed
parents: 473
diff changeset
   772
            {
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
   773
                Global.StopAndSendCrashReport(ex);
362
867beb89ee19 Move GetUserIDFromAddress from the CryptableMailItem to ThisAddIn.
Dean Looyengoed
parents: 361
diff changeset
   774
            }
569
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   775
            finally
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   776
            {
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   777
                // Release objects
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   778
                if (al != null)
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   779
                {
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   780
                    Marshal.ReleaseComObject(al);
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   781
                    al = null;
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   782
                }
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   783
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   784
                if (addressLists != null)
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   785
                {
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   786
                    Marshal.ReleaseComObject(addressLists);
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   787
                    addressLists = null;
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   788
                }
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   789
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   790
                if (entry != null)
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   791
                {
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   792
                    Marshal.ReleaseComObject(entry);
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   793
                    entry = null;
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   794
                }
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   795
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   796
                if (addressEntry != null)
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   797
                {
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   798
                    Marshal.ReleaseComObject(addressEntry);
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   799
                    addressEntry = null;
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   800
                }
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   801
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   802
                if (entries != null)
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   803
                {
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   804
                    Marshal.ReleaseComObject(entries);
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   805
                    entries = null;
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   806
                }
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   807
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   808
                if (ns != null)
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   809
                {
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   810
                    Marshal.ReleaseComObject(ns);
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   811
                    ns = null;
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   812
                }
608
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   813
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   814
                if (contacts != null)
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   815
                {
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   816
                    Marshal.ReleaseComObject(contacts);
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   817
                    contacts = null;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   818
                }
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   819
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   820
                if (contactsFolders != null)
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   821
                {
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   822
                    Marshal.ReleaseComObject(contactsFolders);
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   823
                    contactsFolders = null;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   824
                }
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   825
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   826
                if (tempStore != null)
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   827
                {
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   828
                    Marshal.ReleaseComObject(tempStore);
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   829
                    tempStore = null;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   830
                }
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   831
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   832
                if (addressBook != null)
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   833
                {
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   834
                    Marshal.ReleaseComObject(addressBook);
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   835
                    addressBook = null;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   836
                }
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   837
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   838
                if (newContact != null)
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   839
                {
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   840
                    Marshal.ReleaseComObject(newContact);
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   841
                    newContact = null;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   842
                }
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   843
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   844
                if (addressBookItems != null)
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   845
                {
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   846
                    Marshal.ReleaseComObject(addressBookItems);
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   847
                    addressBookItems = null;
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   848
                }
569
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   849
            }
362
867beb89ee19 Move GetUserIDFromAddress from the CryptableMailItem to ThisAddIn.
Dean Looyengoed
parents: 361
diff changeset
   850
587
cecb650d6cd8 Improve logging including the GetUserID method not finding an ID.
Dean Looyengoed
parents: 586
diff changeset
   851
            // Log if no ID was found
cecb650d6cd8 Improve logging including the GetUserID method not finding an ID.
Dean Looyengoed
parents: 586
diff changeset
   852
            if (string.IsNullOrWhiteSpace(id))
cecb650d6cd8 Improve logging including the GetUserID method not finding an ID.
Dean Looyengoed
parents: 586
diff changeset
   853
            {
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
   854
                Global.AddToLog("GetUserID: failed to find an ID.");
587
cecb650d6cd8 Improve logging including the GetUserID method not finding an ID.
Dean Looyengoed
parents: 586
diff changeset
   855
            }
cecb650d6cd8 Improve logging including the GetUserID method not finding an ID.
Dean Looyengoed
parents: 586
diff changeset
   856
511
4a970a30be20 Get rid of unnecessary null/empty check as the structure of the method has changed.
Dean Looyengoed
parents: 510
diff changeset
   857
            return (id);
362
867beb89ee19 Move GetUserIDFromAddress from the CryptableMailItem to ThisAddIn.
Dean Looyengoed
parents: 361
diff changeset
   858
        }
867beb89ee19 Move GetUserIDFromAddress from the CryptableMailItem to ThisAddIn.
Dean Looyengoed
parents: 361
diff changeset
   859
867beb89ee19 Move GetUserIDFromAddress from the CryptableMailItem to ThisAddIn.
Dean Looyengoed
parents: 361
diff changeset
   860
        /// <summary>
455
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   861
        /// Create a new Outlook MailItem from the given PEPMessage and sends it.
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   862
        /// The sent message will not be processed as the send unencrypted property will be set to true.
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   863
        /// </summary>
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   864
        /// <param name="message">The message to send.</param>
475
7a23ec4d8b28 Add deleteAfterSend parameter in SendWithoutProcessing method.
Dean Looyengoed
parents: 474
diff changeset
   865
        /// <param name="deleteAfterSend">Whether the message is deleted after sending (true) or a copy is saved (false).</param>
7a23ec4d8b28 Add deleteAfterSend parameter in SendWithoutProcessing method.
Dean Looyengoed
parents: 474
diff changeset
   866
        public void SendWithoutProcessing(PEPMessage message,
7a23ec4d8b28 Add deleteAfterSend parameter in SendWithoutProcessing method.
Dean Looyengoed
parents: 474
diff changeset
   867
                                          bool deleteAfterSend)
455
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   868
        {
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   869
            Outlook.MailItem newItem;
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   870
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   871
            newItem = Application.CreateItem(Outlook.OlItemType.olMailItem);
586
2c2bfd7f1e43 Improve handling of optional properties in PEPMessage.
Dean Looyengoed
parents: 576
diff changeset
   872
            message.ApplyTo(newItem, false); // Do NOT include optional properties!
455
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   873
502
4b4d88db09eb When sending a PEPMessage, set the UseTNEF property to false to avoid winmail.dat in some circumstances.
Dean Looyengoed
parents: 501
diff changeset
   874
            // Do not allow TNEF/RTF format with 'winmail.dat' attachment
548
626fa51f7131 Use MAPIHelper throughout code. Also now clear UNSENT flag when creating new Mirrors.
Dean Looyengoed
parents: 540
diff changeset
   875
            MAPIHelper.SetProperty(newItem, MAPIHelper.PR_USE_TNEF, false);
570
21d996cd35e8 Stop searching through Exchange AddressLists due to performance.
Dean Looyengoed
parents: 569
diff changeset
   876
565
ba35cfbfa0ee Stop setting user property for 'do not process' and instead use a do not process list.
Dean Looyengoed
parents: 562
diff changeset
   877
            // Save the new item to the default folder of the sending account
ba35cfbfa0ee Stop setting user property for 'do not process' and instead use a do not process list.
Dean Looyengoed
parents: 562
diff changeset
   878
            // This must be done so an EntryID is created.
ba35cfbfa0ee Stop setting user property for 'do not process' and instead use a do not process list.
Dean Looyengoed
parents: 562
diff changeset
   879
            newItem.Save();
502
4b4d88db09eb When sending a PEPMessage, set the UseTNEF property to false to avoid winmail.dat in some circumstances.
Dean Looyengoed
parents: 501
diff changeset
   880
565
ba35cfbfa0ee Stop setting user property for 'do not process' and instead use a do not process list.
Dean Looyengoed
parents: 562
diff changeset
   881
            // Set property to not process on send
ba35cfbfa0ee Stop setting user property for 'do not process' and instead use a do not process list.
Dean Looyengoed
parents: 562
diff changeset
   882
            this.doNotProcessList.Add(newItem.EntryID);
ba35cfbfa0ee Stop setting user property for 'do not process' and instead use a do not process list.
Dean Looyengoed
parents: 562
diff changeset
   883
ba35cfbfa0ee Stop setting user property for 'do not process' and instead use a do not process list.
Dean Looyengoed
parents: 562
diff changeset
   884
            // Send
475
7a23ec4d8b28 Add deleteAfterSend parameter in SendWithoutProcessing method.
Dean Looyengoed
parents: 474
diff changeset
   885
            newItem.DeleteAfterSubmit = deleteAfterSend;
465
3f5d92b648ce Make SendWithoutProcessing public.
Dean Looyengoed
parents: 462
diff changeset
   886
            ((Outlook._MailItem)newItem).Send();
455
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   887
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   888
            Marshal.ReleaseComObject(newItem);
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   889
            newItem = null;
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   890
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   891
            return;
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   892
        }
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   893
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   894
        /// <summary>
671
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   895
        /// Gets whether the given account is trusted (on the account whitelist).
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   896
        /// Character case and whitespace is ignored during comparison.
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   897
        /// </summary>
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   898
        /// <param name="address">The address of the account.</param>
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   899
        /// <returns>True if the account with the given address is trusted by default (on the whitelist), otherwise false.</returns>
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   900
        private bool GetIsAccountTrusted(string address)
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   901
        {
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   902
            bool isTrusted = false;
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   903
            string searchAddress = address.ToUpper().Trim();
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   904
            string searchDomain = searchAddress.Contains("@") ? searchAddress.Substring(searchAddress.LastIndexOf("@")) : null;
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   905
            string whitelistAccount;
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   906
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   907
            for (int i = 0; i < this._AccountWhitelist.Length; i++)
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   908
            {
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   909
                whitelistAccount = this._AccountWhitelist[i].ToUpper().Trim();
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   910
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   911
                // Check for exact match
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   912
                if (searchAddress == whitelistAccount)
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   913
                {
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   914
                    isTrusted = true;
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   915
                    break;
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   916
                }
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   917
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   918
                // Check for domain match
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   919
                if ((searchDomain != null) &&
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   920
                    whitelistAccount.StartsWith("@") &&
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   921
                    (searchDomain == whitelistAccount))
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   922
                {
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   923
                    isTrusted = true;
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   924
                    break;
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   925
                }
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   926
            }
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   927
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   928
            return (isTrusted);
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   929
        }
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   930
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   931
        /// <summary>
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   932
        /// Writes/saves any supported configuration/property values to the registry.
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   933
        /// </summary>
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   934
        private void WriteConfigToRegistry()
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   935
        {
452
9be34118b38f Add IsSendWithoutKeyEnabled config option and read from registry.
Dean Looyengoed
parents: 451
diff changeset
   936
            /* Note: 
9be34118b38f Add IsSendWithoutKeyEnabled config option and read from registry.
Dean Looyengoed
parents: 451
diff changeset
   937
             * Do not save the below properties which can only be modified from the registry
649
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
   938
             *   • AccountWhitelist
453
4b8c31936610 Add crash report config options and read from registry.
Dean Looyengoed
parents: 452
diff changeset
   939
             *   • CrashReportSendAddress
4b8c31936610 Add crash report config options and read from registry.
Dean Looyengoed
parents: 452
diff changeset
   940
             *   • ExtraKeys
627
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
   941
             *   • IsCrashReportVisible
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
   942
             *   • IsDeveloperModeEnabled
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
   943
             *   • IsPassiveModeEnabled
452
9be34118b38f Add IsSendWithoutKeyEnabled config option and read from registry.
Dean Looyengoed
parents: 451
diff changeset
   944
             */
9be34118b38f Add IsSendWithoutKeyEnabled config option and read from registry.
Dean Looyengoed
parents: 451
diff changeset
   945
462
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
   946
            try
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   947
            {
462
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
   948
                using (RegistryKey key1 = Registry.CurrentUser.OpenSubKey(REG_KEY_SOFTWARE, true))
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   949
                {
462
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
   950
                    using (RegistryKey key2 = key1.CreateSubKey(REG_KEY_PEP))
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
   951
                    {
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
   952
                        // Set encryption state of each account
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
   953
                        using (RegistryKey key3 = key2.CreateSubKey(REG_KEY_ENCRYPTED_ACCOUNTS_LIST))
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   954
                        {
462
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
   955
                            foreach (KeyValuePair<string, bool> entry in this._EncryptedAccountsList)
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
   956
                            {
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
   957
                                key3.SetValue(entry.Key,
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
   958
                                              entry.Value.ToString(),
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
   959
                                              RegistryValueKind.String);
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
   960
                            }
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   961
                        }
627
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
   962
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
   963
                        key2.SetValue(REG_NAME_IS_ENCRYPT_ALL_ACCOUNTS_ENABLED, this._IsEncryptAllAccountsEnabled.ToString());
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
   964
                        key2.SetValue(REG_NAME_IS_KEY_SERVER_USED, this._IsKeyServerUsed.ToString());
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
   965
                        key2.SetValue(REG_NAME_IS_UNENCRYPTED_SUBJECT_ENABLED, this._IsUnencryptedSubjectEnabled.ToString());
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
   966
                        key2.SetValue(REG_NAME_IS_VERBOSE_LOGGING_ENABLED, this._IsVerboseLoggingEnabled.ToString());
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   967
                    }
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   968
                }
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   969
            }
462
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
   970
            catch (Exception ex)
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
   971
            {
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
   972
                Global.StopAndSendCrashReport(ex);
462
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
   973
            }
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   974
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   975
            return;
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   976
        }
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   977
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   978
        /// <summary>
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   979
        /// Reads/loads any configuration/property values from the registry.
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   980
        /// </summary>
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   981
        private void ReadConfigFromRegistry()
0
6dfec3b090d6 initial commit
vb
parents:
diff changeset
   982
        {
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   983
            bool isSuccessful;
515
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
   984
            int parsedIntValue;
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   985
            bool parsedBoolValue;
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   986
            string keyValue;
649
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
   987
            object value;
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
   988
            string[] registryWhitelist;
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
   989
            List<string> whitelist;
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   990
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   991
            /* Note: property accessors (instead of private members) are used for the
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   992
             * few cases where changing a property requires additional steps (like updating pEp engine).
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   993
             */
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   994
462
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
   995
            try
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   996
            {
515
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
   997
                using (RegistryKey key1 = Registry.CurrentUser.OpenSubKey(REG_KEY_SOFTWARE))
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
   998
                {
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
   999
                    using (RegistryKey keyOffice = key1.OpenSubKey(REG_KEY_MICROSOFT_OFFICE))
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
  1000
                    {
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
  1001
                        using (RegistryKey keyPreferences = keyOffice.OpenSubKey(Application.Version.Substring(0, 2) + ".0\\Outlook\\Preferences\\"))
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
  1002
                        {
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
  1003
                            /* Attempt to get IsTNEFDisabled
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
  1004
                             *  "12" Outlook 2007
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
  1005
                             *  "14" Outlook 2010
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
  1006
                             *  "15" Outlook 2013
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
  1007
                             *  "16" Outlook 2016
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
  1008
                             */
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
  1009
                            keyValue = keyPreferences.GetValue(ThisAddIn.REG_NAME_IS_TNEF_DISABLED, Global.IS_TNEF_DISABLED_DEFAULT).ToString();
515
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
  1010
                            isSuccessful = int.TryParse(keyValue, out parsedIntValue);
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
  1011
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
  1012
                            if (isSuccessful)
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
  1013
                            {
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
  1014
                                this.IsTNEFDisabled = (parsedIntValue > 0);
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
  1015
                            }
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
  1016
                        }
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
  1017
                    }
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
  1018
                }
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
  1019
462
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1020
                using (RegistryKey key1 = Registry.CurrentUser.OpenSubKey(REG_KEY_SOFTWARE, true))
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
  1021
                {
462
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1022
                    using (RegistryKey key2 = key1.CreateSubKey(REG_KEY_PEP))
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
  1023
                    {
649
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
  1024
                        // Attempt to get AccountWhitelist
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
  1025
                        value = key2.GetValue(REG_NAME_ACCOUNT_WHITELIST, null);
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
  1026
                        if (value != null)
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
  1027
                        {
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
  1028
                            whitelist = new List<string>();
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
  1029
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
  1030
                            // Copy over hardcoded values
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
  1031
                            for (int i = 0; i < Global.HARDCODED_ACCOUNT_WHITELIST.Length; i++)
649
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
  1032
                            {
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
  1033
                                whitelist.Add(Global.HARDCODED_ACCOUNT_WHITELIST[i].Trim());
649
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
  1034
                            }
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
  1035
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
  1036
                            // Copy over registry values
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
  1037
                            registryWhitelist = value.ToString().Split(';');
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
  1038
                            for (int i = 0; i < registryWhitelist.Length; i++)
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
  1039
                            {
650
568a3a9c2d33 Add account whitelist property and trim when making the list.
Dean Looyengoed
parents: 649
diff changeset
  1040
                                whitelist.Add(registryWhitelist[i].Trim());
649
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
  1041
                            }
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
  1042
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
  1043
                            this._AccountWhitelist = whitelist.ToArray();
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
  1044
                        }
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
  1045
462
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1046
                        // Attempt to get CrashReportSendAddress
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
  1047
                        this._CrashReportSendAddress = key2.GetValue(REG_NAME_CRASH_REPORT_SEND_ADDRESS, Global.CRASH_REPORT_SEND_ADDRESS_DEFAULT).ToString();
453
4b8c31936610 Add crash report config options and read from registry.
Dean Looyengoed
parents: 452
diff changeset
  1048
462
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1049
                        // Get encryption state of each account in the registry -- any previous values are cleared
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1050
                        this.EncryptedAccountsList.Clear();
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1051
                        using (RegistryKey key3 = key2.CreateSubKey(REG_KEY_ENCRYPTED_ACCOUNTS_LIST))
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1052
                        {
462
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1053
                            foreach (string name in key3.GetValueNames())
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1054
                            {
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
  1055
                                keyValue = key3.GetValue(name, Global.ENCRYPT_ACCOUNTS_BY_DEFAULT).ToString();
462
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1056
                                isSuccessful = bool.TryParse(keyValue, out parsedBoolValue);
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1057
462
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1058
                                if (isSuccessful)
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1059
                                {
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1060
                                    this.EncryptedAccountsList.Add(name, parsedBoolValue);
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1061
                                }
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1062
                            }
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1063
                        }
627
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1064
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1065
                        // Attempt to get ExtraKeys value 
649
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
  1066
                        value = key2.GetValue(REG_NAME_EXTRA_KEYS);
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
  1067
                        if (value != null)
627
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1068
                        {
649
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
  1069
                            this._ExtraKeys = value.ToString().Split(',');
627
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1070
                        }
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1071
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1072
                        // Attempt to get IsCrashReportVisible
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
  1073
                        keyValue = key2.GetValue(REG_NAME_IS_CRASH_REPORT_VISIBLE, Global.IS_CRASH_REPORT_VISIBLE_DEFAULT).ToString();
627
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1074
                        isSuccessful = bool.TryParse(keyValue, out parsedBoolValue);
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1075
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1076
                        if (isSuccessful)
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1077
                        {
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1078
                            this._IsCrashReportVisible = parsedBoolValue;
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1079
                        }
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1080
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1081
                        // Attempt to get IsDeveloperModeEnabled
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
  1082
                        keyValue = key2.GetValue(REG_NAME_IS_DEVELOPER_MODE_ENABLED, Global.IS_DEVELOPER_MODE_ENABLED_DEFAULT).ToString();
627
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1083
                        isSuccessful = bool.TryParse(keyValue, out parsedBoolValue);
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1084
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1085
                        if (isSuccessful)
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1086
                        {
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1087
                            this._IsDeveloperModeEnabled = parsedBoolValue;
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1088
                        }
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1089
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1090
                        // Attempt to get IsEncryptAllAccountsEnabled value
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
  1091
                        keyValue = key2.GetValue(REG_NAME_IS_ENCRYPT_ALL_ACCOUNTS_ENABLED, Global.IS_ENCRYPT_ALL_ACCOUNTS_ENABLED_DEFAULT).ToString();
627
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1092
                        isSuccessful = bool.TryParse(keyValue, out parsedBoolValue);
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1093
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1094
                        if (isSuccessful)
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1095
                        {
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1096
                            this.IsEncryptAllAccountsEnabled = parsedBoolValue;
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1097
                        }
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1098
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1099
                        // Attempt to get IsKeyServerUsed value
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
  1100
                        keyValue = key2.GetValue(REG_NAME_IS_KEY_SERVER_USED, Global.IS_KEY_SERVER_USED_DEFAULT).ToString();
627
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1101
                        isSuccessful = bool.TryParse(keyValue, out parsedBoolValue);
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1102
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1103
                        if (isSuccessful)
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1104
                        {
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1105
                            this.IsKeyServerUsed = parsedBoolValue; // Must use property accessor
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1106
                        }
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1107
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1108
                        // Attempt to get IsPassiveModeEnabled value
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
  1109
                        keyValue = key2.GetValue(REG_NAME_IS_PASSIVE_MODE_ENABLED, Global.IS_PASSIVE_MODE_ENABLED_DEFAULT).ToString();
627
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1110
                        isSuccessful = bool.TryParse(keyValue, out parsedBoolValue);
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1111
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1112
                        if (isSuccessful)
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1113
                        {
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1114
                            this.IsPassiveModeEnabled = parsedBoolValue; // Must use property accessor
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1115
                        }
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1116
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1117
                        // Attempt to get IsUnencryptedSubjectEnabled value
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
  1118
                        keyValue = key2.GetValue(REG_NAME_IS_UNENCRYPTED_SUBJECT_ENABLED, Global.IS_UNENCRYPTED_SUBJECT_ENABLED_DEFAULT).ToString();
627
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1119
                        isSuccessful = bool.TryParse(keyValue, out parsedBoolValue);
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1120
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1121
                        if (isSuccessful)
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1122
                        {
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1123
                            this.IsUnencryptedSubjectEnabled = parsedBoolValue; // Must use property accessor
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1124
                        }
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1125
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1126
                        // Attempt to get IsVerboseLoggingEnabled value
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
  1127
                        keyValue = key2.GetValue(REG_NAME_IS_VERBOSE_LOGGING_ENABLED, Global.IS_VERBOSE_LOGGING_ENABLED_DEFAULT).ToString();
627
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1128
                        isSuccessful = bool.TryParse(keyValue, out parsedBoolValue);
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1129
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1130
                        if (isSuccessful)
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1131
                        {
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1132
                            this.IsVerboseLoggingEnabled = parsedBoolValue; // Must use property accessor
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1133
                        }
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
  1134
                    }
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
  1135
                }
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
  1136
            }
462
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1137
            catch (Exception ex)
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1138
            {
660
e5346cda03ff Merge GlobalConst and GlobalExceptionHandler into only one Global class.
Dean Looyengoed
parents: 659
diff changeset
  1139
                Global.StopAndSendCrashReport(ex);
462
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1140
            }
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1141
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1142
            return;
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1143
        }
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1144
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1145
        /// <summary>
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1146
        /// Copies any necessary data from the given options form state back into this add-ins current state.
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1147
        /// The registry is also updated by this method.
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1148
        /// </summary>
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1149
        /// <param name="state">The state to copy data from.</param>
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1150
        public void SetOptionsState(FormOptions.State state)
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1151
        {
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1152
            if (state != null)
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1153
            {
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1154
                /* Note: property accessors (instead of private members) are used for the
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1155
                 * few cases where changing a property requires additional steps (like updating pEp engine).
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1156
                 */
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1157
                foreach (KeyValuePair<string, bool> entry in state.EncryptedAccountsList)
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1158
                {
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1159
                    if (this.EncryptedAccountsList.ContainsKey(entry.Key))
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1160
                    {
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1161
                        // Modify value
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1162
                        this.EncryptedAccountsList[entry.Key] = entry.Value;
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1163
                    }
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1164
                    else
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1165
                    {
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1166
                        // Create new entry (if there was an additional account added to the session)
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1167
                        this.EncryptedAccountsList.Add(entry.Key, entry.Value);
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1168
                    }
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1169
                }
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1170
659
a1712cc16fdb Report system information in about page of options.
Dean Looyengoed
parents: 652
diff changeset
  1171
                this.IsEncryptAllAccountsEnabled = state.IsEncryptAllAccountsEnabled;
a1712cc16fdb Report system information in about page of options.
Dean Looyengoed
parents: 652
diff changeset
  1172
                this.IsKeyServerUsed = state.IsKeyServerUsed;
a1712cc16fdb Report system information in about page of options.
Dean Looyengoed
parents: 652
diff changeset
  1173
                this.IsTNEFDisabled = state.IsTNEFDisabled;
a1712cc16fdb Report system information in about page of options.
Dean Looyengoed
parents: 652
diff changeset
  1174
                this.IsUnencryptedSubjectEnabled = state.IsUnencryptedSubjectEnabled;
a1712cc16fdb Report system information in about page of options.
Dean Looyengoed
parents: 652
diff changeset
  1175
                this.IsVerboseLoggingEnabled = state.IsVerboseLoggingEnabled;
a1712cc16fdb Report system information in about page of options.
Dean Looyengoed
parents: 652
diff changeset
  1176
219
ee11aec8fa86 Save and restore the complete options state between instances of the options form.
Dean Looyengoed
parents: 209
diff changeset
  1177
                // Save last state for next options opening
ee11aec8fa86 Save and restore the complete options state between instances of the options form.
Dean Looyengoed
parents: 209
diff changeset
  1178
                this.lastOptionsState = state.Copy();
ee11aec8fa86 Save and restore the complete options state between instances of the options form.
Dean Looyengoed
parents: 209
diff changeset
  1179
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1180
                // Update registry (in case of unforseen app shutdown)
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1181
                this.WriteConfigToRegistry();
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1182
            }
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1183
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1184
            return;
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1185
        }
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1186
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1187
        /// <summary>
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1188
        /// Builds a new options form state using this add-ins current state.
44dac4bb337a Complete the state management in b