From 8980a505b1e694dc2a0c48d7d02d79928dff6322 Mon Sep 17 00:00:00 2001 From: RKrom Date: Thu, 14 Feb 2013 06:43:40 +0000 Subject: [PATCH] Changed the EmailDestination to work if Outlook is installed as MAPI client but the Outlook plugin is not installed. Also made some progress on the MAPI Recipient properties, but this still doesn't work. git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2486 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- Greenshot/Destinations/EmailDestination.cs | 14 ++++++++++--- Greenshot/Helpers/MailHelper.cs | 23 ++++++++++++++-------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/Greenshot/Destinations/EmailDestination.cs b/Greenshot/Destinations/EmailDestination.cs index 3233e11ae..173a31291 100644 --- a/Greenshot/Destinations/EmailDestination.cs +++ b/Greenshot/Destinations/EmailDestination.cs @@ -49,9 +49,8 @@ namespace Greenshot.Destinations { isActiveFlag = true; mapiClient = EmailConfigHelper.GetMapiClient(); if (!string.IsNullOrEmpty(mapiClient)) { - if (mapiClient.ToLower().Contains("microsoft outlook")) { - isActiveFlag = false; - } + // Active as we have a mapi client, can be disabled later + isActiveFlag = true; } } } @@ -84,6 +83,15 @@ namespace Greenshot.Destinations { public override bool isActive { get { + if (isActiveFlag) { + // Disable if the office plugin is installed and the client is outlook + Type outlookdestination = Type.GetType("GreenshotOfficePlugin.OutlookDestination,GreenshotOfficePlugin"); + if (outlookdestination != null) { + if (mapiClient.ToLower().Contains("microsoft outlook")) { + isActiveFlag = false; + } + } + } return base.isActive && isActiveFlag; } } diff --git a/Greenshot/Helpers/MailHelper.cs b/Greenshot/Helpers/MailHelper.cs index f1da599e8..dea02bd4f 100644 --- a/Greenshot/Helpers/MailHelper.cs +++ b/Greenshot/Helpers/MailHelper.cs @@ -55,10 +55,16 @@ namespace Greenshot.Helpers { public static void SendImage(string fullPath, string title) { MapiMailMessage message = new MapiMailMessage(title, null); message.Files.Add(fullPath); - message._recipientCollection.Add(new Recipient(conf.MailApiTo, RecipientType.To)); - message._recipientCollection.Add(new Recipient(conf.MailApiCC, RecipientType.CC)); - message._recipientCollection.Add(new Recipient(conf.MailApiBCC, RecipientType.BCC)); - message.ShowDialog(); + if (!string.IsNullOrEmpty(conf.MailApiTo)) { + message._recipientCollection.Add(new Recipient(conf.MailApiTo, RecipientType.To)); + } + if (!string.IsNullOrEmpty(conf.MailApiCC)) { + message._recipientCollection.Add(new Recipient(conf.MailApiCC, RecipientType.CC)); + } + if (!string.IsNullOrEmpty(conf.MailApiTo)) { + message._recipientCollection.Add(new Recipient(conf.MailApiBCC, RecipientType.BCC)); + } + message.ShowDialog(); } @@ -251,7 +257,9 @@ namespace Greenshot.Helpers { // Check for error if (errorCode != MAPI_CODES.SUCCESS && errorCode != MAPI_CODES.USER_ABORT) { - _LogErrorMapi(errorCode); + string errorText = GetMapiError(errorCode); + LOG.Error("Error sending MAPI Email. Error: " + errorText + " (code = " + errorCode + ")."); + MessageBox.Show(errorText, "Mail (MAPI) destination", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } @@ -350,7 +358,7 @@ namespace Greenshot.Helpers { /// /// Logs any Mapi errors. /// - private void _LogErrorMapi(MAPI_CODES errorCode) { + private string GetMapiError(MAPI_CODES errorCode) { string error = string.Empty; @@ -437,8 +445,7 @@ namespace Greenshot.Helpers { error = "MAPI Invalid parameter."; break; } - - LOG.Error("Error sending MAPI Email. Error: " + error + " (code = " + errorCode + ")."); + return error; } #endregion Private Methods