ThisAddIn.cs
author Thomas
Mon, 25 Mar 2019 13:27:16 +0100
branchsync
changeset 2610 09fde2338362
parent 2594 b4351ec5c330
parent 2607 8a9eddf5347a
child 2627 47eb50143f2a
permissions -rw-r--r--
Merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2551
577313f9e962 OUT-507: Improve setting of 'pEp Processing' category
Thomas
parents: 2541
diff changeset
     1
using pEp.Extensions;
577313f9e962 OUT-507: Improve setting of 'pEp Processing' category
Thomas
parents: 2541
diff changeset
     2
using pEp.UI;
155
cda43d18bcd3 Add state to handshake form and decouple it from the encryption status panel
Dean Looyengoed
parents: 144
diff changeset
     3
using pEpCOMServerAdapterLib;
cda43d18bcd3 Add state to handshake form and decouple it from the encryption status panel
Dean Looyengoed
parents: 144
diff changeset
     4
using System;
0
6dfec3b090d6 initial commit
vb
parents:
diff changeset
     5
using System.Collections.Generic;
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
     6
using System.ComponentModel;
155
cda43d18bcd3 Add state to handshake form and decouple it from the encryption status panel
Dean Looyengoed
parents: 144
diff changeset
     7
using System.Globalization;
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
     8
using System.IO;
0
6dfec3b090d6 initial commit
vb
parents:
diff changeset
     9
using System.Runtime.InteropServices;
2328
db219aed7eaa Reorder setting rules and view folders. Remove some superfluous return statements.
Thomas
parents: 2293
diff changeset
    10
using System.Threading.Tasks;
47
d3b5164cc922 read in extra keys
Volker Birk <vb@pep-project.org>
parents: 46
diff changeset
    11
using System.Windows.Forms;
714
761f853c4c0f For all Myself identities, calculate user ID using a hash of the windows Environment.UserName;
Dean Looyengoed
parents: 686
diff changeset
    12
using Office = Microsoft.Office.Core;
0
6dfec3b090d6 initial commit
vb
parents:
diff changeset
    13
using Outlook = Microsoft.Office.Interop.Outlook;
6dfec3b090d6 initial commit
vb
parents:
diff changeset
    14
6dfec3b090d6 initial commit
vb
parents:
diff changeset
    15
