Skip to content

Commit f1b0444

Browse files
authored
Merge pull request #31 from FlexConfirmMail/do-not-block-delayed-send
Fix a bug that delayed sending is blocked
2 parents 23a2567 + 7e187b8 commit f1b0444

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

ThisAddIn.cs

+25-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Windows.Interop;
55
using Outlook = Microsoft.Office.Interop.Outlook;
66
using System.Collections.Generic;
7+
using System;
78

89
namespace FlexConfirmMail
910
{
@@ -14,6 +15,8 @@ public partial class ThisAddIn
1415
private Outlook.Inspectors Inspectors { get; set; } = null;
1516
private Dictionary<string, Outlook.MailItem> SelectedMailDictionary { get; set; } = new Dictionary<string, Outlook.MailItem>();
1617
private Dictionary<string, List<RecipientInfo>> EntryIdToOriginalRecipientsDictionary { get; set; } = new Dictionary<string, List<RecipientInfo>>();
18+
private string OutBoxFolderPath { get; set; } = null;
19+
1720

1821
private void ThisAddIn_Startup(object sender, System.EventArgs e)
1922
{
@@ -26,7 +29,16 @@ private void ThisAddIn_Startup(object sender, System.EventArgs e)
2629
}
2730
Explorers.NewExplorer += new Outlook.ExplorersEvents_NewExplorerEventHandler(ThisAddIn_NewExplorer);
2831
Inspectors = Application.Inspectors;
29-
Inspectors.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(ThisAddIn_NewInspector);
32+
Inspectors.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(ThisAddIn_NewInspector);
33+
try
34+
{
35+
OutBoxFolderPath = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox).FolderPath;
36+
}
37+
catch
38+
{
39+
// If the target folder type does not exist, Outlook raises an error.
40+
// It is a possible situation, so ignore it.
41+
}
3042
ShowBanner();
3143
}
3244

@@ -69,7 +81,18 @@ private void ThisAddIn_NewInspector(Outlook.Inspector inspector)
6981

7082
private void ThisAddIn_SelectionChange()
7183
{
72-
Outlook.Explorer acriveExplorer = Application.ActiveExplorer();
84+
Outlook.Explorer acriveExplorer = Application.ActiveExplorer();
85+
if (!string.IsNullOrEmpty(OutBoxFolderPath) &&
86+
StringComparer.InvariantCultureIgnoreCase.Equals(acriveExplorer.CurrentFolder.FolderPath, OutBoxFolderPath))
87+
{
88+
// When deferred delivery is enabled, a mail is moved to the outbox and delivered after spending the delay time.
89+
// If we access any of properties of the mail in the outbox, the mail is regarded as "edited" and not delivered
90+
// even after spending the delay time.
91+
// So if the folder is the outbox, return before accessing properties of the mail.
92+
// Note that if a mail in the outbox is opened with a new inspector, it is regarded as "edited", which is Outlook's
93+
// specification, so we don't add this check for ThisAddIn_NewInspector.
94+
return;
95+
}
7396
if (acriveExplorer.Selection.Count > 0)
7497
{
7598
object item = acriveExplorer.Selection[1];

0 commit comments

Comments
 (0)