PEPSettings.cs
author Thomas
Mon, 03 Sep 2018 14:04:38 +0200
branchOUT-283
changeset 2353 81975e284b07
parent 2198 fdda622085c6
child 2206 d0173d827aa2
child 2390 2567ecbe949c
child 2410 80c01cc1dec1
permissions -rw-r--r--
Add MAPI methods to set properties via p/invoke
     1 using Microsoft.Win32;
     2 using System;
     3 using System.Collections.Generic;
     4 using System.Collections.ObjectModel;
     5 using System.Collections.Specialized;
     6 using System.ComponentModel;
     7 using System.Globalization;
     8 using System.IO;
     9 
    10 namespace pEp
    11 {
    12     /// <summary>
    13     /// Class to store and maintain all configurations/settings for pEp for Outlook.
    14     /// </summary>
    15     internal class PEPSettings : INotifyPropertyChanged,
    16                                  Interfaces.IReset
    17     {
    18         /// <summary>
    19         /// Event raised when a property is changed on a component.
    20         /// </summary>
    21         public event PropertyChangedEventHandler PropertyChanged;
    22 
    23         /// <summary>
    24         /// Defines whether to add a disclaimer to a message.
    25         /// </summary>
    26         public enum Disclaimer
    27         {
    28             None = 0,
    29             OnlyEncryptedMessages,
    30             AllMessages
    31         }
    32 
    33         public const string PEP_OWN_USER_ID                                     = "pEp_own_userId";
    34 
    35         public const string REG_KEY_SOFTWARE                                    = "Software";
    36         public const string REG_KEY_PEP                                         = "pEp";
    37         public const string REG_KEY_PEP_FOR_OUTLOOK                             = "Outlook";
    38         public const string REG_KEY_PEP_UPDATER                                 = "Updater";
    39         public const string REG_KEY_MICROSOFT_OFFICE                            = "Microsoft\\Office";
    40         public const string REG_KEY_ENCRYPTED_ACCOUNTS_LIST                     = "EncryptedAccountsList";
    41         public const string REG_KEY_ACCOUNT_SETTINGS_LIST                       = "AccountSettingsList";
    42         public const string REG_NAME_ACCOUNT_SETTING_ADD_DISCLAIMER             = "AddDisclaimer";
    43         public const string REG_NAME_ACCOUNT_SETTING_DISCLAIMER_TEXT            = "DisclaimerText";
    44         public const string REG_NAME_ACCOUNT_SETTING_IS_DECRYPT_ALWAYS_ENABLED  = "IsDecryptAlwaysEnabled";
    45         public const string REG_NAME_ACCOUNT_SETTING_IS_PEP_ENABLED             = "IsPEPEnabled";
    46         public const string REG_NAME_ACCOUNT_SETTING_IS_SECURE_STORAGE_ENABLED  = "IsSecureStorageEnabled";
    47         public const string REG_NAME_ACCOUNT_SETTING_IS_SYNC_ENABLED            = "IsSyncEnabled";
    48         public const string REG_NAME_ACCOUNT_SETTING_SENT_FOLDER_ENTRYID        = "SentFolderEntryId";
    49         public const string REG_NAME_ACCOUNT_SETTING_SMTP_ADDRESS               = "SmtpAddress";
    50         public const string REG_NAME_ACCOUNT_SETTING_TYPE                       = "Type";
    51         public const string REG_NAME_ACCOUNT_SETTING_USER_NAME                  = "UserName";
    52         public const string REG_NAME_ACCOUNT_WHITELIST                          = "AccountWhitelist";
    53         public const string REG_NAME_CRASH_REPORT_SEND_ADDRESS                  = "CrashReportSendAddress";
    54         public const string REG_NAME_DEFAULT_CODEPAGE_OUT                       = "Default_CodePageOut"; // Name defined by Microsoft
    55         public const string REG_NAME_EXTRA_KEYS                                 = "ExtraKeys";
    56         public const string REG_NAME_IS_AUTO_UPDATE_ENABLED                     = "IsAutoUpdateEnabled";
    57         public const string REG_NAME_IS_CRASH_REPORT_VISIBLE                    = "IsCrashReportVisible";
    58         public const string REG_NAME_IS_DEVELOPER_MODE_ENABLED                  = "IsDeveloperModeEnabled";
    59         public const string REG_NAME_IS_DISABLE_PROTECTION_FOR_CONTACTS_ENABLED = "IsDisableProtectionForContactsEnabled";
    60         public const string REG_NAME_IS_ENCRYPT_ALL_ACCOUNTS_ENABLED            = "IsEncryptAllAccountsEnabled";
    61         public const string REG_NAME_IS_FIRST_STARTUP_COMPLETE                  = "IsFirstStartupComplete";
    62         public const string REG_NAME_IS_INBOX_CLEANING_ENABLED                  = "IsInboxCleaningEnabled";
    63         public const string REG_NAME_IS_KEY_SERVER_USED                         = "IsKeyServerUsed";
    64         public const string REG_NAME_IS_NEVER_UNSECURE_OPTION_VISIBLE           = "IsNeverUnsecureOptionVisible";
    65         public const string REG_NAME_IS_PASSIVE_MODE_ENABLED                    = "IsPassiveModeEnabled";
    66         public const string REG_NAME_IS_PEP_FOLDER_VISIBLE                      = "IsPEPFolderVisible";
    67         public const string REG_NAME_IS_READER_SPLASH_ENABLED                   = "IsReaderSplashEnabled";
    68         public const string REG_NAME_IS_SECURITY_LOSS_WARNING_ENABLED           = "IsSecurityLossWarningEnabled";
    69         public const string REG_NAME_IS_SENSITIVE_DATA_LOGGING_ENABLED          = "IsSensitiveDataLoggingEnabled";
    70         public const string REG_NAME_IS_SYNC_ENABLED_FOR_ALL_ACCOUNTS           = "IsSyncEnabledForAllAccounts";
    71         public const string REG_NAME_IS_TNEF_DISABLED                           = "DisableTNEF"; // Name defined by Microsoft
    72         public const string REG_NAME_IS_UNENCRYPTED_SUBJECT_ENABLED             = "IsUnencryptedSubjectEnabled";
    73         public const string REG_NAME_IS_VERBOSE_LOGGING_ENABLED                 = "IsVerboseLoggingEnabled";
    74         public const string REG_NAME_TRUSTWORDS_CULTURE                         = "TrustwordsCulture";
    75 
    76         public const bool                  ACCOUNT_SETTING_IS_DECRYPT_ALWAYS_ENABLED_DEFAULT  = true;
    77         public const bool                  ACCOUNT_SETTING_IS_PEP_ENABLED_DEFAULT             = true;
    78         public const bool                  ACCOUNT_SETTING_IS_SECURE_STORAGE_ENABLED_DEFAULT  = PEPSettings.ENCRYPT_ACCOUNTS_BY_DEFAULT;
    79         public const bool                  ACCOUNT_SETTING_IS_SYNC_ENABLED_DEFAULT            = true;
    80         public const string                ACCOUNT_SETTING_SENT_FOLDER_ENTRYID_DEFAULT        = null;
    81         public const string                ACCOUNT_SETTING_SMTP_ADDRESS_DEFAULT               = null;
    82         public const string                ACCOUNT_SETTING_TYPE_DEFAULT                       = null;
    83         public const string                ACCOUNT_SETTING_USER_NAME_DEFAULT                  = null;  
    84         public static readonly string[]    ACCOUNT_WHITELIST_DEFAULT                          = new string[] { };
    85         public static Disclaimer           ADD_DISCLAIMER_DEFAULT                             = Disclaimer.None;
    86         public const string                CRASH_REPORT_SEND_ADDRESS_DEFAULT                  = "crashreport@prettyeasyprivacy.com";
    87         public const string                CULTURE_CODE_DEFAULT                               = "en";
    88         public const string                DISCLAIMER_TEXT_DEFAULT                            = null;
    89         public const bool                  ENCRYPT_ACCOUNTS_BY_DEFAULT                        = true;
    90         public const bool                  IS_AUTO_UPDATE_ENABLED_DEFAULT                     = true;
    91         public const bool                  IS_CRASH_REPORT_VISIBLE_DEFAULT                    = true;
    92         public const bool                  IS_DEVELOPER_MODE_ENABLED_DEFAULT                  = false;
    93         public const bool                  IS_DISABLE_PROTECTION_FOR_CONTACTS_ENABLED_DEFAULT = false;
    94         public const bool                  IS_ENCRYPT_ALL_ACCOUNTS_ENABLED_DEFAULT            = false;
    95         public const bool                  IS_INBOX_CLEANING_ENABLED_DEFAULT                  = false;
    96         public const bool                  IS_KEY_SERVER_USED_DEFAULT                         = false;
    97         public const bool                  IS_NEVER_UNSECURE_OPTION_VISIBLE_DEFAULT           = false;
    98         public const bool                  IS_PASSIVE_MODE_ENABLED_DEFAULT                    = false;
    99         public const bool                  IS_PEP_FOLDER_VISIBLE_DEFAULT                      = true;
   100         public const bool                  IS_READER_SPLASH_ENABLED_DEFAULT                   = true;
   101 #if READER_RELEASE_MODE
   102         public const bool                  IS_SECURITY_LOSS_WARNING_ENABLED_DEFAULT           = true;
   103 #else
   104         public const bool                  IS_SECURITY_LOSS_WARNING_ENABLED_DEFAULT           = false;
   105 #endif
   106         public const bool                  IS_SENSITIVE_DATA_LOGGING_ENABLED_DEFAULT          = false;
   107         public const bool                  IS_SYNC_ENABLED_FOR_ALL_ACCOUNTS_DEFAULT           = true;
   108         public const bool                  IS_TNEF_DISABLED_DEFAULT                           = false;
   109         public const bool                  IS_UNENCRYPTED_SUBJECT_ENABLED_DEFAULT             = true;
   110         public const bool                  IS_VERBOSE_LOGGING_ENABLED_DEFAULT                 = false;
   111 
   112         private ObservableCollection<PEPAccountSettings> _AccountSettingsList;
   113         private string[]                                 _AccountWhitelist;
   114         private string                                   _CrashReportSendAddress;
   115         private string[]                                 _ExtraKeys;
   116         private bool                                     _IsAutoUpdateEnabled;
   117         private bool                                     _IsCrashReportVisible;
   118         private bool                                     _IsDeveloperModeEnabled;
   119         private bool                                     _IsDisableProtectionForContactsEnabled;
   120         private bool                                     _IsEncryptAllAccountsEnabled;
   121         private bool                                     _IsFirstStartupComplete;
   122         private bool                                     _IsInboxCleaningEnabled;
   123         private bool                                     _IsKeyServerUsed;
   124         private bool                                     _IsNeverUnsecureOptionVisible;
   125         private bool                                     _IsPassiveModeEnabled;
   126         private bool                                     _IsPEPFolderVisible;
   127         private bool                                     _IsReaderSplashEnabled;
   128         private bool                                     _IsSecurityLossWarningEnabled;
   129         private bool                                     _IsSensitiveDataLoggingEnabled;
   130         private bool                                     _IsSyncEnabledForAllAccounts;
   131         private bool                                     _IsTNEFDisabled;
   132         private bool                                     _IsUnencryptedSubjectEnabled;
   133         private bool                                     _IsVerboseLoggingEnabled;
   134         private CultureInfo                              _TrustwordsCulture;
   135 
   136         /**************************************************************
   137          * 
   138          * Constructors
   139          * 
   140          *************************************************************/
   141 
   142         /// <summary>
   143         /// Default constructor.
   144         /// </summary>
   145         public PEPSettings()
   146         {
   147             this.Reset();
   148         }
   149 
   150         /**************************************************************
   151          * 
   152          * Property Accessors
   153          * 
   154          *************************************************************/
   155 
   156         /// <summary>
   157         /// Gets the list of accounts and their corresponding settings.
   158         /// This initially is only those accounts which already existed in the registry.
   159         /// An external function should validate this list with the current accounts list in Outlook.
   160         /// </summary>
   161         public ObservableCollection<PEPAccountSettings> AccountSettingsList
   162         {
   163             get { return (this._AccountSettingsList); }
   164         }
   165 
   166         /// <summary>
   167         /// Gets the account whitelist as the combination of hardcoded and registry values.
   168         /// Can only be set from the registry or hardcoded values.
   169         /// </summary>
   170         public string[] AccountWhitelist
   171         {
   172             get { return (this._AccountWhitelist); }
   173         }
   174 
   175         /// <summary>
   176         /// Gets the email address to send any crash report to.
   177         /// Can only be set from the registry.
   178         /// </summary>
   179         public string CrashReportSendAddress
   180         {
   181             get { return (this._CrashReportSendAddress); }
   182         }
   183 
   184         /// <summary>
   185         /// Contains a list of smtp addresses that are to be excluded
   186         /// during synchronization of the pEp and Outlook accounts lists.
   187         /// Note: This property is only needed for newly added accounts 
   188         /// without having Outlook restarted. As the Outlook.Accounts
   189         /// collection does not get updated when an account is added 
   190         /// while Outlook is running, we have to make sure to not delete
   191         /// such account settings during shutdown or other sync tasks.
   192         /// </summary>
   193         public List<string> AccountsAddedWhileRunningList { get; set; } = new List<string>();
   194 
   195         /// <summary>
   196         /// Gets any extra encryption keys that were loaded from the registry.
   197         /// Can only be set from the registry.
   198         /// </summary>
   199         public string[] ExtraKeys
   200         {
   201             get { return (this._ExtraKeys); }
   202         }
   203 
   204         /// <summary>
   205         /// Gets or sets whether auto update is enabled.
   206         /// </summary>
   207         public bool IsAutoUpdateEnabled
   208         {
   209             get { return (this._IsAutoUpdateEnabled); }
   210             set
   211             {
   212                 if (object.Equals(this._IsAutoUpdateEnabled, value) == false)
   213                 {
   214                     this._IsAutoUpdateEnabled = value;
   215                     this.RaisePropertyChangedEvent(nameof(this.IsAutoUpdateEnabled));
   216                 }
   217             }
   218         }
   219 
   220         /// <summary>
   221         /// Gets whether the crash report window is visible to the user.
   222         /// Can only be set from the registry.
   223         /// </summary>
   224         public bool IsCrashReportVisible
   225         {
   226             get { return (this._IsCrashReportVisible); }
   227         }
   228 
   229         /// <summary>
   230         /// Gets whether developer mode is enabled.
   231         /// Can only be set from the registry.
   232         /// </summary>
   233         public bool IsDeveloperModeEnabled
   234         {
   235             get { return (this._IsDeveloperModeEnabled); }
   236         }
   237 
   238         /// <summary>
   239         /// Gets whether disabling protection per contact is enabled.
   240         /// Can only be set from the registry.
   241         /// </summary>
   242         public bool IsDisableProtectionForContactsEnabled
   243         {
   244             get { return (this._IsDisableProtectionForContactsEnabled); }
   245         }
   246 
   247         /// <summary>
   248         /// Gets or sets whether data should be stored encrypted for all accounts.
   249         /// </summary>
   250         public bool IsEncryptAllAccountsEnabled
   251         {
   252             get { return (this._IsEncryptAllAccountsEnabled); }
   253             set
   254             {
   255                 if (object.Equals(this._IsEncryptAllAccountsEnabled, value) == false)
   256                 {
   257                     this._IsEncryptAllAccountsEnabled = value;
   258                     this.RaisePropertyChangedEvent(nameof(this.IsEncryptAllAccountsEnabled));
   259                 }
   260             }
   261         }
   262 
   263         /// <summary>
   264         /// Gets or sets whether first startup of the add-in has already been completed.
   265         /// </summary>
   266         public bool IsFirstStartupComplete
   267         {
   268             get { return (this._IsFirstStartupComplete); }
   269             set
   270             {
   271                 if (object.Equals(this._IsFirstStartupComplete, value) == false)
   272                 {
   273                     this._IsFirstStartupComplete = value;
   274                     this.RaisePropertyChangedEvent(nameof(this.IsFirstStartupComplete));
   275                 }
   276             }
   277         }
   278 
   279         /// <summary>
   280         /// Gets or sets whether the inbox should be automatically cleaned from old keysync messages
   281         /// </summary>
   282         public bool IsInboxCleaningEnabled
   283         {
   284             get { return (this._IsInboxCleaningEnabled); }
   285             set
   286             {
   287                 if (object.Equals(this._IsInboxCleaningEnabled, value) == false)
   288                 {
   289                     this._IsInboxCleaningEnabled = value;
   290                     this.RaisePropertyChangedEvent(nameof(this.IsInboxCleaningEnabled));
   291                 }
   292             }
   293         }
   294 
   295         /// <summary>
   296         /// Gets or sets whether to use key servers.
   297         /// </summary>
   298         public bool IsKeyServerUsed
   299         {
   300             get { return (this._IsKeyServerUsed); }
   301             set
   302             {
   303                 if (object.Equals(this._IsKeyServerUsed, value) == false)
   304                 {
   305                     this._IsKeyServerUsed = value;
   306                     this.RaisePropertyChangedEvent(nameof(this.IsKeyServerUsed));
   307                 }
   308             }
   309         }
   310 
   311         /// <summary>
   312         /// Gets or sets whether the never unsecure option/button is visible in the UI.
   313         /// </summary>
   314         public bool IsNeverUnsecureOptionVisible
   315         {
   316             get { return (this._IsNeverUnsecureOptionVisible); }
   317             set
   318             {
   319                 if (object.Equals(this._IsNeverUnsecureOptionVisible, value) == false)
   320                 {
   321                     this._IsNeverUnsecureOptionVisible = value;
   322                     this.RaisePropertyChangedEvent(nameof(this.IsNeverUnsecureOptionVisible));
   323                 }
   324             }
   325         }
   326 
   327         /// <summary>
   328         /// Gets or sets whether passive mode is enabled.
   329         /// Passive mode will not attach keys unless keys are received.
   330         /// </summary>
   331         public bool IsPassiveModeEnabled
   332         {
   333             get { return (this._IsPassiveModeEnabled); }
   334             set
   335             {
   336                 if (object.Equals(this._IsPassiveModeEnabled, value) == false)
   337                 {
   338                     this._IsPassiveModeEnabled = value;
   339                     this.RaisePropertyChangedEvent(nameof(this.IsPassiveModeEnabled));
   340                 }
   341             }
   342         }
   343 
   344         /// <summary>
   345         /// Gets or sets whether the pEp folder (and its contents) are visible in the navigation pane.
   346         /// </summary>
   347         public bool IsPEPFolderVisible
   348         {
   349             get { return (this._IsPEPFolderVisible); }
   350             set
   351             {
   352                 if (object.Equals(this._IsPEPFolderVisible, value) == false)
   353                 {
   354                     this._IsPEPFolderVisible = value;
   355                     this.RaisePropertyChangedEvent(nameof(this.IsPEPFolderVisible));
   356                 }
   357             }
   358         }
   359 
   360         /// <summary>
   361         /// Gets or sets whether the reader splash screen is enabled.
   362         /// When enabled, the splash will be shown at startup.
   363         /// This value is ignored if ReleaseMode != Reader.
   364         /// </summary>
   365         public bool IsReaderSplashEnabled
   366         {
   367             get { return (this._IsReaderSplashEnabled); }
   368             set
   369             {
   370                 if (object.Equals(this._IsReaderSplashEnabled, value) == false)
   371                 {
   372                     this._IsReaderSplashEnabled = value;
   373                     this.RaisePropertyChangedEvent(nameof(this.IsReaderSplashEnabled));
   374                 }
   375             }
   376         }
   377 
   378         /// <summary>
   379         /// Gets or sets whether to display a warning when sending a message (forward/reply)
   380         /// unencrypted that was previously encrypted.
   381         /// </summary>
   382         public bool IsSecurityLossWarningEnabled
   383         {
   384             get { return (this._IsSecurityLossWarningEnabled); }
   385             set
   386             {
   387                 if (object.Equals(this._IsSecurityLossWarningEnabled, value) == false)
   388                 {
   389                     this._IsSecurityLossWarningEnabled = value;
   390                     this.RaisePropertyChangedEvent(nameof(this.IsSecurityLossWarningEnabled));
   391                 }
   392             }
   393         }
   394 
   395         /// <summary>
   396         /// Gets or sets whether sensitive data logging is enabled.
   397         /// </summary>
   398         public bool IsSensitiveDataLoggingEnabled
   399         {
   400             get { return (this._IsSensitiveDataLoggingEnabled); }
   401             set
   402             {
   403                 if (object.Equals(this._IsSensitiveDataLoggingEnabled, value) == false)
   404                 {
   405                     this._IsSensitiveDataLoggingEnabled = value;
   406                     this.RaisePropertyChangedEvent(nameof(this.IsSensitiveDataLoggingEnabled));
   407                 }
   408             }
   409         }
   410 
   411         /// <summary>
   412         /// Gets or sets whether key sync is disabled for all accounts.
   413         /// </summary>
   414         public bool IsSyncEnabledForAllAccounts
   415         {
   416             get { return (this._IsSyncEnabledForAllAccounts); }
   417             set
   418             {
   419                 if (object.Equals(this._IsSyncEnabledForAllAccounts, value) == false)
   420                 {
   421                     this._IsSyncEnabledForAllAccounts = value;
   422                     this.RaisePropertyChangedEvent(nameof(this.IsSyncEnabledForAllAccounts));
   423 
   424                     Globals.ThisAddIn.SyncWithSettings();
   425                 }
   426             }
   427         }
   428 
   429         /// <summary>
   430         /// Gets or sets whether TNEF/RTF format is forcefully disabled in the registry.
   431         /// Can only be set from the registry.
   432         /// </summary>
   433         public bool IsTNEFDisabled
   434         {
   435             get { return (this._IsTNEFDisabled); }
   436         }
   437 
   438         /// <summary>
   439         /// Gets or sets whether to enable encryption of message subjects.
   440         /// </summary>
   441         public bool IsUnencryptedSubjectEnabled
   442         {
   443             get { return (this._IsUnencryptedSubjectEnabled); }
   444             set
   445             {
   446                 if (object.Equals(this._IsUnencryptedSubjectEnabled, value) == false)
   447                 {
   448                     this._IsUnencryptedSubjectEnabled = value;
   449                     this.RaisePropertyChangedEvent(nameof(this.IsUnencryptedSubjectEnabled));
   450                 }
   451             }
   452         }
   453 
   454         /// <summary>
   455         /// Gets or sets whether verbose logging is enabled.
   456         /// </summary>
   457         public bool IsVerboseLoggingEnabled
   458         {
   459             get { return (this._IsVerboseLoggingEnabled); }
   460             set
   461             {
   462                 if (object.Equals(this._IsVerboseLoggingEnabled, value) == false)
   463                 {
   464                     this._IsVerboseLoggingEnabled = value;
   465                     this.RaisePropertyChangedEvent(nameof(this.IsVerboseLoggingEnabled));
   466                 }
   467             }
   468         }
   469 
   470         /// <summary>
   471         /// Gets or sets the culture to display the trustwords in.
   472         /// </summary>
   473         public CultureInfo TrustwordsCulture
   474         {
   475             get { return (this._TrustwordsCulture); }
   476             set
   477             {
   478                 if (object.Equals(this._TrustwordsCulture, value) == false)
   479                 {
   480                     this._TrustwordsCulture = value;
   481                     this.RaisePropertyChangedEvent(nameof(this.TrustwordsCulture));
   482                 }
   483             }
   484         }
   485 
   486         /**************************************************************
   487          * 
   488          * Methods
   489          * 
   490          *************************************************************/
   491 
   492         /// <summary>
   493         /// Raises the property changed event, if possible, with the given arguments.
   494         /// </summary>
   495         /// <param name="propertyName">The name of the property that changed.</param>
   496         private void RaisePropertyChangedEvent(string propertyName)
   497         {
   498             this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
   499             return;
   500         }
   501 
   502         /// <summary>
   503         /// Resets the object to it's default state/values.
   504         /// </summary>
   505         public void Reset()
   506         {
   507             // Disconnect events
   508             if (this._AccountSettingsList != null)
   509             {
   510                 this._AccountSettingsList.CollectionChanged -= AccountSettingsList_CollectionChanged;
   511 
   512                 foreach (PEPAccountSettings acctSettings in this._AccountSettingsList)
   513                 {
   514                     acctSettings.PropertyChanged -= PEPAccountSettings_PropertyChanged;
   515                 }
   516             }
   517 
   518             this._AccountSettingsList = new ObservableCollection<PEPAccountSettings>();
   519             this._AccountWhitelist = PEPSettings.ACCOUNT_WHITELIST_DEFAULT;
   520             this._CrashReportSendAddress = PEPSettings.CRASH_REPORT_SEND_ADDRESS_DEFAULT;
   521             this._ExtraKeys = null;
   522             this._IsAutoUpdateEnabled = PEPSettings.IS_AUTO_UPDATE_ENABLED_DEFAULT;
   523             this._IsCrashReportVisible = PEPSettings.IS_CRASH_REPORT_VISIBLE_DEFAULT;
   524             this._IsDeveloperModeEnabled = PEPSettings.IS_DEVELOPER_MODE_ENABLED_DEFAULT;
   525             this._IsDisableProtectionForContactsEnabled = PEPSettings.IS_DISABLE_PROTECTION_FOR_CONTACTS_ENABLED_DEFAULT;
   526             this._IsEncryptAllAccountsEnabled = PEPSettings.IS_ENCRYPT_ALL_ACCOUNTS_ENABLED_DEFAULT;
   527             this._IsFirstStartupComplete = false;
   528             this._IsInboxCleaningEnabled = PEPSettings.IS_INBOX_CLEANING_ENABLED_DEFAULT;
   529             this._IsKeyServerUsed = PEPSettings.IS_KEY_SERVER_USED_DEFAULT;
   530             this._IsNeverUnsecureOptionVisible = PEPSettings.IS_NEVER_UNSECURE_OPTION_VISIBLE_DEFAULT;
   531             this._IsPassiveModeEnabled = PEPSettings.IS_PASSIVE_MODE_ENABLED_DEFAULT;
   532             this._IsPEPFolderVisible = PEPSettings.IS_PEP_FOLDER_VISIBLE_DEFAULT;
   533             this._IsReaderSplashEnabled = PEPSettings.IS_READER_SPLASH_ENABLED_DEFAULT;
   534             this._IsSecurityLossWarningEnabled = PEPSettings.IS_SECURITY_LOSS_WARNING_ENABLED_DEFAULT;
   535             this._IsSensitiveDataLoggingEnabled = PEPSettings.IS_SENSITIVE_DATA_LOGGING_ENABLED_DEFAULT;
   536             this._IsSyncEnabledForAllAccounts = PEPSettings.IS_SYNC_ENABLED_FOR_ALL_ACCOUNTS_DEFAULT;
   537             this._IsTNEFDisabled = PEPSettings.IS_TNEF_DISABLED_DEFAULT;
   538             this._IsUnencryptedSubjectEnabled = PEPSettings.IS_UNENCRYPTED_SUBJECT_ENABLED_DEFAULT;
   539             this._IsVerboseLoggingEnabled = PEPSettings.IS_VERBOSE_LOGGING_ENABLED_DEFAULT;
   540             this._TrustwordsCulture = null; // Allow application to decide since default is UI language
   541 
   542             // Connect events
   543             this._AccountSettingsList.CollectionChanged += AccountSettingsList_CollectionChanged;
   544 
   545             this.RaisePropertyChangedEvent(nameof(this.AccountSettingsList));
   546             this.RaisePropertyChangedEvent(nameof(this.AccountWhitelist));
   547             this.RaisePropertyChangedEvent(nameof(this.CrashReportSendAddress));
   548             this.RaisePropertyChangedEvent(nameof(this.ExtraKeys));
   549             this.RaisePropertyChangedEvent(nameof(this.IsAutoUpdateEnabled));
   550             this.RaisePropertyChangedEvent(nameof(this.IsCrashReportVisible));
   551             this.RaisePropertyChangedEvent(nameof(this.IsDeveloperModeEnabled));
   552             this.RaisePropertyChangedEvent(nameof(this.IsDisableProtectionForContactsEnabled));
   553             this.RaisePropertyChangedEvent(nameof(this.IsEncryptAllAccountsEnabled));
   554             this.RaisePropertyChangedEvent(nameof(this.IsFirstStartupComplete));
   555             this.RaisePropertyChangedEvent(nameof(this.IsInboxCleaningEnabled));
   556             this.RaisePropertyChangedEvent(nameof(this.IsKeyServerUsed));
   557             this.RaisePropertyChangedEvent(nameof(this.IsNeverUnsecureOptionVisible));
   558             this.RaisePropertyChangedEvent(nameof(this.IsPassiveModeEnabled));
   559             this.RaisePropertyChangedEvent(nameof(this.IsPEPFolderVisible));
   560             this.RaisePropertyChangedEvent(nameof(this.IsReaderSplashEnabled));
   561             this.RaisePropertyChangedEvent(nameof(this.IsSecurityLossWarningEnabled));
   562             this.RaisePropertyChangedEvent(nameof(this.IsSensitiveDataLoggingEnabled));
   563             this.RaisePropertyChangedEvent(nameof(this.IsSyncEnabledForAllAccounts));
   564             this.RaisePropertyChangedEvent(nameof(this.IsTNEFDisabled));
   565             this.RaisePropertyChangedEvent(nameof(this.IsUnencryptedSubjectEnabled));
   566             this.RaisePropertyChangedEvent(nameof(this.IsVerboseLoggingEnabled));
   567             this.RaisePropertyChangedEvent(nameof(this.TrustwordsCulture));
   568 
   569             return;
   570         }
   571 
   572         /// <summary>
   573         /// Gets the account settings object that corresponds with the given SMTP address.
   574         /// This will return the first match in the list if somehow more than one.
   575         /// </summary>
   576         /// <param name="smtpAddress">The SMTP address of the account settings to get.</param>
   577         /// <returns>The matching account settings, otherwise false.</returns>
   578         public PEPAccountSettings GetAccountSettings(string smtpAddress)
   579         {
   580             PEPAccountSettings result = null;
   581 
   582             if (string.IsNullOrEmpty(smtpAddress) == false)
   583             {
   584                 foreach (PEPAccountSettings acctSettings in this._AccountSettingsList)
   585                 {
   586                     // Compare only by the address
   587                     if (acctSettings.EqualsByAddress(smtpAddress))
   588                     {
   589                         result = acctSettings;
   590                         break;
   591                     }
   592                 }
   593             }
   594 
   595             return (result);
   596         }
   597 
   598         /**************************************************************
   599          * 
   600          * Registry Methods
   601          * 
   602          *************************************************************/
   603 
   604         /// <summary>
   605         /// Writes/saves the updater config for Outlook to the registry.
   606         /// This should only be called after the value of _IsAutoUpdateEnabled is stable.
   607         /// This method is called automatically within WriteConfigToRegistry().
   608         /// </summary>
   609         public void SaveUpdaterConfigToRegistry()
   610         {
   611             try
   612             {
   613                 // Check if key exists and update if necessary
   614                 bool keyExists = false;
   615                 string updateStr = string.Format(pEp.Properties.Settings.Default.UpdateURL, pEp.Properties.Settings.Default.Serial);
   616                 string pEpKey = Path.Combine(PEPSettings.REG_KEY_SOFTWARE, PEPSettings.REG_KEY_PEP);
   617                 string updaterKey = Path.Combine(pEpKey, PEPSettings.REG_KEY_PEP_UPDATER);
   618 
   619                 Log.Verbose("SaveUpdaterConfigToRegistry: Key to check/update: " + updaterKey);
   620                 Log.SensitiveData("SaveUpdaterConfigToRegistry: Value to check for: " + updateStr);
   621 
   622                 using (RegistryKey key = Registry.CurrentUser.OpenSubKey(updaterKey))
   623                 {
   624                     var value = key?.GetValue(Globals.PEP_NAME_INSTALL);
   625                     Log.SensitiveData("SaveUpdaterConfigToRegistry: Value found in registry: " + value?.ToString());
   626                     keyExists = (value?.Equals(updateStr) == true);
   627                     Log.Verbose("SaveUpdaterConfigToRegistry: " + (keyExists ? "Same value found in registry." : "No value or different value found."));
   628                 }              
   629 
   630                 // If key exists and update is disabled, delete key
   631                 if (keyExists &&
   632                     (this._IsAutoUpdateEnabled == false))
   633                 {
   634                     Log.Verbose("SaveUpdaterConfigToRegistry: Key exists and IsAutoUpdateEnabled is false. Deleting value.");
   635                     using (RegistryKey key = Registry.CurrentUser.OpenSubKey(pEpKey, true))
   636                     {
   637                         key?.DeleteSubKeyTree(PEPSettings.REG_KEY_PEP_UPDATER, false); // Do not throw execption
   638                         Log.Verbose("SaveUpdaterConfigToRegistry: Key deleted");
   639                     }
   640                 }
   641                 // If key doesn't exist and update is enabled, create key
   642                 else if ((keyExists == false) &&
   643                          this._IsAutoUpdateEnabled)
   644                 {
   645                     Log.Verbose("SaveUpdaterConfigToRegistry: Key doesn't exist or is different and IsAutoUpdateEnabled is true. Trying to set value.");
   646                     using (RegistryKey key = Registry.CurrentUser.CreateSubKey(updaterKey))
   647                     {
   648                         key?.SetValue(Globals.PEP_NAME_INSTALL, updateStr, RegistryValueKind.String);
   649                         Log.Verbose("SaveUpdaterConfigToRegistry: Value set");
   650                     }
   651                 }
   652             }
   653             catch (Exception ex)
   654             {
   655                 Log.Error("SaveUpdaterConfigToRegistry: Failure occured, " + ex.ToString());
   656             }
   657         }
   658 
   659         /// <summary>
   660         /// Compares the given PEPSettings and checks for equality.
   661         /// </summary>
   662         /// <param name="obj">The object to check equality with.</param>
   663         /// <returns>True if both objects are considered equal, otherwise false.</returns>
   664         public bool Equals(PEPSettings obj)
   665         {
   666             if (obj == null)
   667             {
   668                 return (false);
   669             }
   670 
   671             // First, check general pEp settings
   672             if (Comparisons.Equals(this.AccountWhitelist, obj.AccountWhitelist) &&
   673                 Comparisons.Equals(this.CrashReportSendAddress, obj.CrashReportSendAddress) &&
   674                 Comparisons.Equals(this.ExtraKeys, obj.ExtraKeys) &&
   675                 Comparisons.Equals(this.IsAutoUpdateEnabled, obj.IsAutoUpdateEnabled) &&
   676                 Comparisons.Equals(this.IsCrashReportVisible, obj.IsCrashReportVisible) &&
   677                 Comparisons.Equals(this.IsDeveloperModeEnabled, obj.IsDeveloperModeEnabled) &&
   678                 Comparisons.Equals(this.IsDisableProtectionForContactsEnabled, obj.IsDisableProtectionForContactsEnabled) &&
   679                 Comparisons.Equals(this.IsEncryptAllAccountsEnabled, obj.IsEncryptAllAccountsEnabled) &&
   680                 Comparisons.Equals(this.IsFirstStartupComplete, obj.IsFirstStartupComplete) &&
   681                 Comparisons.Equals(this.IsInboxCleaningEnabled, obj.IsInboxCleaningEnabled) &&
   682                 Comparisons.Equals(this.IsKeyServerUsed, obj.IsKeyServerUsed) &&
   683                 Comparisons.Equals(this.IsNeverUnsecureOptionVisible, obj.IsNeverUnsecureOptionVisible) &&
   684                 Comparisons.Equals(this.IsPassiveModeEnabled, obj.IsPassiveModeEnabled) &&
   685                 Comparisons.Equals(this.IsPEPFolderVisible, obj.IsPEPFolderVisible) &&
   686                 Comparisons.Equals(this.IsReaderSplashEnabled, obj.IsReaderSplashEnabled) &&
   687                 Comparisons.Equals(this.IsSecurityLossWarningEnabled, obj.IsSecurityLossWarningEnabled) &&
   688                 Comparisons.Equals(this.IsSensitiveDataLoggingEnabled, obj.IsSensitiveDataLoggingEnabled) &&
   689                 Comparisons.Equals(this.IsSyncEnabledForAllAccounts, obj.IsSyncEnabledForAllAccounts) &&
   690                 Comparisons.Equals(this.IsTNEFDisabled, obj.IsTNEFDisabled) &&
   691                 Comparisons.Equals(this.IsUnencryptedSubjectEnabled, obj.IsUnencryptedSubjectEnabled) &&
   692                 Comparisons.Equals(this.IsVerboseLoggingEnabled, obj.IsVerboseLoggingEnabled) &&
   693                 Comparisons.Equals(this.TrustwordsCulture, obj.TrustwordsCulture))
   694             {
   695                 // Check if the number of accounts matches
   696                 if (this.AccountSettingsList?.Count != obj.AccountSettingsList?.Count)
   697                 {
   698                     return false;
   699                 }
   700 
   701                 // Check if the account settings are equal for each account
   702                 for (int i = 0; i < this.AccountSettingsList?.Count; i++)
   703                 {
   704                     var acctSettings1 = this.AccountSettingsList[i];
   705                     var acctSettings2 = obj.AccountSettingsList[i];
   706 
   707                     if ((Comparisons.Equals(acctSettings1.AddDisclaimer, acctSettings2.AddDisclaimer) &&
   708                          Comparisons.Equals(acctSettings1.DisclaimerText, acctSettings2.DisclaimerText) &&
   709                          Comparisons.Equals(acctSettings1.IsDecryptAlwaysEnabled, acctSettings2.IsDecryptAlwaysEnabled) &&
   710                          Comparisons.Equals(acctSettings1.IsPEPEnabled, acctSettings2.IsPEPEnabled) &&
   711                          Comparisons.Equals(acctSettings1.IsSecureStorageEnabled, acctSettings2.IsSecureStorageEnabled) &&
   712                          Comparisons.Equals(acctSettings1.IsSyncEnabled, acctSettings2.IsSyncEnabled) &&
   713                          Comparisons.Equals(acctSettings1.SentFolderEntryId, acctSettings2.SentFolderEntryId) &&
   714                          Comparisons.Equals(acctSettings1.SmtpAddress, acctSettings2.SmtpAddress) &&
   715                          Comparisons.Equals(acctSettings1.Type, acctSettings2.Type)) == false)
   716                     {
   717                         return false;
   718                     }
   719                 }
   720 
   721                 return true;
   722             }
   723 
   724             return false;
   725         }
   726 
   727         /// <summary>
   728         /// Writes/saves any supported configuration/property values to the registry.
   729         /// </summary>
   730         public void SaveToRegistry()
   731         {
   732             /* Note: 
   733              * Do not save the below properties which can only be modified from the registry
   734              *   • AccountWhitelist
   735              *   • CrashReportSendAddress
   736              *   • ExtraKeys
   737              *   • IsCrashReportVisible
   738              *   • IsDeveloperModeEnabled
   739              *   • IsSensitiveDataLoggingEnabled
   740              *   • IsDisableProtectionForContactsEnabled
   741              *   • IsTNEFDisabled
   742              */
   743 
   744             string pEpForOutlookRegKey = Path.Combine(PEPSettings.REG_KEY_SOFTWARE, PEPSettings.REG_KEY_PEP, PEPSettings.REG_KEY_PEP_FOR_OUTLOOK);
   745 
   746             try
   747             {
   748                 // Update the accounts list
   749                 Globals.ThisAddIn.SyncAccountsList();
   750 
   751                 // Get current state and only save if changes have been made
   752                 PEPSettings currentStateInRegistry = new PEPSettings();
   753                 currentStateInRegistry.LoadFromRegistry();
   754 
   755                 if (this?.Equals(currentStateInRegistry) != true)
   756                 {
   757                     using (RegistryKey pEpKey = Registry.CurrentUser.CreateSubKey(pEpForOutlookRegKey))
   758                     {
   759                         // Set account settings
   760                         using (RegistryKey keyAcctSettingsList = pEpKey.CreateSubKey(PEPSettings.REG_KEY_ACCOUNT_SETTINGS_LIST))
   761                         {
   762                             // Delete accounts that do not exist in Outlook (anymore)
   763                             if (currentStateInRegistry?.AccountSettingsList?.Count != this.AccountSettingsList?.Count)
   764                             {
   765                                 foreach (PEPAccountSettings accountInRegistry in currentStateInRegistry.AccountSettingsList)
   766                                 {
   767                                     if (this.GetAccountSettings(accountInRegistry?.SmtpAddress) == null)
   768                                     {
   769                                         try
   770                                         {
   771                                             keyAcctSettingsList.DeleteSubKeyTree(accountInRegistry.SmtpAddress);
   772                                         }
   773                                         catch (Exception ex)
   774                                         {
   775                                             Log.Error("SaveToRegistry: Error deleting account key. " + ex.ToString());
   776                                         }
   777                                     }
   778                                 }
   779                             }
   780 
   781                             // Update all existing accounts if necessary
   782                             foreach (PEPAccountSettings acctSettings in this._AccountSettingsList)
   783                             {
   784                                 try
   785                                 {
   786                                     if (string.IsNullOrWhiteSpace(acctSettings.SmtpAddress) == false)
   787                                     {
   788                                         using (RegistryKey keyAcctSettings = keyAcctSettingsList.CreateSubKey(acctSettings.SmtpAddress))
   789                                         {
   790                                             keyAcctSettings.SetValue(PEPSettings.REG_NAME_ACCOUNT_SETTING_IS_DECRYPT_ALWAYS_ENABLED, acctSettings.IsDecryptAlwaysEnabled.ToString(), RegistryValueKind.String);
   791                                             keyAcctSettings.SetValue(PEPSettings.REG_NAME_ACCOUNT_SETTING_IS_PEP_ENABLED, acctSettings.IsPEPEnabled.ToString(), RegistryValueKind.String);
   792                                             keyAcctSettings.SetValue(PEPSettings.REG_NAME_ACCOUNT_SETTING_IS_SECURE_STORAGE_ENABLED, acctSettings.IsSecureStorageEnabled.ToString(), RegistryValueKind.String);
   793                                             keyAcctSettings.SetValue(PEPSettings.REG_NAME_ACCOUNT_SETTING_IS_SYNC_ENABLED, acctSettings.IsSyncEnabled.ToString(), RegistryValueKind.String);
   794 
   795                                             if (acctSettings.SentFolderEntryId != null)
   796                                             {
   797                                                 keyAcctSettings.SetValue(PEPSettings.REG_NAME_ACCOUNT_SETTING_SENT_FOLDER_ENTRYID, acctSettings.SentFolderEntryId, RegistryValueKind.String);
   798                                             }
   799 
   800                                             if (acctSettings.SmtpAddress != null)
   801                                             {
   802                                                 keyAcctSettings.SetValue(PEPSettings.REG_NAME_ACCOUNT_SETTING_SMTP_ADDRESS, acctSettings.SmtpAddress, RegistryValueKind.String);
   803                                             }
   804 
   805                                             if (acctSettings.Type != null)
   806                                             {
   807                                                 keyAcctSettings.SetValue(PEPSettings.REG_NAME_ACCOUNT_SETTING_TYPE, acctSettings.Type, RegistryValueKind.String);
   808                                             }
   809 
   810                                             if (acctSettings.UserName != null)
   811                                             {
   812                                                 keyAcctSettings.SetValue(PEPSettings.REG_NAME_ACCOUNT_SETTING_USER_NAME, acctSettings.UserName, RegistryValueKind.String);
   813                                             }
   814                                         }
   815                                     }
   816                                 }
   817                                 catch { }
   818                             }
   819                         }
   820 
   821                         // Delete any existing EncryptedAccountsList in the registry (a legacy value)
   822                         try
   823                         {
   824                             pEpKey.DeleteSubKeyTree(PEPSettings.REG_KEY_ENCRYPTED_ACCOUNTS_LIST, false); // Do not throw exception
   825                         }
   826                         catch { }
   827 
   828                         pEpKey.SetValue(PEPSettings.REG_NAME_IS_AUTO_UPDATE_ENABLED, this._IsAutoUpdateEnabled.ToString(), RegistryValueKind.String);
   829                         pEpKey.SetValue(PEPSettings.REG_NAME_IS_ENCRYPT_ALL_ACCOUNTS_ENABLED, this._IsEncryptAllAccountsEnabled.ToString(), RegistryValueKind.String);
   830                         pEpKey.SetValue(PEPSettings.REG_NAME_IS_INBOX_CLEANING_ENABLED, this._IsInboxCleaningEnabled.ToString(), RegistryValueKind.String);
   831                         pEpKey.SetValue(PEPSettings.REG_NAME_IS_KEY_SERVER_USED, this._IsKeyServerUsed.ToString(), RegistryValueKind.String);
   832                         pEpKey.SetValue(PEPSettings.REG_NAME_IS_NEVER_UNSECURE_OPTION_VISIBLE, this._IsNeverUnsecureOptionVisible.ToString(), RegistryValueKind.String);
   833                         pEpKey.SetValue(PEPSettings.REG_NAME_IS_PEP_FOLDER_VISIBLE, this._IsPEPFolderVisible.ToString(), RegistryValueKind.String);
   834                         pEpKey.SetValue(PEPSettings.REG_NAME_IS_READER_SPLASH_ENABLED, this._IsReaderSplashEnabled.ToString(), RegistryValueKind.String);
   835                         pEpKey.SetValue(PEPSettings.REG_NAME_IS_SECURITY_LOSS_WARNING_ENABLED, this._IsSecurityLossWarningEnabled.ToString(), RegistryValueKind.String);
   836                         pEpKey.SetValue(PEPSettings.REG_NAME_IS_SYNC_ENABLED_FOR_ALL_ACCOUNTS, this._IsSyncEnabledForAllAccounts.ToString(), RegistryValueKind.String);
   837                         pEpKey.SetValue(PEPSettings.REG_NAME_IS_UNENCRYPTED_SUBJECT_ENABLED, this._IsUnencryptedSubjectEnabled.ToString(), RegistryValueKind.String);
   838                         pEpKey.SetValue(PEPSettings.REG_NAME_IS_VERBOSE_LOGGING_ENABLED, this._IsVerboseLoggingEnabled.ToString(), RegistryValueKind.String);
   839                         pEpKey.SetValue(PEPSettings.REG_NAME_TRUSTWORDS_CULTURE, (this._TrustwordsCulture?.TwoLetterISOLanguageName ?? string.Empty), RegistryValueKind.String);
   840                         pEpKey.SetValue(PEPSettings.REG_NAME_IS_PASSIVE_MODE_ENABLED, this._IsPassiveModeEnabled.ToString(), RegistryValueKind.String);
   841 
   842                         // Set IsFirstStartupComplete
   843                         if (this._IsFirstStartupComplete)
   844                         {
   845                             pEpKey.SetValue(PEPSettings.REG_NAME_IS_FIRST_STARTUP_COMPLETE, (true).ToString(), RegistryValueKind.String);
   846                         }
   847                         else
   848                         {
   849                             // Remove the value entirely if startup is not completed
   850                             try
   851                             {
   852                                 pEpKey.DeleteValue(PEPSettings.REG_NAME_IS_FIRST_STARTUP_COMPLETE, false); // Do not throw exception
   853                             }
   854                             catch { }
   855                         }
   856                     }
   857                 }
   858 
   859                 // Make sure to update the Updater registry values which can also be done separately
   860                 this.SaveUpdaterConfigToRegistry();
   861             }
   862             catch (Exception ex)
   863             {
   864                 Log.Error("SaveToRegistry: Failure occured, " + ex.ToString());
   865             }
   866 
   867             return;
   868         }
   869 
   870         /// <summary>
   871         /// Reads/loads any configuration/property values from the registry.
   872         /// Warning: This will raise all property changed events even if the values don't change.
   873         /// </summary>
   874         public void LoadFromRegistry()
   875         {
   876             bool isSuccessful;
   877             bool isPropertySet;
   878             int parsedIntValue;
   879             bool parsedBoolValue;
   880             string keyValue;
   881             object value;
   882             string[] registryWhitelist;
   883             List<string> extraKeys;
   884             List<string> whitelist;
   885             PEPAccountSettings acctSettings;
   886             PEPAccountSettings existingAcctSettings;
   887             Dictionary<string, bool> legacyEncryptedAccountsList = new Dictionary<string, bool>();
   888 
   889             ///////////////////////////////////////////////////////////
   890             // Read non-pEp values
   891             ///////////////////////////////////////////////////////////
   892 
   893             // Attempt to get IsTNEFDisabled
   894             isPropertySet = false;
   895             try
   896             {
   897                 using (RegistryKey key1 = Registry.CurrentUser.OpenSubKey(PEPSettings.REG_KEY_SOFTWARE))
   898                 {
   899                     using (RegistryKey keyOffice = key1?.OpenSubKey(PEPSettings.REG_KEY_MICROSOFT_OFFICE))
   900                     {
   901                         /* Outlook versions
   902                          *  "12" Outlook 2007
   903                          *  "14" Outlook 2010
   904                          *  "15" Outlook 2013
   905                          *  "16" Outlook 2016
   906                          */
   907                         using (RegistryKey keyPreferences = keyOffice?.OpenSubKey(Globals.ThisAddIn.Application.Version.Substring(0, 2) + ".0\\Outlook\\Preferences\\"))
   908                         {
   909                             // Attempt to get IsTNEFDisabled
   910                             keyValue = keyPreferences?.GetValue(PEPSettings.REG_NAME_IS_TNEF_DISABLED, PEPSettings.IS_TNEF_DISABLED_DEFAULT).ToString();
   911 
   912                             // Try parsing as int
   913                             isSuccessful = int.TryParse(keyValue, out parsedIntValue);
   914                             if (isSuccessful)
   915                             {
   916                                 this._IsTNEFDisabled = (parsedIntValue > 0);
   917                                 isPropertySet = true;
   918                             }
   919 
   920                             // Try parsing as bool (this will handle the default value)
   921                             if (isSuccessful == false)
   922                             {
   923                                 isSuccessful = bool.TryParse(keyValue, out parsedBoolValue);
   924                                 if (isSuccessful)
   925                                 {
   926                                     this._IsTNEFDisabled = parsedBoolValue;
   927                                     isPropertySet = true;
   928                                 }
   929                             }
   930                         }
   931                     }
   932                 }
   933             }
   934             catch
   935             {
   936                 Log.Warning("LoadFromRegistry: Failure occured reading TNEF disabled status");
   937             }
   938             finally
   939             {
   940                 if (isPropertySet == false)
   941                 {
   942                     this._IsTNEFDisabled = PEPSettings.IS_TNEF_DISABLED_DEFAULT;
   943                 }
   944 
   945                 this.RaisePropertyChangedEvent(nameof(this.IsTNEFDisabled));
   946             }
   947 
   948             ///////////////////////////////////////////////////////////
   949             // Read pEp values
   950             ///////////////////////////////////////////////////////////
   951 
   952             string pEpForOutlookKey = Path.Combine(PEPSettings.REG_KEY_SOFTWARE, PEPSettings.REG_KEY_PEP, REG_KEY_PEP_FOR_OUTLOOK);
   953             try
   954             {
   955                 using (RegistryKey pEpKey = Registry.CurrentUser.OpenSubKey(pEpForOutlookKey))
   956                 {
   957                     if (pEpKey != null)
   958                     {
   959                         // Attempt to get AccountSettingsList
   960                         isPropertySet = false;
   961                         try
   962                         {
   963                             this._AccountSettingsList.Clear();
   964                             using (RegistryKey keyAcctSettingsList = pEpKey.OpenSubKey(PEPSettings.REG_KEY_ACCOUNT_SETTINGS_LIST))
   965                             {
   966                                 if (keyAcctSettingsList != null)
   967                                 {
   968                                     foreach (string smtpAddress in keyAcctSettingsList.GetSubKeyNames())
   969                                     {
   970                                         try
   971                                         {
   972                                             using (RegistryKey keyAcctSettings = keyAcctSettingsList.OpenSubKey(smtpAddress))
   973                                             {
   974                                                 acctSettings = new PEPAccountSettings(smtpAddress);
   975                                                 this._AccountSettingsList.Add(acctSettings);
   976 
   977                                                 // AddDisclaimer
   978                                                 value = keyAcctSettings.GetValue(PEPSettings.REG_NAME_ACCOUNT_SETTING_ADD_DISCLAIMER, null);
   979                                                 if (value != null)
   980                                                 {
   981                                                     if (int.TryParse(value as string, out parsedIntValue))
   982                                                     {
   983                                                         try
   984                                                         {
   985                                                             acctSettings.AddDisclaimer = (Disclaimer)parsedIntValue;
   986                                                             isPropertySet = true;
   987                                                         }
   988                                                         catch (Exception ex)
   989                                                         {
   990                                                             acctSettings.AddDisclaimer = PEPSettings.ADD_DISCLAIMER_DEFAULT;
   991                                                             Log.Error("LoadFromRegistry: Error getting AddDisclaimer value. " + ex.ToString());
   992                                                         }
   993                                                     }
   994                                                 }
   995 
   996                                                 // DisclaimerText
   997                                                 value = keyAcctSettings.GetValue(PEPSettings.REG_NAME_ACCOUNT_SETTING_DISCLAIMER_TEXT, null);
   998                                                 if (string.IsNullOrEmpty(value as string) == false)
   999                                                 {
  1000                                                     acctSettings.DisclaimerText = (value as string)?.Trim();
  1001                                                     isPropertySet = true;
  1002                                                 }
  1003 
  1004                                                 // IsDecryptAlwaysEnabled
  1005                                                 value = keyAcctSettings.GetValue(PEPSettings.REG_NAME_ACCOUNT_SETTING_IS_DECRYPT_ALWAYS_ENABLED, null);
  1006                                                 if (value != null)
  1007                                                 {
  1008                                                     isSuccessful = bool.TryParse(value.ToString(), out parsedBoolValue);
  1009                                                     if (isSuccessful)
  1010                                                     {
  1011                                                         acctSettings.IsDecryptAlwaysEnabled = parsedBoolValue;
  1012                                                         isPropertySet = true;
  1013                                                     }
  1014                                                 }
  1015 
  1016                                                 // IsPEPEnabled
  1017                                                 value = keyAcctSettings.GetValue(PEPSettings.REG_NAME_ACCOUNT_SETTING_IS_PEP_ENABLED, null);
  1018                                                 if (value != null)
  1019                                                 {
  1020                                                     isSuccessful = bool.TryParse(value.ToString(), out parsedBoolValue);
  1021                                                     if (isSuccessful)
  1022                                                     {
  1023                                                         acctSettings.IsPEPEnabled = parsedBoolValue;
  1024                                                         isPropertySet = true;
  1025                                                     }
  1026                                                 }
  1027 
  1028                                                 // IsSecureStorageEnabled
  1029                                                 value = keyAcctSettings.GetValue(PEPSettings.REG_NAME_ACCOUNT_SETTING_IS_SECURE_STORAGE_ENABLED, null);
  1030                                                 if (value != null)
  1031                                                 {
  1032                                                     isSuccessful = bool.TryParse(value.ToString(), out parsedBoolValue);
  1033                                                     if (isSuccessful)
  1034                                                     {
  1035                                                         acctSettings.IsSecureStorageEnabled = parsedBoolValue;
  1036                                                         isPropertySet = true;
  1037                                                     }
  1038                                                 }
  1039 
  1040                                                 // IsSyncEnabled
  1041                                                 value = keyAcctSettings.GetValue(PEPSettings.REG_NAME_ACCOUNT_SETTING_IS_SYNC_ENABLED, null);
  1042                                                 if (value != null)
  1043                                                 {
  1044                                                     isSuccessful = bool.TryParse(value.ToString(), out parsedBoolValue);
  1045                                                     if (isSuccessful)
  1046                                                     {
  1047                                                         acctSettings.IsSyncEnabled = parsedBoolValue;
  1048                                                         isPropertySet = true;
  1049                                                     }
  1050                                                 }
  1051 
  1052                                                 // SentFolderEntryId
  1053                                                 value = keyAcctSettings.GetValue(PEPSettings.REG_NAME_ACCOUNT_SETTING_SENT_FOLDER_ENTRYID, null);
  1054                                                 if (value != null)
  1055                                                 {
  1056                                                     if (string.IsNullOrWhiteSpace((string)value) == false)
  1057                                                     {
  1058                                                         acctSettings.SentFolderEntryId = ((string)value).Trim();
  1059                                                         isPropertySet = true;
  1060                                                     }
  1061                                                 }
  1062 
  1063                                                 // SmtpAddress
  1064                                                 value = keyAcctSettings.GetValue(PEPSettings.REG_NAME_ACCOUNT_SETTING_SMTP_ADDRESS, null);
  1065                                                 if (value != null)
  1066                                                 {
  1067                                                     if (string.IsNullOrWhiteSpace((string)value) == false)
  1068                                                     {
  1069                                                         acctSettings.SmtpAddress = ((string)value).Trim();
  1070                                                         isPropertySet = true;
  1071                                                     }
  1072                                                 }
  1073 
  1074                                                 // Type
  1075                                                 value = keyAcctSettings.GetValue(PEPSettings.REG_NAME_ACCOUNT_SETTING_TYPE, null);
  1076                                                 if (value != null)
  1077                                                 {
  1078                                                     if (string.IsNullOrWhiteSpace((string)value) == false)
  1079                                                     {
  1080                                                         acctSettings.Type = ((string)value).Trim();
  1081                                                         isPropertySet = true;
  1082                                                     }
  1083                                                 }
  1084 
  1085                                                 // UserName
  1086                                                 value = keyAcctSettings.GetValue(PEPSettings.REG_NAME_ACCOUNT_SETTING_USER_NAME, null);
  1087                                                 if (value != null)
  1088                                                 {
  1089                                                     if (string.IsNullOrWhiteSpace((string)value) == false)
  1090                                                     {
  1091                                                         acctSettings.UserName = ((string)value).Trim();
  1092                                                         isPropertySet = true;
  1093                                                     }
  1094                                                 }
  1095                                             }
  1096                                         }
  1097                                         catch { }
  1098                                     }
  1099                                 }
  1100                             }
  1101                         }
  1102                         catch
  1103                         {
  1104                             Log.Warning("LoadFromRegistry: Unable to fully read AccountSettingsList");
  1105                         }
  1106                         finally
  1107                         {
  1108                             if (isPropertySet == false)
  1109                             {
  1110                                 this._AccountSettingsList.Clear();
  1111                             }
  1112 
  1113                             this.RaisePropertyChangedEvent(nameof(this.AccountSettingsList));
  1114                         }
  1115 
  1116                         // For backwards compatibility, also read in the older encrypted accounts list (if it exists)
  1117                         try
  1118                         {
  1119                             legacyEncryptedAccountsList.Clear();
  1120                             using (RegistryKey key3 = pEpKey.OpenSubKey(PEPSettings.REG_KEY_ENCRYPTED_ACCOUNTS_LIST))
  1121                             {
  1122                                 if (key3 != null)
  1123                                 {
  1124                                     foreach (string name in key3.GetValueNames())
  1125                                     {
  1126                                         value = key3.GetValue(name, PEPSettings.ENCRYPT_ACCOUNTS_BY_DEFAULT);
  1127 
  1128                                         if (value != null)
  1129                                         {
  1130                                             isSuccessful = bool.TryParse(value.ToString(), out parsedBoolValue);
  1131                                             if ((isSuccessful) &&
  1132                                                 (legacyEncryptedAccountsList.ContainsKey(name) == false))
  1133                                             {
  1134                                                 legacyEncryptedAccountsList.Add(name, parsedBoolValue);
  1135                                             }
  1136                                         }
  1137                                     }
  1138                                 }
  1139                             }
  1140                         }
  1141                         catch { }
  1142 
  1143                         /* Merge the new format of the accounts list with the old format.
  1144                          * Whatever entries already in AccountSettingsList are considered valid.
  1145                          * (the existing list takes priority over the legacy encrypted accounts list entries).
  1146                          * This means only entries in the legacy encrypted accounts list whose address does not match
  1147                          * with an existing entry in the AccountSettingsList will be added. Logic elsewhere must remove
  1148                          * invalid entries (old accounts).
  1149                          */
  1150                         foreach (KeyValuePair<string, bool> entry in legacyEncryptedAccountsList)
  1151                         {
  1152                             // Any match means it already exists, no need to handle multiple here
  1153                             existingAcctSettings = this.GetAccountSettings(entry.Key);
  1154 
  1155                             if (existingAcctSettings == null)
  1156                             {
  1157                                 acctSettings = new PEPAccountSettings();
  1158                                 acctSettings.SmtpAddress = entry.Key;
  1159                                 acctSettings.IsSecureStorageEnabled = entry.Value;
  1160 
  1161                                 this._AccountSettingsList.Add(acctSettings);
  1162                             }
  1163                         }
  1164 
  1165                         // Attempt to get AccountWhitelist
  1166                         isPropertySet = false;
  1167                         try
  1168                         {
  1169                             value = pEpKey.GetValue(PEPSettings.REG_NAME_ACCOUNT_WHITELIST, null);
  1170                             if (value != null)
  1171                             {
  1172                                 whitelist = new List<string>();
  1173 
  1174                                 // Copy over hardcoded values
  1175                                 for (int i = 0; i < PEPSettings.ACCOUNT_WHITELIST_DEFAULT.Length; i++)
  1176                                 {
  1177                                     whitelist.Add(PEPSettings.ACCOUNT_WHITELIST_DEFAULT[i].Trim());
  1178                                 }
  1179 
  1180                                 // Copy over registry values
  1181                                 registryWhitelist = value.ToString().Split(';');
  1182                                 for (int i = 0; i < registryWhitelist.Length; i++)
  1183                                 {
  1184                                     whitelist.Add(registryWhitelist[i].Trim());
  1185                                 }
  1186 
  1187                                 this._AccountWhitelist = whitelist.ToArray();
  1188                                 isPropertySet = true;
  1189                             }
  1190                         }
  1191                         catch
  1192                         {
  1193                             Log.Warning("LoadFromRegistry: Unable to read AccountWhitelist");
  1194                         }
  1195                         finally
  1196                         {
  1197                             if (isPropertySet == false)
  1198                             {
  1199                                 whitelist = new List<string>();
  1200 
  1201                                 // Copy over hardcoded values
  1202                                 for (int i = 0; i < PEPSettings.ACCOUNT_WHITELIST_DEFAULT.Length; i++)
  1203                                 {
  1204                                     whitelist.Add(PEPSettings.ACCOUNT_WHITELIST_DEFAULT[i].Trim());
  1205                                 }
  1206 
  1207                                 this._AccountWhitelist = whitelist.ToArray();
  1208                             }
  1209 
  1210                             this.RaisePropertyChangedEvent(nameof(this.AccountWhitelist));
  1211                         }
  1212 
  1213                         // Attempt to get CrashReportSendAddress
  1214                         isPropertySet = false;
  1215                         try
  1216                         {
  1217                             keyValue = pEpKey.GetValue(PEPSettings.REG_NAME_CRASH_REPORT_SEND_ADDRESS, PEPSettings.CRASH_REPORT_SEND_ADDRESS_DEFAULT) as string;
  1218                             if (keyValue != null)
  1219                             {
  1220                                 this._CrashReportSendAddress = keyValue;
  1221                                 isPropertySet = true;
  1222                             }
  1223                         }
  1224                         catch
  1225                         {
  1226                             Log.Warning("LoadFromRegistry: Unable to read CrashReportSendAddress");
  1227                         }
  1228                         finally
  1229                         {
  1230                             if (isPropertySet == false)
  1231                             {
  1232                                 this._CrashReportSendAddress = PEPSettings.CRASH_REPORT_SEND_ADDRESS_DEFAULT;
  1233                             }
  1234 
  1235                             this.RaisePropertyChangedEvent(nameof(this.CrashReportSendAddress));
  1236                         }
  1237 
  1238                         // Attempt to get ExtraKeys value
  1239                         isPropertySet = false;
  1240                         try
  1241                         {
  1242                             value = pEpKey.GetValue(PEPSettings.REG_NAME_EXTRA_KEYS, null);
  1243                             if (value != null)
  1244                             {
  1245                                 extraKeys = new List<string>(value.ToString().Split(','));
  1246 
  1247                                 // Trim any whitespace and remove empty
  1248                                 for (int i = (extraKeys.Count - 1); i >= 0; i--)
  1249                                 {
  1250                                     extraKeys[i] = extraKeys[i].Trim();
  1251 
  1252                                     if (string.IsNullOrEmpty(extraKeys[i]))
  1253                                     {
  1254                                         extraKeys.RemoveAt(i);
  1255                                     }
  1256                                 }
  1257 
  1258                                 this._ExtraKeys = extraKeys.ToArray();
  1259                                 isPropertySet = true;
  1260                             }
  1261                         }
  1262                         catch
  1263                         {
  1264                             Log.Warning("LoadFromRegistry: Unable to read ExtraKeys");
  1265                         }
  1266                         finally
  1267                         {
  1268                             if (isPropertySet == false)
  1269                             {
  1270                                 this._ExtraKeys = null;
  1271                             }
  1272 
  1273                             this.RaisePropertyChangedEvent(nameof(this.ExtraKeys));
  1274                         }
  1275 
  1276                         // Attempt to get IsAutoUpdateEnabled
  1277                         isPropertySet = false;
  1278                         try
  1279                         {
  1280                             keyValue = pEpKey.GetValue(PEPSettings.REG_NAME_IS_AUTO_UPDATE_ENABLED, PEPSettings.IS_AUTO_UPDATE_ENABLED_DEFAULT).ToString();
  1281                             isSuccessful = bool.TryParse(keyValue, out parsedBoolValue);
  1282 
  1283                             if (isSuccessful)
  1284                             {
  1285                                 this._IsAutoUpdateEnabled = parsedBoolValue;
  1286                                 isPropertySet = true;
  1287                             }
  1288                         }
  1289                         catch
  1290                         {
  1291                             Log.Warning("LoadFromRegistry: Unable to read IsAutoUpdateEnabled");
  1292                         }
  1293                         finally
  1294                         {
  1295                             if (isPropertySet == false)
  1296                             {
  1297                                 this._IsAutoUpdateEnabled = PEPSettings.IS_AUTO_UPDATE_ENABLED_DEFAULT;
  1298                             }
  1299 
  1300                             this.RaisePropertyChangedEvent(nameof(this.IsAutoUpdateEnabled));
  1301                         }
  1302 
  1303                         // Attempt to get IsCrashReportVisible
  1304                         isPropertySet = false;
  1305                         try
  1306                         {
  1307                             keyValue = pEpKey.GetValue(PEPSettings.REG_NAME_IS_CRASH_REPORT_VISIBLE, PEPSettings.IS_CRASH_REPORT_VISIBLE_DEFAULT).ToString();
  1308                             isSuccessful = bool.TryParse(keyValue, out parsedBoolValue);
  1309 
  1310                             if (isSuccessful)
  1311                             {
  1312                                 this._IsCrashReportVisible = parsedBoolValue;
  1313                                 isPropertySet = true;
  1314                             }
  1315                         }
  1316                         catch
  1317                         {
  1318                             Log.Warning("LoadFromRegistry: Unable to read IsCrashReportVisible");
  1319                         }
  1320                         finally
  1321                         {
  1322                             if (isPropertySet == false)
  1323                             {
  1324                                 this._IsCrashReportVisible = PEPSettings.IS_CRASH_REPORT_VISIBLE_DEFAULT;
  1325                             }
  1326 
  1327                             this.RaisePropertyChangedEvent(nameof(this.IsCrashReportVisible));
  1328                         }
  1329 
  1330                         // Attempt to get IsDeveloperModeEnabled
  1331                         isPropertySet = false;
  1332                         try
  1333                         {
  1334                             keyValue = pEpKey.GetValue(PEPSettings.REG_NAME_IS_DEVELOPER_MODE_ENABLED, PEPSettings.IS_DEVELOPER_MODE_ENABLED_DEFAULT).ToString();
  1335                             isSuccessful = bool.TryParse(keyValue, out parsedBoolValue);
  1336 
  1337                             if (isSuccessful)
  1338                             {
  1339                                 this._IsDeveloperModeEnabled = parsedBoolValue;
  1340                                 isPropertySet = true;
  1341                             }
  1342                         }
  1343                         catch
  1344                         {
  1345                             Log.Warning("LoadFromRegistry: Unable to read IsDeveloperModeEnabled");
  1346                         }
  1347                         finally
  1348                         {
  1349                             if (isPropertySet == false)
  1350                             {
  1351                                 this._IsDeveloperModeEnabled = PEPSettings.IS_DEVELOPER_MODE_ENABLED_DEFAULT;
  1352                             }
  1353 
  1354                             this.RaisePropertyChangedEvent(nameof(this.IsDeveloperModeEnabled));
  1355                         }
  1356 
  1357                         // Attempt to get IsDisableProtectionForContactsEnabled
  1358                         isPropertySet = false;
  1359                         try
  1360                         {
  1361                             keyValue = pEpKey.GetValue(PEPSettings.REG_NAME_IS_DISABLE_PROTECTION_FOR_CONTACTS_ENABLED, PEPSettings.IS_DISABLE_PROTECTION_FOR_CONTACTS_ENABLED_DEFAULT).ToString();
  1362                             isSuccessful = bool.TryParse(keyValue, out parsedBoolValue);
  1363 
  1364                             if (isSuccessful)
  1365                             {
  1366                                 this._IsDisableProtectionForContactsEnabled = parsedBoolValue;
  1367                                 isPropertySet = true;
  1368                             }
  1369                         }
  1370                         catch
  1371                         {
  1372                             Log.Warning("LoadFromRegistry: Unable to read IsDisableProtectionForContactsEnabled");
  1373                         }
  1374                         finally
  1375                         {
  1376                             if (isPropertySet == false)
  1377                             {
  1378                                 this._IsDisableProtectionForContactsEnabled = PEPSettings.IS_DISABLE_PROTECTION_FOR_CONTACTS_ENABLED_DEFAULT;
  1379                             }
  1380 
  1381                             this.RaisePropertyChangedEvent(nameof(this.IsDisableProtectionForContactsEnabled));
  1382                         }
  1383 
  1384                         // Attempt to get IsEncryptAllAccountsEnabled value
  1385                         isPropertySet = false;
  1386                         try
  1387                         {
  1388                             keyValue = pEpKey.GetValue(PEPSettings.REG_NAME_IS_ENCRYPT_ALL_ACCOUNTS_ENABLED, PEPSettings.IS_ENCRYPT_ALL_ACCOUNTS_ENABLED_DEFAULT).ToString();
  1389                             isSuccessful = bool.TryParse(keyValue, out parsedBoolValue);
  1390 
  1391                             if (isSuccessful)
  1392                             {
  1393                                 this._IsEncryptAllAccountsEnabled = parsedBoolValue;
  1394                                 isPropertySet = true;
  1395                             }
  1396                         }
  1397                         catch
  1398                         {
  1399                             Log.Warning("LoadFromRegistry: Unable to read IsEncryptAllAccountsEnabled");
  1400                         }
  1401                         finally
  1402                         {
  1403                             if (isPropertySet == false)
  1404                             {
  1405                                 this._IsEncryptAllAccountsEnabled = PEPSettings.IS_ENCRYPT_ALL_ACCOUNTS_ENABLED_DEFAULT;
  1406                             }
  1407 
  1408                             this.RaisePropertyChangedEvent(nameof(this.IsEncryptAllAccountsEnabled));
  1409                         }
  1410 
  1411                         // Attempt to get IsInboxCleaningEnabled value
  1412                         isPropertySet = false;
  1413                         try
  1414                         {
  1415                             keyValue = pEpKey.GetValue(PEPSettings.REG_NAME_IS_INBOX_CLEANING_ENABLED, PEPSettings.IS_INBOX_CLEANING_ENABLED_DEFAULT).ToString();
  1416                             isSuccessful = bool.TryParse(keyValue, out parsedBoolValue);
  1417 
  1418                             if (isSuccessful)
  1419                             {
  1420                                 this._IsInboxCleaningEnabled = parsedBoolValue;
  1421                                 isPropertySet = true;
  1422                             }
  1423                         }
  1424                         catch
  1425                         {
  1426                             Log.Warning("LoadFromRegistry: Unable to read IsInboxCleaningEnabled");
  1427                         }
  1428                         finally
  1429                         {
  1430                             if (isPropertySet == false)
  1431                             {
  1432                                 this._IsInboxCleaningEnabled = PEPSettings.IS_INBOX_CLEANING_ENABLED_DEFAULT;
  1433                             }
  1434 
  1435                             this.RaisePropertyChangedEvent(nameof(this.IsInboxCleaningEnabled));
  1436                         }
  1437 
  1438                         // Attempt to get IsFirstStartupComplete value
  1439                         isPropertySet = false;
  1440                         try
  1441                         {
  1442                             keyValue = pEpKey.GetValue(PEPSettings.REG_NAME_IS_FIRST_STARTUP_COMPLETE, false).ToString();
  1443                             isSuccessful = bool.TryParse(keyValue, out parsedBoolValue);
  1444 
  1445                             if (isSuccessful)
  1446                             {
  1447                                 this._IsFirstStartupComplete = parsedBoolValue;
  1448                                 isPropertySet = true;
  1449                             }
  1450                         }
  1451                         catch
  1452                         {
  1453                             Log.Warning("LoadFromRegistry: Unable to read IsFirstStartupComplete");
  1454                         }
  1455                         finally
  1456                         {
  1457                             if (isPropertySet == false)
  1458                             {
  1459                                 this._IsFirstStartupComplete = false;
  1460                             }
  1461 
  1462                             this.RaisePropertyChangedEvent(nameof(this.IsFirstStartupComplete));
  1463                         }
  1464 
  1465                         // Attempt to get IsKeyServerUsed value
  1466                         isPropertySet = false;
  1467                         try
  1468                         {
  1469                             keyValue = pEpKey.GetValue(PEPSettings.REG_NAME_IS_KEY_SERVER_USED, PEPSettings.IS_KEY_SERVER_USED_DEFAULT).ToString();
  1470                             isSuccessful = bool.TryParse(keyValue, out parsedBoolValue);
  1471 
  1472                             if (isSuccessful)
  1473                             {
  1474                                 this._IsKeyServerUsed = parsedBoolValue;
  1475                                 isPropertySet = true;
  1476                             }
  1477                         }
  1478                         catch
  1479                         {
  1480                             Log.Warning("LoadFromRegistry: Unable to read IsKeyServerUsed");
  1481                         }
  1482                         finally
  1483                         {
  1484                             if (isPropertySet == false)
  1485                             {
  1486                                 this._IsKeyServerUsed = PEPSettings.IS_KEY_SERVER_USED_DEFAULT;
  1487                             }
  1488 
  1489                             this.RaisePropertyChangedEvent(nameof(this.IsKeyServerUsed));
  1490                         }
  1491 
  1492                         // Attempt to get IsNeverUnsecureOptionVisible value
  1493                         isPropertySet = false;
  1494                         try
  1495                         {
  1496                             keyValue = pEpKey.GetValue(PEPSettings.REG_NAME_IS_NEVER_UNSECURE_OPTION_VISIBLE, PEPSettings.IS_NEVER_UNSECURE_OPTION_VISIBLE_DEFAULT).ToString();
  1497                             isSuccessful = bool.TryParse(keyValue, out parsedBoolValue);
  1498 
  1499                             if (isSuccessful)
  1500                             {
  1501                                 this._IsNeverUnsecureOptionVisible = parsedBoolValue;
  1502                                 isPropertySet = true;
  1503                             }
  1504                         }
  1505                         catch
  1506                         {
  1507                             Log.Warning("LoadFromRegistry: Unable to read IsNeverUnsecureOptionVisible");
  1508                         }
  1509                         finally
  1510                         {
  1511                             if (isPropertySet == false)
  1512                             {
  1513                                 this._IsNeverUnsecureOptionVisible = PEPSettings.IS_NEVER_UNSECURE_OPTION_VISIBLE_DEFAULT;
  1514                             }
  1515 
  1516                             this.RaisePropertyChangedEvent(nameof(this.IsNeverUnsecureOptionVisible));
  1517                         }
  1518 
  1519                         // Attempt to get IsPassiveModeEnabled value
  1520                         isPropertySet = false;
  1521                         try
  1522                         {
  1523                             keyValue = pEpKey.GetValue(PEPSettings.REG_NAME_IS_PASSIVE_MODE_ENABLED, PEPSettings.IS_PASSIVE_MODE_ENABLED_DEFAULT).ToString();
  1524                             isSuccessful = bool.TryParse(keyValue, out parsedBoolValue);
  1525 
  1526                             if (isSuccessful)
  1527                             {
  1528                                 this._IsPassiveModeEnabled = parsedBoolValue;
  1529                                 isPropertySet = true;
  1530                             }
  1531                         }
  1532                         catch
  1533                         {
  1534                             Log.Warning("LoadFromRegistry: Unable to read IsPassiveModeEnabled");
  1535                         }
  1536                         finally
  1537                         {
  1538                             if (isPropertySet == false)
  1539                             {
  1540                                 this._IsPassiveModeEnabled = PEPSettings.IS_PASSIVE_MODE_ENABLED_DEFAULT;
  1541                             }
  1542 
  1543                             this.RaisePropertyChangedEvent(nameof(this.IsPassiveModeEnabled));
  1544                         }
  1545 
  1546                         // Attempt to get IsPEPFolderVisible value
  1547                         isPropertySet = false;
  1548                         try
  1549                         {
  1550                             keyValue = pEpKey.GetValue(PEPSettings.REG_NAME_IS_PEP_FOLDER_VISIBLE, PEPSettings.IS_PEP_FOLDER_VISIBLE_DEFAULT).ToString();
  1551                             isSuccessful = bool.TryParse(keyValue, out parsedBoolValue);
  1552 
  1553                             if (isSuccessful)
  1554                             {
  1555                                 this._IsPEPFolderVisible = parsedBoolValue;
  1556                                 isPropertySet = true;
  1557                             }
  1558                         }
  1559                         catch
  1560                         {
  1561                             Log.Warning("LoadFromRegistry: Unable to read IsPEPFolderVisible");
  1562                         }
  1563                         finally
  1564                         {
  1565                             if (isPropertySet == false)
  1566                             {
  1567                                 this._IsPEPFolderVisible = PEPSettings.IS_PEP_FOLDER_VISIBLE_DEFAULT;
  1568                             }
  1569 
  1570                             this.RaisePropertyChangedEvent(nameof(this.IsPEPFolderVisible));
  1571                         }
  1572 
  1573                         // Attempt to get IsReaderSplashEnabled value
  1574                         isPropertySet = false;
  1575                         try
  1576                         {
  1577                             keyValue = pEpKey.GetValue(PEPSettings.REG_NAME_IS_READER_SPLASH_ENABLED, PEPSettings.IS_READER_SPLASH_ENABLED_DEFAULT).ToString();
  1578                             isSuccessful = bool.TryParse(keyValue, out parsedBoolValue);
  1579 
  1580                             if (isSuccessful)
  1581                             {
  1582                                 this._IsReaderSplashEnabled = parsedBoolValue;
  1583                                 isPropertySet = true;
  1584                             }
  1585                         }
  1586                         catch
  1587                         {
  1588                             Log.Warning("LoadFromRegistry: Unable to read IsReaderSplashEnabled");
  1589                         }
  1590                         finally
  1591                         {
  1592                             if (isPropertySet == false)
  1593                             {
  1594                                 this._IsReaderSplashEnabled = PEPSettings.IS_READER_SPLASH_ENABLED_DEFAULT;
  1595                             }
  1596 
  1597                             this.RaisePropertyChangedEvent(nameof(this.IsReaderSplashEnabled));
  1598                         }
  1599 
  1600                         // Attempt to get IsSecurityLossWarningEnabled value
  1601                         isPropertySet = false;
  1602                         try
  1603                         {
  1604                             keyValue = pEpKey.GetValue(PEPSettings.REG_NAME_IS_SECURITY_LOSS_WARNING_ENABLED, PEPSettings.IS_SECURITY_LOSS_WARNING_ENABLED_DEFAULT).ToString();
  1605                             isSuccessful = bool.TryParse(keyValue, out parsedBoolValue);
  1606 
  1607                             if (isSuccessful)
  1608                             {
  1609                                 this._IsSecurityLossWarningEnabled = parsedBoolValue;
  1610                                 isPropertySet = true;
  1611                             }
  1612                         }
  1613                         catch
  1614                         {
  1615                             Log.Warning("LoadFromRegistry: Unable to read IsSecurityLossWarningEnabled");
  1616                         }
  1617                         finally
  1618                         {
  1619                             if (isPropertySet == false)
  1620                             {
  1621                                 this._IsSecurityLossWarningEnabled = PEPSettings.IS_SECURITY_LOSS_WARNING_ENABLED_DEFAULT;
  1622                             }
  1623 
  1624                             this.RaisePropertyChangedEvent(nameof(this.IsSecurityLossWarningEnabled));
  1625                         }
  1626 
  1627                         // Attempt to get IsSensitiveDataLoggingEnabled value
  1628                         isPropertySet = false;
  1629                         try
  1630                         {
  1631                             keyValue = pEpKey.GetValue(PEPSettings.REG_NAME_IS_SENSITIVE_DATA_LOGGING_ENABLED, PEPSettings.IS_SENSITIVE_DATA_LOGGING_ENABLED_DEFAULT).ToString();
  1632                             isSuccessful = bool.TryParse(keyValue, out parsedBoolValue);
  1633 
  1634                             if (isSuccessful)
  1635                             {
  1636                                 this._IsSensitiveDataLoggingEnabled = parsedBoolValue;
  1637                                 isPropertySet = true;
  1638                             }
  1639                         }
  1640                         catch
  1641                         {
  1642                             Log.Warning("LoadFromRegistry: Unable to read IsSensitiveDataLoggingEnabled");
  1643                         }
  1644                         finally
  1645                         {
  1646                             if (isPropertySet == false)
  1647                             {
  1648                                 this._IsSensitiveDataLoggingEnabled = PEPSettings.IS_SENSITIVE_DATA_LOGGING_ENABLED_DEFAULT;
  1649                             }
  1650 
  1651                             this.RaisePropertyChangedEvent(nameof(this.IsSensitiveDataLoggingEnabled));
  1652                         }
  1653 
  1654                         // Attempt to get IsSyncEnabledForAllAccounts value
  1655                         isPropertySet = false;
  1656                         try
  1657                         {
  1658                             keyValue = pEpKey.GetValue(PEPSettings.REG_NAME_IS_SYNC_ENABLED_FOR_ALL_ACCOUNTS, PEPSettings.IS_SYNC_ENABLED_FOR_ALL_ACCOUNTS_DEFAULT).ToString();
  1659                             isSuccessful = bool.TryParse(keyValue, out parsedBoolValue);
  1660 
  1661                             if (isSuccessful)
  1662                             {
  1663                                 this._IsSyncEnabledForAllAccounts = parsedBoolValue;
  1664                                 isPropertySet = true;
  1665                             }
  1666                         }
  1667                         catch
  1668                         {
  1669                             Log.Warning("LoadFromRegistry: Unable to read IsSyncEnabledForAllAccounts");
  1670                         }
  1671                         finally
  1672                         {
  1673                             if (isPropertySet == false)
  1674                             {
  1675                                 this._IsSyncEnabledForAllAccounts = PEPSettings.IS_SYNC_ENABLED_FOR_ALL_ACCOUNTS_DEFAULT;
  1676                             }
  1677 
  1678                             this.RaisePropertyChangedEvent(nameof(this.IsSyncEnabledForAllAccounts));
  1679                         }
  1680 
  1681                         // Attempt to get IsUnencryptedSubjectEnabled value
  1682                         isPropertySet = false;
  1683                         try
  1684                         {
  1685                             keyValue = pEpKey.GetValue(PEPSettings.REG_NAME_IS_UNENCRYPTED_SUBJECT_ENABLED, PEPSettings.IS_UNENCRYPTED_SUBJECT_ENABLED_DEFAULT).ToString();
  1686                             isSuccessful = bool.TryParse(keyValue, out parsedBoolValue);
  1687 
  1688                             if (isSuccessful)
  1689                             {
  1690                                 this._IsUnencryptedSubjectEnabled = parsedBoolValue;
  1691                                 isPropertySet = true;
  1692                             }
  1693                         }
  1694                         catch
  1695                         {
  1696                             Log.Warning("LoadFromRegistry: Unable to read IsUnencryptedSubjectEnabled");
  1697                         }
  1698                         finally
  1699                         {
  1700                             if (isPropertySet == false)
  1701                             {
  1702                                 this._IsUnencryptedSubjectEnabled = PEPSettings.IS_UNENCRYPTED_SUBJECT_ENABLED_DEFAULT;
  1703                             }
  1704 
  1705                             this.RaisePropertyChangedEvent(nameof(this.IsUnencryptedSubjectEnabled));
  1706                         }
  1707 
  1708                         // Attempt to get IsVerboseLoggingEnabled value
  1709                         isPropertySet = false;
  1710                         try
  1711                         {
  1712                             keyValue = pEpKey.GetValue(PEPSettings.REG_NAME_IS_VERBOSE_LOGGING_ENABLED, PEPSettings.IS_VERBOSE_LOGGING_ENABLED_DEFAULT).ToString();
  1713                             isSuccessful = bool.TryParse(keyValue, out parsedBoolValue);
  1714 
  1715                             if (isSuccessful)
  1716                             {
  1717                                 this._IsVerboseLoggingEnabled = parsedBoolValue;
  1718                                 isPropertySet = true;
  1719                             }
  1720                         }
  1721                         catch
  1722                         {
  1723                             Log.Warning("LoadFromRegistry: Unable to read IsVerboseLoggingEnabled");
  1724                         }
  1725                         finally
  1726                         {
  1727                             if (isPropertySet == false)
  1728                             {
  1729                                 this._IsVerboseLoggingEnabled = PEPSettings.IS_VERBOSE_LOGGING_ENABLED_DEFAULT;
  1730                             }
  1731 
  1732                             this.RaisePropertyChangedEvent(nameof(this.IsVerboseLoggingEnabled));
  1733                         }
  1734 
  1735                         // Attempt to get TrustwordsCulture value
  1736                         isPropertySet = false;
  1737                         try
  1738                         {
  1739                             keyValue = pEpKey.GetValue(PEPSettings.REG_NAME_TRUSTWORDS_CULTURE, string.Empty).ToString();
  1740 
  1741                             if (string.IsNullOrEmpty(keyValue) == false)
  1742                             {
  1743                                 this._TrustwordsCulture = new CultureInfo(keyValue);
  1744                                 isPropertySet = true;
  1745                             }
  1746                         }
  1747                         catch
  1748                         {
  1749                             Log.Warning("LoadFromRegistry: Unable to read TrustwordsCulture");
  1750                         }
  1751                         finally
  1752                         {
  1753                             if (isPropertySet == false)
  1754                             {
  1755                                 this._TrustwordsCulture = null;
  1756                             }
  1757 
  1758                             this.RaisePropertyChangedEvent(nameof(this.TrustwordsCulture));
  1759                         }
  1760                     }
  1761                 }
  1762             }
  1763             catch (Exception ex)
  1764             {
  1765                 Log.Error("LoadFromRegistry: Failure occured, " + ex.ToString());
  1766             }
  1767 
  1768             return;
  1769         }
  1770 
  1771         /**************************************************************
  1772          * 
  1773          * Event Handling
  1774          * 
  1775          *************************************************************/
  1776 
  1777         /// <summary>
  1778         /// Event handler for when a collection changed event occurs within the account settings collection.
  1779         /// </summary>
  1780         private void AccountSettingsList_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
  1781         {
  1782             // Remove events
  1783             if (e.OldItems != null)
  1784             {
  1785                 foreach (PEPAccountSettings acctSettings in e.OldItems)
  1786                 {
  1787                     acctSettings.PropertyChanged -= PEPAccountSettings_PropertyChanged;
  1788                 }
  1789             }
  1790 
  1791             // Connect events
  1792             if (e.NewItems != null)
  1793             {
  1794                 foreach (PEPAccountSettings acctSettings in e.NewItems)
  1795                 {
  1796                     acctSettings.PropertyChanged += PEPAccountSettings_PropertyChanged;
  1797                 }
  1798             }
  1799 
  1800             this.RaisePropertyChangedEvent(nameof(this.AccountSettingsList));
  1801 
  1802             return;
  1803         }
  1804 
  1805         /// <summary>
  1806         /// Event handler for when a property of an item in the account settings collection changes.
  1807         /// </summary>
  1808         private void PEPAccountSettings_PropertyChanged(object sender, PropertyChangedEventArgs e)
  1809         {
  1810             int index = -1;
  1811 
  1812             try
  1813             {
  1814                 index = this.AccountSettingsList.IndexOf(sender as PEPAccountSettings);
  1815             }
  1816             catch { }
  1817 
  1818             this.RaisePropertyChangedEvent(nameof(this.AccountSettingsList) + "[" + index + "]." + e.PropertyName);
  1819 
  1820             return;
  1821         }
  1822 
  1823         /**************************************************************
  1824          * 
  1825          * Sub-classes
  1826          * 
  1827          *************************************************************/
  1828 
  1829         /// <summary>
  1830         /// Class to store and maintain all configurations/settings for an account managed by pEp.
  1831         /// </summary>
  1832         internal class PEPAccountSettings : INotifyPropertyChanged,
  1833                                             Interfaces.ICopy<PEPAccountSettings>,
  1834                                             Interfaces.IReset
  1835         {
  1836             /// <summary>
  1837             /// Event raised when a property is changed on a component.
  1838             /// </summary>
  1839             public event PropertyChangedEventHandler PropertyChanged;
  1840 
  1841             protected Disclaimer    _AddDisclaimer;
  1842             protected string        _DisclaimerText;
  1843             protected bool          _IsDecryptAlwaysEnabled;
  1844             protected bool          _IsPEPEnabled;
  1845             protected bool          _IsSecureStorageEnabled;
  1846             protected bool          _IsSyncEnabled;
  1847             protected string        _SentFolderEntryId;
  1848             protected string        _SmtpAddress;
  1849             protected string        _Type;
  1850             protected string        _UserName;
  1851 
  1852             /**************************************************************
  1853              * 
  1854              * Constructors
  1855              * 
  1856              *************************************************************/
  1857 
  1858             /// <summary>
  1859             /// Default constructor.
  1860             /// </summary>
  1861             public PEPAccountSettings()
  1862             {
  1863                 this.Reset();
  1864             }
  1865 
  1866             /// <summary>
  1867             /// Default constructor.
  1868             /// </summary>
  1869             /// <param name="smtpAddress">The SMTP address of the account.</param>
  1870             public PEPAccountSettings(string smtpAddress)
  1871             {
  1872                 this.Reset();
  1873 
  1874                 if (object.Equals(this._SmtpAddress, smtpAddress) == false)
  1875                 {
  1876                     this._SmtpAddress = smtpAddress;
  1877                     this.RaisePropertyChangedEvent(nameof(this.SmtpAddress));
  1878                 }
  1879             }
  1880 
  1881             /**************************************************************
  1882              * 
  1883              * Property Accessors
  1884              * 
  1885              *************************************************************/
  1886 
  1887             /// <summary>
  1888             /// Gets whether to add a disclaimer to messages of this account.
  1889             /// This can only be set from the Registry.
  1890             /// </summary>
  1891             public Disclaimer AddDisclaimer
  1892             {
  1893                 get { return this._AddDisclaimer; }
  1894                 set
  1895                 {
  1896                     if (object.Equals(this._AddDisclaimer, value) == false)
  1897                     {
  1898                         this._AddDisclaimer = value;
  1899                         this.RaisePropertyChangedEvent(nameof(this.AddDisclaimer));
  1900                     }
  1901                 }
  1902             }
  1903 
  1904             /// <summary>
  1905             /// Gets the text of the disclaimer if activated.
  1906             /// This can only be set from the Registry.
  1907             /// </summary>
  1908             public string DisclaimerText
  1909             {
  1910                 get { return this._DisclaimerText; }
  1911                 set
  1912                 {
  1913                     if (object.Equals(this._DisclaimerText, value) == false)
  1914                     {
  1915                         this._DisclaimerText = value;
  1916                         this.RaisePropertyChangedEvent(nameof(this.DisclaimerText));
  1917                     }
  1918                 }
  1919             }
  1920 
  1921             /// <summary>
  1922             /// Gets or sets whether decryption is enabled for this account
  1923             /// even if pEp is disabled.
  1924             /// </summary>
  1925             public bool IsDecryptAlwaysEnabled
  1926             {
  1927                 get { return (this._IsDecryptAlwaysEnabled); }
  1928                 set
  1929                 {
  1930                     if (object.Equals(this._IsDecryptAlwaysEnabled, value) == false)
  1931                     {
  1932                         this._IsDecryptAlwaysEnabled = value;
  1933                         this.RaisePropertyChangedEvent(nameof(this.IsDecryptAlwaysEnabled));
  1934                     }
  1935                 }
  1936             }
  1937 
  1938             /// <summary>
  1939             /// Gets or sets whether pEp is enabled for the account.
  1940             /// </summary>
  1941             public bool IsPEPEnabled
  1942             {
  1943                 get { return (this._IsPEPEnabled); }
  1944                 set
  1945                 {
  1946                     if (object.Equals(this._IsPEPEnabled, value) == false)
  1947                     {
  1948                         this._IsPEPEnabled = value;
  1949                         this.RaisePropertyChangedEvent(nameof(this.IsPEPEnabled));
  1950                     }
  1951                 }
  1952             }
  1953 
  1954             /// <summary>
  1955             /// Gets or sets whether data for the account should be stored securely.
  1956             /// Secure/Encrypted accounts are on untrusted servers.
  1957             /// </summary>
  1958             public bool IsSecureStorageEnabled
  1959             {
  1960                 get { return (this._IsSecureStorageEnabled); }
  1961                 set
  1962                 {
  1963                     if (object.Equals(this._IsSecureStorageEnabled, value) == false)
  1964                     {
  1965                         this._IsSecureStorageEnabled = value;
  1966                         this.RaisePropertyChangedEvent(nameof(this.IsSecureStorageEnabled));
  1967                     }
  1968                 }
  1969             }
  1970 
  1971             /// <summary>
  1972             /// Gets or sets whether synchronization between devices is enabled for the account.
  1973             /// </summary>
  1974             public bool IsSyncEnabled
  1975             {
  1976                 get { return (this._IsSyncEnabled); }
  1977                 set
  1978                 {
  1979                     if (object.Equals(this._IsSyncEnabled, value) == false)
  1980                     {
  1981                         this._IsSyncEnabled = value;
  1982                         this.RaisePropertyChangedEvent(nameof(this.IsSyncEnabled));
  1983                     }
  1984                 }
  1985             }
  1986 
  1987             /// <summary>
  1988             /// Gets or sets the EntryID (if defined) for the Sent folder of the account.
  1989             /// This is only used as an override if the default sent folder does not exist.
  1990             /// </summary>
  1991             public string SentFolderEntryId
  1992             {
  1993                 get { return (this._SentFolderEntryId); }
  1994                 set
  1995                 {
  1996                     if (object.Equals(this._SentFolderEntryId, value) == false)
  1997                     {
  1998                         this._SentFolderEntryId = value;
  1999                         this.RaisePropertyChangedEvent(nameof(this.SentFolderEntryId));
  2000                     }
  2001                 }
  2002             }
  2003 
  2004             /// <summary>
  2005             /// Gets or sets the SMTP address of the account.
  2006             /// This is used to associate settings with an Outlook account.
  2007             /// </summary>
  2008             public string SmtpAddress
  2009             {
  2010                 get { return (this._SmtpAddress); }
  2011                 set
  2012                 {
  2013                     if (object.Equals(this._SmtpAddress, value) == false)
  2014                     {
  2015                         this._SmtpAddress = value;
  2016                         this.RaisePropertyChangedEvent(nameof(this.SmtpAddress));
  2017                     }
  2018                 }
  2019             }
  2020 
  2021             /// <summary>
  2022             /// Gets or sets the Type of the account.
  2023             /// This MUST match 1-to-1 with the Outlook.OlAccountType enumeration converted to a string.
  2024             /// </summary>
  2025             public string Type
  2026             {
  2027                 get { return (this._Type); }
  2028                 set
  2029                 {
  2030                     if (object.Equals(this._Type, value) == false)
  2031                     {
  2032                         this._Type = value;
  2033                         this.RaisePropertyChangedEvent(nameof(this.Type));
  2034                     }
  2035                 }
  2036             }
  2037 
  2038             /// <summary>
  2039             /// Gets or sets the UserName of the account.
  2040             /// </summary>
  2041             public string UserName
  2042             {
  2043                 get { return (this._UserName); }
  2044                 set
  2045                 {
  2046                     if (object.Equals(this._UserName, value) == false)
  2047                     {
  2048                         this._UserName = value;
  2049                         this.RaisePropertyChangedEvent(nameof(this.UserName));
  2050                     }
  2051                 }
  2052             }
  2053 
  2054             /**************************************************************
  2055              * 
  2056              * Methods
  2057              * 
  2058              *************************************************************/
  2059 
  2060             /// <summary>
  2061             /// Raises the property changed event, if possible, with the given arguments.
  2062             /// </summary>
  2063             /// <param name="propertyName">The name of the property that changed.</param>
  2064             protected void RaisePropertyChangedEvent(string propertyName)
  2065             {
  2066                 this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  2067                 return;
  2068             }
  2069 
  2070             /// <summary>
  2071             /// Resets the object to its default state/values.
  2072             /// </summary>
  2073             public void Reset()
  2074             {
  2075                 this._AddDisclaimer = PEPSettings.ADD_DISCLAIMER_DEFAULT;
  2076                 this._DisclaimerText = PEPSettings.DISCLAIMER_TEXT_DEFAULT;
  2077                 this._IsDecryptAlwaysEnabled = PEPSettings.ACCOUNT_SETTING_IS_DECRYPT_ALWAYS_ENABLED_DEFAULT;
  2078                 this._IsPEPEnabled = PEPSettings.ACCOUNT_SETTING_IS_PEP_ENABLED_DEFAULT;
  2079                 this._IsSecureStorageEnabled = PEPSettings.ACCOUNT_SETTING_IS_SECURE_STORAGE_ENABLED_DEFAULT;
  2080                 this._IsSyncEnabled = PEPSettings.ACCOUNT_SETTING_IS_SYNC_ENABLED_DEFAULT;
  2081                 this._SentFolderEntryId = PEPSettings.ACCOUNT_SETTING_SENT_FOLDER_ENTRYID_DEFAULT;
  2082                 this._SmtpAddress = PEPSettings.ACCOUNT_SETTING_SMTP_ADDRESS_DEFAULT;
  2083                 this._Type = PEPSettings.ACCOUNT_SETTING_TYPE_DEFAULT;
  2084                 this._UserName = PEPSettings.ACCOUNT_SETTING_USER_NAME_DEFAULT;
  2085 
  2086                 this.RaisePropertyChangedEvent(nameof(this.AddDisclaimer));
  2087                 this.RaisePropertyChangedEvent(nameof(this.DisclaimerText));
  2088                 this.RaisePropertyChangedEvent(nameof(this.IsDecryptAlwaysEnabled));
  2089                 this.RaisePropertyChangedEvent(nameof(this.IsPEPEnabled));
  2090                 this.RaisePropertyChangedEvent(nameof(this.IsSecureStorageEnabled));
  2091                 this.RaisePropertyChangedEvent(nameof(this.IsSyncEnabled));
  2092                 this.RaisePropertyChangedEvent(nameof(this.SentFolderEntryId));
  2093                 this.RaisePropertyChangedEvent(nameof(this.SmtpAddress));
  2094                 this.RaisePropertyChangedEvent(nameof(this.Type));
  2095                 this.RaisePropertyChangedEvent(nameof(this.UserName));
  2096             }
  2097 
  2098             /// <summary>
  2099             /// Gets a deep copy of the object and all its data.
  2100             /// </summary>
  2101             /// <returns>The deep copy of the object.</returns>
  2102             public PEPAccountSettings Copy()
  2103             {
  2104                 PEPAccountSettings copy = new PEPAccountSettings();
  2105 
  2106                 copy.AddDisclaimer = this._AddDisclaimer;
  2107                 copy.DisclaimerText = this._DisclaimerText;
  2108                 copy.IsDecryptAlwaysEnabled = this._IsDecryptAlwaysEnabled;
  2109                 copy.IsPEPEnabled = this._IsPEPEnabled;
  2110                 copy.IsSecureStorageEnabled = this._IsSecureStorageEnabled;
  2111                 copy.IsSyncEnabled = this._IsSyncEnabled;
  2112                 copy.SentFolderEntryId = this._SentFolderEntryId;
  2113                 copy.SmtpAddress = this._SmtpAddress;
  2114                 copy.Type = this._Type;
  2115                 copy.UserName = this._UserName;
  2116 
  2117                 return (copy);
  2118             }
  2119 
  2120             /// <summary>
  2121             /// Indicates whether the current PEPAccountSettings is equal to another PEPAccountSettings by address only (case insensitive).
  2122             /// Note: If either (or both) address is null or empty, they are considered NOT equal.
  2123             /// </summary>
  2124             /// <param name="obj">The PEPAccountSettings to compare against.</param>
  2125             /// <returns>True if the given address and this object's address are neither null nor empty and considered equal, otherwise false.</returns>
  2126             public bool EqualsByAddress(PEPAccountSettings obj)
  2127             {
  2128                 bool areEqual = false;
  2129 
  2130                 if ((obj != null) &&
  2131                     (string.IsNullOrEmpty(obj.SmtpAddress) == false) &&
  2132                     (string.IsNullOrEmpty(this._SmtpAddress) == false))
  2133                 {
  2134                     areEqual = string.Equals(this._SmtpAddress.Trim(), obj.SmtpAddress.Trim(), StringComparison.OrdinalIgnoreCase);
  2135                 }
  2136 
  2137                 return (areEqual);
  2138             }
  2139 
  2140             /// <summary>
  2141             /// Indicates whether the current PEPAccountSettings is equal to an address only (case insensitive).
  2142             /// Note: If either (or both) address is null or empty, they are considered NOT equal.
  2143             /// </summary>
  2144             /// <param name="address">The address to compare against.</param>
  2145             /// <returns>True if the given address and this object's address are neither null nor empty and considered equal, otherwise false.</returns>
  2146             public bool EqualsByAddress(string address)
  2147             {
  2148                 bool areEqual = false;
  2149 
  2150                 if ((string.IsNullOrEmpty(address) == false) &&
  2151                     (string.IsNullOrEmpty(this._SmtpAddress) == false))
  2152                 {
  2153                     areEqual = string.Equals(this._SmtpAddress.Trim(), address.Trim(), StringComparison.OrdinalIgnoreCase);
  2154                 }
  2155 
  2156                 return (areEqual);
  2157             }
  2158         }
  2159     }
  2160 }