Microsoft MVP성태의 닷넷 이야기
.NET Framework: 682. 아웃룩 사용자를 위한 중국어 스팸 필터 Add-in [링크 복사], [링크+제목 복사]
조회: 12605
글쓴 사람
정성태 (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

비밀번호

댓글 작성자
 




... 31  32  33  34  [35]  36  37  38  39  40  41  42  43  44  45  ...
NoWriterDateCnt.TitleFile(s)
12752정성태8/4/20216420개발 환경 구성: 592. JetBrains의 IDE(예를 들어, PyCharm)에서 Visual Studio 키보드 매핑 적용
12751정성태8/4/20219488개발 환경 구성: 591. Windows 10 WSL2 환경에서 docker-compose 빌드하는 방법
12750정성태8/3/20216285디버깅 기술: 181. windbg - 콜 스택의 "Call Site" 오프셋 값이 가리키는 위치
12749정성태8/2/20215691개발 환경 구성: 590. Visual Studio 2017부터 단위 테스트에 DataRow 특성 지원
12748정성태8/2/20216299개발 환경 구성: 589. Azure Active Directory - tenant의 관리자(admin) 계정 로그인 방법
12747정성태8/1/20216897오류 유형: 748. 오류 기록 - MICROSOFT GRAPH – HOW TO IMPLEMENT IAUTHENTICATIONPROVIDER파일 다운로드1
12746정성태7/31/20218912개발 환경 구성: 588. 네트워크 장비 환경을 시뮬레이션하는 Packet Tracer 프로그램 소개
12745정성태7/31/20216753개발 환경 구성: 587. Azure Active Directory - tenant의 관리자 계정 로그인 방법
12744정성태7/30/20217359개발 환경 구성: 586. Azure Active Directory에 연결된 App 목록을 확인하는 방법?
12743정성태7/30/20218038.NET Framework: 1083. Azure Active Directory - 외부 Token Cache 저장소를 사용하는 방법파일 다운로드1
12742정성태7/30/20217311개발 환경 구성: 585. Azure AD 인증을 위한 사용자 인증 유형
12741정성태7/29/20218506.NET Framework: 1082. Azure Active Directory - Microsoft Graph API 호출 방법파일 다운로드1
12740정성태7/29/20217194오류 유형: 747. SharePoint - InvalidOperationException 0x80131509
12739정성태7/28/20217151오류 유형: 746. Azure Active Directory - IDW10106: The 'ClientId' option must be provided.
12738정성태7/28/20217729오류 유형: 745. Azure Active Directory - Client credential flows must have a scope value with /.default suffixed to the resource identifier (application ID URI).
12737정성태7/28/20216700오류 유형: 744. Azure Active Directory - The resource principal named api://...[client_id]... was not found in the tenant
12736정성태7/28/20217180오류 유형: 743. Active Azure Directory에서 "API permissions"의 권한 설정이 "Not granted for ..."로 나오는 문제
12735정성태7/27/20217720.NET Framework: 1081. C# - Azure AD 인증을 지원하는 데스크톱 애플리케이션 예제(Windows Forms) [2]파일 다운로드1
12734정성태7/26/202123723스크립트: 20. 특정 단어로 시작하거나/끝나는 문자열을 포함/제외하는 정규 표현식 - Look-around
12733정성태7/23/202111056.NET Framework: 1081. Self-Contained/SingleFile 유형의 .NET Core/5+ 실행 파일을 임베딩한다면? [1]파일 다운로드2
12732정성태7/23/20216362오류 유형: 742. SharePoint - The super user account utilized by the cache is not configured.
12731정성태7/23/20217467개발 환경 구성: 584. Add Internal URLs 화면에서 "Save" 버튼이 비활성화 된 경우
12730정성태7/23/20219018개발 환경 구성: 583. Visual Studio Code - Go 코드에서 입력을 받는 경우
12729정성태7/22/20217976.NET Framework: 1080. xUnit 단위 테스트에 메서드/클래스 수준의 문맥 제공 - Fixture
12728정성태7/22/20217449.NET Framework: 1079. MSTestv2 단위 테스트에 메서드/클래스/어셈블리 수준의 문맥 제공
12727정성태7/21/20218396.NET Framework: 1078. C# 단위 테스트 - MSTestv2/NUnit의 Assert.Inconclusive 사용법(?) [1]
... 31  32  33  34  [35]  36  37  38  39  40  41  42  43  44  45  ...