Microsoft MVP성태의 닷넷 이야기
.NET Framework: 682. 아웃룩 사용자를 위한 중국어 스팸 필터 Add-in [링크 복사], [링크+제목 복사]
조회: 12679
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 3개 있습니다.)

아웃룩 사용자를 위한 중국어 스팸 필터 Add-in

최근 들어 중국어 스팸 메일이 부쩍 늘었습니다. 아웃룩의 "Junk Email Options" / "International" / "Blocked Encoding List..." 기능을 이용해 중국어 문자(Chinese Simplified, Chinese Traditional)를 블록시켰지만 통하지 않았습니다. 검색해 보니, 해당 기능은 유니코드 인코딩된 메일에 대해서는 유효하지 않다고! ^^;

도메인명 기준으로 스팸 처리하는 것도 슬슬 귀찮아집니다. 왜냐하면, 심지어 .org에서도 스팸이 오는 등 꽤나 다양한 도메인에서 오기 때문입니다. 그런데, 의외인 것은 검색을 해도 아웃룩에 대해 중국어 스팸 필터 확장이 없다는 것입니다. (물론, 있을지도 모릅니다.) 그래서 그냥 만들어 버렸습니다. ^^;

방법은 대강 다음의 문서에 있으니,

Walkthrough: Creating Your First VSTO Add-In for Outlook
; https://learn.microsoft.com/en-us/visualstudio/vsto/walkthrough-creating-your-first-vsto-add-in-for-outlook

비주얼 스튜디오에서 "Visual C#" / "Office/SharePoint" / "VSTO Add-ins"의 "Outlook 2013 and 2016 VSTO Add-in" 프로젝트를 선택해 메일이 왔을 때의 이벤트 처리를 추가하고,

How to: Programmatically Perform Actions When an E-Mail Message Is Received
; https://learn.microsoft.com/en-us/visualstudio/vsto/how-to-programmatically-perform-actions-when-an-e-mail-message-is-received

메일의 제목에 2개 이상의 중국어 문자가 포함된 경우 스팸 메일로 간주하고 '정크 메일' 함으로 보내게 했습니다. 다음은 그에 대한 소스 코드입니다.

using Outlook = Microsoft.Office.Interop.Outlook;

namespace CharacterRangeFilter
{
    public partial class ThisAddIn
    {
        Outlook.NameSpace outlookNameSpace;
        Outlook.MAPIFolder inbox;
        Outlook.Items items;

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            outlookNameSpace = this.Application.GetNamespace("MAPI");
            inbox = outlookNameSpace.GetDefaultFolder(
                    Microsoft.Office.Interop.Outlook.
                    OlDefaultFolders.olFolderInbox);

            items = inbox.Items;
            items.ItemAdd +=
                new Outlook.ItemsEvents_ItemAddEventHandler(items_ItemAdd);
        }

        void items_ItemAdd(object Item)
        {
            Outlook.MailItem mail = (Outlook.MailItem)Item;
            if (Item != null)
            {
                if (mail.MessageClass == "IPM.Note")
                {
                    if (HasChineseCharacters2More(mail) == true)
                    {
                        mail.Move(outlookNameSpace.GetDefaultFolder(
                            Microsoft.Office.Interop.Outlook.
                            OlDefaultFolders.olFolderJunk));
                    }
                }
            }
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

        bool HasChineseCharacters2More(Outlook.MailItem mail)
        {
            if (string.IsNullOrEmpty(mail.Subject) == true)
            {
                return false;
            }

            string title = mail.Subject;
            int count = 0;

            // https://ko.wikipedia.org/wiki/%EC%9C%A0%EB%8B%88%EC%BD%94%EB%93%9C_%EB%B8%94%EB%A1%9D
            foreach (char ch in title)
            {
                switch (ch)
                {
                    case char i when i >= 0x2e80 && i <= 0x2eff: // CJK Radicals Supplement
                        count++;
                        break;

                    case char i when i >= 0x2f00 && i <= 0x2fdf: // Kangxi Radicals
                        count++;
                        break;

                    case char i when i >= 0x3000 && i <= 0x303f: // CJK Symbols and Punctuation
                        count++;
                        break;

                    case char i when i >= 0x3400 && i <= 0x4dbf: // CJK Unified Ideographs Extension A
                        count++;
                        break;

                    case char i when i >= 0x4e00 && i <= 0x9fff: // CJK Unified Ideographs
                        count++;
                        break;

                        // for now, except for 2 SIP area
                        /*
                        2 SIP U+20000..U+2A6DF CJK Unified Ideographs Extension B
                        2 SIP U+2A700..U+2B73F CJK Unified Ideographs Extension C
                        2 SIP U+2B740..U+2B81F CJK Unified Ideographs Extension D
                        2 SIP U+2B820..U+2CEAF CJK Unified Ideographs Extension E
                        2 SIP U+2CEB0..U+2EBEF CJK Unified Ideographs Extension F
                        2 SIP U+2F800..U+2FA1F CJK Compatibility Ideographs Supplement
                        */
                }
            }

            return count > 1;
        }

        #region VSTO generated code

        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }
        
