-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathThisAddIn.cs
More file actions
115 lines (97 loc) · 3.3 KB
/
Copy pathThisAddIn.cs
File metadata and controls
115 lines (97 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using FlexConfirmMail.Config;
using FlexConfirmMail.Dialog;
using System.Windows.Forms;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace FlexConfirmMail
{
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.ItemSend += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemSendEventHandler(ThisAddIn_ItemSend);
ShowBanner();
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
private void ThisAddIn_ItemSend(object Item, ref bool Cancel)
{
Outlook.MailItem mail = (Outlook.MailItem)Item;
// First of all, enable Cancel flag. This makes Outlook
// NOT to send the mail even if something goes awry.
Cancel = true;
try
{
if (DoCheck(mail))
{
Cancel = false;
QueueLogger.Log("Check finished [send=yes]");
}
else
{
QueueLogger.Log("Check finished [send=no]");
}
}
catch (System.Exception e)
{
QueueLogger.Log(e);
}
// Never send a message with a debug build!
#if DEBUG
Cancel = true;
#endif
}
private void ShowBanner()
{
try
{
QueueLogger.Log($"Start {Global.AppName} {Global.Version}");
QueueLogger.Log($"* Outlook {Application.Version}");
QueueLogger.Log($"* {System.Environment.OSVersion.VersionString}");
QueueLogger.Log($"* AppData is {FileUtil.GetUserDir()}");
}
catch (System.Exception e)
{
QueueLogger.Log(e);
}
}
private bool DoCheck(Outlook.MailItem mail)
{
QueueLogger.Log($"Setup config for mail (Subject={mail.Subject})");
ConfigData config = new ConfigData();
FileLoader.Load(config, FileUtil.GetUserDir());
MainDialog mainDialog = new MainDialog(config, mail);
if (mainDialog.SkipConfirm())
{
return true;
}
if (mainDialog.ShowDialog() == true)
{
if (!config.CountEnabled)
{
return true;
}
if (new CountDialog(config).ShowDialog() == true)
{
return true;
}
}
return false;
}
protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
return new Ribbon();
}
#region VSTO で生成されたコード
/// <summary>
/// デザイナーのサポートに必要なメソッドです。
/// このメソッドの内容をコード エディターで変更しないでください。
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}