Skip to content

Commit 07a4179

Browse files
authored
Merge pull request #45 from t-miyake/develop
メール送信前の確認画面で添付ファイルを開ける機能を追加
2 parents 3ddb618 + 6a88d0c commit 07a4179

24 files changed

+560
-93
lines changed

OutlookOkan/Models/GenerateCheckList.cs

+42-22
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ internal CheckList GenerateCheckListFromMail<T>(T item, GeneralSetting generalSe
8282
var attachmentsSettingCsv = new ReadAndWriteCsv("AttachmentsSetting.csv");
8383
var attachmentsSettingList = attachmentsSettingCsv.GetCsvRecords<AttachmentsSetting>(attachmentsSettingCsv.LoadCsv<AttachmentsSettingMap>());
8484
if (attachmentsSettingList.Count > 0) attachmentsSetting = attachmentsSettingList[0];
85+
if (string.IsNullOrEmpty(attachmentsSetting.TargetAttachmentFileExtensionOfOpen)) attachmentsSetting.TargetAttachmentFileExtensionOfOpen = ".pdf,.txt,.csv,.rtf,.htm,.html,.doc,.docx,.xls,.xlm,.xlsm,.xlsx,.ppt,.pptx,.bmp,.gif,.jpg,.jpeg,.png,.fif,.pub,.vsd,.vsdx";
8586

8687
var recipientsAndAttachmentsNameCsv = new ReadAndWriteCsv("RecipientsAndAttachmentsName.csv");
8788
var recipientsAndAttachmentsNameList = recipientsAndAttachmentsNameCsv.GetCsvRecords<RecipientsAndAttachmentsName>(recipientsAndAttachmentsNameCsv.LoadCsv<RecipientsAndAttachmentsNameMap>())
@@ -102,22 +103,22 @@ internal CheckList GenerateCheckListFromMail<T>(T item, GeneralSetting generalSe
102103

103104
#endregion
104105

105-
var isMailItem = (typeof(T) == typeof(Outlook._MailItem));
106+
var isMailItem = (typeof(T) == typeof(Outlook.MailItem));
106107

107108
if (isMailItem)
108109
{
109-
_checkList.MailType = GetMailBodyFormat(((Outlook._MailItem)item).BodyFormat) ?? Resources.FailedToGetInformation;
110-
_checkList.MailBody = GetMailBody(((Outlook._MailItem)item).BodyFormat, ((Outlook._MailItem)item).Body ?? Resources.FailedToGetInformation);
110+
_checkList.MailType = GetMailBodyFormat(((Outlook.MailItem)item).BodyFormat) ?? Resources.FailedToGetInformation;
111+
_checkList.MailBody = GetMailBody(((Outlook.MailItem)item).BodyFormat, ((Outlook.MailItem)item).Body ?? Resources.FailedToGetInformation);
111112
_checkList.MailBody = AddMessageToBodyPreview(_checkList.MailBody, autoAddMessageSetting);
112113

113-
_checkList.MailHtmlBody = ((Outlook._MailItem)item).HTMLBody ?? Resources.FailedToGetInformation;
114+
_checkList.MailHtmlBody = ((Outlook.MailItem)item).HTMLBody ?? Resources.FailedToGetInformation;
114115
}
115116
else
116117
{
117118
_checkList.MailType = Resources.MeetingRequest;
118-
_checkList.MailBody = string.IsNullOrEmpty(((Outlook._MeetingItem)item).Body) ? Resources.FailedToGetInformation : ((Outlook._MeetingItem)item).Body.Replace("\r\n\r\n", "\r\n");
119+
_checkList.MailBody = string.IsNullOrEmpty(((Outlook.MeetingItem)item).Body) ? Resources.FailedToGetInformation : ((Outlook.MeetingItem)item).Body.Replace("\r\n\r\n", "\r\n");
119120

120-
if (((Outlook._MeetingItem)item).RTFBody is byte[] byteArray)
121+
if (((Outlook.MeetingItem)item).RTFBody is byte[] byteArray)
121122
{
122123
var encoding = new System.Text.ASCIIEncoding();
123124
_checkList.MailHtmlBody = encoding.GetString(byteArray);
@@ -176,27 +177,27 @@ private CheckList GetSenderAndSenderDomain<T>(in T item, CheckList checkList)
176177
{
177178
try
178179
{
179-
if (typeof(T) == typeof(Outlook._MailItem) && !string.IsNullOrEmpty(((Outlook._MailItem)item).SentOnBehalfOfName))
180+
if (typeof(T) == typeof(Outlook.MailItem) && !string.IsNullOrEmpty(((Outlook.MailItem)item).SentOnBehalfOfName))
180181
{
181182
//代理送信の場合。
182-
checkList.Sender = ((Outlook._MailItem)item).Sender?.Address ?? Resources.FailedToGetInformation;
183+
checkList.Sender = ((Outlook.MailItem)item).Sender?.Address ?? Resources.FailedToGetInformation;
183184

184185
if (IsValidEmailAddress(checkList.Sender))
185186
{
186187
//メールアドレスが取得できる場合はそのまま使う。
187188
checkList.SenderDomain = checkList.Sender.Substring(checkList.Sender.IndexOf("@", StringComparison.Ordinal));
188-
checkList.Sender = $@"{checkList.Sender} ([{((Outlook._MailItem)item).SentOnBehalfOfName}] {Resources.SentOnBehalf})";
189+
checkList.Sender = $@"{checkList.Sender} ([{((Outlook.MailItem)item).SentOnBehalfOfName}] {Resources.SentOnBehalf})";
189190
}
190191
else
191192
{
192193
//代理送信の場合かつExchangeのCN。
193-
checkList.Sender = $@"[{((Outlook._MailItem)item).SentOnBehalfOfName}] {Resources.SentOnBehalf}";
194+
checkList.Sender = $@"[{((Outlook.MailItem)item).SentOnBehalfOfName}] {Resources.SentOnBehalf}";
194195
checkList.SenderDomain = @"------------------";
195196

196197
Outlook.ExchangeDistributionList exchangeDistributionList = null;
197198
Outlook.ExchangeUser exchangeUser = null;
198199

199-
var sender = ((Outlook._MailItem)item).Sender;
200+
var sender = ((Outlook.MailItem)item).Sender;
200201

201202
var isDone = false;
202203
var errorCount = 0;
@@ -227,14 +228,14 @@ private CheckList GetSenderAndSenderDomain<T>(in T item, CheckList checkList)
227228
if (!(exchangeUser is null))
228229
{
229230
//ユーザの代理送信。
230-
checkList.Sender = $@"{exchangeUser.PrimarySmtpAddress} ([{((Outlook._MailItem)item).SentOnBehalfOfName}] {Resources.SentOnBehalf})";
231+
checkList.Sender = $@"{exchangeUser.PrimarySmtpAddress} ([{((Outlook.MailItem)item).SentOnBehalfOfName}] {Resources.SentOnBehalf})";
231232
checkList.SenderDomain = exchangeUser.PrimarySmtpAddress.Substring(exchangeUser.PrimarySmtpAddress.IndexOf("@", StringComparison.Ordinal));
232233
}
233234

234235
if (!(exchangeDistributionList is null))
235236
{
236237
//配布リストの代理送信。
237-
checkList.Sender = $@"{exchangeDistributionList.PrimarySmtpAddress} ([{((Outlook._MailItem)item).SentOnBehalfOfName}] {Resources.SentOnBehalf})";
238+
checkList.Sender = $@"{exchangeDistributionList.PrimarySmtpAddress} ([{((Outlook.MailItem)item).SentOnBehalfOfName}] {Resources.SentOnBehalf})";
238239
checkList.SenderDomain = exchangeDistributionList.PrimarySmtpAddress.Substring(exchangeDistributionList.PrimarySmtpAddress.IndexOf("@", StringComparison.Ordinal));
239240
}
240241
}
@@ -1017,11 +1018,11 @@ private CheckList CheckKeywordForSubject(CheckList checkList, IReadOnlyCollectio
10171018

10181019
var mailItemSender = ((dynamic)item).SenderEmailAddress;
10191020

1020-
if (typeof(T) == typeof(Outlook._MailItem))
1021+
if (typeof(T) == typeof(Outlook.MailItem))
10211022
{
1022-
if (!string.IsNullOrEmpty(((Outlook._MailItem)item).SentOnBehalfOfName) && !string.IsNullOrEmpty(((Outlook._MailItem)item).Sender.Address))
1023+
if (!string.IsNullOrEmpty(((Outlook.MailItem)item).SentOnBehalfOfName) && !string.IsNullOrEmpty(((Outlook.MailItem)item).Sender.Address))
10231024
{
1024-
mailItemSender = ((Outlook._MailItem)item).Sender.Address;
1025+
mailItemSender = ((Outlook.MailItem)item).Sender.Address;
10251026
}
10261027
}
10271028

@@ -1118,10 +1119,10 @@ private CheckList CheckKeywordForSubject(CheckList checkList, IReadOnlyCollectio
11181119
/// <returns>埋め込みファイル名のList</returns>
11191120
private List<string> MakeEmbeddedAttachmentsList<T>(T item, string mailHtmlBody)
11201121
{
1121-
if (typeof(T) == typeof(Outlook._MailItem))
1122+
if (typeof(T) == typeof(Outlook.MailItem))
11221123
{
11231124
//HTML形式の場合のみ、処理対象とする。
1124-
if (((Outlook._MailItem)item).BodyFormat != Outlook.OlBodyFormat.olFormatHTML) return null;
1125+
if (((Outlook.MailItem)item).BodyFormat != Outlook.OlBodyFormat.olFormatHTML) return null;
11251126
}
11261127

11271128
var matches = Regex.Matches(mailHtmlBody, @"cid:.*?@");
@@ -1158,6 +1159,7 @@ private CheckList GetAttachmentsInformation<T>(in T item, CheckList checkList, b
11581159

11591160
var tempDirectoryPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));
11601161
_ = Directory.CreateDirectory(tempDirectoryPath);
1162+
checkList.TempFilePath = tempDirectoryPath;
11611163

11621164
for (var i = 0; i < ((dynamic)item).Attachments.Count; i++)
11631165
{
@@ -1207,14 +1209,16 @@ private CheckList GetAttachmentsInformation<T>(in T item, CheckList checkList, b
12071209
if (fileType == ".p7s" || fileType == "p7s") continue;
12081210

12091211
var isEncrypted = false;
1210-
1212+
var tempFilePath = "";
1213+
var isCanOpen = false;
12111214
try
12121215
{
1216+
12131217
if ((attachmentsSetting.IsWarningWhenEncryptedZipIsAttached || attachmentsSetting.IsProhibitedWhenEncryptedZipIsAttached) && fileName != Resources.Unknown)
12141218
{
12151219
if (attachmentsSetting.IsEnableAllAttachedFilesAreDetectEncryptedZip || fileType == ".zip" || fileType == "zip")
12161220
{
1217-
var tempFilePath = Path.Combine(tempDirectoryPath, fileName);
1221+
tempFilePath = Path.Combine(tempDirectoryPath, fileName);
12181222
((dynamic)item).Attachments[i + 1].SaveAsFile(tempFilePath);
12191223

12201224
var zipTools = new ZipTools();
@@ -1235,6 +1239,14 @@ private CheckList GetAttachmentsInformation<T>(in T item, CheckList checkList, b
12351239
File.Delete(tempFilePath);
12361240
}
12371241
}
1242+
1243+
if (attachmentsSetting.IsEnableOpenAttachedFiles && attachmentsSetting.TargetAttachmentFileExtensionOfOpen.ToLower().Contains(fileType.ToLower()))
1244+
{
1245+
//ファイルを開くためにテンポラリディレクトリにコピーして、そのパスを記録
1246+
tempFilePath = Path.Combine(tempDirectoryPath, fileName);
1247+
((dynamic)item).Attachments[i + 1].SaveAsFile(tempFilePath);
1248+
isCanOpen = true;
1249+
}
12381250
}
12391251
catch (Exception)
12401252
{
@@ -1251,7 +1263,11 @@ private CheckList GetAttachmentsInformation<T>(in T item, CheckList checkList, b
12511263
IsTooBig = ((dynamic)item).Attachments[i + 1].Size >= 10485760,
12521264
IsEncrypted = isEncrypted,
12531265
IsChecked = false,
1254-
IsDangerous = isDangerous
1266+
IsDangerous = isDangerous,
1267+
IsCanOpen = isCanOpen,
1268+
IsNotMustOpenBeforeCheck = !(attachmentsSetting.IsEnableOpenAttachedFiles && attachmentsSetting.IsMustOpenBeforeCheckTheAttachedFiles && isCanOpen),
1269+
Open = isCanOpen ? Resources.Open : "---",
1270+
FilePath = tempFilePath
12551271
});
12561272

12571273
continue;
@@ -1268,7 +1284,11 @@ private CheckList GetAttachmentsInformation<T>(in T item, CheckList checkList, b
12681284
IsTooBig = ((dynamic)item).Attachments[i + 1].Size >= 10485760,
12691285
IsEncrypted = isEncrypted,
12701286
IsChecked = false,
1271-
IsDangerous = isDangerous
1287+
IsDangerous = isDangerous,
1288+
IsCanOpen = isCanOpen,
1289+
IsNotMustOpenBeforeCheck = !(attachmentsSetting.IsEnableOpenAttachedFiles && attachmentsSetting.IsMustOpenBeforeCheckTheAttachedFiles && isCanOpen),
1290+
Open = isCanOpen ? Resources.Open : "---",
1291+
FilePath = tempFilePath
12721292
});
12731293
}
12741294
}

OutlookOkan/OutlookOkan.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<PublishUrl>publish\</PublishUrl>
3636
<InstallUrl />
3737
<TargetCulture>en</TargetCulture>
38-
<ApplicationVersion>2.7.0.0</ApplicationVersion>
38+
<ApplicationVersion>2.7.1.0</ApplicationVersion>
3939
<AutoIncrementApplicationRevision>false</AutoIncrementApplicationRevision>
4040
<UpdateEnabled>false</UpdateEnabled>
4141
<UpdateInterval>0</UpdateInterval>

OutlookOkan/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("2.7.0.0")]
36-
[assembly: AssemblyFileVersion("2.7.0.0")]
35+
[assembly: AssemblyVersion("2.7.1.0")]
36+
[assembly: AssemblyFileVersion("2.7.1.0")]
3737
[assembly: NeutralResourcesLanguage("en-US")]
3838

OutlookOkan/Properties/Resources.Designer.cs

+64-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)