From 3adf9e9a51bd5e485e50d0298f9d226db85c6173 Mon Sep 17 00:00:00 2001 From: Robin Krom Date: Thu, 18 Mar 2021 19:25:54 +0100 Subject: [PATCH] BUG-2743: Cleanup of MAPI & Outlook logic, removed the check on "HKEY_LOCAL_MACHINE\SOFTWARE(\WOW6432Node)\Microsoft\Windows Messaging Subsystem" with the MAPI value in favor of the HKEY_LOCAL_MACHINE\SOFTWARE(\WOW6432Node)\Clients\Mail where the default value contains the name, this should hopefully solve some issues. --- Greenshot/Destinations/EmailDestination.cs | 16 +++--- Greenshot/Helpers/MailHelper.cs | 10 +--- .../Destinations/OutlookDestination.cs | 24 +++++++-- GreenshotPlugin/Core/EmailConfigHelper.cs | 54 ------------------- 4 files changed, 28 insertions(+), 76 deletions(-) delete mode 100644 GreenshotPlugin/Core/EmailConfigHelper.cs diff --git a/Greenshot/Destinations/EmailDestination.cs b/Greenshot/Destinations/EmailDestination.cs index 0ba93ff59..326e27e9c 100644 --- a/Greenshot/Destinations/EmailDestination.cs +++ b/Greenshot/Destinations/EmailDestination.cs @@ -26,6 +26,7 @@ using Greenshot.Configuration; using Greenshot.Helpers; using GreenshotPlugin.Core; using GreenshotPlugin.Interfaces; +using Microsoft.Win32; namespace Greenshot.Destinations { /// @@ -39,12 +40,9 @@ namespace Greenshot.Destinations { static EmailDestination() { // Logic to decide what email implementation we use - if (!EmailConfigHelper.HasMapi()) return; - - _isActiveFlag = false; - _mapiClient = EmailConfigHelper.GetMapiClient(); + _mapiClient = RegistryHive.LocalMachine.ReadKey64Or32(@"Clients\Mail"); if (!string.IsNullOrEmpty(_mapiClient)) { - // Active as we have a mapi client, can be disabled later + // Active as we have a MAPI client, can be disabled later _isActiveFlag = true; } } @@ -66,11 +64,9 @@ namespace Greenshot.Destinations { if (_isActiveFlag) { // Disable if the office plugin is installed and the client is outlook // TODO: Change this! It always creates an exception, as the plugin has not been loaded the type is not there :( - Type outlookdestination = Type.GetType("GreenshotOfficePlugin.OutlookDestination,GreenshotOfficePlugin"); - if (outlookdestination != null) { - if (_mapiClient.ToLower().Contains("microsoft outlook")) { - _isActiveFlag = false; - } + var outlookDestination = Type.GetType("GreenshotOfficePlugin.OutlookDestination,GreenshotOfficePlugin", false); + if (outlookDestination != null && _mapiClient.ToLower().Contains("microsoft outlook")) { + _isActiveFlag = false; } } return base.IsActive && _isActiveFlag; diff --git a/Greenshot/Helpers/MailHelper.cs b/Greenshot/Helpers/MailHelper.cs index 5111ba2cf..3bc09b5f8 100644 --- a/Greenshot/Helpers/MailHelper.cs +++ b/Greenshot/Helpers/MailHelper.cs @@ -80,15 +80,7 @@ namespace Greenshot.Helpers { // Store the list of currently active windows, so we can make sure we show the email window later! var windowsBefore = WindowDetails.GetVisibleWindows(); - //bool isEmailSend = false; - //if (EmailConfigHelper.HasOutlook() && (CoreConfig.OutputEMailFormat == EmailFormat.OUTLOOK_HTML || CoreConfig.OutputEMailFormat == EmailFormat.OUTLOOK_TXT)) { - // isEmailSend = OutlookExporter.ExportToOutlook(tmpFile, captureDetails); - //} - if (/*!isEmailSend &&*/ EmailConfigHelper.HasMapi()) { - // Fallback to MAPI - // Send the email - SendImage(tmpFile, captureDetails.Title); - } + SendImage(tmpFile, captureDetails.Title); WindowDetails.ActiveNewerWindows(windowsBefore); } diff --git a/GreenshotOfficePlugin/Destinations/OutlookDestination.cs b/GreenshotOfficePlugin/Destinations/OutlookDestination.cs index 65ccf03be..f08269c51 100644 --- a/GreenshotOfficePlugin/Destinations/OutlookDestination.cs +++ b/GreenshotOfficePlugin/Destinations/OutlookDestination.cs @@ -30,6 +30,7 @@ using GreenshotPlugin.IniFile; using GreenshotPlugin.Interfaces; using GreenshotPlugin.Interfaces.Plugin; using Microsoft.Office.Interop.Outlook; +using Microsoft.Win32; namespace GreenshotOfficePlugin.Destinations { /// @@ -47,23 +48,40 @@ namespace GreenshotOfficePlugin.Destinations { private const string MapiClient = "Microsoft Outlook"; private readonly string _outlookInspectorCaption; private readonly OlObjectClass _outlookInspectorType; - private readonly OutlookEmailExporter _outlookEmailExporter = new OutlookEmailExporter(); + private readonly OutlookEmailExporter _outlookEmailExporter = new(); static OutlookDestination() { - if (EmailConfigHelper.HasOutlook()) { + if (HasOutlook()) { IsActiveFlag = true; } ExePath = PluginUtils.GetExePath("OUTLOOK.EXE"); if (ExePath != null && File.Exists(ExePath)) { WindowDetails.AddProcessToExcludeFromFreeze("outlook"); } else { - ExePath = null; + ExePath = GetOutlookExePath(); } if (ExePath == null) { IsActiveFlag = false; } } + + private static string GetOutlookExePath() => RegistryHive.LocalMachine.ReadKey64Or32(@"Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE"); + + /// + /// Check if Outlook is installed + /// + /// Returns true if outlook is installed + private static bool HasOutlook() + { + string outlookPath = GetOutlookExePath(); + if (outlookPath == null) + { + return false; + } + return File.Exists(outlookPath); + } + public OutlookDestination() { } diff --git a/GreenshotPlugin/Core/EmailConfigHelper.cs b/GreenshotPlugin/Core/EmailConfigHelper.cs deleted file mode 100644 index 9eb8a7bfe..000000000 --- a/GreenshotPlugin/Core/EmailConfigHelper.cs +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Greenshot - a free and open source screenshot tool - * Copyright (C) 2007-2021 Thomas Braun, Jens Klingen, Robin Krom - * - * For more information see: http://getgreenshot.org/ - * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -using System.IO; -using Microsoft.Win32; - -namespace GreenshotPlugin.Core { - /// - /// Description of EmailConfigHelper. - /// - public static class EmailConfigHelper { - - public static string GetMapiClient() => RegistryHive.LocalMachine.ReadKey64Or32(@"Clients\Mail"); - - public static bool HasMapi() - { - var value = RegistryHive.LocalMachine.ReadKey64Or32(@"Microsoft\Windows Messaging Subsystem", "MAPI", "0"); - return "1".Equals(value); - } - - public static string GetOutlookExePath() => RegistryHive.LocalMachine.ReadKey64Or32(@"Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE"); - - /// - /// Check if Outlook is installed - /// - /// Returns true if outlook is installed - public static bool HasOutlook() { - string outlookPath = GetOutlookExePath(); - if (outlookPath == null) - { - return false; - } - return File.Exists(outlookPath); - } - } -}