ThisAddIn.cs
author Dean Looyengoed
Fri, 27 May 2016 00:14:24 +0200
changeset 935 5308aa8494f0
parent 933 949c70c767f1
child 937 675c4cd069e0
child 970 d676bc7cbad6
permissions -rw-r--r--
Update language list and trustwords language selection to use latest engine format.
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.Globalization;
0
6dfec3b090d6 initial commit
vb
parents:
diff changeset
     6
using System.Runtime.InteropServices;
714
761f853c4c0f For all Myself identities, calculate user ID using a hash of the windows Environment.UserName;
Dean Looyengoed
parents: 686
diff changeset
     7
using System.Security.Cryptography;
761f853c4c0f For all Myself identities, calculate user ID using a hash of the windows Environment.UserName;
Dean Looyengoed
parents: 686
diff changeset
     8
using System.Text;
0
6dfec3b090d6 initial commit
vb
parents:
diff changeset
     9
using System.Threading;
47
d3b5164cc922 read in extra keys
Volker Birk <vb@pep-project.org>
parents: 46
diff changeset
    10
using System.Windows.Forms;
714
761f853c4c0f For all Myself identities, calculate user ID using a hash of the windows Environment.UserName;
Dean Looyengoed
parents: 686
diff changeset
    11
using Office = Microsoft.Office.Core;
0
6dfec3b090d6 initial commit
vb
parents:
diff changeset
    12
using Outlook = Microsoft.Office.Interop.Outlook;
6dfec3b090d6 initial commit
vb
parents:
diff changeset
    13
6dfec3b090d6 initial commit
vb
parents:
diff changeset
    14
