4
4
using System . Windows . Interop ;
5
5
using Outlook = Microsoft . Office . Interop . Outlook ;
6
6
using System . Collections . Generic ;
7
+ using System ;
7
8
8
9
namespace FlexConfirmMail
9
10
{
@@ -14,6 +15,8 @@ public partial class ThisAddIn
14
15
private Outlook . Inspectors Inspectors { get ; set ; } = null ;
15
16
private Dictionary < string , Outlook . MailItem > SelectedMailDictionary { get ; set ; } = new Dictionary < string , Outlook . MailItem > ( ) ;
16
17
private Dictionary < string , List < RecipientInfo > > EntryIdToOriginalRecipientsDictionary { get ; set ; } = new Dictionary < string , List < RecipientInfo > > ( ) ;
18
+ private string OutBoxFolderPath { get ; set ; } = null ;
19
+
17
20
18
21
private void ThisAddIn_Startup ( object sender , System . EventArgs e )
19
22
{
@@ -26,7 +29,16 @@ private void ThisAddIn_Startup(object sender, System.EventArgs e)
26
29
}
27
30
Explorers . NewExplorer += new Outlook . ExplorersEvents_NewExplorerEventHandler ( ThisAddIn_NewExplorer ) ;
28
31
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
+ }
30
42
ShowBanner ( ) ;
31
43
}
32
44
@@ -69,7 +81,18 @@ private void ThisAddIn_NewInspector(Outlook.Inspector inspector)
69
81
70
82
private void ThisAddIn_SelectionChange ( )
71
83
{
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
+ }
73
96
if ( acriveExplorer . Selection . Count > 0 )
74
97
{
75
98
object item = acriveExplorer . Selection [ 1 ] ;
0 commit comments