namespace pEp
6dfec3b090d6 initial commit
vb
parents:
diff changeset
    16
{
6dfec3b090d6 initial commit
vb
parents:
diff changeset
    17
    public partial class ThisAddIn
6dfec3b090d6 initial commit
vb
parents:
diff changeset
    18
    {
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    19
        #region VSTO generated code
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    20
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    21
        /// <summary>
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    22
        /// Required method for Designer support - do not modify
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    23
        /// the contents of this method with the code editor.
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    24
        /// </summary>
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    25
        private void InternalStartup()
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    26
        {
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    27
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    28
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    29
        }
201
9e0548fa3942 Code reformatting.
Markus Schaber <markus@pep-security.net>
parents: 191
diff changeset
    30
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    31
        #endregion
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    32
1441
5d86ae076016 Add custom FirstStartup and NewAccount events to ThisAddIn.
Dean
parents: 1438
diff changeset
    33
        /// <summary>
5d86ae076016 Add custom FirstStartup and NewAccount events to ThisAddIn.
Dean
parents: 1438
diff changeset
    34
        /// Custom event for when the add-in is starting for the first time.
5d86ae076016 Add custom FirstStartup and NewAccount events to ThisAddIn.
Dean
parents: 1438
diff changeset
    35
        /// </summary>
5d86ae076016 Add custom FirstStartup and NewAccount events to ThisAddIn.
Dean
parents: 1438
diff changeset
    36
        internal event EventHandler FirstStartup;
5d86ae076016 Add custom FirstStartup and NewAccount events to ThisAddIn.
Dean
parents: 1438
diff changeset
    37
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
    38
        private List<KeyValuePair<CultureInfo, string>> _LanguageList       = null;
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
    39
        private static pEpEngine                        _PEPEngine          = null;
1987
6bda709ddb91 COM-49: When system.db is missing, adapter keeps restaring in a loop with no error message.
Markus Schaber <markus@pep-security.net>
parents: 1986
diff changeset
    40
        private static Exception                        _PEPEngineException = null;
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
    41
        private Outlook.Folder                          _PEPStoreRootFolder = null;
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
    42
        private PEPSettings                             _Settings           = null;
1948
be0dd58ec451 OUT-370: Add OutlookOptions and read them from registry.
Thomas
parents: 1944
diff changeset
    43
        private OutlookOptions                          _OutlookOptions     = null;
1770
5cae62d6ad4c Move decryption stack to own class
Thomas
parents: 1764
diff changeset
    44
        private static DecryptionStack                  _DecryptionStack    = null;
64
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
    45
1405
cd14f9d6cb61 Fix warnings.
Dean
parents: 1398
diff changeset
    46
#if !READER_RELEASE_MODE
cd14f9d6cb61 Fix warnings.
Dean
parents: 1398
diff changeset
    47
        private AdapterCallbacks adapterCallbacks = null;
cd14f9d6cb61 Fix warnings.
Dean
parents: 1398
diff changeset
    48
#endif
cd14f9d6cb61 Fix warnings.
Dean
parents: 1398
diff changeset
    49
2293
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
    50
        private bool                        initialized                 = false;
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
    51
        private bool                        isItemSendHandlerEnabled    = true;
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
    52
        private FormControlOptions.State    lastOptionsState            = null;
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
    53
        private List<WatchedFolder>         watchedFolders              = new List<WatchedFolder>();
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
    54
        private System.Windows.Forms.Timer  inboxCleaner                = null;
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
    55
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
    56
        private List<WatchedExplorer>       watchedExplorers            = new List<WatchedExplorer>();
2359
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
    57
        private List<WatchedInspector>      watchedInspectors           = new List<WatchedInspector>();
2293
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
    58
        private object                      mutexWatchedExplorers       = new object();
2359
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
    59
        private object                      mutexWatchedInspectors      = new object();
2293
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
    60
        private Outlook.Explorers           explorers                   = null;
2359
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
    61
        private Outlook.Inspectors          inspectors                  = null;
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    62
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    63
        /**************************************************************
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    64
         * 
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    65
         * Property Accessors
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    66
         * 
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    67
         *************************************************************/
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    68
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
    69
        /// <summary>
854
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
    70
        /// Gets the list of languages supported in the pEp engine.
935
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    71
        /// The list of language includes a key-value pair of the culture as well as a 
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    72
        /// display phrase in the native language for the trustwords.
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    73
        /// (phrase example: "I want to display the trustwords in English language")
854
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
    74
        /// </summary>
935
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    75
        internal List<KeyValuePair<CultureInfo, string>> LanguageList
854
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
    76
        {
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
    77
            get
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
    78
            {
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
    79
                string code;
935
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    80
                string phrase;
854
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
    81
                string engineList;
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
    82
                string[] languages;
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
    83
                string[] language;
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
    84
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
    85
                if (this._LanguageList == null)
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
    86
                {
935
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    87
                    this._LanguageList = new List<KeyValuePair<CultureInfo, string>>();
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    88
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    89
                    try
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    90
                    {
1343
1520e906a692 OUT-117: Catching up rename-refactorings from COM-24, COM-29, COM-30, COM-31
Markus Schaber <markus@pep-security.net>
parents: 1340
diff changeset
    91
                        engineList = ThisAddIn.PEPEngine.GetLanguageList();
935
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    92
                    }
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    93
                    catch
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    94
                    {
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    95
                        engineList = "";
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
    96
                        Log.Error("LanguageList: Failed to get list from engine.");
935
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    97
                    }
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
    98
854
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
    99
                    languages = engineList.Split('\n');
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   100
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   101
                    // Go through each language group
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   102
                    for (int i = 0; i < languages.Length; i++)
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   103
                    {
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   104
                        language = languages[i].Split(',');
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   105
935
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
   106
                        if (language.Length == 3)
854
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   107
                        {
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   108
                            code = language[0].Trim();
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   109
                            code = code.Replace("\"", "");
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   110
1583
33f126865e01 Initial commit
Thomas
parents: 1580
diff changeset
   111
                            phrase = language[1].Trim();
935
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
   112
                            phrase = phrase.Replace("\"", "");
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
   113
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
   114
                            this._LanguageList.Add(new KeyValuePair<CultureInfo, string>(new CultureInfo(code),
5308aa8494f0 Update language list and trustwords language selection to use latest engine format.
Dean Looyengoed
parents: 933
diff changeset
   115
                                                                                         phrase));
854
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   116
                        }
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   117
                    }
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   118
                }
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   119
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   120
                return (this._LanguageList);
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   121
            }
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   122
        }
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   123
f47d5c915d54 Support changing trustwords language during advanced handshake.
Dean Looyengoed
parents: 853
diff changeset
   124
        /// <summary>
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   125
        /// Gets the static pEp engine reference.
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   126
        /// </summary>
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   127
        internal static pEpEngine PEPEngine
64
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   128
        {
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   129
            get
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   130
            {
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   131
                if (ThisAddIn._PEPEngine == null)
64
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   132
                {
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   133
                    try
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   134
                    {
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   135
                        ThisAddIn._PEPEngine = new pEpEngine();
64
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   136
                    }
467
aeb05f7b2704 Finish initial implementation of global exception handler and sending crash report.
Dean Looyengoed
parents: 465
diff changeset
   137
                    catch (Exception ex)
64
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   138
                    {
1987
6bda709ddb91 COM-49: When system.db is missing, adapter keeps restaring in a loop with no error message.
Markus Schaber <markus@pep-security.net>
parents: 1986
diff changeset
   139
                        // As Globals.StopAndSendCrashReport below internally tries to access the engine
6bda709ddb91 COM-49: When system.db is missing, adapter keeps restaring in a loop with no error message.
Markus Schaber <markus@pep-security.net>
parents: 1986
diff changeset
   140
                        // several times, we need to prevent infinite recursion in case of engine
6bda709ddb91 COM-49: When system.db is missing, adapter keeps restaring in a loop with no error message.
Markus Schaber <markus@pep-security.net>
parents: 1986
diff changeset
   141
                        // initializaition failure.
6bda709ddb91 COM-49: When system.db is missing, adapter keeps restaring in a loop with no error message.
Markus Schaber <markus@pep-security.net>
parents: 1986
diff changeset
   142
                        if (_PEPEngineException != null)
2003
c0dfc0f23c17 Use PEPSettings to check for own identities and always use a userId
Thomas
parents: 1992
diff changeset
   143
                            return null;
1987
6bda709ddb91 COM-49: When system.db is missing, adapter keeps restaring in a loop with no error message.
Markus Schaber <markus@pep-security.net>
parents: 1986
diff changeset
   144
                        _PEPEngineException = ex;
6bda709ddb91 COM-49: When system.db is missing, adapter keeps restaring in a loop with no error message.
Markus Schaber <markus@pep-security.net>
parents: 1986
diff changeset
   145
467
aeb05f7b2704 Finish initial implementation of global exception handler and sending crash report.
Dean Looyengoed
parents: 465
diff changeset
   146
                        string summaryMessage = Properties.Resources.Message_InitError + " " +
aeb05f7b2704 Finish initial implementation of global exception handler and sending crash report.
Dean Looyengoed
parents: 465
diff changeset
   147
                                                Properties.Resources.Message_Reinstall;
860
ff259b6535c7 Merge 'Global' and 'Globals' together.
Dean Looyengoed
parents: 859
diff changeset
   148
                        Globals.StopAndSendCrashReport(ex, summaryMessage, false, true);
460
690f8853d7ae Start to implement the global exception handler in ThisAddIn.
Dean Looyengoed
parents: 455
diff changeset
   149
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   150
                        return (null);
64
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   151
                    }
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   152
                }
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   153
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   154
                return (ThisAddIn._PEPEngine);
64
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   155
            }
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   156
        }
5111a11eed7f replacing TextMessage object with struct
Volker Birk <vb@pep-project.org>
parents: 61
diff changeset
   157
611
70127a03488a Alphabetize order of properties.
Dean Looyengoed
parents: 608
diff changeset
   158
        /// <summary>
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   159
        /// Gets the root folder of the pEp data store.
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   160
        /// This is primarily used to save unencrypted outlook mail items (mirrors).
1115
f152a1ffe405 Rename 'pEp' to 'PEPEngine' and 'TempFolder' to 'PEPStoreRootFolder' in ThisAddIn.
Dean
parents: 1114
diff changeset
   161
        /// </summary>
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   162
        internal Outlook.Folder PEPStoreRootFolder
1115
f152a1ffe405 Rename 'pEp' to 'PEPEngine' and 'TempFolder' to 'PEPStoreRootFolder' in ThisAddIn.
Dean
parents: 1114
diff changeset
   163
        {
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   164
            get { return (this._PEPStoreRootFolder); }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   165
        }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   166
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   167
        /// <summary>
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   168
        /// Gets the current pEp settings for the add-in.
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   169
        /// </summary>
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   170
        internal PEPSettings Settings
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   171
        {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   172
            get { return (this._Settings); }
1090
6234a0b9c6a8 Add PEPSettings class and move all add-in configuration into it.
Dean
parents: 1082
diff changeset
   173
        }
6234a0b9c6a8 Add PEPSettings class and move all add-in configuration into it.
Dean
parents: 1082
diff changeset
   174
1770
5cae62d6ad4c Move decryption stack to own class
Thomas
parents: 1764
diff changeset
   175
        /// <summary>
1948
be0dd58ec451 OUT-370: Add OutlookOptions and read them from registry.
Thomas
parents: 1944
diff changeset
   176
        /// Gets the Outlook options set in the program.
be0dd58ec451 OUT-370: Add OutlookOptions and read them from registry.
Thomas
parents: 1944
diff changeset
   177
        /// </summary>
be0dd58ec451 OUT-370: Add OutlookOptions and read them from registry.
Thomas
parents: 1944
diff changeset
   178
        internal OutlookOptions OutlookOptions
be0dd58ec451 OUT-370: Add OutlookOptions and read them from registry.
Thomas
parents: 1944
diff changeset
   179
        {
be0dd58ec451 OUT-370: Add OutlookOptions and read them from registry.
Thomas
parents: 1944
diff changeset
   180
            get { return (this._OutlookOptions); }
be0dd58ec451 OUT-370: Add OutlookOptions and read them from registry.
Thomas
parents: 1944
diff changeset
   181
        }
be0dd58ec451 OUT-370: Add OutlookOptions and read them from registry.
Thomas
parents: 1944
diff changeset
   182
be0dd58ec451 OUT-370: Add OutlookOptions and read them from registry.
Thomas
parents: 1944
diff changeset
   183
        /// <summary>
1770
5cae62d6ad4c Move decryption stack to own class
Thomas
parents: 1764
diff changeset
   184
        /// Gets the decryption stack.
5cae62d6ad4c Move decryption stack to own class
Thomas
parents: 1764
diff changeset
   185
        /// </summary>
5cae62d6ad4c Move decryption stack to own class
Thomas
parents: 1764
diff changeset
   186
        internal static DecryptionStack DecryptionStack
5cae62d6ad4c Move decryption stack to own class
Thomas
parents: 1764
diff changeset
   187
        {
5cae62d6ad4c Move decryption stack to own class
Thomas
parents: 1764
diff changeset
   188
            get
5cae62d6ad4c Move decryption stack to own class
Thomas
parents: 1764
diff changeset
   189
            {
5cae62d6ad4c Move decryption stack to own class
Thomas
parents: 1764
diff changeset
   190
                if (ThisAddIn._DecryptionStack == null)
5cae62d6ad4c Move decryption stack to own class
Thomas
parents: 1764
diff changeset
   191
                {
5cae62d6ad4c Move decryption stack to own class
Thomas
parents: 1764
diff changeset
   192
                    ThisAddIn._DecryptionStack = new DecryptionStack();
5cae62d6ad4c Move decryption stack to own class
Thomas
parents: 1764
diff changeset
   193
                }
5cae62d6ad4c Move decryption stack to own class
Thomas
parents: 1764
diff changeset
   194
5cae62d6ad4c Move decryption stack to own class
Thomas
parents: 1764
diff changeset
   195
                return ThisAddIn._DecryptionStack;
5cae62d6ad4c Move decryption stack to own class
Thomas
parents: 1764
diff changeset
   196
            }
5cae62d6ad4c Move decryption stack to own class
Thomas
parents: 1764
diff changeset
   197
        }
5cae62d6ad4c Move decryption stack to own class
Thomas
parents: 1764
diff changeset
   198
190
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
         * 
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   201
         * Methods
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   202
         * 
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   203
         *************************************************************/
335
6411b6eb2638 Add initial backstage menu for options.
Dean Looyengoed
parents: 330
diff changeset
   204
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
   205
        /// <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
   206
        /// 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
   207
        /// </summary>
326
2acfe22efee4 Remove pEp ribbon tab and add ribbon for backstage options (disabled for now).
Dean Looyengoed
parents: 307
diff changeset
   208
        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
   209
        {
340
ded73ac01f51 Implement the send unencrypted option in the ribbon.
Dean Looyengoed
parents: 335
diff changeset
   210
            return new RibbonCustomizations();
335
6411b6eb2638 Add initial backstage menu for options.
Dean Looyengoed
parents: 330
diff changeset
   211
        }
0
6dfec3b090d6 initial commit
vb
parents:
diff changeset
   212
1734
aad357d2f2f0 OUT-285: Limit automatically triggered decryptions (through new mail events) to 5 at a time
Thomas
parents: 1718
diff changeset
   213
        /// <summary>
2293
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
   214
        /// Adds a new WatchedExplorer to the list of watched explorers.
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
   215
        /// </summary>
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
   216
        /// <param name="watchedExplorer">The WatchedExplorer to add.</param>
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
   217
        internal void AddToWatchedExplorers(WatchedExplorer watchedExplorer)
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
   218
        {
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
   219
            lock (mutexWatchedExplorers)
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
   220
            {
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
   221
                this.watchedExplorers.Add(watchedExplorer);
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
   222
            }
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
   223
        }
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
   224
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
   225
        /// <summary>
2359
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   226
        /// Adds a new WatchedInspector to the list of watched inspectors.
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   227
        /// </summary>
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   228
        /// <param name="watchedInspector">The WatchedInspector to add.</param>
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   229
        internal void AddToWatchedInspectors(WatchedInspector watchedInspector)
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   230
        {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   231
            lock (mutexWatchedInspectors)
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   232
            {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   233
                this.watchedInspectors.Add(watchedInspector);
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   234
            }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   235
        }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   236
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   237
        /// <summary>
2293
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
   238
        /// Removes a WatchedExplorer from the list of watched explorers.
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
   239
        /// </summary>
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
   240
        /// <param name="watchedExplorer">The WatchedExplorer to remove.</param>
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
   241
        internal void RemoveFromWatchedExplorers(WatchedExplorer watchedExplorer)
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
   242
        {
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
   243
            lock (mutexWatchedExplorers)
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
   244
            {
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
   245
                this.watchedExplorers.Remove(watchedExplorer);
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
   246
            }
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
   247
        }
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
   248
2dd69aea9675 Fix draft protection for inline messages
Thomas
parents: 2258
diff changeset
   249
        /// <summary>
2359
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   250
        /// Removes a WatchedInspector from the list of watched inspectors.
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   251
        /// </summary>
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   252
        /// <param name="WatchedInspector">The WatchedInspector to remove.</param>
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   253
        internal void RemoveFromWatchedInspectors(WatchedInspector watchedInspector)
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   254
        {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   255
            lock (mutexWatchedInspectors)
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   256
            {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   257
                this.watchedInspectors.Remove(watchedInspector);
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   258
            }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   259
        }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   260
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   261
        /// <summary>
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   262
        /// Gets the WatchedExplorer or WatchedInspector in which the given mail item resides.
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   263
        /// </summary>
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   264
        /// <param name="omi">The Outlook mail item to process with.</param>
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   265
        /// <returns>The WatchedExplorer or WatchedInspector the mail item resides in or null if an error occured.</returns>
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   266
        internal WatchedWindow GetWatchedParentWindow(Outlook.MailItem omi)
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   267
        {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   268
            try
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   269
            {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   270
                // First, check all watched explorers
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   271
                foreach (var watchedExplorer in this.watchedExplorers)
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   272
                {
2361
25169290ded2 Fix search algorithm for watched parent window
Thomas
parents: 2359
diff changeset
   273
                    if (watchedExplorer?.CurrentMailItem?.MAPIOBJECT?.Equals(omi?.MAPIOBJECT) == true)
2359
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   274
                    {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   275
                        return watchedExplorer;
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   276
                    }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   277
                }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   278
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   279
                // If window hasn't been found yet, check inspectors
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   280
                foreach (var watchedInspector in this.watchedInspectors)
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   281
                {
2361
25169290ded2 Fix search algorithm for watched parent window
Thomas
parents: 2359
diff changeset
   282
                    if (watchedInspector?.CurrentMailItem?.MAPIOBJECT?.Equals(omi?.MAPIOBJECT) == true)
2359
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   283
                    {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   284
                        return watchedInspector;
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   285
                    }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   286
                }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   287
            }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   288
            catch (Exception ex)
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   289
            {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   290
                Log.Error("GetWatchedParentWindow: Error getting window. " + ex.ToString());
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   291
            }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   292
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   293
            // If no window has been found, return null
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   294
            return null;
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   295
        }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   296
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   297
        /// <summary>
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   298
        /// Gets the watched window for an Inspector or Explorer object.
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   299
        /// </summary>
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   300
        /// <param name="window">The Inspector or Explorer window to get its WatchedWindow for.</param>
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   301
        /// <returns>The watched window or null if not found.</returns>
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   302
        internal WatchedWindow GetWatchedWindow(dynamic window)
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   303
        {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   304
            Outlook.Explorer explorer = null;
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   305
            Outlook.Inspector inspector = null;
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   306
            WatchedWindow watchedWindow = null;
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   307
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   308
            try
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   309
            {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   310
                // First, try if window is an explorer
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   311
                explorer = window as Outlook.Explorer;
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   312
                if (explorer != null)
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   313
                {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   314
                    if (this.watchedExplorers.Count == 1)
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   315
                    {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   316
                        watchedWindow = this.watchedExplorers[0];
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   317
                    }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   318
                    else
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   319
                    {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   320
                        foreach (var watchedExplorer in this.watchedExplorers)
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   321
                        {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   322
                            if (watchedExplorer?.Explorer?.Equals(explorer) == true)
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   323
                            {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   324
                                watchedWindow = watchedExplorer;
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   325
                                break;
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   326
                            }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   327
                        }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   328
                    }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   329
                }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   330
                else
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   331
                {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   332
                    // If window is no explorer, try if it is an inspector
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   333
                    inspector = window as Outlook.Inspector;
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   334
                    if (inspector != null)
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   335
                    {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   336
                        if (this.watchedInspectors.Count == 1)
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   337
                        {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   338
                            watchedWindow = this.watchedInspectors[0];
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   339
                        }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   340
                        else
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   341
                        {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   342
                            foreach (var watchedInspector in this.watchedInspectors)
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   343
                            {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   344
                                if (watchedInspector?.Inspector?.Equals(inspector) == true)
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   345
                                {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   346
                                    watchedWindow = watchedInspector;
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   347
                                    break;
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   348
                                }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   349
                            }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   350
                        }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   351
                    }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   352
                }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   353
            }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   354
            catch (Exception ex)
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   355
            {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   356
                Log.Error("GetWatchedWindow: Error occured. " + ex.ToString());
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   357
            }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   358
            finally
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   359
            {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   360
                explorer = null;
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   361
                inspector = null;
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   362
            }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   363
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   364
            return watchedWindow;
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   365
        }
2499
5ecc968a27fd OUT-507: Add 'pEp Internal' category to all incoming items and remove again after decryption
Thomas
parents: 2485
diff changeset
   366
2359
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   367
        /// <summary>
1557
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   368
        /// This updates the accounts list in pEp settings with the ones found in Outlook, adding new accounts and removing
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   369
        /// all accounts that are not there anymore.
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   370
        /// </summary>
1557
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   371
        internal void SyncAccountsList()
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   372
        {
2513
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   373
            bool accountAdded = false;
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   374
            bool exists;
1556
2687fc205e9c OUT-200: Ask user whether to sync a new account or not
Thomas
parents: 1555
diff changeset
   375
            string dialogMessage = string.Empty;
1499
c64aee1cce18 OUT-170: Make SyncWithSettings() update own identity flags in the engine.
Dean
parents: 1498
diff changeset
   376
            Outlook.NameSpace ns = null;
c64aee1cce18 OUT-170: Make SyncWithSettings() update own identity flags in the engine.
Dean
parents: 1498
diff changeset
   377
            Outlook.Account account = null;
c64aee1cce18 OUT-170: Make SyncWithSettings() update own identity flags in the engine.
Dean
parents: 1498
diff changeset
   378
            Outlook.Accounts accounts = null;
2513
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   379
            Outlook.Store store = null;
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   380
            Outlook.Stores stores = null;
1564
aee92531fdc3 Add extensive logging to startup and some simplification
Thomas
parents: 1561
diff changeset
   381
            PEPSettings.PEPAccountSettings acctSettings;
2513
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   382
            List<string> sharedAccountStores = new List<string>();
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   383
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   384
            try
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   385
            {
1499
c64aee1cce18 OUT-170: Make SyncWithSettings() update own identity flags in the engine.
Dean
parents: 1498
diff changeset
   386
                ns = Application.Session;
1557
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   387
                accounts = ns?.Accounts;
1499
c64aee1cce18 OUT-170: Make SyncWithSettings() update own identity flags in the engine.
Dean
parents: 1498
diff changeset
   388
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   389
                if (this._Settings != null)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   390
                {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   391
                    // Add any new Outlook accounts to the account settings list
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   392
                    for (int i = 1; i <= accounts.Count; i++)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   393
                    {
1499
c64aee1cce18 OUT-170: Make SyncWithSettings() update own identity flags in the engine.
Dean
parents: 1498
diff changeset
   394
                        account = accounts[i];
c64aee1cce18 OUT-170: Make SyncWithSettings() update own identity flags in the engine.
Dean
parents: 1498
diff changeset
   395
c64aee1cce18 OUT-170: Make SyncWithSettings() update own identity flags in the engine.
Dean
parents: 1498
diff changeset
   396
                        if (string.IsNullOrWhiteSpace(account.SmtpAddress) == false)
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   397
                        {
1564
aee92531fdc3 Add extensive logging to startup and some simplification
Thomas
parents: 1561
diff changeset
   398
                            // Check if it is already in the list
2063
cf63da070820 Further implementation. Still some parts left.
Thomas
parents: 2058
diff changeset
   399
                            var accountSettings = this._Settings.GetAccountSettings(account.SmtpAddress);
cf63da070820 Further implementation. Still some parts left.
Thomas
parents: 2058
diff changeset
   400
                            if (accountSettings == null)
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   401
                            {
2058
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   402
                                // Create pEp settings for the new account
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   403
                                account.CreatePEPSettings();
2513
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   404
                                accountAdded = true;
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   405
                            }
2063
cf63da070820 Further implementation. Still some parts left.
Thomas
parents: 2058
diff changeset
   406
                            else
cf63da070820 Further implementation. Still some parts left.
Thomas
parents: 2058
diff changeset
   407
                            {
cf63da070820 Further implementation. Still some parts left.
Thomas
parents: 2058
diff changeset
   408
                                // Check for properties that might have not been set correctly due to errors
cf63da070820 Further implementation. Still some parts left.
Thomas
parents: 2058
diff changeset
   409
                                // UserName
cf63da070820 Further implementation. Still some parts left.
Thomas
parents: 2058
diff changeset
   410
                                if (string.IsNullOrEmpty(accountSettings.UserName))
cf63da070820 Further implementation. Still some parts left.
Thomas
parents: 2058
diff changeset
   411
                                {
cf63da070820 Further implementation. Still some parts left.
Thomas
parents: 2058
diff changeset
   412
                                    try
cf63da070820 Further implementation. Still some parts left.
Thomas
parents: 2058
diff changeset
   413
                                    {
cf63da070820 Further implementation. Still some parts left.
Thomas
parents: 2058
diff changeset
   414
                                        accountSettings.UserName = account.UserName;
cf63da070820 Further implementation. Still some parts left.
Thomas
parents: 2058
diff changeset
   415
                                    }
cf63da070820 Further implementation. Still some parts left.
Thomas
parents: 2058
diff changeset
   416
                                    catch (Exception ex)
cf63da070820 Further implementation. Still some parts left.
Thomas
parents: 2058
diff changeset
   417
                                    {
cf63da070820 Further implementation. Still some parts left.
Thomas
parents: 2058
diff changeset
   418
                                        Log.Error("SyncAccountsList: Error adding user name. " + ex.ToString());
cf63da070820 Further implementation. Still some parts left.
Thomas
parents: 2058
diff changeset
   419
                                    }
cf63da070820 Further implementation. Still some parts left.
Thomas
parents: 2058
diff changeset
   420
                                }
cf63da070820 Further implementation. Still some parts left.
Thomas
parents: 2058
diff changeset
   421
                            }
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   422
                        }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   423
                        else
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   424
                        {
2063
cf63da070820 Further implementation. Still some parts left.
Thomas
parents: 2058
diff changeset
   425
                            Log.Warning("SyncAccountsList: Invalid Smtp address detected, skipping account.");
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   426
                        }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   427
1499
c64aee1cce18 OUT-170: Make SyncWithSettings() update own identity flags in the engine.
Dean
parents: 1498
diff changeset
   428
                        account = null;
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   429
                    }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   430
2513
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   431
                    // Add shared mail boxes
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   432
                    stores = ns?.Stores;
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   433
                    for (int i = 1; i <= stores.Count; i++)
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   434
                    {
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   435
                        store = stores[i];
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   436
                        if (store.ExchangeStoreType == Outlook.OlExchangeStoreType.olExchangeMailbox)
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   437
                        {
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   438
                            if (store.GetSmtpAddress(out string address, out string userName))
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   439
                            {
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   440
                                if (this.Settings.GetAccountSettings(address) == null)
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   441
                                {
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   442
                                    // Add to account settings if necessary
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   443
                                    Log.Verbose("GetSmtpAddress: Adding shared account " + address);
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   444
                                    this.Settings.AccountSettingsList.Add(new PEPSettings.PEPAccountSettings()
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   445
                                    {
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   446
                                        SmtpAddress = address,
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   447
                                        IsSecureStorageEnabled = false,
2562
3dbba3e9ed86 Improve logging
Thomas
parents: 2561
diff changeset
   448
                                        IsSyncEnabled = false,
2514
d6f26905fb48 Set shared account as Exchange type
Thomas
parents: 2513
diff changeset
   449
                                        Type = Outlook.OlAccountType.olExchange.ToString(),
2513
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   450
                                        UserName = userName
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   451
                                    });
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   452
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   453
                                    accountAdded = true;
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   454
                                }
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   455
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   456
                                sharedAccountStores.Add(address);
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   457
                            }
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   458
                        }
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   459
                    }
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   460
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   461
                    // Remove any entries of the account settings list not in Outlook
1499
c64aee1cce18 OUT-170: Make SyncWithSettings() update own identity flags in the engine.
Dean
parents: 1498
diff changeset
   462
                    // This is needed to skip any entries in the registry that may be invalid, user created, or no longer in Outlook
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   463
                    for (int i = (this._Settings.AccountSettingsList.Count - 1); i >= 0; i--)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   464
                    {
1564
aee92531fdc3 Add extensive logging to startup and some simplification
Thomas
parents: 1561
diff changeset
   465
                        acctSettings = this._Settings.AccountSettingsList[i];
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   466
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   467
                        // Check if it exists in Outlook
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   468
                        exists = false;
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   469
                        for (int j = 1; j <= accounts.Count; j++)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   470
                        {
1499
c64aee1cce18 OUT-170: Make SyncWithSettings() update own identity flags in the engine.
Dean
parents: 1498
diff changeset
   471
                            account = accounts[j];
1522
cc9a14ce8514 OUT-170: Exlude identity. Also initial implementation of new NotifyHandshake with synchronization signal.
Thomas
parents: 1519
diff changeset
   472
2063
cf63da070820 Further implementation. Still some parts left.
Thomas
parents: 2058
diff changeset
   473
                            if (acctSettings.EqualsByAddress(account.SmtpAddress))
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   474
                            {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   475
                                exists = true;
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   476
                            }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   477
1499
c64aee1cce18 OUT-170: Make SyncWithSettings() update own identity flags in the engine.
Dean
parents: 1498
diff changeset
   478
                            account = null;
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   479
2328
db219aed7eaa Reorder setting rules and view folders. Remove some superfluous return statements.
Thomas
parents: 2293
diff changeset
   480
                            if (exists)
db219aed7eaa Reorder setting rules and view folders. Remove some superfluous return statements.
Thomas
parents: 2293
diff changeset
   481
                            {
db219aed7eaa Reorder setting rules and view folders. Remove some superfluous return statements.
Thomas
parents: 2293
diff changeset
   482
                                break;
db219aed7eaa Reorder setting rules and view folders. Remove some superfluous return statements.
Thomas
parents: 2293
diff changeset
   483
                            }
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   484
                        }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   485
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   486
                        // Delete if necessary
2063
cf63da070820 Further implementation. Still some parts left.
Thomas
parents: 2058
diff changeset
   487
                        if ((exists == false) &&
2513
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   488
                            (Globals.ThisAddIn.Settings?.AccountsAddedWhileRunningList?.Contains(acctSettings?.SmtpAddress) != true) &&
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   489
                            (sharedAccountStores.Contains(acctSettings.SmtpAddress) == false))
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   490
                        {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   491
                            this._Settings.AccountSettingsList.RemoveAt(i);
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   492
                        }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   493
                    }
2513
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   494
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   495
                    if (accountAdded)
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   496
                    {
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   497
                        // Set view filters and rules
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   498
                        this.SetRulesAndViewFilters(this._Settings?.HideInternalMessages ?? PEPSettings.HIDE_INTERNAL_MESSAGES_DEFAULT);
e64e9b9a0e64 OUT-532: Add shared mailbox stores to pEp settings account list
Thomas
parents: 2509
diff changeset
   499
                    }
1557
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   500
                }
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   501
            }
1936
83060fe7965d Renaming enums and exceptions
Thomas
parents: 1933
diff changeset
   502
            catch (Exception ex)
1557
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   503
            {
1936
83060fe7965d Renaming enums and exceptions
Thomas
parents: 1933
diff changeset
   504
                Log.Error("SyncAccountsList: Error occured. " + ex.ToString());
1557
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   505
            }
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   506
            finally
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   507
            {
1992
7d4917d04ccb Modify Registry deletion of unused accounts
Thomas
parents: 1989
diff changeset
   508
                ns = null;
7d4917d04ccb Modify Registry deletion of unused accounts
Thomas
parents: 1989
diff changeset
   509
                account = null;
7d4917d04ccb Modify Registry deletion of unused accounts
Thomas
parents: 1989
diff changeset
   510
                accounts = null;
1557
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   511
            }
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   512
        }
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   513
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   514
        /// <summary>
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   515
        /// Syncronizes the current settings class with the pEp for Outlook instance and the pEp engine.
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   516
        /// Warning: This code should be kept synchronized with the Settings_PropertyChanged event.
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   517
        /// <param name="syncAccountsList">Whether to also update the accounts list in pEp settings. 
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   518
        /// </summary>
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   519
        internal void SyncWithSettings(bool syncAccountsList = false)
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   520
        {
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   521
            bool exists;
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   522
            string dialogMessage = string.Empty;
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   523
            pEpIdentity[] ownIdentities;
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   524
            List<KeyValuePair<CultureInfo, string>> languages;
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   525
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   526
            try
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   527
            {
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   528
                if (this._Settings != null)
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   529
                {
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   530
                    // Update the Outlook accounts list with the one maintained in pEp settings if needed.
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   531
                    if (syncAccountsList)
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   532
                    {
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   533
                        this.SyncAccountsList();
84c8e24e8fa4 OUT-200: Restructure settings synchronization
Thomas
parents: 1556
diff changeset
   534
                    }
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   535
1522
cc9a14ce8514 OUT-170: Exlude identity. Also initial implementation of new NotifyHandshake with synchronization signal.
Thomas
parents: 1519
diff changeset
   536
                    /* Sync the account settings with the engine's own identity flags.
cc9a14ce8514 OUT-170: Exlude identity. Also initial implementation of new NotifyHandshake with synchronization signal.
Thomas
parents: 1519
diff changeset
   537
                     * Warning: RegisterMyself() must already have been called so the engine has all own identities.
cc9a14ce8514 OUT-170: Exlude identity. Also initial implementation of new NotifyHandshake with synchronization signal.
Thomas
parents: 1519
diff changeset
   538
                     * The engine can commonly have more own identities than what is in the accounts list.
cc9a14ce8514 OUT-170: Exlude identity. Also initial implementation of new NotifyHandshake with synchronization signal.
Thomas
parents: 1519
diff changeset
   539
                     * This isn't a problem though and engine-only identities will not be changed here.
cc9a14ce8514 OUT-170: Exlude identity. Also initial implementation of new NotifyHandshake with synchronization signal.
Thomas
parents: 1519
diff changeset
   540
                     */
1499
c64aee1cce18 OUT-170: Make SyncWithSettings() update own identity flags in the engine.
Dean
parents: 1498
diff changeset
   541
                    ownIdentities = ThisAddIn.PEPEngine.OwnIdentitiesRetrieve();
c64aee1cce18 OUT-170: Make SyncWithSettings() update own identity flags in the engine.
Dean
parents: 1498
diff changeset
   542
                    foreach (PEPSettings.PEPAccountSettings acctSettings in this._Settings.AccountSettingsList)
c64aee1cce18 OUT-170: Make SyncWithSettings() update own identity flags in the engine.
Dean
parents: 1498
diff changeset
   543
                    {
c64aee1cce18 OUT-170: Make SyncWithSettings() update own identity flags in the engine.
Dean
parents: 1498
diff changeset
   544
                        // Find the own identity that matches with the account settings
c64aee1cce18 OUT-170: Make SyncWithSettings() update own identity flags in the engine.
Dean
parents: 1498
diff changeset
   545
                        foreach (pEpIdentity ident in ownIdentities)
c64aee1cce18 OUT-170: Make SyncWithSettings() update own identity flags in the engine.
Dean
parents: 1498
diff changeset
   546
                        {
1522
cc9a14ce8514 OUT-170: Exlude identity. Also initial implementation of new NotifyHandshake with synchronization signal.
Thomas
parents: 1519
diff changeset
   547
                            pEpIdentity ownIdent = ident;
cc9a14ce8514 OUT-170: Exlude identity. Also initial implementation of new NotifyHandshake with synchronization signal.
Thomas
parents: 1519
diff changeset
   548
cc9a14ce8514 OUT-170: Exlude identity. Also initial implementation of new NotifyHandshake with synchronization signal.
Thomas
parents: 1519
diff changeset
   549
                            if (acctSettings.EqualsByAddress(ownIdent.Address))
1499
c64aee1cce18 OUT-170: Make SyncWithSettings() update own identity flags in the engine.
Dean
parents: 1498
diff changeset
   550
                            {
1576
e86332ff82fc OUT-209: Add disable key sync for all accounts option
Thomas
parents: 1575
diff changeset
   551
                                // Sync the engine's own identity flags with the account or global settings
1577
e1fc661de901 OUT-209: Adjust design to new specs.
Thomas
parents: 1576
diff changeset
   552
                                if (this._Settings.IsSyncEnabledForAllAccounts)
1576
e86332ff82fc OUT-209: Add disable key sync for all accounts option
Thomas
parents: 1575
diff changeset
   553
                                {
1577
e1fc661de901 OUT-209: Adjust design to new specs.
Thomas
parents: 1576
diff changeset
   554
                                    if (ownIdent.GetIsSyncEnabled() == false)
1576
e86332ff82fc OUT-209: Add disable key sync for all accounts option
Thomas
parents: 1575
diff changeset
   555
                                    {
1577
e1fc661de901 OUT-209: Adjust design to new specs.
Thomas
parents: 1576
diff changeset
   556
                                        ThisAddIn.PEPEngine.UnsetIdentityFlags(ref ownIdent, pEpIdentityFlags.pEpIdfNotForSync);
1576
e86332ff82fc OUT-209: Add disable key sync for all accounts option
Thomas
parents: 1575
diff changeset
   557
                                    }
e86332ff82fc OUT-209: Add disable key sync for all accounts option
Thomas
parents: 1575
diff changeset
   558
                                }
e86332ff82fc OUT-209: Add disable key sync for all accounts option
Thomas
parents: 1575
diff changeset
   559
                                else if (ownIdent.GetIsSyncEnabled() != acctSettings.IsSyncEnabled)
1522
cc9a14ce8514 OUT-170: Exlude identity. Also initial implementation of new NotifyHandshake with synchronization signal.
Thomas
parents: 1519
diff changeset
   560
                                {
cc9a14ce8514 OUT-170: Exlude identity. Also initial implementation of new NotifyHandshake with synchronization signal.
Thomas
parents: 1519
diff changeset
   561
                                    if (acctSettings.IsSyncEnabled)
cc9a14ce8514 OUT-170: Exlude identity. Also initial implementation of new NotifyHandshake with synchronization signal.
Thomas
parents: 1519
diff changeset
   562
                                    {
cc9a14ce8514 OUT-170: Exlude identity. Also initial implementation of new NotifyHandshake with synchronization signal.
Thomas
parents: 1519
diff changeset
   563
                                        ThisAddIn.PEPEngine.UnsetIdentityFlags(ref ownIdent, pEpIdentityFlags.pEpIdfNotForSync);
cc9a14ce8514 OUT-170: Exlude identity. Also initial implementation of new NotifyHandshake with synchronization signal.
Thomas
parents: 1519
diff changeset
   564
                                    }
cc9a14ce8514 OUT-170: Exlude identity. Also initial implementation of new NotifyHandshake with synchronization signal.
Thomas
parents: 1519
diff changeset
   565
                                    else
cc9a14ce8514 OUT-170: Exlude identity. Also initial implementation of new NotifyHandshake with synchronization signal.
Thomas
parents: 1519
diff changeset
   566
                                    {
cc9a14ce8514 OUT-170: Exlude identity. Also initial implementation of new NotifyHandshake with synchronization signal.
Thomas
parents: 1519
diff changeset
   567
                                        ThisAddIn.PEPEngine.SetIdentityFlags(ref ownIdent, pEpIdentityFlags.pEpIdfNotForSync);
cc9a14ce8514 OUT-170: Exlude identity. Also initial implementation of new NotifyHandshake with synchronization signal.
Thomas
parents: 1519
diff changeset
   568
                                    }
cc9a14ce8514 OUT-170: Exlude identity. Also initial implementation of new NotifyHandshake with synchronization signal.
Thomas
parents: 1519
diff changeset
   569
                                }
1499
c64aee1cce18 OUT-170: Make SyncWithSettings() update own identity flags in the engine.
Dean
parents: 1498
diff changeset
   570
                                break;
c64aee1cce18 OUT-170: Make SyncWithSettings() update own identity flags in the engine.
Dean
parents: 1498
diff changeset
   571
                            }
c64aee1cce18 OUT-170: Make SyncWithSettings() update own identity flags in the engine.
Dean
parents: 1498
diff changeset
   572
                        }
c64aee1cce18 OUT-170: Make SyncWithSettings() update own identity flags in the engine.
Dean
parents: 1498
diff changeset
   573
                    }
c64aee1cce18 OUT-170: Make SyncWithSettings() update own identity flags in the engine.
Dean
parents: 1498
diff changeset
   574
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   575
                    // Sync IsKeyServerUsed with engine
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   576
                    if (this._Settings.IsKeyServerUsed)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   577
                    {
1337
6b93b1a3b751 OUT-117: Catching up rename-refactorings from COM-24, COM-29, COM-30, COM-31
Markus Schaber <markus@pep-security.net>
parents: 1328
diff changeset
   578
                        ThisAddIn.PEPEngine.StartKeyserverLookup();
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   579
                    }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   580
                    else
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   581
                    {
1337
6b93b1a3b751 OUT-117: Catching up rename-refactorings from COM-24, COM-29, COM-30, COM-31
Markus Schaber <markus@pep-security.net>
parents: 1328
diff changeset
   582
                        ThisAddIn.PEPEngine.StopKeyserverLookup();
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   583
                    }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   584
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   585
                    // Sync IsPassiveModeEnabled with engine
1337
6b93b1a3b751 OUT-117: Catching up rename-refactorings from COM-24, COM-29, COM-30, COM-31
Markus Schaber <markus@pep-security.net>
parents: 1328
diff changeset
   586
                    ThisAddIn.PEPEngine.PassiveMode(this._Settings.IsPassiveModeEnabled);
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   587
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   588
                    // Sync IsPEPFolderVisible with Outlook
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   589
                    this.SetPEPStoreRootFolderVisibility(this._Settings.IsPEPFolderVisible);
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   590
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   591
                    // Sync IsUnencryptedSubjectEnabled with engine
1337
6b93b1a3b751 OUT-117: Catching up rename-refactorings from COM-24, COM-29, COM-30, COM-31
Markus Schaber <markus@pep-security.net>
parents: 1328
diff changeset
   592
                    ThisAddIn.PEPEngine.UnencryptedSubject(this._Settings.IsUnencryptedSubjectEnabled);
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   593
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   594
                    // Sync IsVerboseLoggingEnabled with engine
1337
6b93b1a3b751 OUT-117: Catching up rename-refactorings from COM-24, COM-29, COM-30, COM-31
Markus Schaber <markus@pep-security.net>
parents: 1328
diff changeset
   595
                    ThisAddIn.PEPEngine.VerboseLogging(this._Settings.IsVerboseLoggingEnabled);
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   596
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   597
                    // Sync TrustwordsCulture with engine
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   598
                    if (this._Settings.TrustwordsCulture != null)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   599
                    {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   600
                        // Validate it exists in the engine list
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   601
                        exists = false;
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   602
                        languages = this.LanguageList;
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   603
                        foreach (KeyValuePair<CultureInfo, string> entry in languages)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   604
                        {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   605
                            if (entry.Key.LCID == this._Settings.TrustwordsCulture.LCID)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   606
                            {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   607
                                exists = true;
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   608
                                break;
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   609
                            }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   610
                        }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   611
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   612
                        if (exists == false)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   613
                        {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   614
                            // Reset to default
1351
80e7cec5b7cc Select the default trustwords language as the UI language.
Dean
parents: 1350
diff changeset
   615
                            this._Settings.TrustwordsCulture = this.GetActiveUICulture();
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   616
                            Log.Warning("SyncWithSettings: Invalid TrustwordsCulture detected, setting to default.");
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   617
                        }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   618
                    }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   619
                    else
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   620
                    {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   621
                        // Reset to default
1351
80e7cec5b7cc Select the default trustwords language as the UI language.
Dean
parents: 1350
diff changeset
   622
                        this._Settings.TrustwordsCulture = this.GetActiveUICulture();
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   623
                    }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   624
                }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   625
            }
1499
c64aee1cce18 OUT-170: Make SyncWithSettings() update own identity flags in the engine.
Dean
parents: 1498
diff changeset
   626
            catch (Exception ex)
c64aee1cce18 OUT-170: Make SyncWithSettings() update own identity flags in the engine.
Dean
parents: 1498
diff changeset
   627
            {
c64aee1cce18 OUT-170: Make SyncWithSettings() update own identity flags in the engine.
Dean
parents: 1498
diff changeset
   628
                Log.Error("SyncWithSettings: Failure occured, " + ex.ToString());
c64aee1cce18 OUT-170: Make SyncWithSettings() update own identity flags in the engine.
Dean
parents: 1498
diff changeset
   629
            }
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   630
        }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   631
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   632
        /// <summary>
1441
5d86ae076016 Add custom FirstStartup and NewAccount events to ThisAddIn.
Dean
parents: 1438
diff changeset
   633
        /// Compares the given settings with the current state of Outlook and detects any changes.
1580
8260c64f4aae Small restructuring in startup
Thomas
parents: 1578
diff changeset
   634
        /// This is currently only used to identify first startup.
1441
5d86ae076016 Add custom FirstStartup and NewAccount events to ThisAddIn.
Dean
parents: 1438
diff changeset
   635
        /// </summary>
5d86ae076016 Add custom FirstStartup and NewAccount events to ThisAddIn.
Dean
parents: 1438
diff changeset
   636
        /// <param name="lastSettings">The last settings to compare with. 
5d86ae076016 Add custom FirstStartup and NewAccount events to ThisAddIn.
Dean
parents: 1438
diff changeset
   637
        /// This should be the settings just loaded from the registry at startup (last saved settings).</param>
5d86ae076016 Add custom FirstStartup and NewAccount events to ThisAddIn.
Dean
parents: 1438
diff changeset
   638
        private void DetectChangesFromLastSettings(PEPSettings lastSettings)
5d86ae076016 Add custom FirstStartup and NewAccount events to ThisAddIn.
Dean
parents: 1438
diff changeset
   639
        {
5d86ae076016 Add custom FirstStartup and NewAccount events to ThisAddIn.
Dean
parents: 1438
diff changeset
   640
            // Detect first startup
5d86ae076016 Add custom FirstStartup and NewAccount events to ThisAddIn.
Dean
parents: 1438
diff changeset
   641
            if (lastSettings.IsFirstStartupComplete == false)
5d86ae076016 Add custom FirstStartup and NewAccount events to ThisAddIn.
Dean
parents: 1438
diff changeset
   642
            {
5d86ae076016 Add custom FirstStartup and NewAccount events to ThisAddIn.
Dean
parents: 1438
diff changeset
   643
                this.FirstStartup?.Invoke(this, new EventArgs());
5d86ae076016 Add custom FirstStartup and NewAccount events to ThisAddIn.
Dean
parents: 1438
diff changeset
   644
            }
5d86ae076016 Add custom FirstStartup and NewAccount events to ThisAddIn.
Dean
parents: 1438
diff changeset
   645
        }
5d86ae076016 Add custom FirstStartup and NewAccount events to ThisAddIn.
Dean
parents: 1438
diff changeset
   646
5d86ae076016 Add custom FirstStartup and NewAccount events to ThisAddIn.
Dean
parents: 1438
diff changeset
   647
        /// <summary>
626
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   648
        /// Detects and disables GPG for Windows GpgOL Outlook add-in.
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   649
        /// </summary>
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   650
        /// <returns>True if the GpgOL add-in was disabled.</returns>
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   651
        private bool DisableGpgOL()
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   652
        {
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   653
            bool wasDisabled = false;
830
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   654
            Office.COMAddIns comAddIns = null;
626
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   655
830
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   656
            try
626
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   657
            {
830
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   658
                comAddIns = Globals.ThisAddIn.Application.COMAddIns;
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   659
                foreach (Office.COMAddIn addin in comAddIns)
626
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   660
                {
830
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   661
                    if (string.Equals(addin.Description, "GpgOL - The GnuPG Outlook Plugin", StringComparison.OrdinalIgnoreCase))
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   662
                    {
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   663
                        addin.Connect = false;
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   664
                        wasDisabled = true;
626
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   665
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   666
                        Log.Info("DisableGpgOL: GpgOL was detected and disabled.");
830
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   667
                    }
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   668
                }
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   669
            }
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   670
            catch (Exception ex)
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   671
            {
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   672
                Log.Error("DisableGpgOL: Error trying to disable GpgOL, " + ex.ToString());
830
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   673
            }
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   674
            finally
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   675
            {
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   676
                if (comAddIns != null)
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   677
                {
1507
d315f34fae0b remove a couple of ReleaseComObject() calls
Volker Birk <vb@pep-project.org>
parents: 1503
diff changeset
   678
                    // Marshal.ReleaseComObject(comAddIns);
830
592efb9cf41d Handle and log errors in DisableGpgOL method.
Dean Looyengoed
parents: 820
diff changeset
   679
                    comAddIns = null;
626
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   680
                }
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   681
            }
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   682
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   683
            return (wasDisabled);
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   684
        }
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   685
6fce9c5a037e Add and implement DisableGpgOL method.
Dean Looyengoed
parents: 625
diff changeset
   686
        /// <summary>
2359
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   687
        /// Sends a request to recalculate the message rating of all open windows (except one) again.
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   688
        /// </summary>
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   689
        /// <param name="windowToExclude">The window to not calculate its rating for</param>
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   690
        internal void RecalculateAllWindows(WatchedWindow windowToExclude)
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   691
        {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   692
            for (int i = 0; i < this.watchedExplorers.Count; i++)
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   693
            {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   694
                if ((windowToExclude as WatchedExplorer)?.Equals(this.watchedExplorers[i]) != true)
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   695
                {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   696
                    this.watchedExplorers[i].RequestRatingAndUIUpdate();
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   697
                }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   698
            }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   699
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   700
            for (int i = 0; i < this.watchedInspectors.Count; i++)
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   701
            {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   702
                if ((windowToExclude as WatchedInspector)?.Equals(this.watchedInspectors[i]) != true)
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   703
                {
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   704
                    this.watchedInspectors[i].RequestRatingAndUIUpdate();
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   705
                }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   706
            }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   707
        }
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   708
0e6191d039e4 Major restructuration:
Thomas
parents: 2351
diff changeset
   709
        /// <summary>
1497
50187f1f8ecf Rework RegisterMyself() to handle exceptions by itself.
Dean
parents: 1491
diff changeset
   710
        /// Registers each own identity in the pEp engine.
50187f1f8ecf Rework RegisterMyself() to handle exceptions by itself.
Dean
parents: 1491
diff changeset
   711
        /// An own identity represents 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
   712
        /// </summary>
910
9bd60ca2c6ac Add offline support (mostly for Exchange accounts).
Dean Looyengoed
parents: 902
diff changeset
   713
        internal void RegisterMyself()
0
6dfec3b090d6 initial commit
vb
parents:
diff changeset
   714
        {
2003
c0dfc0f23c17 Use PEPSettings to check for own identities and always use a userId
Thomas
parents: 1992
diff changeset
   715
            if (Globals.ThisAddIn.Settings.AccountSettingsList != null)
0
6dfec3b090d6 initial commit
vb
parents:
diff changeset
   716
            {
2058
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   717
                foreach (var acctSettings in Globals.ThisAddIn.Settings.AccountSettingsList)
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   718
                {
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   719
                    this.RegisterMyself(acctSettings);
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   720
                }
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   721
            }
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   722
        }
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   723
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   724
        /// <summary>
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   725
        /// Registers a pEpIdentity in the pEp engine.
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   726
        /// </summary>
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   727
        internal void RegisterMyself(PEPSettings.PEPAccountSettings acctSettings)
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   728
        {
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   729
            pEpIdentity ownIdentity;
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   730
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   731
            if (acctSettings != null)
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   732
            {
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   733
                // Create pEpIdentity
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   734
                ownIdentity = new pEpIdentity
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   735
                {
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   736
                    Address = acctSettings.SmtpAddress,
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   737
                    UserId = PEPSettings.PEP_OWN_USER_ID,
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   738
                    UserName = acctSettings.UserName
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   739
                };
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   740
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   741
                // Set not for sync flag if necessary
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   742
                if ((acctSettings.Type.Contains("Imap")) ||
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   743
                    ((Globals.ThisAddIn.Settings.IsSyncEnabledForAllAccounts == false) &&
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   744
                     (acctSettings.IsSyncEnabled == false)))
575
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   745
                {
2058
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   746
                    ownIdentity.Flags = pEpIdentityFlags.pEpIdfNotForSync;
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   747
                }
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   748
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   749
                // Log information if invalid
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   750
                if (string.IsNullOrWhiteSpace(ownIdentity.Address))
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   751
                {
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   752
                    Log.Warning("RegisterMyself: Myself doesn't have an address.");
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   753
                }
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   754
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   755
                if (string.IsNullOrWhiteSpace(ownIdentity.UserName))
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   756
                {
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   757
                    Log.Warning("RegisterMyself: Myself doesn't have a user name.");
575
27512d0d41cf Rewrite RegisterMyself method to release objects and log issues.
Dean Looyengoed
parents: 571
diff changeset
   758
                }
2058
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   759
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   760
                /* Call engine to register myself (doesn't matter if already done in a past instance)
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   761
                 * Note that key generation can take place during the call to Myself if it's a new installation
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   762
                 * and the engine is unable to elect a key. In this situation key generation can take some time.
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   763
                 * It takes long-enough for the call to the adapter to timeout here and throw an exception.
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   764
                 * However, since the fingerprint of the own identity is not actually needed here, the assumption is 
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   765
                 * made that the engine will be OK and continue processing.
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   766
                 * The exception is simply ignored and we go to the next identity. 
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   767
                 */
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   768
                try
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   769
                {
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   770
                    ThisAddIn.PEPEngine.Myself(ownIdentity);
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   771
                }
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   772
                catch (COMException ex)
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   773
                {
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   774
                    Log.Warning("RegisterMyself: Engine returned exception, " + ex.ToString());
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   775
                }
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   776
            }
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   777
            else
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   778
            {
ecee220c7d7d OUT-417: Detect new account during message creation.
Thomas
parents: 2053
diff changeset
   779
                Log.Error("RegisterMyself: account settings are null.");
1497
50187f1f8ecf Rework RegisterMyself() to handle exceptions by itself.
Dean
parents: 1491
diff changeset
   780
            }
190
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   781
        }
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   782
a685c30e07d2 Refactor/comment/partial rewrite of the ThisAddIn class.
Dean Looyengoed
parents: 168
diff changeset
   783
        /// <summary>
738
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   784
        /// Create a new Outlook MailItem from the given PEPMessage and send it.
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   785
        /// The sent message will not be processed by the 'Application_ItemSend' event.
744
278a6ecd7639 Document and implement special handling for Exchange ActiveSync issues during send.
Dean Looyengoed
parents: 743
diff changeset
   786
        /// WARNING: Exchange ActiveSync accounts ignore the deleteAfterSend parameter (always false).
455
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   787
        /// </summary>
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   788
        /// <param name="message">The message to send.</param>
475
7a23ec4d8b28 Add deleteAfterSend parameter in SendWithoutProcessing method.
Dean Looyengoed
parents: 474
diff changeset
   789
        /// <param name="deleteAfterSend">Whether the message is deleted after sending (true) or a copy is saved (false).</param>
1455
8df403ec31ee OUT-167: Detect anytime From/SendingAccount != To recipient in keysync.
Dean
parents: 1454
diff changeset
   790
        /// <param name="validateSendingAccount">Validates that the SendingAccount matches the From identity of the given message.
8df403ec31ee OUT-167: Detect anytime From/SendingAccount != To recipient in keysync.
Dean
parents: 1454
diff changeset
   791
        /// This can catch situations (and throw exceptions) where the default account would be used instead.</param>
1833
45ccf9517e8e Add dedicated decryption task for FPP messages
Thomas
parents: 1823
diff changeset
   792
        /// <param name="processMessage">Whether or not to process this message through the pEp engine.</param>
45ccf9517e8e Add dedicated decryption task for FPP messages
Thomas
parents: 1823
diff changeset
   793
        internal void CreateAndSendMessage(PEPMessage message,
45ccf9517e8e Add dedicated decryption task for FPP messages
Thomas
parents: 1823
diff changeset
   794
                                           bool deleteAfterSend,
45ccf9517e8e Add dedicated decryption task for FPP messages
Thomas
parents: 1823
diff changeset
   795
                                           bool validateSendingAccount,
2584
c5a783090136 Do not set KeyImport header to outer message
Thomas
parents: 2567
diff changeset
   796
                                           bool processMessage = false)
455
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   797
        {
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   798
            Outlook.MailItem newItem;
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   799
            Globals.ReturnStatus sts;
455
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   800
1833
45ccf9517e8e Add dedicated decryption task for FPP messages
Thomas
parents: 1823
diff changeset
   801
            this.isItemSendHandlerEnabled = processMessage;
1394
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   802
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   803
            try
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   804
            {
1394
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   805
                newItem = Application.CreateItem(Outlook.OlItemType.olMailItem);
1467
622a86775584 OUT-167: Make sure to set SendUsingAccount during SendWithoutProcessing.
Thomas
parents: 1465
diff changeset
   806
622a86775584 OUT-167: Make sure to set SendUsingAccount during SendWithoutProcessing.
Thomas
parents: 1465
diff changeset
   807
                /* Notes:
622a86775584 OUT-167: Make sure to set SendUsingAccount during SendWithoutProcessing.
Thomas
parents: 1465
diff changeset
   808
                 * Do NOT include internal Header Fields (MAPI properties) on outgoing messages!
622a86775584 OUT-167: Make sure to set SendUsingAccount during SendWithoutProcessing.
Thomas
parents: 1465
diff changeset
   809
                 * The sender must be set from the from identity (setSender=true)
622a86775584 OUT-167: Make sure to set SendUsingAccount during SendWithoutProcessing.
Thomas
parents: 1465
diff changeset
   810
                 */
622a86775584 OUT-167: Make sure to set SendUsingAccount during SendWithoutProcessing.
Thomas
parents: 1465
diff changeset
   811
                sts = message.ApplyTo(newItem, false, true);
1394
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   812
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   813
                if (sts == Globals.ReturnStatus.Success)
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   814
                {
1455
8df403ec31ee OUT-167: Detect anytime From/SendingAccount != To recipient in keysync.
Dean
parents: 1454
diff changeset
   815
                    // Check that the sending account is the From identity
8df403ec31ee OUT-167: Detect anytime From/SendingAccount != To recipient in keysync.
Dean
parents: 1454
diff changeset
   816
                    if ((validateSendingAccount) &&
8df403ec31ee OUT-167: Detect anytime From/SendingAccount != To recipient in keysync.
Dean
parents: 1454
diff changeset
   817
                        (message.From != null))
8df403ec31ee OUT-167: Detect anytime From/SendingAccount != To recipient in keysync.
Dean
parents: 1454
diff changeset
   818
                    {
2565
2bc5570f217d Try to set Send account if not set yet
Thomas
parents: 2555
diff changeset
   819
                        if (newItem.SetSendUsingAccount(message.From.Address) == false)
1455
8df403ec31ee OUT-167: Detect anytime From/SendingAccount != To recipient in keysync.
Dean
parents: 1454
diff changeset
   820
                        {
2565
2bc5570f217d Try to set Send account if not set yet
Thomas
parents: 2555
diff changeset
   821
                            throw new Exception("Sending account does not match from identity or error setting Send account");
1455
8df403ec31ee OUT-167: Detect anytime From/SendingAccount != To recipient in keysync.
Dean
parents: 1454
diff changeset
   822
                        }
8df403ec31ee OUT-167: Detect anytime From/SendingAccount != To recipient in keysync.
Dean
parents: 1454
diff changeset
   823
                    }
8df403ec31ee OUT-167: Detect anytime From/SendingAccount != To recipient in keysync.
Dean
parents: 1454
diff changeset
   824
1394
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   825
                    // Do not allow TNEF/RTF format with 'winmail.dat' attachment
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   826
                    MapiHelper.SetProperty(newItem, MapiProperty.PidLidUseTnef, false);
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   827
2587
41b38b5db5f9 Process initial message before sending
Thomas
parents: 2585
diff changeset
   828
                    // If ForceUnencrypted property is set, add it to mail item (only if message is to be processed)
41b38b5db5f9 Process initial message before sending
Thomas
parents: 2585
diff changeset
   829
                    if (processMessage && 
41b38b5db5f9 Process initial message before sending
Thomas
parents: 2585
diff changeset
   830
                        message.ForceUnencrypted)
2102
3939ad287c0c Initial commit for PGP key import.
Thomas
parents: 2092
diff changeset
   831
                    {
3939ad287c0c Initial commit for PGP key import.
Thomas
parents: 2092
diff changeset
   832
                        newItem.SetPEPProperty(MailItemExtensions.PEPProperty.ForceUnencrypted, true);
3939ad287c0c Initial commit for PGP key import.
Thomas
parents: 2092
diff changeset
   833
                    }
3939ad287c0c Initial commit for PGP key import.
Thomas
parents: 2092
diff changeset
   834
1394
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   835
                    /* Send
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   836
                     * 
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   837
                     * Note: For ActiveSync accounts, the DeleteAfterSubmit property is ignored.
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   838
                     * This means the message will always appear in the sent folder by default.
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   839
                     * The reason for this is unknown.
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   840
                     * 
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   841
                     * It's possible this is related to the ActiveSync specification version
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   842
                     * and therefore may behave differently depending on Outlook version.
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   843
                     * More research is needed here.
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   844
                     */
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   845
                    newItem.DeleteAfterSubmit = deleteAfterSend;
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   846
                    ((Outlook._MailItem)newItem).Send();
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   847
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   848
                    newItem = null;
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   849
                }
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   850
                else
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   851
                {
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   852
                    newItem.PermanentlyDelete();
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   853
                    newItem = null;
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   854
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   855
                    throw new Exception("Failed to create MailItem to send");
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   856
                }
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   857
            }
1394
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   858
            catch
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   859
            {
1822
5164def51fea Attach public key to initial message
Thomas
parents: 1820
diff changeset
   860
                throw new Exception("CreateMessageAndSend: Failed to send MailItem.");
1394
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   861
            }
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   862
            finally
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   863
            {
1fb7ea1e40ba OUT-17: Disable Application_ItemSend when within the SendWithoutProcessing method.
Dean
parents: 1390
diff changeset
   864
                this.isItemSendHandlerEnabled = true;
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   865
            }
455
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   866
        }
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   867
a4158ad1f4b7 Add method to create a new Outlook MailItem and send it without processing.
Dean Looyengoed
parents: 453
diff changeset
   868
        /// <summary>
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   869
        /// Create a new 'sent' Outlook MailItem and place it in the given store.
744
278a6ecd7639 Document and implement special handling for Exchange ActiveSync issues during send.
Dean Looyengoed
parents: 743
diff changeset
   870
        /// WARNING: Exchange ActiveSync accounts are not supported by this method. The sent
278a6ecd7639 Document and implement special handling for Exchange ActiveSync issues during send.
Dean Looyengoed
parents: 743
diff changeset
   871
        /// message will always appear in the drafts folder.
738
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   872
        /// </summary>
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   873
        /// <param name="sendingStore">The store to save the sent message to.</param>
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   874
        /// <param name="acctSettings">The sending account settings.</param>
738
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   875
        /// <param name="sentMessage">The message that is sent.</param>
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   876
        /// <param name="storedRating">The rating to store to the sent message mail item.
970
d676bc7cbad6 Store the outgoing color rating for sent messages where possible.
Dean Looyengoed
parents: 935
diff changeset
   877
        /// Will only be set if not undefined (default). Warning: Only use this on trusted servers.</param>
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   878
        private void CreateNewSentMail(Outlook.Store sendingStore,
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   879
                                       PEPSettings.PEPAccountSettings acctSettings,
970
d676bc7cbad6 Store the outgoing color rating for sent messages where possible.
Dean Looyengoed
parents: 935
diff changeset
   880
                                       PEPMessage sentMessage,
1337
6b93b1a3b751 OUT-117: Catching up rename-refactorings from COM-24, COM-29, COM-30, COM-31
Markus Schaber <markus@pep-security.net>
parents: 1328
diff changeset
   881
                                       pEpRating storedRating = pEpRating.pEpRatingUndefined)
738
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   882
        {
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   883
            Int32 messageFlags;
738
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   884
            Outlook.MailItem sentMailItem = null;
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   885
            Outlook.Folder sentFolder = null;
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   886
            Outlook.NameSpace ns = Application.Session;
1511
9f431f11aaf5 we definitely need an address
Volker Birk <vb@pep-project.org>
parents: 1510
diff changeset
   887
            Outlook.Folder rootFolder = null;
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   888
            Outlook.Folders folders = null;
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   889
            Outlook.Folder folder = null;
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   890
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   891
            /* The process is:
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   892
             * 1. Use the Store.GetDefaultFolder(olFolderSentMail) to try to get the default Sent folder. 
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   893
             *    However, this can fail for a number of reasons, depending on server and folder configuration.
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   894
             * 2. As a fallback, search for the Sent folder by matching the Sent folder Entry ID
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   895
             *    However, this can also fail if no Sent folder Entry ID has been recorded.
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   896
             * 3. As another fallback, search by Folder name ("SENT") for an existing Sent folder
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   897
             *    If found, record the folder's Entry ID. If not, goto point 4.
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   898
             * 4. If everything of the above fails, create a new Sent folder and record the Entry ID.     
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   899
             */
738
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   900
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   901
            try
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
   902
            {
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   903
                if ((sendingStore != null) &&
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   904
                    (acctSettings != null) &&
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   905
                    (sentMessage != null))
1108
47880211c601 OUT-55: Initial fix for missing sent messages
Thomas
parents: 1096
diff changeset
   906
                {
1522
cc9a14ce8514 OUT-170: Exlude identity. Also initial implementation of new NotifyHandshake with synchronization signal.
Thomas
parents: 1519
diff changeset
   907
                    rootFolder = (Outlook.Folder)sendingStore.GetRootFolder();
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   908
                    if (rootFolder != null)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   909
                    {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   910
                        folders = rootFolder.Folders;
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   911
                    }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   912
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   913
                    // Step 1
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   914
                    try
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   915
                    {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   916
                        sentFolder = (Outlook.Folder)sendingStore.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   917
                    }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   918
                    catch
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   919
                    {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   920
                        if (sentFolder != null)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   921
                        {
1507
d315f34fae0b remove a couple of ReleaseComObject() calls
Volker Birk <vb@pep-project.org>
parents: 1503
diff changeset
   922
                            // Marshal.ReleaseComObject(sentFolder);
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   923
                            sentFolder = null;
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   924
                        }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   925
                    }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   926
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   927
                    // Step 2
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   928
                    if (sentFolder == null)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   929
                    {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   930
                        try
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   931
                        {
1348
c394606d6f6c Change to .net standard capitalization rules in several places.
Dean
parents: 1347
diff changeset
   932
                            /* Search for folder by entry ID
c394606d6f6c Change to .net standard capitalization rules in several places.
Dean
parents: 1347
diff changeset
   933
                             * Normally, the way to go would be the following line:
c394606d6f6c Change to .net standard capitalization rules in several places.
Dean
parents: 1347
diff changeset
   934
                             * sentFolder = (Outlook.Folder)ns.GetItemFromID(acctSettings.SentFolderEntryId, sendingStore.StoreID);
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   935
                             * However, for some reason, this can come up with the following error: "Could not open the item. Try again."
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   936
                             * Therefore, the below solution is used:
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   937
                             */
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   938
                            if (folders != null)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   939
                            {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   940
                                for (int i = 1; i <= folders.Count; i++)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   941
                                {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   942
                                    folder = (Outlook.Folder)folders[i];
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   943
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   944
                                    if (folder != null)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   945
                                    {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   946
                                        if ((string.IsNullOrEmpty(folder.EntryID) == false) &&
1348
c394606d6f6c Change to .net standard capitalization rules in several places.
Dean
parents: 1347
diff changeset
   947
                                            (string.Equals(folder.EntryID, acctSettings.SentFolderEntryId)))
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   948
                                        {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   949
                                            sentFolder = folder;
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   950
                                            break;
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   951
                                        }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   952
1516
0a838ded02dd comment out all ReleaseComObject()
Volker Birk <vb@pep-project.org>
parents: 1511
diff changeset
   953
                                        // Marshal.ReleaseComObject(folder);
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   954
                                        folder = null;
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   955
                                    }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   956
                                }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   957
                            }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   958
                        }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   959
                        catch
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   960
                        {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   961
                            if (sentFolder != null)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   962
                            {
1507
d315f34fae0b remove a couple of ReleaseComObject() calls
Volker Birk <vb@pep-project.org>
parents: 1503
diff changeset
   963
                                // Marshal.ReleaseComObject(sentFolder);
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   964
                                sentFolder = null;
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   965
                            }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   966
                        }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   967
                    }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   968
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   969
                    // Step 3
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   970
                    if (sentFolder == null)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   971
                    {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   972
                        try
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   973
                        {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   974
                            //Search for folder by name
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   975
                            if (folders != null)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   976
                            {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   977
                                for (int i = 1; i <= folders.Count; i++)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   978
                                {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   979
                                    folder = (Outlook.Folder)folders[i];
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   980
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   981
                                    if (folder != null)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   982
                                    {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   983
                                        if ((string.IsNullOrEmpty(folder.Name) == false) &&
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   984
                                            (folder.Name.Trim().StartsWith(Globals.CUSTOM_SENT_FOLDER_NAME, StringComparison.OrdinalIgnoreCase)))
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   985
                                        {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   986
                                            sentFolder = folder;
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   987
                                            break;
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   988
                                        }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   989
1516
0a838ded02dd comment out all ReleaseComObject()
Volker Birk <vb@pep-project.org>
parents: 1511
diff changeset
   990
                                        // Marshal.ReleaseComObject(folder);
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   991
                                        folder = null;
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   992
                                    }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   993
                                }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   994
                            }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   995
                        }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   996
                        catch
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   997
                        {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   998
                            if (sentFolder != null)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
   999
                            {
1507
d315f34fae0b remove a couple of ReleaseComObject() calls
Volker Birk <vb@pep-project.org>
parents: 1503
diff changeset
  1000
                                // Marshal.ReleaseComObject(sentFolder);
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1001
                                sentFolder = null;
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1002
                            }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1003
                        }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1004
                    }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1005
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1006
                    // Step 4
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1007
                    if (sentFolder == null)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1008
                    {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1009
                        try
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1010
                        {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1011
                            // Create folder
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1012
                            if (folders != null)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1013
                            {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1014
                                sentFolder = (Outlook.Folder)folders.Add(Globals.CUSTOM_SENT_FOLDER_NAME);
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1015
                            }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1016
                        }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1017
                        catch (Exception ex)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1018
                        {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1019
                            if (sentFolder != null)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1020
                            {
1507
d315f34fae0b remove a couple of ReleaseComObject() calls
Volker Birk <vb@pep-project.org>
parents: 1503
diff changeset
  1021
                                // Marshal.ReleaseComObject(sentFolder);
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1022
                                sentFolder = null;
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1023
                            }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1024
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1025
                            Log.Error("CreateNewSentMail: No Sent folder found and no new Sent folder could be created because of the following error: " + ex.ToString());
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1026
                        }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1027
                    }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1028
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1029
                    if (sentFolder != null)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1030
                    {
1348
c394606d6f6c Change to .net standard capitalization rules in several places.
Dean
parents: 1347
diff changeset
  1031
                        acctSettings.SentFolderEntryId = sentFolder.EntryID;
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1032
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1033
                        // Create the basic sent mail item
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1034
                        sentMailItem = (Outlook.MailItem)sentFolder.Items.Add(Outlook.OlItemType.olMailItem);
1299
523bb6ad5ccc Add setSender parameter to ApplyTo() method and only use it in CreateNewSentMail()
Thomas
parents: 1287
diff changeset
  1035
                        sentMessage.ApplyTo(sentMailItem, false, true); // Do NOT include internal Header Fields (MAPI properties)!
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1036
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1037
                        // Set the date and time the mail item was sent
1275
2a69f2f93ca3 OUT-83: Catch more MAPIProperty.SetProperty errors when creating a new sent message.
Dean
parents: 1271
diff changeset
  1038
                        try
2a69f2f93ca3 OUT-83: Catch more MAPIProperty.SetProperty errors when creating a new sent message.
Dean
parents: 1271
diff changeset
  1039
                        {
1350
8fdce6140e29 Change more places to .net standard capitalization rules.
Dean
parents: 1349
diff changeset
  1040
                            MapiHelper.SetProperty(sentMailItem, MapiProperty.PidTagClientSubmitTime, DateTime.Now.ToUniversalTime());
1275
2a69f2f93ca3 OUT-83: Catch more MAPIProperty.SetProperty errors when creating a new sent message.
Dean
parents: 1271
diff changeset
  1041
                        }
2a69f2f93ca3 OUT-83: Catch more MAPIProperty.SetProperty errors when creating a new sent message.
Dean
parents: 1271
diff changeset
  1042
                        catch { }
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1043
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1044
                        // Set flags
1275
2a69f2f93ca3 OUT-83: Catch more MAPIProperty.SetProperty errors when creating a new sent message.
Dean
parents: 1271
diff changeset
  1045
                        try
2a69f2f93ca3 OUT-83: Catch more MAPIProperty.SetProperty errors when creating a new sent message.
Dean
parents: 1271
diff changeset
  1046
                        {
1350
8fdce6140e29 Change more places to .net standard capitalization rules.
Dean
parents: 1349
diff changeset
  1047
                            messageFlags = (System.Int32)MapiHelper.GetProperty(sentMailItem, MapiProperty.PidTagMessageFlags);
8fdce6140e29 Change more places to .net standard capitalization rules.
Dean
parents: 1349
diff changeset
  1048
                            messageFlags &= ~((System.Int32)MapiPropertyValue.EnumPidTagMessageFlags.mfUnsent);  // Clear UNSENT flag -- must be done before save
8fdce6140e29 Change more places to .net standard capitalization rules.
Dean
parents: 1349
diff changeset
  1049
                            messageFlags |= ((System.Int32)MapiPropertyValue.EnumPidTagMessageFlags.mfRead);     // Mark as read
8fdce6140e29 Change more places to .net standard capitalization rules.
Dean
parents: 1349
diff changeset
  1050
                            MapiHelper.SetProperty(sentMailItem, MapiProperty.PidTagMessageFlags, messageFlags);
1275
2a69f2f93ca3 OUT-83: Catch more MAPIProperty.SetProperty errors when creating a new sent message.
Dean
parents: 1271
diff changeset
  1051
                        }
2a69f2f93ca3 OUT-83: Catch more MAPIProperty.SetProperty errors when creating a new sent message.
Dean
parents: 1271
diff changeset
  1052
                        catch { }
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1053
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1054
                        // Save pEp rating
1275
2a69f2f93ca3 OUT-83: Catch more MAPIProperty.SetProperty errors when creating a new sent message.
Dean
parents: 1271
diff changeset
  1055
                        try
2a69f2f93ca3 OUT-83: Catch more MAPIProperty.SetProperty errors when creating a new sent message.
Dean
parents: 1271
diff changeset
  1056
                        {
1303
5b20f1bee571 Add and implement class for MailItem extension methods.
Dean
parents: 1299
diff changeset
  1057
                            sentMailItem.SetPEPProperty(MailItemExtensions.PEPProperty.Rating, storedRating);
1275
2a69f2f93ca3 OUT-83: Catch more MAPIProperty.SetProperty errors when creating a new sent message.
Dean
parents: 1271
diff changeset
  1058
                        }
2a69f2f93ca3 OUT-83: Catch more MAPIProperty.SetProperty errors when creating a new sent message.
Dean
parents: 1271
diff changeset
  1059
                        catch { }
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1060
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1061
                        // Save changes to the mail item (must be done last for some properties)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1062
                        sentMailItem.Save();
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1063
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1064
                        /* Attempt to move to the sent folder.
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1065
                         * For ActiveSync accounts, this will fail with the error:
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1066
                         * 'Sorry, Exchange ActiveSync doesn't support what you're trying to do.'
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1067
                         * This is because the .Items.Add(folder) will ignore the specified folder and create in local Drafts.
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1068
                         * Then "Exchange ActiveSync doesn’t support the Drafts folder" so it can't be moved out.
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1069
                         * Even in the Outlook UI a draft cannot be 'dragged' out of the drafts folder.
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1070
                         */
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1071
                        try
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1072
                        {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1073
                            sentMailItem.Move(sentFolder);
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1074
                        }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1075
                        catch { }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1076
                    }
738
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
  1077
                }
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
  1078
            }
743
5bad37bca12f Do not include optional properties when calling .ApplyTo for a sent mail item.
Dean Looyengoed
parents: 738
diff changeset
  1079
            catch (Exception ex)
5bad37bca12f Do not include optional properties when calling .ApplyTo for a sent mail item.
Dean Looyengoed
parents: 738
diff changeset
  1080
            {
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1081
                Log.Error("CreateNewSentMail: Error occured, " + ex.ToString());
886
7dbe50a11f81 Avoid code analysis warning CA2200.
Dean Looyengoed
parents: 883
diff changeset
  1082
                throw;
743
5bad37bca12f Do not include optional properties when calling .ApplyTo for a sent mail item.
Dean Looyengoed
parents: 738
diff changeset
  1083
            }
738
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
  1084
            finally
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
  1085
            {
2328
db219aed7eaa Reorder setting rules and view folders. Remove some superfluous return statements.
Thomas
parents: 2293
diff changeset
  1086
                folder = null;
db219aed7eaa Reorder setting rules and view folders. Remove some superfluous return statements.
Thomas
parents: 2293
diff changeset
  1087
                folders = null;
db219aed7eaa Reorder setting rules and view folders. Remove some superfluous return statements.
Thomas
parents: 2293
diff changeset
  1088
                ns = null;
db219aed7eaa Reorder setting rules and view folders. Remove some superfluous return statements.
Thomas
parents: 2293
diff changeset
  1089
                rootFolder = null;
db219aed7eaa Reorder setting rules and view folders. Remove some superfluous return statements.
Thomas
parents: 2293
diff changeset
  1090
                sentFolder = null;
db219aed7eaa Reorder setting rules and view folders. Remove some superfluous return statements.
Thomas
parents: 2293
diff changeset
  1091
                sentMailItem = null;
738
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
  1092
            }
ac649e82fd98 Create and save the sent mail item exactly the same as how it was composed.
Dean Looyengoed
parents: 726
diff changeset
  1093
        }
1340
9b3c8e11f274 OUT-117: Mostly formatting fixes
Dean
parents: 1337
diff changeset
  1094
745
832f49345e6f Add PermanentlyDelete method to remove any drafts or original mail item after send.
Dean Looyengoed
parents: 744
diff changeset
  1095
        /// <summary>
671
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1096
        /// Gets whether the given account is trusted (on the account whitelist).
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1097
        /// Character case and whitespace is ignored during comparison.
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1098
        /// </summary>
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1099
        /// <param name="address">The address of the account.</param>
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1100
        /// <returns>True if the account with the given address is trusted by default (on the whitelist), otherwise false.</returns>
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1101
        private bool GetIsAccountTrusted(string address)
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1102
        {
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1103
            bool isTrusted = false;
1349
77c31d9ef5a6 Switch to .ToUpperInvariant().
Dean
parents: 1348
diff changeset
  1104
            string searchAddress = address.ToUpperInvariant().Trim();
671
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1105
            string searchDomain = searchAddress.Contains("@") ? searchAddress.Substring(searchAddress.LastIndexOf("@")) : null;
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1106
            string whitelistAccount;
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1107
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1108
            for (int i = 0; i < this._Settings.AccountWhitelist.Length; i++)
671
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1109
            {
1349
77c31d9ef5a6 Switch to .ToUpperInvariant().
Dean
parents: 1348
diff changeset
  1110
                whitelistAccount = this._Settings.AccountWhitelist[i].ToUpperInvariant().Trim();
671
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1111
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1112
                // Check for exact match
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1113
                if (searchAddress == whitelistAccount)
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1114
                {
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1115
                    isTrusted = true;
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1116
                    break;
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1117
                }
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1118
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1119
                // Check for domain match
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1120
                if ((searchDomain != null) &&
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1121
                    whitelistAccount.StartsWith("@") &&
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1122
                    (searchDomain == whitelistAccount))
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1123
                {
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1124
                    isTrusted = true;
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1125
                    break;
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1126
                }
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1127
            }
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1128
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1129
            return (isTrusted);
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1130
        }
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1131
57fdc1b20a02 Add method to get account trust by searching the whitelist.
Dean Looyengoed
parents: 667
diff changeset
  1132
        /// <summary>
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1133
        /// 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
  1134
        /// 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
  1135
        /// </summary>
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1136
        /// <param name="state">The state to copy data from.</param>
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1137
        internal void SetOptionsState(FormControlOptions.State state)
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1138
        {
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1139
            bool isBlacklisted;
839
a9a34f09b857 Implement blacklist.
Dean Looyengoed
parents: 838
diff changeset
  1140
            string fpr1;
a9a34f09b857 Implement blacklist.
Dean Looyengoed
parents: 838
diff changeset
  1141
            string fpr2;
a9a34f09b857 Implement blacklist.
Dean Looyengoed
parents: 838
diff changeset
  1142
            string[] blacklist;
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1143
            PEPSettings.PEPAccountSettings acctSettings;
839
a9a34f09b857 Implement blacklist.
Dean Looyengoed
parents: 838
diff changeset
  1144
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1145
            if (state != null)
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1146
            {
1382
f37576e7edbb OUT-87: Support adding new fingerprints to the blacklist.
Dean
parents: 1379
diff changeset
  1147
                // Get the blacklist
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1148
                try
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1149
                {
1379
bd9b72ad2f54 Spelling correction.
Dean
parents: 1374
diff changeset
  1150
                    blacklist = ThisAddIn.PEPEngine.BlacklistRetrieve();
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1151
                }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1152
                catch (COMException ex)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1153
                {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1154
                    blacklist = new string[0];
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1155
                    Log.Error("SetOptionsState: Error getting blacklist from engine. " + ex.ToString());
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1156
                }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1157
1382
f37576e7edbb OUT-87: Support adding new fingerprints to the blacklist.
Dean
parents: 1379
diff changeset
  1158
                // Remove any fingerprints no longer in the engine blacklist
839
a9a34f09b857 Implement blacklist.
Dean Looyengoed
parents: 838
diff changeset
  1159
                if (blacklist != null)
a9a34f09b857 Implement blacklist.
Dean Looyengoed
parents: 838
diff changeset
  1160
                {
a9a34f09b857 Implement blacklist.
Dean Looyengoed
parents: 838
diff changeset
  1161
                    for (int i = (blacklist.Length - 1); i >= 0; i--)
a9a34f09b857 Implement blacklist.
Dean Looyengoed
parents: 838
diff changeset
  1162
                    {
a9a34f09b857 Implement blacklist.
Dean Looyengoed
parents: 838
diff changeset
  1163
                        fpr1 = this.RemoveFprFormatting(blacklist[i]);
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1164
                        isBlacklisted = false;
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1165
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1166
                        if (string.IsNullOrEmpty(fpr1) == false)
839
a9a34f09b857 Implement blacklist.
Dean Looyengoed
parents: 838
diff changeset
  1167
                        {
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1168
                            // Check if fingerprint is still blacklisted
1382
f37576e7edbb OUT-87: Support adding new fingerprints to the blacklist.
Dean
parents: 1379
diff changeset
  1169
                            foreach (KVPair<PEPIdentity, bool> entry in state.Blacklist)
839
a9a34f09b857 Implement blacklist.
Dean Looyengoed
parents: 838
diff changeset
  1170
                            {
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1171
                                fpr2 = this.RemoveFprFormatting(entry.Key.Fingerprint);
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1172
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1173
                                // Value is true if the entry is blacklisted
1382
f37576e7edbb OUT-87: Support adding new fingerprints to the blacklist.
Dean
parents: 1379
diff changeset
  1174
                                if ((string.Equals(fpr1, fpr2, StringComparison.OrdinalIgnoreCase)) &&
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1175
                                    (entry.Value))
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1176
                                {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1177
                                    isBlacklisted = true;
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1178
                                    break;
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1179
                                }
839
a9a34f09b857 Implement blacklist.
Dean Looyengoed
parents: 838
diff changeset
  1180
                            }
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1181
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1182
                            if (isBlacklisted == false)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1183
                            {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1184
                                try
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1185
                                {
1337
6b93b1a3b751 OUT-117: Catching up rename-refactorings from COM-24, COM-29, COM-30, COM-31
Markus Schaber <markus@pep-security.net>
parents: 1328
diff changeset
  1186
                                    ThisAddIn.PEPEngine.BlacklistDelete(fpr1);
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1187
                                }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1188
                                catch (COMException ex)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1189
                                {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1190
                                    Log.Error("SetOptionsState: Failed to delete blacklist entry, " + ex.ToString());
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1191
                                }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1192
                            }
839
a9a34f09b857 Implement blacklist.
Dean Looyengoed
parents: 838
diff changeset
  1193
                        }
a9a34f09b857 Implement blacklist.
Dean Looyengoed
parents: 838
diff changeset
  1194
                    }
a9a34f09b857 Implement blacklist.
Dean Looyengoed
parents: 838
diff changeset
  1195
                }
a9a34f09b857 Implement blacklist.
Dean Looyengoed
parents: 838
diff changeset
  1196
1382
f37576e7edbb OUT-87: Support adding new fingerprints to the blacklist.
Dean
parents: 1379
diff changeset
  1197
                // Add any new fingerprints to the engine blacklist
f37576e7edbb OUT-87: Support adding new fingerprints to the blacklist.
Dean
parents: 1379
diff changeset
  1198
                foreach (KVPair<PEPIdentity, bool> entry in state.Blacklist)
839
a9a34f09b857 Implement blacklist.
Dean Looyengoed
parents: 838
diff changeset
  1199
                {
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1200
                    fpr1 = this.RemoveFprFormatting(entry.Key.Fingerprint);
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1201
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1202
                    // Value is true if the entry is blacklisted
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1203
                    if ((entry.Value) &&
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1204
                        (string.IsNullOrEmpty(fpr1) == false))
839
a9a34f09b857 Implement blacklist.
Dean Looyengoed
parents: 838
diff changeset
  1205
                    {
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1206
                        try
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1207
                        {
1337
6b93b1a3b751 OUT-117: Catching up rename-refactorings from COM-24, COM-29, COM-30, COM-31
Markus Schaber <markus@pep-security.net>
parents: 1328
diff changeset
  1208
                            if (ThisAddIn.PEPEngine.BlacklistIsListed(fpr1) == false)
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1209
                            {
1337
6b93b1a3b751 OUT-117: Catching up rename-refactorings from COM-24, COM-29, COM-30, COM-31
Markus Schaber <markus@pep-security.net>
parents: 1328
diff changeset
  1210
                                ThisAddIn.PEPEngine.BlacklistAdd(fpr1);
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1211
                            }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1212
                        }
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1213
                        catch (COMException ex)
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1214
                        {
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1215
                            Log.Error("SetOptionsState: Failed to add new blacklist entry, " + ex.ToString());
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1216
                        }
839
a9a34f09b857 Implement blacklist.
Dean Looyengoed
parents: 838
diff changeset
  1217
                    }
a9a34f09b857 Implement blacklist.
Dean Looyengoed
parents: 838
diff changeset
  1218
                }
1250
e219136cec9d OUT-87: Complete the new blacklist implementation.
Dean
parents: 1249
diff changeset
  1219
1460
0b65f50c102e OUT-162: OUT-164: OUT-176: Allow managing a separate display state for account options.
Dean
parents: 1455
diff changeset
  1220
                foreach (FormControlOptions.AccountState entry in state.AccountSettingsList)
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1221
                {
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1222
                    /* pEp internally uses account types as defined by microsoft.
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1223
                     * This means they have 'ol' before the type (Example: 'olImap').
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1224
                     * This isn't always user friendly so for the options UI the 'ol' is removed.
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1225
                     * However, when comparing again with the settings list, this 'ol' must be added back.
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1226
                     */
1522
cc9a14ce8514 OUT-170: Exlude identity. Also initial implementation of new NotifyHandshake with synchronization signal.
Thomas
parents: 1519
diff changeset
  1227
                    acctSettings = this._Settings.GetAccountSettings(entry.SmtpAddress);
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1228
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1229
                    if (acctSettings != null)
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1230
                    {
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1231
                        // Modify existing value
1348
c394606d6f6c Change to .net standard capitalization rules in several places.
Dean
parents: 1347
diff changeset
  1232
                        // The following are skipped: SentFolderEntryId, SmtpAddress & Type
1790
314f3162286c Implement options UI
Thomas
parents: 1784
diff changeset
  1233
                        acctSettings.IsDecryptAlwaysEnabled = entry.IsDecryptAlwaysEnabled;
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1234
                        acctSettings.IsPEPEnabled = entry.IsPEPEnabled;
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1235
                        acctSettings.IsSecureStorageEnabled = entry.IsSecureStorageEnabled;
1488
cc7028d7409a OUT-170: Add IsSyncEnabled in options and settings.
Dean
parents: 1487
diff changeset
  1236
                        acctSettings.IsSyncEnabled = entry.IsSyncEnabled;
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1237
                    }
1166
5f600ac7b163 Remove 'ol' from account type when displayed in the options UI.
Dean
parents: 1155
diff changeset
  1238
                    else
5f600ac7b163 Remove 'ol' from account type when displayed in the options UI.
Dean
parents: 1155
diff changeset
  1239
                    {
1460
0b65f50c102e OUT-162: OUT-164: OUT-176: Allow managing a separate display state for account options.
Dean
parents: 1455
diff changeset
  1240
                        Log.Warning("SetOptionsState: Existing account settings not found.");
1166
5f600ac7b163 Remove 'ol' from account type when displayed in the options UI.
Dean
parents: 1155
diff changeset
  1241
                    }
203
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1242
                }
44dac4bb337a Complete the state management in both the options form and this add-in.
Dean Looyengoed
parents: 201
diff changeset
  1243
2432
22efd23b72f6 OUT-520: Add option to hide/show pEp internal messages
Thomas
parents: 2430
diff changeset
  1244
                // Un/set rules and view filters if necessary
22efd23b72f6 OUT-520: Add option to hide/show pEp internal messages
Thomas
parents: 2430
diff changeset
  1245
                if (state.HideInternalMessages != this._Settings.HideInternalMessages)
22efd23b72f6 OUT-520: Add option to hide/show pEp internal messages
Thomas
parents: 2430
diff changeset
  1246
                {
2501
ed057eb9a7c4 Add 'pEp Processing' category and use it to hide messages during processing
Thomas
parents: 2499
diff changeset
  1247
                    this.SetRules(state.HideInternalMessages);
2432
22efd23b72f6 OUT-520: Add option to hide/show pEp internal messages
Thomas
parents: 2430
diff changeset
  1248
                }
22efd23b72f6 OUT-520: Add option to hide/show pEp internal messages
Thomas
parents: 2430
diff changeset
  1249
                this._Settings.HideInternalMessages = state.HideInternalMessages;
22efd23b72f6 OUT-520: Add option to hide/show pEp internal messages
Thomas
parents: 2430
diff changeset
  1250
1262
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1251
                this._Settings.IsAutoUpdateEnabled = state.IsAutoUpdateEnabled;
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1252
                this._Settings.IsEncryptAllAccountsEnabled = state.IsEncryptAllAccountsEnabled;
92840238d7af Manual merge of ThisAddIn with latest default branch code.
Dean
parents: 1261
diff changeset
  1253
                this._Settings.IsKeyServerUsed = state.IsKeyServerUsed;
1314
4b4f0b1943fb OUT-109: Implement option to show/hide the Store Protected button.
Dean
parents: 1304
diff changeset