        #endregion
    }
}

규칙이 매우 간단한데, 일단 저 혼자 쓸 것이므로 이 정도면 충분하기에 정한 기준입니다. 위의 소스 코드는 현재 github에도 올렸으니, 사용자 정의 조건을 설정하는 창을 만들어 pull request를 보내주시면 언제든 ^^ 반영해드리겠습니다.

stjeong/CharacterRangeFilter 
; https://github.com/stjeong/CharacterRangeFilter

컴파일된 바이너리는 클릭원스를 이용했습니다. (VSTO add-in을 ClickOnce로 배포할 수 있다는 것은 처음 알았군요. ^^)

Deploying an Office Solution by Using ClickOnce
; https://learn.microsoft.com/en-us/visualstudio/vsto/deploying-an-office-solution-by-using-clickonce

위의 문서에 보면 VSTOInstaller를 이용한 방법도 나오는데,

%commonprogramfiles%\microsoft shared\VSTO\10.0\VSTOInstaller.exe

이번에는 그냥 ClickOnce로 했습니다. 하는 김에 Office Store에도 넣으려고 했는데 ^^

Make your solutions available in Microsoft AppSource and within Office
; https://learn.microsoft.com/en-us/office/dev/store/submit-to-appsource-via-partner-center

아쉽게도 지금 개발자 인증에 문제가 있어서 포기했습니다. (혹시, 다음번 기회가 되면 경험 삼아 올려봐야겠습니다.)




그냥 설치만 하고 싶으신 분들은, 다음의 절차를 따라야 합니다.

우선 인증서가 문제인데요, 제가 개인적인 목적으로 만든 것이라 정식 인증서 발급까지 받지는 못했습니다. 따라서, 테스트 인증서를 여러분들의 로컬 PC에 설치해야 하는데, 이를 위해 다음의 인증서를 다운로드하고,

http://sysnet.blob.core.windows.net/temp/stjeong.cer

관리자 권한의 cmd.exe 명령행 프롬프트를 띄운 후 다음과 같은 명령어로 등록해 줍니다.

C:\temp>certmgr.exe -add stjeong.cer -c -s -r localMachine Root
CertMgr Succeeded

C:\temp>certmgr.exe -add stjeong.cer -c -s -r localMachine TrustedPublisher
CertMgr Succeeded

[업데이트: 2018-10-04] 위의 과정을 처리해 주는 CertMgr2.exe를 만들었으니 http://sysnet.blob.core.windows.net/temp/office/CertMgr2.zip 파일을 다운로드 해 압축을 푼 후 실행만 하면 됩니다.

그다음, 아래의 경로를 방문해 setup.exe를 실행해 주면 됩니다.

http://sysnet.blob.core.windows.net/temp/office/setup.exe

정상적으로 설치된 경우, 아웃룩의 "Options" / "Add-ins" 영역에 다음과 같이 "CharacterRangeFilter" 확장이 보일 것입니다.

china_spam_filter_for_outlook_1.png