namespace pEp
6dfec3b090d6 initial commit
vb
parents:
diff changeset
    15
{
6dfec3b090d6 initial commit
vb
parents:
diff changeset
    16
    public partial class ThisAddIn
6dfec3b090d6 initial commit
vb
parents:
diff changeset
    17
    {
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    18
        #region VSTO generated code
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    19
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    20
        /// <summary>
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    21
        /// Required method for Designer support - do not modify
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    22
        /// the contents of this method with the code editor.
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    23
        /// </summary>
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    24
        private void InternalStartup()
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    25
        {
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    26
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    27
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    28
        }
201
9e0548fa3942 Code reformatting.
Markus Schaber <markus@pep-security.net>
parents: 191
diff changeset
    29
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    30
        #endregion
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    31
831
02fc35559e5b Add IsDisableProtectionForContactsEnabled setting and read it from the registry.
Dean Looyengoed
parents: 830
diff changeset
    32
        private const string REG_KEY_SOFTWARE                                    = "Software";
02fc35559e5b Add IsDisableProtectionForContactsEnabled setting and read it from the registry.
Dean Looyengoed
parents: 830
diff changeset
    33
        private const string REG_KEY_PEP                                         = "pEp";
02fc35559e5b Add IsDisableProtectionForContactsEnabled setting and read it from the registry.
Dean Looyengoed
parents: 830
diff changeset
    34
        private const string REG_KEY_MICROSOFT_OFFICE                            = "Microsoft\\Office";
02fc35559e5b Add IsDisableProtectionForContactsEnabled setting and read it from the registry.
Dean Looyengoed
parents: 830
diff changeset
    35
        private const string REG_KEY_ENCRYPTED_ACCOUNTS_LIST                     = "EncryptedAccountsList";
02fc35559e5b Add IsDisableProtectionForContactsEnabled setting and read it from the registry.
Dean Looyengoed
parents: 830
diff changeset
    36
        private const string REG_NAME_ACCOUNT_WHITELIST                          = "AccountWhitelist";
02fc35559e5b Add IsDisableProtectionForContactsEnabled setting and read it from the registry.
Dean Looyengoed
parents: 830
diff changeset
    37
        private const string REG_NAME_CRASH_REPORT_SEND_ADDRESS                  = "CrashReportSendAddress";
02fc35559e5b Add IsDisableProtectionForContactsEnabled setting and read it from the registry.
Dean Looyengoed
parents: 830
diff changeset
    38
        private const string REG_NAME_DEFAULT_CODEPAGE_OUT                       = "Default_CodePageOut"; // Name defined by Microsoft
02fc35559e5b Add IsDisableProtectionForContactsEnabled setting and read it from the registry.
Dean Looyengoed
parents: 830
diff changeset
    39
        private const string REG_NAME_EXTRA_KEYS                                 = "ExtraKeys";
02fc35559e5b Add IsDisableProtectionForContactsEnabled setting and read it from the registry.
Dean Looyengoed
parents: 830
diff changeset
    40
        private const string REG_NAME_IS_CRASH_REPORT_VISIBLE                    = "IsCrashReportVisible";
02fc35559e5b Add IsDisableProtectionForContactsEnabled setting and read it from the registry.
Dean Looyengoed
parents: 830
diff changeset
    41
        private const string REG_NAME_IS_DEVELOPER_MODE_ENABLED                  = "IsDeveloperModeEnabled";
02fc35559e5b Add IsDisableProtectionForContactsEnabled setting and read it from the registry.
Dean Looyengoed
parents: 830
diff changeset
    42
        private const string REG_NAME_IS_DISABLE_PROTECTION_FOR_CONTACTS_ENABLED = "IsDisableProtectionForContactsEnabled";
02fc35559e5b Add IsDisableProtectionForContactsEnabled setting and read it from the registry.
Dean Looyengoed
parents: 830
diff changeset
    43
        private const string REG_NAME_IS_ENCRYPT_ALL_ACCOUNTS_ENABLED            = "IsEncryptAllAccountsEnabled";
02fc35559e5b Add IsDisableProtectionForContactsEnabled setting and read it from the registry.
Dean Looyengoed
parents: 830
diff changeset
    44
        private const string REG_NAME_IS_KEY_SERVER_USED                         = "IsKeyServerUsed";
02fc35559e5b Add IsDisableProtectionForContactsEnabled setting and read it from the registry.
Dean Looyengoed
parents: 830
diff changeset
    45
        private const string REG_NAME_IS_PASSIVE_MODE_ENABLED                    = "IsPassiveModeEnabled";
02fc35559e5b Add IsDisableProtectionForContactsEnabled setting and read it from the registry.
Dean Looyengoed
parents: 830
diff changeset
    46
        private const string REG_NAME_IS_PEP_FOLDER_VISIBLE                      = "IsPEPFolderVisible";
02fc35559e5b Add IsDisableProtectionForContactsEnabled setting and read it from the registry.
Dean Looyengoed
parents: 830
diff changeset
    47
        private const string REG_NAME_IS_TNEF_DISABLED                           = "DisableTNEF"; // Name defined by Microsoft
02fc35559e5b Add IsDisableProtectionForContactsEnabled setting and read it from the registry.
Dean Looyengoed
parents: 830
diff changeset
    48
        private const string REG_NAME_IS_UNENCRYPTED_SUBJECT_ENABLED             = "IsUnencryptedSubjectEnabled";
02fc35559e5b Add IsDisableProtectionForContactsEnabled setting and read it from the registry.
Dean Looyengoed
parents: 830
diff changeset
    49
        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
    50
935
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    51
        private string[]                                _AccountWhitelist                      = Globals.HARDCODED_ACCOUNT_WHITELIST;
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    52
        private CultureInfo                             _ActiveCulture                         = Globals.CULTURE_DEFAULT;
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    53
        private string                                  _CrashReportSendAddress                = Globals.CRASH_REPORT_SEND_ADDRESS_DEFAULT;
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    54
        private Dictionary<string, bool>                _EncryptedAccountsList                 = new Dictionary<string, bool>();
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    55
        private string[]                                _ExtraKeys                             = null;
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    56
        private bool                                    _IsCrashReportVisible                  = Globals.IS_CRASH_REPORT_VISIBLE_DEFAULT;
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    57
        private bool                                    _IsDeveloperModeEnabled                = Globals.IS_DEVELOPER_MODE_ENABLED_DEFAULT;
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    58
        private bool                                    _IsDisableProtectionForContactsEnabled = Globals.IS_DISABLE_PROTECTION_FOR_CONTACTS_ENABLED_DEFAULT;
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    59
        private bool                                    _IsEncryptAllAccountsEnabled           = Globals.IS_ENCRYPT_ALL_ACCOUNTS_ENABLED_DEFAULT;
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    60
        private bool                                    _IsKeyServerUsed                       = Globals.IS_KEY_SERVER_USED_DEFAULT;
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    61
        private bool                                    _IsPassiveModeEnabled                  = Globals.IS_PASSIVE_MODE_ENABLED_DEFAULT;
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    62
        private bool                                    _IsPEPFolderVisible                    = Globals.IS_PEP_FOLDER_VISIBLE_DEFAULT;
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    63
        private bool                                    _IsTNEFDisabled                        = Globals.IS_TNEF_DISABLED_DEFAULT;
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    64
        private bool                                    _IsUnencryptedSubjectEnabled           = Globals.IS_UNENCRYPTED_SUBJECT_ENABLED_DEFAULT;
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    65
        private bool                                    _IsVerboseLoggingEnabled               = Globals.IS_VERBOSE_LOGGING_ENABLED_DEFAULT;
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    66
        private List<KeyValuePair<CultureInfo, string>> _LanguageList                          = null;
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    67
        private static pEpEngine                        _pEp                                   = null;
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    68
        private Outlook.Folder                          _TempFolder                            = null;
64
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
    69
837
727a8fb5a9c0 Decrypt sent items in ActiveSync accounts when the server is trusted.
Dean Looyengoed
parents: 836
diff changeset
    70
        private bool                       initialized        = false;
727a8fb5a9c0 Decrypt sent items in ActiveSync accounts when the server is trusted.
Dean Looyengoed
parents: 836
diff changeset
    71
        private FormOptions.State          lastOptionsState   = null;
727a8fb5a9c0 Decrypt sent items in ActiveSync accounts when the server is trusted.
Dean Looyengoed
parents: 836
diff changeset
    72
        private Dictionary<string, string> userIDCache        = new Dictionary<string, string>();
727a8fb5a9c0 Decrypt sent items in ActiveSync accounts when the server is trusted.
Dean Looyengoed
parents: 836
diff changeset
    73
        private List<WatchedSentFolder>    watchedSentFolders = new List<WatchedSentFolder>();
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    74
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    75
        /**************************************************************
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    76
         * 
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    77
         * Property Accessors
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    78
         * 
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    79
         *************************************************************/
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    80
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    81
        /// <summary>
650
568a3a9c2d33 Add account whitelist property and trim when making the list.
Dean Looyengoed
parents: 649
diff changeset
    82
        /// 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
    83
        /// </summary>
910
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
    84
        internal string[] AccountWhitelist
650
568a3a9c2d33 Add account whitelist property and trim when making the list.
Dean Looyengoed
parents: 649
diff changeset
    85
        {
568a3a9c2d33 Add account whitelist property and trim when making the list.
Dean Looyengoed
parents: 649
diff changeset
    86
            get { return (this._AccountWhitelist); }
568a3a9c2d33 Add account whitelist property and trim when making the list.
Dean Looyengoed
parents: 649
diff changeset
    87
        }
568a3a9c2d33 Add account whitelist property and trim when making the list.
Dean Looyengoed
parents: 649
diff changeset
    88
568a3a9c2d33 Add account whitelist property and trim when making the list.
Dean Looyengoed
parents: 649
diff changeset
    89
        /// <summary>
854
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
    90
        /// Gets the active culture which is set from the UI language.
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
    91
        /// </summary>
910
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
    92
        internal CultureInfo ActiveCulture
854
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
    93
        {
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
    94
            get { return (this._ActiveCulture); }
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
    95
        }
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
    96
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
    97
        /// <summary>
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
    98
        /// Gets the email address to send any crash report to.
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
    99
        /// Can only be set from the registry.
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   100
        /// </summary>
910
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
   101
        internal string CrashReportSendAddress
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   102
        {
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   103
            get { return (this._CrashReportSendAddress); }
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   104
        }
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   105
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   106
        /// <summary>
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   107
        /// 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
   108
        /// 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
   109
        /// 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
   110
        /// </summary>
910
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
   111
        internal Dictionary<string, bool> EncryptedAccountsList
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   112
        {
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   113
            get { return (this._EncryptedAccountsList); }
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   114
        }
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   115
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
   116
        /// <summary>
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   117
        /// Gets any extra encryption keys that were loaded from the registry.
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   118
        /// Can only be set from the registry.
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   119
        /// </summary>
910
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
   120
        internal string[] ExtraKeys
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   121
        {
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   122
            get { return (this._ExtraKeys); }
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   123
        }
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   124
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   125
        /// <summary>
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   126
        /// Gets whether the crash report window is visible to the user.
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   127
        /// Can only be set from the registry.
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   128
        /// </summary>
910
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
   129
        internal bool IsCrashReportVisible
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   130
        {
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   131
            get { return (this._IsCrashReportVisible); }
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   132
        }
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   133
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   134
        /// <summary>
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   135
        /// Gets whether developer mode is enabled.
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   136
        /// Can only be set from the registry.
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   137
        /// </summary>
910
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
   138
        internal bool IsDeveloperModeEnabled
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   139
        {
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   140
            get { return (this._IsDeveloperModeEnabled); }
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   141
        }
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   142
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   143
        /// <summary>
831
02fc35559e5b Add IsDisableProtectionForContactsEnabled setting and read it from the registry.
Dean Looyengoed
parents: 830
diff changeset
   144
        /// Gets whether disabling protection per contact is enabled.
02fc35559e5b Add IsDisableProtectionForContactsEnabled setting and read it from the registry.
Dean Looyengoed
parents: 830
diff changeset
   145
        /// Can only be set from the registry.
02fc35559e5b Add IsDisableProtectionForContactsEnabled setting and read it from the registry.
Dean Looyengoed
parents: 830
diff changeset
   146
        /// </summary>
910
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
   147
        internal bool IsDisableProtectionForContactsEnabled
831
02fc35559e5b Add IsDisableProtectionForContactsEnabled setting and read it from the registry.
Dean Looyengoed
parents: 830
diff changeset
   148
        {
02fc35559e5b Add IsDisableProtectionForContactsEnabled setting and read it from the registry.
Dean Looyengoed
parents: 830
diff changeset
   149
            get { return (this._IsDisableProtectionForContactsEnabled); }
02fc35559e5b Add IsDisableProtectionForContactsEnabled setting and read it from the registry.
Dean Looyengoed
parents: 830
diff changeset
   150
        }
02fc35559e5b Add IsDisableProtectionForContactsEnabled setting and read it from the registry.
Dean Looyengoed
parents: 830
diff changeset
   151
02fc35559e5b Add IsDisableProtectionForContactsEnabled setting and read it from the registry.
Dean Looyengoed
parents: 830
diff changeset
   152
        /// <summary>
451
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   153
        /// 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
   154
        /// </summary>
910
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
   155
        internal bool IsEncryptAllAccountsEnabled
451
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   156
        {
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   157
            get { return (this._IsEncryptAllAccountsEnabled); }
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   158
            set { this._IsEncryptAllAccountsEnabled = value; }
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   159
        }
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   160
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   161
        /// <summary>
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   162
        /// 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
   163
        /// When set, this also updates the pEp engine.
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   164
        /// </summary>
910
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
   165
        internal bool IsKeyServerUsed
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   166
        {
451
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   167
            get { return (this._IsKeyServerUsed); }
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   168
            set
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   169
            {
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   170
                this._IsKeyServerUsed = value;
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   171
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   172
                // Start/stop key server
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   173
                if (this._IsKeyServerUsed)
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   174
                {
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   175
                    ThisAddIn.pEp.start_keyserver_lookup();
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   176
                }
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   177
                else
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   178
                {
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   179
                    ThisAddIn.pEp.stop_keyserver_lookup();
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   180
                }
7dd0bb192256 Standardize all option names and implement subject encryption option.
Dean Looyengoed
parents: 450
diff changeset
   181
            }
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   182
        }
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   183
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   184
        /// <summary>
598
e1ff494dc53b Implement passive mode which can only be enabled from the registry.
Dean Looyengoed
parents: 597
diff changeset
   185
        /// 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
   186
        /// 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
   187
        /// 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
   188
        /// </summary>
910
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
   189
        internal bool IsPassiveModeEnabled
452
9be34118b38f Add IsSendWithoutKeyEnabled config option and read from registry.
Dean Looyengoed
parents: 451
diff changeset
   190
        {
598
e1ff494dc53b Implement passive mode which can only be enabled from the registry.
Dean Looyengoed
parents: 597
diff changeset
   191
            get { return (this._IsPassiveModeEnabled); }
e1ff494dc53b Implement passive mode which can only be enabled from the registry.
Dean Looyengoed
parents: 597
diff changeset
   192
            set
e1ff494dc53b Implement passive mode which can only be enabled from the registry.
Dean Looyengoed
parents: 597
diff changeset
   193
            {
e1ff494dc53b Implement passive mode which can only be enabled from the registry.
Dean Looyengoed
parents: 597
diff changeset
   194
                this._IsPassiveModeEnabled = value;
e1ff494dc53b Implement passive mode which can only be enabled from the registry.
Dean Looyengoed
parents: 597
diff changeset
   195
                ThisAddIn.pEp.passive_mode(this._IsPassiveModeEnabled);
e1ff494dc53b Implement passive mode which can only be enabled from the registry.
Dean Looyengoed
parents: 597
diff changeset
   196
            }
452
9be34118b38f Add IsSendWithoutKeyEnabled config option and read from registry.
Dean Looyengoed
parents: 451
diff changeset
   197
        }
9be34118b38f Add IsSendWithoutKeyEnabled config option and read from registry.
Dean Looyengoed
parents: 451
diff changeset
   198
9be34118b38f Add IsSendWithoutKeyEnabled config option and read from registry.
Dean Looyengoed
parents: 451
diff changeset
   199
        /// <summary>
816
22599c48c284 Add settings/configuration to show or hide the pEp store in the navigation pane.
Dean Looyengoed
parents: 815
diff changeset
   200
        /// Gets or sets whether the pEp folder (and its contents) are visible.
22599c48c284 Add settings/configuration to show or hide the pEp store in the navigation pane.
Dean Looyengoed
parents: 815
diff changeset
   201
        /// When set, this will immediately update folder visiblity.
22599c48c284 Add settings/configuration to show or hide the pEp store in the navigation pane.
Dean Looyengoed
parents: 815
diff changeset
   202
        /// </summary>
910
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
   203
        internal bool IsPEPFolderVisible
816
22599c48c284 Add settings/configuration to show or hide the pEp store in the navigation pane.
Dean Looyengoed
parents: 815
diff changeset
   204
        {
22599c48c284 Add settings/configuration to show or hide the pEp store in the navigation pane.
Dean Looyengoed
parents: 815
diff changeset
   205
            get { return (this._IsPEPFolderVisible); }
22599c48c284 Add settings/configuration to show or hide the pEp store in the navigation pane.
Dean Looyengoed
parents: 815
diff changeset
   206
            set
22599c48c284 Add settings/configuration to show or hide the pEp store in the navigation pane.
Dean Looyengoed
parents: 815
diff changeset
   207
            {
22599c48c284 Add settings/configuration to show or hide the pEp store in the navigation pane.
Dean Looyengoed
parents: 815
diff changeset
   208
                this._IsPEPFolderVisible = value;
22599c48c284 Add settings/configuration to show or hide the pEp store in the navigation pane.
Dean Looyengoed
parents: 815
diff changeset
   209
                this.SetTempFolderVisibility(this._IsPEPFolderVisible);
22599c48c284 Add settings/configuration to show or hide the pEp store in the navigation pane.
Dean Looyengoed
parents: 815
diff changeset
   210
            }
22599c48c284 Add settings/configuration to show or hide the pEp store in the navigation pane.
Dean Looyengoed
parents: 815
diff changeset
   211
        }
22599c48c284 Add settings/configuration to show or hide the pEp store in the navigation pane.
Dean Looyengoed
parents: 815
diff changeset
   212
22599c48c284 Add settings/configuration to show or hide the pEp store in the navigation pane.
Dean Looyengoed
parents: 815
diff changeset
   213
        /// <summary>
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   214
        /// 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
   215
        /// </summary>
910
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
   216
        internal bool IsTNEFDisabled
588
2d12fb5ee4fc Add developer mode to config and options state.
Dean Looyengoed
parents: 587
diff changeset
   217
        {
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   218
            get { return (this._IsTNEFDisabled); }
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   219
            set { this._IsTNEFDisabled = value; }
453
4b8c31936610 Add crash report config options and read from registry.
Dean Looyengoed
parents: 452
diff changeset
   220
        }
4b8c31936610 Add crash report config options and read from registry.
Dean Looyengoed
parents: 452
diff changeset
   221
4b8c31936610 Add crash report config options and read from registry.
Dean Looyengoed
parents: 452
diff changeset
   222
        /// <summary>
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   223
        /// Gets or sets whether to enable encryption of message subjects.
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   224
        /// 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
   225
        /// </summary>
910
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
   226
        internal bool IsUnencryptedSubjectEnabled
453
4b8c31936610 Add crash report config options and read from registry.
Dean Looyengoed
parents: 452
diff changeset
   227
        {
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   228
            get { return (this._IsUnencryptedSubjectEnabled); }
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   229
            set
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   230
            {
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   231
                this._IsUnencryptedSubjectEnabled = value;
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   232
                ThisAddIn.pEp.unencrypted_subject(this._IsUnencryptedSubjectEnabled);
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   233
            }
453
4b8c31936610 Add crash report config options and read from registry.
Dean Looyengoed
parents: 452
diff changeset
   234
        }
4b8c31936610 Add crash report config options and read from registry.
Dean Looyengoed
parents: 452
diff changeset
   235
4b8c31936610 Add crash report config options and read from registry.
Dean Looyengoed
parents: 452
diff changeset
   236
        /// <summary>
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   237
        /// Gets or sets whether verbose logging is enabled.
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   238
        /// When set, this also updates the pEp engine.
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   239
        /// </summary>
910
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
   240
        internal bool IsVerboseLoggingEnabled
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   241
        {
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   242
            get { return (this._IsVerboseLoggingEnabled); }
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   243
            set
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   244
            {
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   245
                this._IsVerboseLoggingEnabled = value;
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   246
                ThisAddIn.pEp.verbose_logging(this._IsVerboseLoggingEnabled);
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   247
            }
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   248
        }
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
        /// <summary>
854
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   251
        /// Gets the list of languages supported in the pEp engine.
935
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
   252
        /// The list of language includes a key-value pair of the culture as well as a 
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
   253
        /// display phrase in the native language for the trustwords.
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
   254
        /// (phrase example: "I want to display the trustwords in English language")
854
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   255
        /// </summary>
935
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
   256
        internal List<KeyValuePair<CultureInfo, string>> LanguageList
854
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   257
        {
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   258
            get
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   259
            {
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   260
                string code;
935
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
   261
                string phrase;
854
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   262
                string engineList;
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   263
                string[] languages;
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   264
                string[] language;
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   265
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   266
                if (this._LanguageList == null)
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   267
                {
935
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
   268
                    this._LanguageList = new List<KeyValuePair<CultureInfo, string>>();
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
   269
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
   270
                    try
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
   271
                    {
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
   272
                        engineList = ThisAddIn.pEp.get_languagelist();
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
   273
                    }
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
   274
                    catch
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
   275
                    {
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
   276
                        engineList = "";
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
   277
                        Globals.Log("LanguageList: Failed to get list from engine.");
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
   278
                    }
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
   279
854
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   280
                    languages = engineList.Split('\n');
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   281
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   282
                    // Go through each language group
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   283
                    for (int i = 0; i < languages.Length; i++)
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   284
                    {
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   285
                        language = languages[i].Split(',');
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   286
935
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
   287
                        if (language.Length == 3)
854
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   288
                        {
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   289
                            code = language[0].Trim();
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   290
                            code = code.Replace("\"", "");
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   291
935
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
   292
                            phrase = language[2].Trim();
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
   293
                            phrase = phrase.Replace("\"", "");
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
   294
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
   295
                            this._LanguageList.Add(new KeyValuePair<CultureInfo, string>(new CultureInfo(code),
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
   296
                                                                                         phrase));
854
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   297
                        }
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   298
                    }
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   299
                }
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   300
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   301
                return (this._LanguageList);
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   302
            }
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   303
        }
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   304
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   305
        /// <summary>
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   306
        /// Gets the pEp engine which is static.
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   307
        /// </summary>
910
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
   308
        internal static pEpEngine pEp
64
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   309
        {
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   310
            get
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   311
            {
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   312
                if (_pEp == null)
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   313
                {
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   314
                    try
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   315
                    {
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   316
                        _pEp = new pEpEngine();
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   317
                    }
467
aeb05f7b2704 Finish initial implementation of global exception handler and sending crash report.
Dean Looyengoed
parents: 465
diff changeset
   318
                    catch (Exception ex)
64
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   319
                    {
467
aeb05f7b2704 Finish initial implementation of global exception handler and sending crash report.
Dean Looyengoed
parents: 465
diff changeset
   320
                        string summaryMessage = Properties.Resources.Message_InitError + " " +
aeb05f7b2704 Finish initial implementation of global exception handler and sending crash report.
Dean Looyengoed
parents: 465
diff changeset
   321
                                                Properties.Resources.Message_Reinstall;
860
ff259b6535c7 Merge 'Global' and 'Globals' together.
Dean Looyengoed
parents: 859
diff changeset
   322
                        Globals.StopAndSendCrashReport(ex, summaryMessage, false, true);
460
690f8853d7ae Start to implement the global exception handler in ThisAddIn.
Dean Looyengoed
parents: 455
diff changeset
   323
64
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   324
                        return null;
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   325
                    }
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   326
                }
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   327
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   328
                return _pEp;
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   329
            }
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   330
        }
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   331
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   332
        /// <summary>
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   333
        /// Gets the temporary outlook folder used to save unencrypted outlook mail items.
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   334
        /// </summary>
910
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
   335
        internal Outlook.Folder TempFolder
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   336
        {
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   337
            get { return (this._TempFolder); }
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   338
        }
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   339
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   340
        /**************************************************************
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   341
         * 
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   342
         * Methods
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   343
         * 
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   344
         *************************************************************/
335
6411b6eb2638 Add initial backstage menu for options.
Dean Looyengoed
parents: 330
diff changeset
   345
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
   346
        /// <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
   347
        /// 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
   348
        /// </summary>
326
2acfe22efee4 Remove pEp ribbon tab and add ribbon for backstage options (disabled for now).
Dean Looyengoed
parents: 307
diff changeset
   349
        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
   350
        {
340
ded73ac01f51 Implement the send unencrypted option in the ribbon.
Dean Looyengoed
parents: 335
diff changeset
   351
            return new RibbonCustomizations();
335
6411b6eb2638 Add initial backstage menu for options.
Dean Looyengoed
parents: 330
diff changeset
   352
        }
0
6dfec3b090d6 initial commit
vb
parents:
diff changeset
   353
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
   354
        /// <summary>
626
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   355
        /// Detects and disables GPG for Windows GpgOL Outlook add-in.
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   356
        /// </summary>
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   357
        /// <returns>True if the GpgOL add-in was disabled.</returns>
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   358
        private bool DisableGpgOL()
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   359
        {
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   360
            bool wasDisabled = false;
830
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   361
            Office.COMAddIns comAddIns = null;
626
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   362
830
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   363
            try
626
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   364
            {
830
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   365
                comAddIns = Globals.ThisAddIn.Application.COMAddIns;
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   366
                foreach (Office.COMAddIn addin in comAddIns)
626
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   367
                {
830
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   368
                    if (string.Equals(addin.Description, "GpgOL - The GnuPG Outlook Plugin", StringComparison.OrdinalIgnoreCase))
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   369
                    {
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   370
                        addin.Connect = false;
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   371
                        wasDisabled = true;
626
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   372
860
ff259b6535c7 Merge 'Global' and 'Globals' together.
Dean Looyengoed
parents: 859
diff changeset
   373
                        Globals.Log("DisableGpgOL: GpgOL was detected and disabled.");
830
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   374
                    }
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   375
                }
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   376
            }
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   377
            catch (Exception ex)
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   378
            {
860
ff259b6535c7 Merge 'Global' and 'Globals' together.
Dean Looyengoed
parents: 859
diff changeset
   379
                Globals.Log("DisableGpgOL: Error trying to disable GpgOL, " + ex.ToString());
830
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   380
            }
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   381
            finally
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   382
            {
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   383
                if (comAddIns != null)
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   384
                {
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   385
                    Marshal.ReleaseComObject(comAddIns);
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   386
                    comAddIns = null;
626
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   387
                }
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   388
            }
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   389
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   390
            return (wasDisabled);
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   391
        }
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   392
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   393
        /// <summary>
384
a0aa034cb7f3 Create and implement new classes for PEPAttachment, PEPIdentity and PEPMessage.
Dean Looyengoed
parents: 378
diff changeset
   394
        /// 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
   395
        /// 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
   396
        /// </summary>
910
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
   397
        internal void RegisterMyself()
0
6dfec3b090d6 initial commit
vb
parents:
diff changeset
   398
        {
919
252172b0fbec Standardize calls to the Session in ThisAddIn.
Dean Looyengoed
parents: 918
diff changeset
   399
            Outlook.NameSpace ns = this.Application.Session;
575
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   400
            Outlook.Account acct = null;
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   401
            Outlook.Accounts accounts = ns.Accounts;
576
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   402
            Outlook.Recipient currUser = null;
575
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   403
            pEp_identity_s me;
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   404
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   405
            for (int i = 1; i <= accounts.Count; i++)
0
6dfec3b090d6 initial commit
vb
parents:
diff changeset
   406
            {
575
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   407
                acct = accounts[i];
576
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   408
                currUser = acct.CurrentUser;
575
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   409
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   410
                me = new pEp_identity_s();
14
84089e08d01c bugfix for Exchange account(s)
vb
parents: 13
diff changeset
   411
                me.address = acct.SmtpAddress;
576
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   412
                me.username = (currUser != null ? currUser.Name : null);
776
451e3831822b Support passing a contact in the GetUserID method.
Dean Looyengoed
parents: 773
diff changeset
   413
                me.user_id = Globals.ThisAddIn.GetUserID(me.address, null);
12
7dce2af80337 first key will be used to sign a message
vb
parents: 0
diff changeset
   414
575
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   415
                // Log information if invalid
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   416
                if (string.IsNullOrWhiteSpace(me.address))
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   417
                {
860
ff259b6535c7 Merge 'Global' and 'Globals' together.
Dean Looyengoed
parents: 859
diff changeset
   418
                    Globals.Log("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
   419
                }
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   420
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   421
                if (string.IsNullOrWhiteSpace(me.username))
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   422
                {
860
ff259b6535c7 Merge 'Global' and 'Globals' together.
Dean Looyengoed
parents: 859
diff changeset
   423
                    Globals.Log("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
   424
                }
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   425
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   426
                // Call engine
12
7dce2af80337 first key will be used to sign a message
vb
parents: 0
diff changeset
   427
                try
7dce2af80337 first key will be used to sign a message
vb
parents: 0
diff changeset
   428
                {
59
Volker Birk <vb@pep-project.org>
parents: 55
diff changeset
   429
                    pEp.myself(me);
12
7dce2af80337 first key will be used to sign a message
vb
parents: 0
diff changeset
   430
                }
7dce2af80337 first key will be used to sign a message
vb
parents: 0
diff changeset
   431
                catch (COMException ex)
7dce2af80337 first key will be used to sign a message
vb
parents: 0
diff changeset
   432
                {
860
ff259b6535c7 Merge 'Global' and 'Globals' together.
Dean Looyengoed
parents: 859
diff changeset
   433
                    Globals.StopAndSendCrashReport(ex);
12
7dce2af80337 first key will be used to sign a message
vb
parents: 0
diff changeset
   434
                }
575
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   435
576
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   436
                // Release objects
575
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   437
                if (acct != null)
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   438
                {
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   439
                    Marshal.ReleaseComObject(acct);
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   440
                    acct = null;
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   441
                }
576
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   442
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   443
                if (currUser != null)
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   444
                {
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   445
                    Marshal.ReleaseComObject(currUser);
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   446
                    currUser = null;
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   447
                }
575
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   448
            }
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   449
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   450
            // Release objects
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   451
            if (ns != null)
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   452
            {
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   453
                Marshal.ReleaseComObject(ns);
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   454
                ns = null;
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   455
            }
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   456
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   457
            if (acct != null)
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   458
            {
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   459
                Marshal.ReleaseComObject(acct);
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   460
                acct = null;
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   461
            }
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   462
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   463
            if (accounts != null)
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   464
            {
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   465
                Marshal.ReleaseComObject(accounts);
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   466
                accounts = null;
0
6dfec3b090d6 initial commit
vb
parents:
diff changeset
   467
            }
588
2d12fb5ee4fc Add developer mode to config and options state.
Dean Looyengoed
parents: 587
diff changeset
   468
576
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   469
            if (currUser != null)
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   470
            {
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   471
                Marshal.ReleaseComObject(currUser);
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   472
                currUser = null;
e0190df007de Check if current user is null in RegisterMyself method.
Dean Looyengoed
parents: 575
diff changeset
   473
            }
0
6dfec3b090d6 initial commit
vb
parents:
diff changeset
   474
384
a0aa034cb7f3 Create and implement new classes for PEPAttachment, PEPIdentity and PEPMessage.
Dean Looyengoed
parents: 378
diff changeset
   475
            return;
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   476
        }
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   477
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   478
        /// <summary>
624
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   479
        /// 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
   480
        /// This will read the value of the user property.
833
4af5f979b0d8 Support IsDisableProtectionForContactsEnabled in the GetForceUnencrypted(contact) method.
Dean Looyengoed
parents: 831
diff changeset
   481
        /// Note: If IsDisableProtectionForContactsEnabled != true, false will always be returned.
624
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   482
        /// </summary>
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   483
        /// <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
   484
        /// <returns>True if the mail item is force unencrypted, otherwise false or null.</returns>
910
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
   485
        internal bool? GetForceUnencrypted(Outlook.ContactItem contact)
624
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   486
        {
833
4af5f979b0d8 Support IsDisableProtectionForContactsEnabled in the GetForceUnencrypted(contact) method.
Dean Looyengoed
parents: 831
diff changeset
   487
            bool? value = null;
4af5f979b0d8 Support IsDisableProtectionForContactsEnabled in the GetForceUnencrypted(contact) method.
Dean Looyengoed
parents: 831
diff changeset
   488
            Outlook.UserProperties properties;
4af5f979b0d8 Support IsDisableProtectionForContactsEnabled in the GetForceUnencrypted(contact) method.
Dean Looyengoed
parents: 831
diff changeset
   489
            Outlook.UserProperty up;
624
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   490
833
4af5f979b0d8 Support IsDisableProtectionForContactsEnabled in the GetForceUnencrypted(contact) method.
Dean Looyengoed
parents: 831
diff changeset
   491
            if (this._IsDisableProtectionForContactsEnabled)
624
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   492
            {
833
4af5f979b0d8 Support IsDisableProtectionForContactsEnabled in the GetForceUnencrypted(contact) method.
Dean Looyengoed
parents: 831
diff changeset
   493
                properties = contact.UserProperties;
4af5f979b0d8 Support IsDisableProtectionForContactsEnabled in the GetForceUnencrypted(contact) method.
Dean Looyengoed
parents: 831
diff changeset
   494
                up = properties.Find(CryptableMailItem.USER_PROPERTY_KEY_FORCE_UNENCRYPTED);
4af5f979b0d8 Support IsDisableProtectionForContactsEnabled in the GetForceUnencrypted(contact) method.
Dean Looyengoed
parents: 831
diff changeset
   495
4af5f979b0d8 Support IsDisableProtectionForContactsEnabled in the GetForceUnencrypted(contact) method.
Dean Looyengoed
parents: 831
diff changeset
   496
                if (up == null)
4af5f979b0d8 Support IsDisableProtectionForContactsEnabled in the GetForceUnencrypted(contact) method.
Dean Looyengoed
parents: 831
diff changeset
   497
                {
4af5f979b0d8 Support IsDisableProtectionForContactsEnabled in the GetForceUnencrypted(contact) method.
Dean Looyengoed
parents: 831
diff changeset
   498
                    value = null;
4af5f979b0d8 Support IsDisableProtectionForContactsEnabled in the GetForceUnencrypted(contact) method.
Dean Looyengoed
parents: 831
diff changeset
   499
                }
4af5f979b0d8 Support IsDisableProtectionForContactsEnabled in the GetForceUnencrypted(contact) method.
Dean Looyengoed
parents: 831
diff changeset
   500
                else
4af5f979b0d8 Support IsDisableProtectionForContactsEnabled in the GetForceUnencrypted(contact) method.
Dean Looyengoed
parents: 831
diff changeset
   501
                {
4af5f979b0d8 Support IsDisableProtectionForContactsEnabled in the GetForceUnencrypted(contact) method.
Dean Looyengoed
parents: 831
diff changeset
   502
                    value = up.Value;
4af5f979b0d8 Support IsDisableProtectionForContactsEnabled in the GetForceUnencrypted(contact) method.
Dean Looyengoed
parents: 831
diff changeset
   503
                }
624
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   504
833
4af5f979b0d8 Support IsDisableProtectionForContactsEnabled in the GetForceUnencrypted(contact) method.
Dean Looyengoed
parents: 831
diff changeset
   505
                // Release objects
4af5f979b0d8 Support IsDisableProtectionForContactsEnabled in the GetForceUnencrypted(contact) method.
Dean Looyengoed
parents: 831
diff changeset
   506
                if (properties != null)
4af5f979b0d8 Support IsDisableProtectionForContactsEnabled in the GetForceUnencrypted(contact) method.
Dean Looyengoed
parents: 831
diff changeset
   507
                {
4af5f979b0d8 Support IsDisableProtectionForContactsEnabled in the GetForceUnencrypted(contact) method.
Dean Looyengoed
parents: 831
diff changeset
   508
                    Marshal.ReleaseComObject(properties);
4af5f979b0d8 Support IsDisableProtectionForContactsEnabled in the GetForceUnencrypted(contact) method.
Dean Looyengoed
parents: 831
diff changeset
   509
                    properties = null;
4af5f979b0d8 Support IsDisableProtectionForContactsEnabled in the GetForceUnencrypted(contact) method.
Dean Looyengoed
parents: 831
diff changeset
   510
                }
624
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   511
833
4af5f979b0d8 Support IsDisableProtectionForContactsEnabled in the GetForceUnencrypted(contact) method.
Dean Looyengoed
parents: 831
diff changeset
   512
                if (up != null)
4af5f979b0d8 Support IsDisableProtectionForContactsEnabled in the GetForceUnencrypted(contact) method.
Dean Looyengoed
parents: 831
diff changeset
   513
                {
4af5f979b0d8 Support IsDisableProtectionForContactsEnabled in the GetForceUnencrypted(contact) method.
Dean Looyengoed
parents: 831
diff changeset
   514
                    Marshal.ReleaseComObject(up);
4af5f979b0d8 Support IsDisableProtectionForContactsEnabled in the GetForceUnencrypted(contact) method.
Dean Looyengoed
parents: 831
diff changeset
   515
                    up = null;
4af5f979b0d8 Support IsDisableProtectionForContactsEnabled in the GetForceUnencrypted(contact) method.
Dean Looyengoed
parents: 831
diff changeset
   516
                }
624
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   517
            }
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   518
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   519
            return (value);
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   520
        }
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   521
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   522
        /// <summary>
487
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   523
        /// 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
   524
        /// 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
   525
        /// </summary>
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   526
        /// <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
   527
        /// <param name="forceUnencrypted">The force unencrypted status to set.</param>
910
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
   528
        internal void SetForceUnencrypted(Outlook.ContactItem contact,
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
   529
                                          bool forceUnencrypted)
487
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   530
        {
624
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   531
            Outlook.UserProperties properties = contact.UserProperties;
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   532
            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
   533
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   534
            if (up == null)
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   535
            {
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   536
                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
   537
                                                Outlook.OlUserPropertyType.olYesNo, false);
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   538
            }
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   539
664
9dcf25b27787 Rename send unencrypted to force unencrypted throughout code.
Dean Looyengoed
parents: 660
diff changeset
   540
            up.Value = forceUnencrypted;
487
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   541
624
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   542
            // Release objects
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   543
            if (properties != null)
487
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   544
            {
624
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   545
                Marshal.ReleaseComObject(properties);
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   546
                properties = null;
487
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   547
            }
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   548
488
c654979e27ac Fix so release isn't done on null objects...
Dean Looyengoed
parents: 487
diff changeset
   549
            if (up != null)
c654979e27ac Fix so release isn't done on null objects...
Dean Looyengoed
parents: 487
diff changeset
   550
            {
c654979e27ac Fix so release isn't done on null objects...
Dean Looyengoed
parents: 487
diff changeset
   551
                Marshal.ReleaseComObject(up);
c654979e27ac Fix so release isn't done on null objects...
Dean Looyengoed
parents: 487
diff changeset
   552
                up = null;
c654979e27ac Fix so release isn't done on null objects...
Dean Looyengoed
parents: 487
diff changeset
   553
            }
487
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   554
624
a678557a3750 Implement support for force unencrypted in contacts.
Dean Looyengoed
parents: 611
diff changeset
   555
            return;
487
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
b27803e13913 Add initial methods to support contact-based send unencrypted message.
Dean Looyengoed
parents: 482
diff changeset
   558
        /// <summary>
776
451e3831822b Support passing a contact in the GetUserID method.
Dean Looyengoed
parents: 773
diff changeset
   559
        /// Gets the pEp user ID for the given address and contact.
362
867beb89ee19 Move GetUserIDFromAddress from the CryptableMailItem to ThisAddIn.
Dean Looyengoed
parents: 361
diff changeset
   560
        /// </summary>
867beb89ee19 Move GetUserIDFromAddress from the CryptableMailItem to ThisAddIn.
Dean Looyengoed
parents: 361
diff changeset
   561
        /// <param name="address">The address to get the user ID for.</param>
776
451e3831822b Support passing a contact in the GetUserID method.
Dean Looyengoed
parents: 773
diff changeset
   562
        /// <param name="contact">The contact associated with the address (if any).
451e3831822b Support passing a contact in the GetUserID method.
Dean Looyengoed
parents: 773
diff changeset
   563
        /// This value can be null and is not required for 'myself' user IDs.</param>
362
867beb89ee19 Move GetUserIDFromAddress from the CryptableMailItem to ThisAddIn.
Dean Looyengoed
parents: 361
diff changeset
   564
        /// <returns>The user ID (Outlook EntryID) for the given address</returns>
910
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
   565
        internal string GetUserID(string address,
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
   566
                                  Outlook.ContactItem contact)
362
867beb89ee19 Move GetUserIDFromAddress from the CryptableMailItem to ThisAddIn.
Dean Looyengoed
parents: 361
diff changeset
   567
        {
511
4a970a30be20 Get rid of unnecessary null/empty check as the structure of the method has changed.
Dean Looyengoed
parents: 510
diff changeset
   568
            string id = null;
776
451e3831822b Support passing a contact in the GetUserID method.
Dean Looyengoed
parents: 773
diff changeset
   569
            Outlook.Folder contactFolder = null;
507
d0b1586c5235 Add fallback to GetUserID that searches address book entry-by-entry.
Dean Looyengoed
parents: 502
diff changeset
   570
474
a27dbbb2dd88 Add try/catch and error handling around several ThisAddIn methods.
Dean Looyengoed
parents: 473
diff changeset
   571
            try
362
867beb89ee19 Move GetUserIDFromAddress from the CryptableMailItem to ThisAddIn.
Dean Looyengoed
parents: 361
diff changeset
   572
            {
608
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   573
                if (string.IsNullOrEmpty(address) == false)
569
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   574
                {
608
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   575
                    // Search cache
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   576
                    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
   577
                    {
569
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   578
                        try
474
a27dbbb2dd88 Add try/catch and error handling around several ThisAddIn methods.
Dean Looyengoed
parents: 473
diff changeset
   579
                        {
608
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   580
                            id = this.userIDCache[address];
569
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   581
                        }
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   582
                        catch
74cd9fc6dc6e Cleanup UserID calculation method.
Dean Looyengoed
parents: 566
diff changeset
   583
                        {
608
38ba4b8308f2 Update GetUserID method to cache IDs, skip Exchange servers and create new contacts if necessary.
Dean Looyengoed
parents: 607
diff changeset
   584
                            id = null;
510
500cb064737d Remove try/catch around GetUserID that could hide errors.
Dean Looyengoed
parents: 508
diff changeset
   585
                        }
511
4a970a30be20 Get rid of unnecessary null/empty check as the structure of the method has changed.
Dean Looyengoed
parents: 510
diff changeset
   586
                    }
477
23462dc9e619 Release COM objects in GetUserID.
Dean Looyengoed
parents: 475
diff changeset
   587
714
761f853c4c0f For all Myself identities, calculate user ID using a hash of the windows Environment.UserName;
Dean Looyengoed
parents: 686
diff changeset
   588
                    // Handle myself user ID calculation
761f853c4c0f For all Myself identities, calculate user ID using a hash of the windows Environment.UserName;
Dean Looyengoed
parents: 686
diff changeset
   589
                    if (id == null)
761f853c4c0f For all Myself identities, calculate user ID using a hash of the windows Environment.UserName;
Dean Looyengoed
parents: 686
diff changeset
   590
                    {
761f853c4c0f For all Myself identities, calculate user ID using a hash of the windows Environment.UserName;
Dean Looyengoed
parents: 686
diff changeset
   591
                        // Check if the address is myself
910
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
   592
                        if (PEPIdentity.GetIsOwnIdentity(address))
714
761f853c4c0f For all Myself identities, calculate user ID using a hash of the windows Environment.UserName;
Dean Looyengoed
parents: 686
diff changeset
   593
                        {
932
a69608546472 Use "pEp_own_userId" for own identities.
Dean Looyengoed
parents: 931
diff changeset
   594
                            id = "pEp_own_userId"; // Alternatively, null or empty could be used
714
761f853c4c0f For all Myself identities, calculate user ID using a hash of the windows Environment.UserName;
Dean Looyengoed
parents: 686
diff changeset
   595
                            this.userIDCache[address] = id;
761f853c4c0f For all Myself identities, calculate user ID using a hash of the windows Environment.UserName;
Dean Looyengoed
parents: 686
diff changeset
   596
                        }
761f853c4c0f For all Myself identities, calculate user ID using a hash of the windows Environment.UserName;
Dean Looyengoed
parents: 686
diff changeset
   597
                    }
761f853c4c0f For all Myself identities, calculate user ID using a hash of the windows Environment.UserName;
Dean Looyengoed
parents: 686
diff changeset
   598
776
451e3831822b Support passing a contact in the GetUserID method.
Dean Looyengoed
parents: 773
diff changeset
   599
                    // Use a contact EntryID if available
451e3831822b Support passing a contact in the GetUserID method.
Dean Looyengoed
parents: 773
diff changeset
   600
                    if ((id == null) &&
451e3831822b Support passing a contact in the GetUserID method.
Dean Looyengoed
parents: 773
diff changeset
   601
                        (contact != null))
451e3831822b Support passing a contact in the GetUserID method.
Dean Looyengoed
parents: 773
diff changeset
   602
                    {
451e3831822b Support passing a contact in the GetUserID method.
Dean Looyengoed
parents: 773
diff changeset
   603
                        try
451e3831822b Support passing a contact in the GetUserID method.
Dean Looyengoed
parents: 773
diff changeset
   604
                        {
451e3831822b Support passing a contact in the GetUserID method.
Dean Looyengoed
parents: 773
diff changeset
   605
                            contactFolder = (Outlook.Folder)contact.Parent;
451e3831822b Support passing a contact in the GetUserID method.
Dean Looyengoed
parents: 773
diff changeset
   606
                            id = contactFolder.StoreID.ToUpper() + "_" + contact.EntryID.ToUpper();
451e3831822b Support passing a contact in the GetUserID method.
Dean Looyengoed
parents: 773
diff changeset
   607
                            this.userIDCache[address] = id;
451e3831822b Support passing a contact in the GetUserID method.
Dean Looyengoed
parents: 773
diff changeset
   608
                        }
451e3831822b Support passing a contact in the GetUserID method.
Dean Looyengoed
parents: 773
diff changeset
   609
                        catch
451e3831822b Support passing a contact in the GetUserID method.
Dean Looyengoed
parents: 773
diff changeset
   610
                        {
860
ff259b6535c7 Merge 'Global' and 'Globals' together.
Dean Looyengoed
parents: 859
diff changeset
   611
                            Globals.Log("GetUserID: Attempted to use contact but failed.");
776
451e3831822b Support passing a contact in the GetUserID method.
Dean Looyengoed
parents: 773
diff changeset
   612
                        }
451e3831822b Support passing a contact in the GetUserID method.
Dean Looyengoed
parents: 773
diff changeset
   613
                    }
725
41bac55ab436 Comment out user_id calculation using address books.
Dean Looyengoed
parents: 714
diff changeset
   614
858
c0e7c8cd7227 Support virtual users in UserID calculation (return null if not myself and no contact).
Dean Looyengoed
parents: 854
diff changeset
   615
                    /* If no user ID is found at this point, return null.
c0e7c8cd7227 Support virtual users in UserID calculation (return null if not myself and no contact).
Dean Looyengoed
parents: 854
diff changeset
   616
                     * The engine supports 'virtual users' that are only uniquely identified by address.
c0e7c8cd7227 Support virtual users in UserID calculation (return null if not myself and no contact).
Dean Looyengoed
parents: 854
diff changeset
   617
                     * Virtual users will be automatically upgraded if a contact is ever created for the email address.
c0e7c8cd7227 Support virtual users in UserID calculation (return null if not myself and no contact).
Dean Looyengoed
parents: 854
diff changeset
   618
                     */
362
867beb89ee19 Move GetUserIDFromAddress from the CryptableMailItem to ThisAddIn.
Dean Looyengoed
parents: 361
diff changeset
   619
                }
474
a27dbbb2dd88 Add try/catch and error handling around several ThisAddIn methods.
Dean Looyengoed
parents: 473
diff changeset
   620
            }
a27dbbb2dd88 Add try/catch and error handling around several ThisAddIn methods.
Dean Looyengoed
parents: 473
diff changeset
   621
            catch (Exception ex)
a27dbbb2dd88 Add try/catch and error handling around several ThisAddIn methods.
Dean Looyengoed
parents: 473
diff changeset
   622
            {
860
ff259b6535c7 Merge 'Global' and 'Globals' together.
Dean Looyengoed
parents: 859
diff changeset
   623
                Globals.StopAndSendCrashReport(ex);
362
867beb89ee19 Move GetUserIDFromAddress from the CryptableMailItem to ThisAddIn.
Dean Looyengoed
parents: 361
diff changeset
   624
            }
776
451e3831822b Support passing a contact in the GetUserID method.
Dean Looyengoed
parents: 773
diff changeset
   625
            finally
451e3831822b Support passing a contact in the GetUserID method.
Dean Looyengoed
parents: 773
diff changeset
   626
            {
451e3831822b Support passing a contact in the GetUserID method.
Dean Looyengoed
parents: 773
diff changeset
   627
                if (contactFolder != null)
451e3831822b Support passing a contact in the GetUserID method.
Dean Looyengoed
parents: 773
diff changeset
   628
                {
451e3831822b Support passing a contact in the GetUserID method.
Dean Looyengoed
parents: 773
diff changeset
   629
                    Marshal.FinalReleaseComObject(contactFolder);
451e3831822b Support passing a contact in the GetUserID method.
Dean Looyengoed
parents: 773
diff changeset
   630
                    contactFolder = null;
451e3831822b Support passing a contact in the GetUserID method.
Dean Looyengoed
parents: 773
diff changeset
   631
                }
451e3831822b Support passing a contact in the GetUserID method.
Dean Looyengoed
parents: 773
diff changeset
   632
            }
362
867beb89ee19 Move GetUserIDFromAddress from the CryptableMailItem to ThisAddIn.
Dean Looyengoed
parents: 361
diff changeset
   633
511
4a970a30be20 Get rid of unnecessary null/empty check as the structure of the method has changed.
Dean Looyengoed
parents: 510
diff changeset
   634
            return (id);
362
867beb89ee19 Move GetUserIDFromAddress from the CryptableMailItem to ThisAddIn.
Dean Looyengoed
parents: 361
diff changeset
   635
        }
867beb89ee19 Move GetUserIDFromAddress from the CryptableMailItem to ThisAddIn.
Dean Looyengoed
parents: 361
diff changeset
   636
867beb89ee19 Move GetUserIDFromAddress from the CryptableMailItem to ThisAddIn.
Dean Looyengoed
parents: 361
diff changeset
   637
        /// <summary>
738
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   638
        /// Create a new Outlook MailItem from the given PEPMessage and send it.
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   639
        /// The sent message will not be processed by the 'Application_ItemSend' event.
744
278a6ecd7639 Document and implement special handling for Exchange ActiveSync issues during send.
Dean Looyengoed
parents: 743
diff changeset
   640
        /// WARNING: Exchange ActiveSync accounts ignore the deleteAfterSend parameter (always false).
455
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   641
        /// </summary>
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   642
        /// <param name="message">The message to send.</param>
475
7a23ec4d8b28 Add deleteAfterSend parameter in SendWithoutProcessing method.
Dean Looyengoed
parents: 474
diff changeset
   643
        /// <param name="deleteAfterSend">Whether the message is deleted after sending (true) or a copy is saved (false).</param>
910
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
   644
        internal void SendWithoutProcessing(PEPMessage message,
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
   645
                                            bool deleteAfterSend)
455
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   646
        {
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   647
            Outlook.MailItem newItem;
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   648
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   649
            newItem = Application.CreateItem(Outlook.OlItemType.olMailItem);
586
2c2bfd7f1e43 Improve handling of optional properties in PEPMessage.
Dean Looyengoed
parents: 576
diff changeset
   650
            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
   651
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
   652
            // Do not allow TNEF/RTF format with 'winmail.dat' attachment
790
3c818a1fad95 Rename MAPIProperties to MAPIProperty.
Dean Looyengoed
parents: 788
diff changeset
   653
            MAPIHelper.SetProperty(newItem, MAPIProperty.PidLidUseTnef, false);
570
21d996cd35e8 Stop searching through Exchange AddressLists due to performance.
Dean Looyengoed
parents: 569
diff changeset
   654
565
ba35cfbfa0ee Stop setting user property for 'do not process' and instead use a do not process list.
Dean Looyengoed
parents: 562
diff changeset
   655
            // 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
   656
            // 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
   657
            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
   658
744
278a6ecd7639 Document and implement special handling for Exchange ActiveSync issues during send.
Dean Looyengoed
parents: 743
diff changeset
   659
            /* Send
278a6ecd7639 Document and implement special handling for Exchange ActiveSync issues during send.
Dean Looyengoed
parents: 743
diff changeset
   660
             * 
278a6ecd7639 Document and implement special handling for Exchange ActiveSync issues during send.
Dean Looyengoed
parents: 743
diff changeset
   661
             * Note: For ActiveSync accounts, the DeleteAfterSubmit property is ignored.
278a6ecd7639 Document and implement special handling for Exchange ActiveSync issues during send.
Dean Looyengoed
parents: 743
diff changeset
   662
             * This means the message will always appear in the sent folder by default.
278a6ecd7639 Document and implement special handling for Exchange ActiveSync issues during send.
Dean Looyengoed
parents: 743
diff changeset
   663
             * The reason for this is unknown.
278a6ecd7639 Document and implement special handling for Exchange ActiveSync issues during send.
Dean Looyengoed
parents: 743
diff changeset
   664
             * 
278a6ecd7639 Document and implement special handling for Exchange ActiveSync issues during send.
Dean Looyengoed
parents: 743
diff changeset
   665
             * It's possible this is related to the ActiveSync specification version
278a6ecd7639 Document and implement special handling for Exchange ActiveSync issues during send.
Dean Looyengoed
parents: 743
diff changeset
   666
             * and therefore may behave differently depending on Outlook version.
278a6ecd7639 Document and implement special handling for Exchange ActiveSync issues during send.
Dean Looyengoed
parents: 743
diff changeset
   667
             * More research is needed here.
278a6ecd7639 Document and implement special handling for Exchange ActiveSync issues during send.
Dean Looyengoed
parents: 743
diff changeset
   668
             */
475
7a23ec4d8b28 Add deleteAfterSend parameter in SendWithoutProcessing method.
Dean Looyengoed
parents: 474
diff changeset
   669
            newItem.DeleteAfterSubmit = deleteAfterSend;
465
3f5d92b648ce Make SendWithoutProcessing public.
Dean Looyengoed
parents: 462
diff changeset
   670
            ((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
   671
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   672
            Marshal.ReleaseComObject(newItem);
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   673
            newItem = null;
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   674
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   675
            return;
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   676
        }
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   677
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   678
        /// <summary>
738
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   679
        /// Create a new 'sent' Outlook MailItem and place it in the given sent folder.
744
278a6ecd7639 Document and implement special handling for Exchange ActiveSync issues during send.
Dean Looyengoed
parents: 743
diff changeset
   680
        /// WARNING: Exchange ActiveSync accounts are not supported by this method. The sent
278a6ecd7639 Document and implement special handling for Exchange ActiveSync issues during send.
Dean Looyengoed
parents: 743
diff changeset
   681
        /// message will always appear in the drafts folder.
738
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   682
        /// </summary>
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   683
        /// <param name="sentFolder">The folder to place the sent mail item within.</param>
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   684
        /// <param name="sentMessage">The message that is sent.</param>
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   685
        private void CreateNewSentMail(Outlook.Folder sentFolder,
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   686
                                       PEPMessage sentMessage)
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   687
        {
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   688
            System.Int32 messageFlags;
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   689
            Outlook.MailItem sentMailItem = null;
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   690
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   691
            try
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   692
            {
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   693
                // Create the basic sent mail item
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   694
                sentMailItem = (Outlook.MailItem)sentFolder.Items.Add(Outlook.OlItemType.olMailItem);
743
5bad37bca12f Do not include optional properties when calling .ApplyTo for a sent mail item.
Dean Looyengoed
parents: 738
diff changeset
   695
                sentMessage.ApplyTo(sentMailItem, false); // Do NOT include optional properties!
738
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   696
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   697
                // Set the sender
790
3c818a1fad95 Rename MAPIProperties to MAPIProperty.
Dean Looyengoed
parents: 788
diff changeset
   698
                MAPIHelper.SetProperty(sentMailItem, MAPIProperty.PidTagSenderName, sentMessage.From.Username);
3c818a1fad95 Rename MAPIProperties to MAPIProperty.
Dean Looyengoed
parents: 788
diff changeset
   699
                MAPIHelper.SetProperty(sentMailItem, MAPIProperty.PidTagSenderEmailAddress, sentMessage.From.Address);
738
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   700
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   701
                // Set the date and time the mail item was sent
790
3c818a1fad95 Rename MAPIProperties to MAPIProperty.
Dean Looyengoed
parents: 788
diff changeset
   702
                MAPIHelper.SetProperty(sentMailItem, MAPIProperty.PidTagClientSubmitTime, DateTime.Now.ToUniversalTime());
738
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   703
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   704
                // Set flags
790
3c818a1fad95 Rename MAPIProperties to MAPIProperty.
Dean Looyengoed
parents: 788
diff changeset
   705
                messageFlags = (System.Int32)MAPIHelper.GetProperty(sentMailItem, MAPIProperty.PidTagMessageFlags);
788
e8d40b320a3a Start using MAPIPropertyValue class for defined values instead of MAPIHelper.
Dean Looyengoed
parents: 786
diff changeset
   706
                messageFlags &= ~((System.Int32)MAPIPropertyValue.EnumPidTagMessageFlags.mfUnsent);  // Clear UNSENT flag -- must be done before save
e8d40b320a3a Start using MAPIPropertyValue class for defined values instead of MAPIHelper.
Dean Looyengoed
parents: 786
diff changeset
   707
                messageFlags |= ((System.Int32)MAPIPropertyValue.EnumPidTagMessageFlags.mfRead);     // Mark as read
790
3c818a1fad95 Rename MAPIProperties to MAPIProperty.
Dean Looyengoed
parents: 788
diff changeset
   708
                MAPIHelper.SetProperty(sentMailItem, MAPIProperty.PidTagMessageFlags, messageFlags);
738
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   709
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   710
                // Save changes to the mail item (must be done last for some properties)
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   711
                sentMailItem.Save();
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   712
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   713
                /* Attempt to move to the sent folder.
744
278a6ecd7639 Document and implement special handling for Exchange ActiveSync issues during send.
Dean Looyengoed
parents: 743
diff changeset
   714
                 * For ActiveSync accounts, this will fail with the error:
278a6ecd7639 Document and implement special handling for Exchange ActiveSync issues during send.
Dean Looyengoed
parents: 743
diff changeset
   715
                 * 'Sorry, Exchange ActiveSync doesn't support what you're trying to do.'
278a6ecd7639 Document and implement special handling for Exchange ActiveSync issues during send.
Dean Looyengoed
parents: 743
diff changeset
   716
                 * This is because the .Items.Add(folder) will ignore the specified folder and create in local Drafts.
278a6ecd7639 Document and implement special handling for Exchange ActiveSync issues during send.
Dean Looyengoed
parents: 743
diff changeset
   717
                 * Then "Exchange ActiveSync doesn’t support the Drafts folder" so it can't be moved out.
278a6ecd7639 Document and implement special handling for Exchange ActiveSync issues during send.
Dean Looyengoed
parents: 743
diff changeset
   718
                 * Even in the Outlook UI a draft cannot be 'dragged' out of the drafts folder.
738
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   719
                 */
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   720
                try
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   721
                {
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   722
                    sentMailItem.Move(sentFolder);
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   723
                }
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   724
                catch { }
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   725
            }
743
5bad37bca12f Do not include optional properties when calling .ApplyTo for a sent mail item.
Dean Looyengoed
parents: 738
diff changeset
   726
            catch (Exception ex)
5bad37bca12f Do not include optional properties when calling .ApplyTo for a sent mail item.
Dean Looyengoed
parents: 738
diff changeset
   727
            {
892
20d7c0ca7de5 Log errors before re-throwing in CreateNewSentMail.
Dean Looyengoed
parents: 886
diff changeset
   728
                Globals.Log("CreateNewSentMail: Error occured, " + ex.ToString());
886
7dbe50a11f81 Avoid code analysis warning CA2200.
Dean Looyengoed
parents: 883
diff changeset
   729
                throw;
743
5bad37bca12f Do not include optional properties when calling .ApplyTo for a sent mail item.
Dean Looyengoed
parents: 738
diff changeset
   730
            }
738
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   731
            finally
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   732
            {
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   733
                if (sentMailItem != null)
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   734
                {
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   735
                    Marshal.ReleaseComObject(sentMailItem);
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   736
                    sentMailItem = null;
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   737
                }
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   738
            }
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   739
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   740
            return;
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   741
        }
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   742
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   743
        /// <summary>
745
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   744
        /// Permanently deletes the given mail item from Outlook.
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   745
        /// This will also remove any mail item data before save.
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   746
        /// Therefore, it is safe for handling sensitive data.
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   747
        /// </summary>
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   748
        /// <param name="mailItem">The mail item to delete.</param>
899
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   749
        /// <param name="mailStore">The known store containing the mail item being deleted.
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   750
        /// This is used to locate the deleted folder. Leaving empty or setting to null will
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   751
        /// automatically try to find the store using the mail item itself.</param>
910
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
   752
        internal void PermanentlyDelete(Outlook.MailItem mailItem,
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
   753
                                        Outlook.Store mailStore = null)
745
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   754
        {
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   755
            bool deleted = false;
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   756
            string deleteValue;
899
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   757
            Outlook.Folder folder = null;
745
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   758
            Outlook.Folder deletedFolder = null;
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   759
            Outlook.MailItem deletedMailItem = null;
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   760
            Outlook.Attachments attachments = null;
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   761
            Outlook.Recipients recipients = null;
899
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   762
            Outlook.Store store = null;
745
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   763
            Outlook.Items items = null;
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   764
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   765
            try
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   766
            {
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   767
                /* Remove all relevant data from the mail item
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   768
                 * This is done so it is not saved later where it could be unencrypted
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   769
                 */
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   770
                recipients = mailItem.Recipients;
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   771
                while (recipients.Count > 0)
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   772
                {
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   773
                    recipients.Remove(1);
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   774
                }
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   775
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   776
                mailItem.Subject = "";
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   777
                mailItem.BodyFormat = Outlook.OlBodyFormat.olFormatPlain;
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   778
                mailItem.Body = "";
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   779
                mailItem.HTMLBody = "";
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   780
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   781
                attachments = mailItem.Attachments;
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   782
                while (attachments.Count > 0)
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   783
                {
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   784
                    attachments.Remove(1);
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   785
                }
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   786
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   787
                mailItem.Save();
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   788
899
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   789
                // Locate the store for the mailitem if none was given
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   790
                if (mailStore == null)
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   791
                {
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   792
                    try
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   793
                    {
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   794
                        folder = (Outlook.Folder)mailItem.Parent;
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   795
                        store = folder.Store;
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   796
                    }
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   797
                    catch (Exception ex)
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   798
                    {
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   799
                        Globals.Log("PermanentlyDelete: unable to locate parent store, " + ex.ToString());
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   800
                    }
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   801
                    finally
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   802
                    {
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   803
                        // Release objects
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   804
                        if (folder != null)
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   805
                        {
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   806
                            Marshal.ReleaseComObject(folder);
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   807
                            folder = null;
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   808
                        }
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   809
                    }
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   810
                }
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   811
745
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   812
                /* Move the mail item to the deleted folder then delete (otherwise calling .Delete() will only move to deleted items)
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   813
                 * For ActiveSync accounts, the .Move() call will fail with the error:
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   814
                 * 'Sorry, Exchange ActiveSync doesn't support what you're trying to do.'
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   815
                 */
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   816
                try
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   817
                {
899
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   818
                    if (mailStore != null)
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   819
                    {
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   820
                        // Use given store
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   821
                        deletedFolder = (Outlook.Folder)mailStore.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDeletedItems);
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   822
                    }
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   823
                    else
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   824
                    {
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   825
                        // Use calculated store
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   826
                        deletedFolder = (Outlook.Folder)store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDeletedItems);
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   827
                    }
745
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   828
                    deletedMailItem = (Outlook.MailItem)mailItem.Move(deletedFolder);
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   829
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   830
                    /* Change the subject and Save
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   831
                     * If the subject (or another property) is not changed the .Save() call will be ignored
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   832
                     * Calling .Save() is for some reason necessary before .Delete() to work properly
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   833
                     */
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   834
                    deletedMailItem.Subject = "pEp";
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   835
                    deletedMailItem.Save();
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   836
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   837
                    // Now that the mail item is in the deleted folder, calling .Delete() will delete permanently
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   838
                    deletedMailItem.Delete();
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   839
                    deleted = true;
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   840
                }
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   841
                catch { }
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   842
                finally
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   843
                {
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   844
                    if (deletedFolder != null)
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   845
                    {
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   846
                        Marshal.ReleaseComObject(deletedFolder);
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   847
                        deletedFolder = null;
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   848
                    }
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   849
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   850
                    if (deletedMailItem != null)
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   851
                    {
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   852
                        Marshal.ReleaseComObject(deletedMailItem);
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   853
                        deletedMailItem = null;
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   854
                    }
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   855
                }
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   856
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   857
                // Try secondary method supporting ActiveSync accounts
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   858
                if (deleted == false)
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   859
                {
899
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   860
                    if (mailStore != null)
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   861
                    {
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   862
                        // Use given store
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   863
                        deletedFolder = (Outlook.Folder)mailStore.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDeletedItems);
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   864
                    }
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   865
                    else
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   866
                    {
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   867
                        // Use calculated store
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   868
                        deletedFolder = (Outlook.Folder)store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDeletedItems);
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   869
                    }
745
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   870
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   871
                    // Tag the item with a user property so it can be located in the deleted folder
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   872
                    deleteValue = "DELETE_" + mailItem.EntryID;
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   873
                    CryptableMailItem.SetUserProperty(mailItem, "DELETE", deleteValue, Outlook.OlUserPropertyType.olText);
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   874
                    mailItem.Save();
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   875
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   876
                    // Delete the mail item moving to deleted items folder
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   877
                    mailItem.Delete();
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   878
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   879
                    // Permanently delete item by locating in the delete items folder
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   880
                    items = deletedFolder.Items;
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   881
                    for (int i = 1; i <= items.Count; i++)
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   882
                    {
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   883
                        deletedMailItem = items[i];
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   884
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   885
                        // Check if the property exists
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   886
                        if ((string)CryptableMailItem.GetUserProperty(deletedMailItem, "DELETE", "") == deleteValue)
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   887
                        {
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   888
                            deletedMailItem.Delete();
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   889
                            deleted = true;
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   890
                            break;
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   891
                        }
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   892
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   893
                        Marshal.ReleaseComObject(deletedMailItem);
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   894
                        deletedMailItem = null;
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   895
                    }
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   896
                }
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   897
            }
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   898
            catch (Exception ex)
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   899
            {
860
ff259b6535c7 Merge 'Global' and 'Globals' together.
Dean Looyengoed
parents: 859
diff changeset
   900
                Globals.Log("PermanentlyDelete: Failed, " + ex.ToString());
745
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   901
            }
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   902
            finally
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   903
            {
899
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   904
                if (folder != null)
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   905
                {
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   906
                    Marshal.ReleaseComObject(folder);
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   907
                    folder = null;
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   908
                }
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   909
745
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   910
                if (deletedFolder != null)
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   911
                {
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   912
                    Marshal.ReleaseComObject(deletedFolder);
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   913
                    deletedFolder = null;
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   914
                }
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   915
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   916
                if (deletedMailItem != null)
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   917
                {
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   918
                    Marshal.ReleaseComObject(deletedMailItem);
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   919
                    deletedMailItem = null;
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   920
                }
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   921
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   922
                if (attachments != null)
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   923
                {
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   924
                    Marshal.ReleaseComObject(attachments);
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   925
                    attachments = null;
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   926
                }
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   927
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   928
                if (recipients != null)
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   929
                {
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   930
                    Marshal.ReleaseComObject(recipients);
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   931
                    recipients = null;
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   932
                }
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   933
899
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   934
                if (store != null)
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   935
                {
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   936
                    Marshal.ReleaseComObject(store);
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   937
                    store = null;
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   938
                }
376310f19559 Automatically detect the store in PermanentlyDelete if none was given.
Dean Looyengoed
parents: 892
diff changeset
   939
745
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   940
                if (items != null)
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   941
                {
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   942
                    Marshal.ReleaseComObject(items);
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   943
                    items = null;
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   944
                }
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   945
            }
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   946
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   947
            return;
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   948
        }
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   949
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
   950
        /// <summary>
671
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   951
        /// 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
   952
        /// 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
   953
        /// </summary>
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   954
        /// <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
   955
        /// <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
   956
        private bool GetIsAccountTrusted(string address)
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   957
        {
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   958
            bool isTrusted = false;
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   959
            string searchAddress = address.ToUpper().Trim();
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   960
            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
   961
            string whitelistAccount;
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   962
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   963
            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
   964
            {
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   965
                whitelistAccount = this._AccountWhitelist[i].ToUpper().Trim();
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   966
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   967
                // Check for exact match
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   968
                if (searchAddress == whitelistAccount)
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   969
                {
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   970
                    isTrusted = true;
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   971
                    break;
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   972
                }
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   973
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   974
                // Check for domain match
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   975
                if ((searchDomain != null) &&
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   976
                    whitelistAccount.StartsWith("@") &&
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   977
                    (searchDomain == whitelistAccount))
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   978
                {
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   979
                    isTrusted = true;
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   980
                    break;
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   981
                }
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   982
            }
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   983
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   984
            return (isTrusted);
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   985
        }
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   986
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
   987
        /// <summary>
820
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
   988
        /// Writes the pEp required Outlook options to the registry.
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
   989
        /// </summary>
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
   990
        private void SetOutlookRegistryOptions()
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
   991
        {
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
   992
            try
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
   993
            {
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
   994
                using (RegistryKey key1 = Registry.CurrentUser.OpenSubKey(REG_KEY_SOFTWARE))
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
   995
                {
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
   996
                    using (RegistryKey keyOffice = key1.OpenSubKey(REG_KEY_MICROSOFT_OFFICE))
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
   997
                    {
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
   998
                        /* Outlook versions
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
   999
                         *  "12" Outlook 2007
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
  1000
                         *  "14" Outlook 2010
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
  1001
                         *  "15" Outlook 2013
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
  1002
                         *  "16" Outlook 2016
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
  1003
                         */
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
  1004
                        using (RegistryKey keyInternationalOptions = keyOffice.OpenSubKey(Application.Version.Substring(0, 2) + ".0\\Outlook\\Options\\MSHTML\\International", true))
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
  1005
                        {
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
  1006
                            keyInternationalOptions.SetValue(REG_NAME_DEFAULT_CODEPAGE_OUT, (Int32)65001); // UTF-8
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
  1007
                        }
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
  1008
                    }
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
  1009
                }
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
  1010
            }
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
  1011
            catch (Exception ex)
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
  1012
            {
860
ff259b6535c7 Merge 'Global' and 'Globals' together.
Dean Looyengoed
parents: 859
diff changeset
  1013
                Globals.Log("SetOutlookRegistryOptions: Failed to set options, " + ex.ToString());
820
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
  1014
            }
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
  1015
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
  1016
            return;
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
  1017
        }
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
  1018
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
  1019
        /// <summary>
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1020
        /// 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
  1021
        /// </summary>
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1022
        private void WriteConfigToRegistry()
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1023
        {
452
9be34118b38f Add IsSendWithoutKeyEnabled config option and read from registry.
Dean Looyengoed
parents: 451
diff changeset
  1024
            /* Note: 
9be34118b38f Add IsSendWithoutKeyEnabled config option and read from registry.
Dean Looyengoed
parents: 451
diff changeset
  1025
             * 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
  1026
             *   • AccountWhitelist
453
4b8c31936610 Add crash report config options and read from registry.
Dean Looyengoed
parents: 452
diff changeset
  1027
             *   • CrashReportSendAddress
4b8c31936610 Add crash report config options and read from registry.
Dean Looyengoed
parents: 452
diff changeset
  1028
             *   • ExtraKeys
627
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1029
             *   • IsCrashReportVisible
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1030
             *   • IsDeveloperModeEnabled
831
02fc35559e5b Add IsDisableProtectionForContactsEnabled setting and read it from the registry.
Dean Looyengoed
parents: 830
diff changeset
  1031
             *   • IsDisableProtectionForContactsEnabled
627
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1032
             *   • IsPassiveModeEnabled
831
02fc35559e5b Add IsDisableProtectionForContactsEnabled setting and read it from the registry.
Dean Looyengoed
parents: 830
diff changeset
  1033
             *   • IsTNEFDisabled
452
9be34118b38f Add IsSendWithoutKeyEnabled config option and read from registry.
Dean Looyengoed
parents: 451
diff changeset
  1034
             */
9be34118b38f Add IsSendWithoutKeyEnabled config option and read from registry.
Dean Looyengoed
parents: 451
diff changeset
  1035
462
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1036
            try
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1037
            {
462
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1038
                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
  1039
                {
462
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1040
                    using (RegistryKey key2 = key1.CreateSubKey(REG_KEY_PEP))
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1041
                    {
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1042
                        // Set encryption state of each account
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1043
                        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
  1044
                        {
462
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1045
                            foreach (KeyValuePair<string, bool> entry in this._EncryptedAccountsList)
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1046
                            {
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1047
                                key3.SetValue(entry.Key,
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1048
                                              entry.Value.ToString(),
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1049
                                              RegistryValueKind.String);
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1050
                            }
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1051
                        }
627
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1052
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1053
                        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
  1054
                        key2.SetValue(REG_NAME_IS_KEY_SERVER_USED, this._IsKeyServerUsed.ToString());
816
22599c48c284 Add settings/configuration to show or hide the pEp store in the navigation pane.
Dean Looyengoed
parents: 815
diff changeset
  1055
                        key2.SetValue(REG_NAME_IS_PEP_FOLDER_VISIBLE, this._IsPEPFolderVisible.ToString());
627
5cd866dfafd7 Alphabetize read/write configuration methods to match properties order.
Dean Looyengoed
parents: 626
diff changeset
  1056
                        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
  1057
                        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
  1058
                    }
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1059
                }
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1060
            }
462
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1061
            catch (Exception ex)
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1062
            {
861
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1063
                Globals.Log("WriteConfigToRegistry: Failure occured, " + ex.ToString());
462
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1064
            }
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1065
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1066
            return;
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1067
        }
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1068
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1069
        /// <summary>
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1070
        /// 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
  1071
        /// </summary>
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1072
        private void ReadConfigFromRegistry()
0
6dfec3b090d6 initial commit
vb
parents:
diff changeset
  1073
        {
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
  1074
            bool isSuccessful;
861
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1075
            bool isPropertySet;
515
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
  1076
            int parsedIntValue;
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
  1077
            bool parsedBoolValue;
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
  1078
            string keyValue;
649
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
  1079
            object value;
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
  1080
            string[] registryWhitelist;
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
  1081
            List<string> whitelist;
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
  1082
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1083
            /* 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
  1084
             * 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
  1085
             */
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1086
861
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1087
            ///////////////////////////////////////////////////////////
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1088
            // Read non-pEp values
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1089
            ///////////////////////////////////////////////////////////
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1090
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1091
            // Attempt to get IsTNEFDisabled
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1092
            isPropertySet = false;
462
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1093
            try
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
  1094
            {
515
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
  1095
                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
  1096
                {
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
  1097
                    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
  1098
                    {
820
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
  1099
                        /* Outlook versions
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
  1100
                         *  "12" Outlook 2007
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
  1101
                         *  "14" Outlook 2010
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
  1102
                         *  "15" Outlook 2013
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
  1103
                         *  "16" Outlook 2016
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
  1104
                         */
515
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
  1105
                        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
  1106
                        {
820
6a08ad3137da Add SetOutlookRegistryOptions() method and use it to set default out codepage to UTF-8.
Dean Looyengoed
parents: 818
diff changeset
  1107
                            // Attempt to get IsTNEFDisabled
860
ff259b6535c7 Merge 'Global' and 'Globals' together.
Dean Looyengoed
parents: 859
diff changeset
  1108
                            keyValue = keyPreferences.GetValue(ThisAddIn.REG_NAME_IS_TNEF_DISABLED, Globals.IS_TNEF_DISABLED_DEFAULT).ToString();
861
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1109
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1110
                            // Try parsing as int
515
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
  1111
                            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
  1112
                            if (isSuccessful)
ed828de6d215 Read IsTNEFDisabled from the registry and display as read-only in options.
Dean Looyengoed
parents: 513
diff changeset
  1113
                            {
861
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1114
                                this._IsTNEFDisabled = (parsedIntValue > 0);
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1115
                                isPropertySet = true;
649
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
  1116
                            }
ad161bea020a Add AccountWhitelist and read from registry.
Dean Looyengoed
parents: 640
diff changeset
  1117
861
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1118
                            // Try parsing as bool (this will handle the default value)
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1119
                            isSuccessful = bool.TryParse(keyValue, out parsedBoolValue);
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1120
                            if (isSuccessful)
462
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1121
                            {
861
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1122
                                this._IsTNEFDisabled = parsedBoolValue;
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1123
                                isPropertySet = true;
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1124
                            }
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1125
                        }
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
  1126
                    }
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
  1127
                }
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
  1128
            }
462
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1129
            catch (Exception ex)
088a683807a2 Add exception handling around registry access methods.
Dean Looyengoed
parents: 461
diff changeset
  1130
            {
861
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1131
                Globals.Log("ReadConfigFromRegistry: Failure occured reading TNEF disabled status, " + ex.ToString());
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1132
            }
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1133
            finally
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1134
            {
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1135
                if (isPropertySet == false)
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1136
                {
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1137
                    this._IsTNEFDisabled = Globals.IS_TNEF_DISABLED_DEFAULT;
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1138
                }
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1139
            }
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1140
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1141
            ///////////////////////////////////////////////////////////
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1142
            // Read pEp values
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1143
            ///////////////////////////////////////////////////////////
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1144
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1145
            try
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1146
            {
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1147
                using (RegistryKey key1 = Registry.CurrentUser.OpenSubKey(REG_KEY_SOFTWARE, true))
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1148
                {
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1149
                    using (RegistryKey key2 = key1.CreateSubKey(REG_KEY_PEP))
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1150
                    {
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1151
                        // Attempt to get AccountWhitelist
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1152
                        isPropertySet = false;
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1153
                        try
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1154
                        {
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1155
                            value = key2.GetValue(REG_NAME_ACCOUNT_WHITELIST, null);
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1156
                            if (value != null)
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1157
                            {
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1158
                                whitelist = new List<string>();
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1159
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1160
                                // Copy over hardcoded values
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1161
                                for (int i = 0; i < Globals.HARDCODED_ACCOUNT_WHITELIST.Length; i++)
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1162
                                {
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1163
                                    whitelist.Add(Globals.HARDCODED_ACCOUNT_WHITELIST[i].Trim());
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1164
                                }
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1165
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1166
                                // Copy over registry values
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1167
                                registryWhitelist = value.ToString().Split(';');
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1168
                                for (int i = 0; i < registryWhitelist.Length; i++)
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1169
                                {
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1170
                                    whitelist.Add(registryWhitelist[i].Trim());
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1171
                                }
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1172
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1173
                                this._AccountWhitelist = whitelist.ToArray();
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1174
                                isPropertySet = true;
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1175
                            }
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1176
                        }
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1177
                        catch
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1178
                        {
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1179
                            Globals.Log("ReadConfigFromRegistry: Unable to read AccountWhitelist");
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1180
                        }
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset
  1181
                        finally
4ecf6db0f982 Only log failures when reading/writing to the registry. Also make reading more robust.
Dean Looyengoed
parents: 860
diff changeset