diff --git a/GreenshotOfficePlugin/Destinations/OutlookDestination.cs b/GreenshotOfficePlugin/Destinations/OutlookDestination.cs index 3c957e384..b1440d131 100644 --- a/GreenshotOfficePlugin/Destinations/OutlookDestination.cs +++ b/GreenshotOfficePlugin/Destinations/OutlookDestination.cs @@ -181,8 +181,7 @@ namespace GreenshotOfficePlugin { return ShowPickerMenu(false, surface, captureDetails, destinations); } } else { - OutlookEmailExporter.ExportToOutlook(conf.OutlookEmailFormat, tmpFile, FilenameHelper.FillPattern(conf.EmailSubjectPattern, captureDetails, false), attachmentName, conf.EmailTo, conf.EmailCC, conf.EmailBCC); - exportInformation.ExportMade = true; + exportInformation.ExportMade = OutlookEmailExporter.ExportToOutlook(conf.OutlookEmailFormat, tmpFile, FilenameHelper.FillPattern(conf.EmailSubjectPattern, captureDetails, false), attachmentName, conf.EmailTo, conf.EmailCC, conf.EmailBCC); } } ProcessExport(exportInformation, surface); diff --git a/GreenshotOfficePlugin/OfficeExport/OutlookEmailExporter.cs b/GreenshotOfficePlugin/OfficeExport/OutlookEmailExporter.cs index 1004ea439..894ec7fd7 100644 --- a/GreenshotOfficePlugin/OfficeExport/OutlookEmailExporter.cs +++ b/GreenshotOfficePlugin/OfficeExport/OutlookEmailExporter.cs @@ -28,6 +28,9 @@ using Microsoft.Win32; using Greenshot.Interop; using Greenshot.Interop.IE; using System.Threading; +using System.Runtime.InteropServices; +using System.Windows.Forms; +using GreenshotPlugin.Core; namespace Greenshot.Interop.Office { /// @@ -360,36 +363,26 @@ namespace Greenshot.Interop.Office { break; } // So not save, otherwise the email is always stored in Draft folder.. (newMail.Save();) - try { - newMail.Display(false); - newMail.GetInspector().Activate(); - } catch (Exception ex) { - LOG.Warn("Problem displaying the new email, retrying to display it. Problem:", ex); - Thread retryDisplayEmail = new Thread(delegate() { - int retries = 10; - int retryInXSeconds = 5; - while (retries-- > 0) { - Thread.Sleep(retryInXSeconds * 1000); - try { - newMail.Display(false); - newMail.GetInspector().Activate(); - LOG.InfoFormat("Managed to display the message."); - return; - } catch (Exception displayEx) { - LOG.WarnFormat("Error displaying message: {0}, retrying to show email in {1} seconds... Retries left: {2}", displayEx, retryInXSeconds, retries); + do { + try { + newMail.Display(false); + newMail.GetInspector().Activate(); + break; + } catch (Exception ex) { + // Test for rejected + LOG.Warn("Problem displaying the new email, retrying to display it. Problem:", ex); + COMException comEx = ex.InnerException as COMException; + if (comEx != null && (comEx.ErrorCode == COMWrapper.RPC_E_CALL_REJECTED || comEx.ErrorCode == COMWrapper.RPC_E_FAIL)) { + DialogResult result = MessageBox.Show(PluginUtils.Host.GreenshotForm, Language.GetFormattedString("com_rejected", "Outlook "), Language.GetString("com_rejected_title"), MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); + if (result == DialogResult.OK) { + continue; } } - LOG.WarnFormat("Retry failed, saving message to draft."); - try { - newMail.Save(); - } catch (Exception saveEx) { - LOG.WarnFormat("Saving message to draft failed: {0}", saveEx); - } - }); - retryDisplayEmail.Name = "Retry to display email"; - retryDisplayEmail.IsBackground = true; - retryDisplayEmail.Start(); - } + // Not rejected OR pressed cancel + throw ex; + } + } while (true); + if (newItem != null) { newItem.Dispose(); } diff --git a/GreenshotPlugin/Interop/COMWrapper.cs b/GreenshotPlugin/Interop/COMWrapper.cs index 11d993cd7..d78e42eef 100644 --- a/GreenshotPlugin/Interop/COMWrapper.cs +++ b/GreenshotPlugin/Interop/COMWrapper.cs @@ -35,7 +35,8 @@ namespace Greenshot.Interop { private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(COMWrapper)); private const int MK_E_UNAVAILABLE = -2147221021; private const int CO_E_CLASSSTRING = -2147221005; - private const int RPC_E_CALL_REJECTED = unchecked((int)0x80010001); + public const int RPC_E_CALL_REJECTED = unchecked((int)0x80010001); + public const int RPC_E_FAIL = unchecked((int)0x80004005); #region Private Data @@ -661,7 +662,12 @@ namespace Greenshot.Interop { // Test for rejected COMException comEx = ex as COMException; if (comEx != null && comEx.ErrorCode == RPC_E_CALL_REJECTED) { - DialogResult result = MessageBox.Show(Language.GetString("com_rejected"), Language.GetString("com_rejected_title"), MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); + ComProgIdAttribute progIDAttribute = ComProgIdAttribute.GetAttribute(_InterceptType); + string destinationName = ""; + if (progIDAttribute != null) { + destinationName = progIDAttribute.Value + " "; + } + DialogResult result = MessageBox.Show(PluginUtils.Host.GreenshotForm, Language.GetFormattedString("com_rejected", destinationName), Language.GetString("com_rejected_title"), MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); if (result == DialogResult.OK) { continue; }