참고로, 테스트는 Windows 10 + .NET Framework 4.5.2 + 아웃룩 2016에서 한 것입니다. 그 외의 환경에서는 안 될 수도 있습니다




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 3/6/2023]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




1  2  3  4  [5]  6  7  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13509정성태1/3/20242144오류 유형: 887. .NET Core 2 이하의 프로젝트에서 System.Runtime.CompilerServices.Unsafe doesn't support netcoreapp2.0.
13508정성태1/3/20242162오류 유형: 886. ORA-28000: the account is locked
13507정성태1/2/20242826닷넷: 2191. C# - IPGlobalProperties를 이용해 netstat처럼 사용 중인 Socket 목록 구하는 방법파일 다운로드1
13506정성태12/29/20232394닷넷: 2190. C# - 닷넷 코어/5+에서 달라지는 System.Text.Encoding 지원
13505정성태12/27/20232945닷넷: 2189. C# - WebSocket 클라이언트를 닷넷으로 구현하는 예제 (System.Net.WebSockets)파일 다운로드1
13504정성태12/27/20232522닷넷: 2188. C# - ASP.NET Core SignalR로 구현하는 채팅 서비스 예제파일 다운로드1
13503정성태12/27/20232385Linux: 67. WSL 환경 + mlocate(locate) 도구의 /mnt 디렉터리 검색 문제
13502정성태12/26/20232484닷넷: 2187. C# - 다른 프로세스의 환경변수 읽는 예제파일 다운로드1
13501정성태12/25/20232298개발 환경 구성: 700. WSL + uwsgi - IPv6로 바인딩하는 방법
13500정성태12/24/20232362디버깅 기술: 194. Windbg - x64 가상 주소를 물리 주소로 변환
13498정성태12/23/20233049닷넷: 2186. 한국투자증권 KIS Developers OpenAPI의 C# 래퍼 버전 - eFriendOpenAPI NuGet 패키지
13497정성태12/22/20232451오류 유형: 885. Visual Studiio - error : Could not connect to the remote system. Please verify your connection settings, and that your machine is on the network and reachable.
13496정성태12/21/20232433Linux: 66. 리눅스 - 실행 중인 프로세스 내부의 환경변수 설정을 구하는 방법 (gdb)
13495정성태12/20/20232403Linux: 65. clang++로 공유 라이브러리의 -static 옵션 빌드가 가능할까요?
13494정성태12/20/20232535Linux: 64. Linux 응용 프로그램의 (C++) so 의존성 줄이기(ReleaseMinDependency) - 두 번째 이야기
13493정성태12/19/20232627닷넷: 2185. C# - object를 QueryString으로 직렬화하는 방법
13492정성태12/19/20232312개발 환경 구성: 699. WSL에 nopCommerce 예제 구성
13491정성태12/19/20232260Linux: 63. 리눅스 - 다중 그룹 또는 사용자를 리소스에 권한 부여
13490정성태12/19/20232387개발 환경 구성: 698. Golang - GLIBC 의존을 없애는 정적 빌드 방법
13489정성태12/19/20232168개발 환경 구성: 697. GoLand에서 ldflags 지정 방법
13488정성태12/18/20232099오류 유형: 884. HTTP 500.0 - 명령행에서 실행한 ASP.NET Core 응용 프로그램을 실행하는 방법
13487정성태12/16/20232405개발 환경 구성: 696. C# - 리눅스용 AOT 빌드를 docker에서 수행 [1]
13486정성태12/15/20232216개발 환경 구성: 695. Nuget config 파일에 값 설정/삭제 방법
13485정성태12/15/20232097오류 유형: 883. dotnet build/restore - error : Root element is missing
13484정성태12/14/20232172개발 환경 구성: 694. Windows 디렉터리 경로를 WSL의 /mnt 포맷으로 구하는 방법
13483정성태12/14/20232316닷넷: 2184. C# - 하나의 resource 파일을 여러 프로그램에서 (AOT 시에도) 사용하는 방법파일 다운로드1
1  2  3  4  [5]  6  7  8  9  10  11  12  13  14  15  ...