Microsoft MVP성태의 닷넷 이야기
.NET Framework: 682. 아웃룩 사용자를 위한 중국어 스팸 필터 Add-in [링크 복사], [링크+제목 복사],
조회: 12696
글쓴 사람
정성태 (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)
12856정성태11/23/20218895.NET Framework: 1121. C# - 동일한 IP:Port로 바인딩 가능한 서버 소켓 [2]
12855정성태11/13/20216244개발 환경 구성: 605. Azure App Service - Kudu SSH 환경에서 FTP를 이용한 파일 전송
12854정성태11/13/20217798개발 환경 구성: 604. Azure - 윈도우 VM에서 FTP 여는 방법
12853정성태11/10/20216162오류 유형: 766. Azure App Service - JBoss 호스팅 생성 시 "This region has quota of 0 PremiumV3 instances for your subscription. Try selecting different region or SKU."
12851정성태11/1/20217550스크립트: 34. 파이썬 - MySQLdb 기본 예제 코드
12850정성태10/27/20218697오류 유형: 765. 우분투에서 pip install mysqlclient 실행 시 "OSError: mysql_config not found" 오류
12849정성태10/17/20217837스크립트: 33. JavaScript와 C#의 시간 변환 [1]
12848정성태10/17/20218811스크립트: 32. 파이썬 - sqlite3 기본 예제 코드 [1]
12847정성태10/14/20218659스크립트: 31. 파이썬 gunicorn - WORKER TIMEOUT 오류 발생
12846정성태10/7/20218415스크립트: 30. 파이썬 __debug__ 플래그 변수에 따른 코드 실행 제어
12845정성태10/6/20218244.NET Framework: 1120. C# - BufferBlock<T> 사용 예제 [5]파일 다운로드1
12844정성태10/3/20216246오류 유형: 764. MSI 설치 시 "... is accessible and not read-only." 오류 메시지
12843정성태10/3/20216693스크립트: 29. 파이썬 - fork 시 기존 클라이언트 소켓 및 스레드의 동작파일 다운로드1
12842정성태10/1/202125051오류 유형: 763. 파이썬 오류 - AttributeError: type object '...' has no attribute '...'
12841정성태10/1/20218519스크립트: 28. 모든 파이썬 프로세스에 올라오는 특별한 파일 - sitecustomize.py
12840정성태9/30/20218619.NET Framework: 1119. Entity Framework의 Join 사용 시 다중 칼럼에 대한 OR 조건 쿼리파일 다운로드1
12839정성태9/15/20219669.NET Framework: 1118. C# 11 - 제네릭 타입의 특성 적용파일 다운로드1
12838정성태9/13/20219317.NET Framework: 1117. C# - Task에 전달한 Action, Func 유형에 따라 달라지는 async/await 비동기 처리 [2]파일 다운로드1
12837정성태9/11/20218224VC++: 151. Golang - fmt.Errorf, errors.Is, errors.As 설명
12836정성태9/10/20217831Linux: 45. 리눅스 - 실행 중인 다른 프로그램의 출력을 확인하는 방법
12835정성태9/7/20219072.NET Framework: 1116. C# 10 - (15) CallerArgumentExpression 특성 추가 [2]파일 다운로드1
12834정성태9/7/20217468오류 유형: 762. Visual Studio 2019 Build Tools - 'C:\Program' is not recognized as an internal or external command, operable program or batch file.
12833정성태9/6/20216910VC++: 150. Golang - TCP client/server echo 예제 코드파일 다운로드1
12832정성태9/6/20217773VC++: 149. Golang - 인터페이스 포인터가 의미 있을까요?
12831정성태9/6/20216301VC++: 148. Golang - 채널에 따른 다중 작업 처리파일 다운로드1
12830정성태9/6/20218568오류 유형: 761. Internet Explorer에서 파일 다운로드 시 "Your current security settings do not allow this file to be downloaded." 오류
... [31]  32  33  34  35  36  37  38  39  40  41  42  43  44  45  ...