Microsoft MVP성태의 닷넷 이야기
.NET Framework: 682. 아웃룩 사용자를 위한 중국어 스팸 필터 Add-in [링크 복사], [링크+제목 복사]
조회: 12689
글쓴 사람
정성태 (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)
12779정성태8/13/20218972개발 환경 구성: 596. 공공 데이터 포털에서 버스 노선 및 위치 정보 조회 API 사용법
12778정성태8/12/20216242오류 유형: 755. PyCharm - "Manage Repositories"의 목록이 나오지 않는 문제
12777정성태8/12/20217878오류 유형: 754. Visual Studio - Input or output cannot be redirected because the specified file is invalid.
12776정성태8/12/20217202오류 유형: 753. gunicorn과 uwsgi 함께 사용 시 ERR_CONNECTION_REFUSED
12775정성태8/12/202117662스크립트: 22. 파이썬 - 윈도우 환경에서 개발한 Django 앱을 WSL 환경의 gunicorn을 이용해 실행
12774정성태8/11/20218800.NET Framework: 1087. C# - Collection 개체의 다중 스레드 접근 시 "Operations that change non-concurrent collections must have exclusive access" 예외 발생
12773정성태8/11/20217973개발 환경 구성: 595. PyCharm - WSL과 연동해 Django App을 윈도우에서 리눅스 대상으로 개발
12772정성태8/11/20219481스크립트: 21. 파이썬 - 윈도우 환경에서 개발한 Django 앱을 WSL 환경의 uwsgi를 이용해 실행 [1]
12771정성태8/11/20217893Windows: 196. "Microsoft Windows Subsystem for Linux Background Host" / "Vmmem"을 종료하는 방법
12770정성태8/11/20218573.NET Framework: 1086. C# - Windows Forms 응용 프로그램의 자식 컨트롤 부하파일 다운로드1
12769정성태8/11/20216526오류 유형: 752. Python - ImportError: No module named pip._internal.cli.main 두 번째 이야기
12768정성태8/10/20217558.NET Framework: 1085. .NET 6에 포함된 신규 BCL API [1]파일 다운로드1
12767정성태8/10/20218653오류 유형: 752. Python - ImportError: No module named pip._internal.cli.main
12766정성태8/9/20217172Java: 32. closing inbound before receiving peer's close_notify
12765정성태8/9/20216497Java: 31. Cannot load JDBC driver class 'org.mysql.jdbc.Driver'
12764정성태8/9/202144933Java: 30. XML document from ServletContext resource [/WEB-INF/applicationContext.xml] is invalid
12763정성태8/9/20217952Java: 29. java.lang.NullPointerException - com.mysql.jdbc.ConnectionImpl.getServerCharset
12762정성태8/8/202111506Java: 28. IntelliJ - Unable to open debugger port 오류
12761정성태8/8/20218691Java: 27. IntelliJ - java: package javax.inject does not exist [2]
12760정성태8/8/20216092개발 환경 구성: 594. 전용 "Command Prompt for ..." 단축 아이콘 만들기
12759정성태8/8/20219220Java: 26. IntelliJ + Spring Framework + 새로운 Controller 추가 [2]파일 다운로드1
12758정성태8/7/20218582오류 유형: 751. Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)
12757정성태8/7/20219258Java: 25. IntelliJ + Spring Framework 프로젝트 생성
12756정성태8/6/20218066.NET Framework: 1084. C# - .NET Core Web API 단위 테스트 방법 [1]파일 다운로드1
12755정성태8/5/20217175개발 환경 구성: 593. MSTest - 단위 테스트에 static/instance 유형의 private 멤버 접근 방법파일 다운로드1
12754정성태8/5/20218094오류 유형: 750. manage.py - Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
... 31  32  33  [34]  35  36  37  38  39  40  41  42  43  44  45  ...