public void Outlook_ItemSend(object v_item, ref bool v_cancel) { this.m_mailgo.Track.Debug("ACTIVATION: Outlook's email sent event handler ..."); if (!this.m_mailgo.Activated) { return; } this.m_mailgo.Track.Debug("ACTIVATION: License is installed and status is on!"); OL.MailItem t_item = v_item as OL.MailItem; Model.IEmail t_email = new Model.MEmail(); t_email.Sender = this.GetSender(t_item); t_email.Body = t_item.Body; /* 2011/10/30 modified to handle null by msekine */ if (t_email.Body == null) { t_email.Body = "\r\n"; } t_email.Subject = t_item.Subject; //2011/10/11 ‚»‚à‚»‚àMailGo Status‚ªfalse‚Ìꇂ̓`ƒFƒbƒN‚µ‚È‚¢ if (!this.m_status) { return; } foreach (OL.Recipient t_recipient in t_item.Recipients) { string address = string.Empty; if (t_recipient.AddressEntry.Type == "EX") { address = GetSMTPAddressOfExchangeUser(t_item); } else { address = t_recipient.Address; } if (t_recipient.Type == (int)OL.OlMailRecipientType.olTo) { t_email.TO.Add(address); } if (t_recipient.Type == (int)OL.OlMailRecipientType.olCC) { t_email.CC.Add(address); } } if (this.NoCheckEmail(t_email)) { ConfirmRequestWF t_form = new ConfirmRequestWF(); DialogResult t_result = t_form.ShowDialog(); if (t_result != DialogResult.Yes) { this.m_status = m_statusTemp; this.m_bActivated = m_bActivateTemp; v_cancel = true; } else { this.m_bActivatedReally = true; this.SetActivated(); UpdateMailGO(); } return; } else if (this.NoCheckEmail1(t_email)) { ConfirmRequestWF t_form = new ConfirmRequestWF(); DialogResult t_result = t_form.ShowDialog(); if (t_result != DialogResult.Yes) { this.m_status = m_statusTemp; this.m_bActivated = m_bActivateTemp; v_cancel = true; } else { this.m_bActivated = false; this.m_bActivatedReally = false; this.SetDeActivated(); if (DateTime.Now < m_deadLine) { m_bActivated = true; } m_status = m_bActivated; UpdateMailGO(); } return; } if (!this.m_status) { return; } this.OnBeforeSendEmail(t_email, out v_cancel); // «[’ljÁ]“Y•tƒtƒ@ƒCƒ‹ƒvƒƒpƒeƒBƒ`ƒFƒbƒN‹@”\ // Šù‘¶ƒ`ƒFƒbƒN‚ŃLƒƒƒ“ƒZƒ‹‚µ‚Ä‚¢‚éꇂÍAƒ[ƒ‹‘—M‚ðƒLƒƒƒ“ƒZƒ‹‚µ‚ÄI—¹‚·‚éB if (v_cancel == true) { return; } // 2009/9/18 ƒtƒ@ƒCƒ‹ƒvƒƒpƒeƒBƒIƒvƒVƒ‡ƒ“‚̃`ƒFƒbƒN if (this.m_option.CheckWord == false && this.m_option.CheckExcel == false && this.m_option.CheckPowerPoint == false && this.m_option.CheckText == false) { return; } // OS‚̃o[ƒWƒ‡ƒ“‚ðŠm”F‚·‚éB String OS_Version = ""; OperatingSystem osInfo = Environment.OSVersion; if (osInfo.Platform == PlatformID.Win32NT && osInfo.Version.Major == 5 && osInfo.Version.Minor == 1) { OS_Version = "Windows XP"; } else if (osInfo.Platform == PlatformID.Win32NT && osInfo.Version.Major == 6 && osInfo.Version.Minor == 0) { OS_Version = "Windows Vista"; } // 2010/9/13 else if (osInfo.Platform == PlatformID.Win32NT && osInfo.Version.Major == 6 && osInfo.Version.Minor == 1) { OS_Version = "Windows 7"; } else if (osInfo.Version.Major == 6 && osInfo.Version.Minor == 2) { OS_Version = "Windows 8.0"; } else if (osInfo.Version.Major == 6 && osInfo.Version.Minor == 3) { OS_Version = "Windows 8.1"; } else if (osInfo.Version.Major == 10 && osInfo.Version.Minor == 0) { OS_Version = "Windows 10"; } // // “Y•tƒtƒ@ƒCƒ‹‚Ì—L–³‚ðŠm”F‚·‚éB int cnt = 0; foreach (OL.Attachment objAttachment in t_item.Attachments) { cnt++; } // ˆÈ‰º‚Ì‚¢‚Âꂩ‚ÉŠY“–‚·‚é‚Æ‚«‚É“Y•tƒtƒ@ƒCƒ‹ƒ`ƒFƒbƒN‚ðs‚¤B // EOS‚̃o[ƒWƒ‡ƒ“‚ªWindows XP‚Å‚©‚“Y•tƒtƒ@ƒCƒ‹—L‚Ìê‡ // EOS‚̃o[ƒWƒ‡ƒ“‚ªWindows Vista‚Å‚©‚“Y•tƒtƒ@ƒCƒ‹—L‚Ìê‡ if (cnt > 0 && (OS_Version == "Windows XP" || OS_Version == "Windows Vista" || OS_Version == "Windows 7" || OS_Version == "Windows 8.0" || OS_Version == "Windows 8.1" || OS_Version == "Windows 10")) { // ƒ[ƒ‹–{•¶‚̈¶æ‚ðŽæ“¾‚·‚éB string t_company = this.ReadCompany(t_email.Body); // Outlook‚̃o[ƒWƒ‡ƒ“‚ðŽæ“¾‚·‚éB string oKeyName = @"Outlook.Application\CurVer"; string oGetValueName = ""; string outlook_version = ""; try { RegistryKey rKey = Registry.ClassesRoot.OpenSubKey(oKeyName); outlook_version = (string)rKey.GetValue(oGetValueName); rKey.Close(); } catch (NullReferenceException) { this.m_mailgo.Track.Debug("ƒŒƒWƒXƒgƒŠm" + oKeyName + "n‚Ìm" + oGetValueName + "n‚ª‚ ‚è‚Ü‚¹‚ñB"); } // Outlook‚̃o[ƒWƒ‡ƒ“‚ɑΉž‚·‚郌ƒWƒXƒgƒŠƒL[‚ðÝ’è‚·‚éB string rKeyName = ""; // Outlook 2002 if (outlook_version == "Outlook.Application.10") { rKeyName = @"Software\Microsoft\Office\10.0\Outlook\Security"; } // Outlook 2003 else if (outlook_version == "Outlook.Application.11") { rKeyName = @"Software\Microsoft\Office\11.0\Outlook\Security"; } // Outlook 2007 else if (outlook_version == "Outlook.Application.12") { rKeyName = @"Software\Microsoft\Office\12.0\Outlook\Security"; } // OutLook 2010 2010/09/13 else if (outlook_version == "Outlook.Application.14") { rKeyName = @"Software\Microsoft\Office\14.0\Outlook\Security"; } else if (outlook_version == "Outlook.Application.16") { rKeyName = @"Software\Microsoft\Office\16.0\Outlook\Security"; } // ‚»‚Ì‘¼ else { // “Y•tƒtƒ@ƒCƒ‹ƒvƒƒpƒeƒBƒ`ƒFƒbƒN‹@”\‚ðI—¹‚·‚éB return; } string rGetValueName = "OutlookSecureTempFolder"; string location = ""; try { RegistryKey rKey = Registry.CurrentUser.OpenSubKey(rKeyName); location = (string)rKey.GetValue(rGetValueName); rKey.Close(); } catch (NullReferenceException) { this.m_mailgo.Track.Debug("ƒŒƒWƒXƒgƒŠm" + rKeyName + "n‚Ìm" + rGetValueName + "n‚ª‚ ‚è‚Ü‚¹‚ñB"); } // “Y•tƒtƒ@ƒCƒ‹”‚¾‚¯ˆÈ‰º‚ðŒJ‚è•Ô‚·B foreach (OL.Attachment objAttachment in t_item.Attachments) { // @Šg’£Žqƒ`ƒFƒbƒN@2010/9/18 String t_extention = ""; t_extention = Path.GetExtension(objAttachment.FileName); if (t_extention == ".doc") { if (this.m_option.CheckWord == true) { // ƒ`ƒFƒbƒN‘ÎÛB‰½‚à‚µ‚È‚¢‚ŃXƒ‹[‚·‚éB } else { // ƒ`ƒFƒbƒN‘ÎÛŠOB continue; } } else if (t_extention == ".docx") { if (this.m_option.CheckWord == true) { // ƒ`ƒFƒbƒN‘ÎÛB‰½‚à‚µ‚È‚¢‚ŃXƒ‹[‚·‚éB } else { // ƒ`ƒFƒbƒN‘ÎÛŠOB continue; } } else if (t_extention == ".xls") { if (this.m_option.CheckExcel == true) { // ƒ`ƒFƒbƒN‘ÎÛB‰½‚à‚µ‚È‚¢‚ŃXƒ‹[‚·‚éB } else { // ƒ`ƒFƒbƒN‘ÎÛŠOB continue; } } else if (t_extention == ".xlsx") { if (this.m_option.CheckExcel == true) { // ƒ`ƒFƒbƒN‘ÎÛB‰½‚à‚µ‚È‚¢‚ŃXƒ‹[‚·‚éB } else { // ƒ`ƒFƒbƒN‘ÎÛŠOB continue; } } else if (t_extention == ".csv") { if (this.m_option.CheckExcel == true) { // ƒ`ƒFƒbƒN‘ÎÛB‰½‚à‚µ‚È‚¢‚ŃXƒ‹[‚·‚éB } else { // ƒ`ƒFƒbƒN‘ÎÛŠOB continue; } } else if (t_extention == ".ppt") { if (this.m_option.CheckPowerPoint == true) { // ƒ`ƒFƒbƒN‘ÎÛB‰½‚à‚µ‚È‚¢‚ŃXƒ‹[‚·‚éB } else { // ƒ`ƒFƒbƒN‘ÎÛŠOB continue; } } else if (t_extention == ".pptx") { if (this.m_option.CheckPowerPoint == true) { // ƒ`ƒFƒbƒN‘ÎÛB‰½‚à‚µ‚È‚¢‚ŃXƒ‹[‚·‚éB } else { // ƒ`ƒFƒbƒN‘ÎÛŠOB continue; } } else if (t_extention == ".txt") { if (this.m_option.CheckText == true) { // ƒ`ƒFƒbƒN‘ÎÛB‰½‚à‚µ‚È‚¢‚ŃXƒ‹[‚·‚éB } else { // ƒ`ƒFƒbƒN‘ÎÛŠOB continue; } } else { // ƒ`ƒFƒbƒN‘ÎÛŠOB continue; } // @“Y•tƒtƒ@ƒCƒ‹‚̃vƒƒpƒeƒBuƒ^ƒCƒgƒ‹v‚Ì’l‚ðŽæ“¾‚·‚éB int TITLE_ID = 21; // OS‚ªWindows XP‚Ìê‡ if (OS_Version == "Windows XP") { TITLE_ID = 10; } /* * // OS‚ªWindows Vista‚Ìê‡ * else if (OS_Version == "Windows Vista") * { * TITLE_ID = 21; * } * // OS‚ªWindows 7‚Ìê‡ 2010/09/13 * else if (OS_Version == "Windows 7") * { * TITLE_ID = 21; * } * * else if (OS_Version == "Windows 8.0") * { * TITLE_ID = 22; * } * else if (OS_Version == "Windows 8.1") * { * TITLE_ID = 23; * } * else if (OS_Version == "Windows 10") * { * TITLE_ID = 31; * } */ ShellClass shell = new ShellClass(); Folder folder = shell.NameSpace(location); FolderItem folderItem = folder.ParseName(objAttachment.FileName); String t_title = ""; if (folderItem != null) { t_title = folder.GetDetailsOf(folderItem, TITLE_ID); folderItem = null; } folder = null; shell = null; // String l_title = ""; String l_company = ""; try { l_title = t_title.Trim().ToLower(); } catch (NullReferenceException) { l_title = ""; t_title = ""; } try { l_company = t_company.Trim().ToLower(); } catch (NullReferenceException) { l_company = ""; t_company = ""; } v_cancel = false; /* * * // ƒ[ƒ‹–{•¶‚̈¶æ‚Æuƒ^ƒCƒgƒ‹v‚Ì’l‚ð”äŠr‚·‚éB * if (l_company == l_title) * { * // ˆê’v‚·‚éê‡A‰½‚à‚µ‚È‚¢‚ŃXƒ‹[‚·‚éB * * } * else * { * // ˆê’v‚µ‚È‚¢ê‡AŠm”Fƒ_ƒCƒAƒƒO‚ð•\Ž¦‚·‚éB * System.Windows.Forms.DialogResult t_result; * NotMatchWF t_form = new NotMatchWF(objAttachment.FileName, t_title, t_company); * t_result = t_form.ShowDialog(); * * // ‘—MŽÀsƒ{ƒ^ƒ“‰Ÿ‰ºŽžA‚»‚Ì‚Ü‚Ü‘±sB * if (t_result == System.Windows.Forms.DialogResult.OK) * { * v_cancel = false; * } * * // ‘—M’†Ž~ƒ{ƒ^ƒ“‰Ÿ‰ºŽžA‘—M’†Ž~ˆ—‚ðŽÀŽ{B * if (t_result == System.Windows.Forms.DialogResult.Cancel) * { * v_cancel = true; * return; * } * } */ } } // ª[’ljÁ]“Y•tƒtƒ@ƒCƒ‹ƒvƒƒpƒeƒBƒ`ƒFƒbƒN‹@”\ this.m_mailgo.Track.Debug("Cancel sending mail with v_cancel = " + v_cancel); }
public void Outlook_ItemSend(object v_item, ref bool v_cancel) { this.m_mailgo.Track.Debug("ACTIVATION: Outlook's email sent event handler ..."); if (!this.m_installed) { return; } this.m_mailgo.Track.Debug("ACTIVATION: License is installed and status is on!"); OL.MailItem t_item = v_item as OL.MailItem; Model.IEmail t_email = new Model.MEmail(); t_email.Sender = this.GetSender(t_item); t_email.Body = t_item.Body; /* 2011/10/30 modified to handle null by msekine */ if (t_email.Body == null) { t_email.Body = "\r\n"; } t_email.Subject = t_item.Subject; //2011/10/11 そもそもMailGo Statusがfalseの場合はチェックしない if (!this.m_status) { return; } foreach (OL.Recipient t_recipient in t_item.Recipients) { string address = string.Empty; if (t_recipient.AddressEntry.Type == "EX") { address = GetSMTPAddressOfExchangeUser(t_item); } else { address = t_recipient.Address; } if (t_recipient.Type == (int)OL.OlMailRecipientType.olTo) { t_email.TO.Add(address); } if (t_recipient.Type == (int)OL.OlMailRecipientType.olCC) { t_email.CC.Add(address); } } if (this.NoCheckEmail(t_email)) { ConfirmRequestWF t_form = new ConfirmRequestWF(); DialogResult t_result = t_form.ShowDialog(); if (t_result != DialogResult.Yes) { v_cancel = true; } return; } if (!this.m_status) { return; } this.OnBeforeSendEmail(t_email, out v_cancel); // ↓[追加]添付ファイルプロパティチェック機能 // 既存チェックでキャンセルしている場合は、メール送信をキャンセルして終了する。 if (v_cancel == true) { return; } // 2009/9/18 ファイルプロパティオプションのチェック if (this.m_option.CheckWord == false && this.m_option.CheckExcel == false && this.m_option.CheckPowerPoint == false && this.m_option.CheckText == false) { return; } // OSのバージョンを確認する。 String OS_Version = ""; OperatingSystem osInfo = Environment.OSVersion; if (osInfo.Platform == PlatformID.Win32NT && osInfo.Version.Major == 5 && osInfo.Version.Minor == 1) { OS_Version = "Windows XP"; } else if (osInfo.Platform == PlatformID.Win32NT && osInfo.Version.Major == 6 && osInfo.Version.Minor == 0) { OS_Version = "Windows Vista"; } // 2010/9/13 else if (osInfo.Platform == PlatformID.Win32NT && osInfo.Version.Major == 6 && osInfo.Version.Minor == 1) { OS_Version = "Windows 7"; } else if (osInfo.Version.Major == 6 && osInfo.Version.Minor == 2) { OS_Version = "Windows 8.0"; } else if (osInfo.Version.Major == 6 && osInfo.Version.Minor == 3) { OS_Version = "Windows 8.1"; } else if (osInfo.Version.Major == 10 && osInfo.Version.Minor == 0) { OS_Version = "Windows 10"; } // // 添付ファイルの有無を確認する。 int cnt = 0; foreach (OL.Attachment objAttachment in t_item.Attachments) { cnt++; } // 以下のいづれかに該当するときに添付ファイルチェックを行う。 // ・OSのバージョンがWindows XPでかつ添付ファイル有の場合 // ・OSのバージョンがWindows Vistaでかつ添付ファイル有の場合 if (cnt > 0 && (OS_Version == "Windows XP" || OS_Version == "Windows Vista" || OS_Version == "Windows 7" || OS_Version == "Windows 8.0" || OS_Version == "Windows 8.1" || OS_Version == "Windows 10")) { // メール本文の宛先を取得する。 string t_company = this.ReadCompany(t_email.Body); // Outlookのバージョンを取得する。 string oKeyName = @"Outlook.Application\CurVer"; string oGetValueName = ""; string outlook_version = ""; try { RegistryKey rKey = Registry.ClassesRoot.OpenSubKey(oKeyName); outlook_version = (string)rKey.GetValue(oGetValueName); rKey.Close(); } catch (NullReferenceException) { this.m_mailgo.Track.Debug("レジストリ[" + oKeyName + "]の[" + oGetValueName + "]がありません。"); } // Outlookのバージョンに対応するレジストリキーを設定する。 string rKeyName = ""; // Outlook 2002 if (outlook_version == "Outlook.Application.10") { rKeyName = @"Software\Microsoft\Office\10.0\Outlook\Security"; } // Outlook 2003 else if (outlook_version == "Outlook.Application.11") { rKeyName = @"Software\Microsoft\Office\11.0\Outlook\Security"; } // Outlook 2007 else if (outlook_version == "Outlook.Application.12") { rKeyName = @"Software\Microsoft\Office\12.0\Outlook\Security"; } // OutLook 2010 2010/09/13 else if (outlook_version == "Outlook.Application.14") { rKeyName = @"Software\Microsoft\Office\14.0\Outlook\Security"; } else if (outlook_version == "Outlook.Application.16") { rKeyName = @"Software\Microsoft\Office\16.0\Outlook\Security"; } // その他 else { // 添付ファイルプロパティチェック機能を終了する。 return; } string rGetValueName = "OutlookSecureTempFolder"; string location = ""; try { RegistryKey rKey = Registry.CurrentUser.OpenSubKey(rKeyName); location = (string)rKey.GetValue(rGetValueName); rKey.Close(); } catch (NullReferenceException) { this.m_mailgo.Track.Debug("レジストリ[" + rKeyName + "]の[" + rGetValueName + "]がありません。"); } // 添付ファイル数だけ以下を繰り返す。 foreach (OL.Attachment objAttachment in t_item.Attachments) { // 拡張子チェック 2010/9/18 String t_extention = ""; t_extention = Path.GetExtension(objAttachment.FileName); if (t_extention == ".doc") { if (this.m_option.CheckWord == true) { // チェック対象。何もしないでスルーする。 } else { // チェック対象外。 continue; } } else if (t_extention == ".docx") { if (this.m_option.CheckWord == true) { // チェック対象。何もしないでスルーする。 } else { // チェック対象外。 continue; } } else if (t_extention == ".xls") { if (this.m_option.CheckExcel == true) { // チェック対象。何もしないでスルーする。 } else { // チェック対象外。 continue; } } else if (t_extention == ".xlsx") { if (this.m_option.CheckExcel == true) { // チェック対象。何もしないでスルーする。 } else { // チェック対象外。 continue; } } else if (t_extention == ".csv") { if (this.m_option.CheckExcel == true) { // チェック対象。何もしないでスルーする。 } else { // チェック対象外。 continue; } } else if (t_extention == ".ppt") { if (this.m_option.CheckPowerPoint == true) { // チェック対象。何もしないでスルーする。 } else { // チェック対象外。 continue; } } else if (t_extention == ".pptx") { if (this.m_option.CheckPowerPoint == true) { // チェック対象。何もしないでスルーする。 } else { // チェック対象外。 continue; } } else if (t_extention == ".txt") { if (this.m_option.CheckText == true) { // チェック対象。何もしないでスルーする。 } else { // チェック対象外。 continue; } } else { // チェック対象外。 continue; } // 添付ファイルのプロパティ「タイトル」の値を取得する。 int TITLE_ID = 1000; // OSがWindows XPの場合 if (OS_Version == "Windows XP") { TITLE_ID = 10; } // OSがWindows Vistaの場合 else if (OS_Version == "Windows Vista") { TITLE_ID = 21; } // OSがWindows 7の場合 2010/09/13 else if (OS_Version == "Windows 7") { TITLE_ID = 21; } /* * else if (OS_Version == "Windows 8.0") * { * TITLE_ID = 22; * } * else if (OS_Version == "Windows 8.1") * { * TITLE_ID = 23; * } * else if (OS_Version == "Windows 10") * { * TITLE_ID = 31; * } */ ShellClass shell = new ShellClass(); Folder folder = shell.NameSpace(location); FolderItem folderItem = folder.ParseName(objAttachment.FileName); String t_title = ""; if (folderItem != null) { t_title = folder.GetDetailsOf(folderItem, TITLE_ID); folderItem = null; } folder = null; shell = null; // String l_title = ""; String l_company = ""; try { l_title = t_title.Trim().ToLower(); } catch (NullReferenceException) { l_title = ""; t_title = ""; } try { l_company = t_company.Trim().ToLower(); } catch (NullReferenceException) { l_company = ""; t_company = ""; } // メール本文の宛先と「タイトル」の値を比較する。 if (l_company == l_title) { // 一致する場合、何もしないでスルーする。 } else { // 一致しない場合、確認ダイアログを表示する。 System.Windows.Forms.DialogResult t_result; NotMatchWF t_form = new NotMatchWF(objAttachment.FileName, t_title, t_company); t_result = t_form.ShowDialog(); // 送信実行ボタン押下時、そのまま続行。 if (t_result == System.Windows.Forms.DialogResult.OK) { v_cancel = false; } // 送信中止ボタン押下時、送信中止処理を実施。 if (t_result == System.Windows.Forms.DialogResult.Cancel) { v_cancel = true; return; } } } } // ↑[追加]添付ファイルプロパティチェック機能 this.m_mailgo.Track.Debug("Cancel sending mail with v_cancel = " + v_cancel); }