Skip to content

Commit

Permalink
Fix a bug that delayed sending is blocked if a main in outbox is sele…
Browse files Browse the repository at this point in the history
…cted.

When delayed sending is enabled, a mail is moved to the outbox and sent after spending the delay time.
If we access any of properties of the mail in the outbox, the mail is regarded as "edited" and not sent
even after spending the delay time.
So if the folder is the outbox, return before accessing properties of the mail.
  • Loading branch information
HashidaTKS committed Aug 8, 2024
1 parent 23a2567 commit 700a366
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions ThisAddIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Windows.Interop;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Collections.Generic;
using System;

namespace FlexConfirmMail
{
Expand All @@ -14,6 +15,8 @@ public partial class ThisAddIn
private Outlook.Inspectors Inspectors { get; set; } = null;
private Dictionary<string, Outlook.MailItem> SelectedMailDictionary { get; set; } = new Dictionary<string, Outlook.MailItem>();
private Dictionary<string, List<RecipientInfo>> EntryIdToOriginalRecipientsDictionary { get; set; } = new Dictionary<string, List<RecipientInfo>>();
private string OutBoxFolderPath { get; set; } = null;


private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Expand All @@ -26,7 +29,16 @@ private void ThisAddIn_Startup(object sender, System.EventArgs e)
}
Explorers.NewExplorer += new Outlook.ExplorersEvents_NewExplorerEventHandler(ThisAddIn_NewExplorer);
Inspectors = Application.Inspectors;
Inspectors.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(ThisAddIn_NewInspector);
Inspectors.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(ThisAddIn_NewInspector);
try
{
OutBoxFolderPath = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox).FolderPath;
}
catch
{
// If the target folder type does not exist, Outlook raises an error.
// It is a possible situation, so ignore it.
}
ShowBanner();
}

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

private void ThisAddIn_SelectionChange()
{
Outlook.Explorer acriveExplorer = Application.ActiveExplorer();
Outlook.Explorer acriveExplorer = Application.ActiveExplorer();
if (!string.IsNullOrEmpty(OutBoxFolderPath) &&
StringComparer.InvariantCultureIgnoreCase.Equals(acriveExplorer.CurrentFolder.FolderPath, OutBoxFolderPath))
{
// When delayed sending is enabled, a mail is moved to the outbox and sent after spending the delay time.
// If we access any of properties of the mail in the outbox, the mail is regarded as "edited" and not sent
// even after spending the delay time.
// So if the folder is the outbox, return before accessing properties of the mail.
// Note that if a mail in the outbox is opened with a new inspector, it is regarded as "edited", which is Outlook's
// specification, so we don't add this check for ThisAddIn_NewInspector.
return;
}
if (acriveExplorer.Selection.Count > 0)
{
object item = acriveExplorer.Selection[1];
Expand Down

0 comments on commit 700a366

Please sign in to comment.