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