mail 黑名單擷取 (VB.NET)

[VB.NET]mail 黑名單擷取 (原創程式)

splitmail.rar

使用方法:

c:\mail.txt 放黑名單資料

執行程式 會排序 刪除重覆資料

如果是 gmail yahoo hinet seednet

常見免費信箱 封鎖 完整e-mail

奇怪的網域 則直接封鎖*@網域

 

Imports System.IO
Imports System.Text
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
        fileName = "c:\mail.txt"
        If Not File.Exists(fileName) Then
            MessageBox.Show(fileName & "檔案不存在")
            Exit Sub
        End If
        '第一次 去除 重複mail
        distmail(fileName)
        saveMAil(fileName)
        '第一次 去除 重複網域
        distmail(fileName)
        saveMAil(fileName)


    End Sub
    Function saveMAil(ByVal filename As String)
        Dim FileNum As Integer
        FileNum = FreeFile()
        FileOpen(FileNum, filename, OpenMode.Output)
        Dim i As Integer
        Dim a() As String
        ListBox1.SelectedIndex = 0

        For i = 0 To ListBox1.Items.Count - 1
            ListBox1.SelectedIndex = i
            If ListBox1.Text <> "" Then

                a = Split(ListBox1.SelectedItem.ToString, "@")

                If a.Length = 2 Then '如果 沒有@ 則不判斷


                    Dim z = a(1).Substring(0, 2)

                    If z <> "se" And z <> "ho" And z <> "ms" And z <> "ya" And z <> "um" And z <> "xu" And z <> "cm" And z <> "hi"  And z <> "gm" Then

                        PrintLine(FileNum, "*@" & a(1))    '把@後面的字串存進來
                    Else
                        PrintLine(FileNum, ListBox1.SelectedItem.ToString)

                    End If
                End If
            End If

        Next

        FileClose(FileNum)
        Return True

    End Function
    Function distmail(ByVal fileName As String)
        Dim mail As New ArrayList

        Dim ary() As String


        ' 1 先讀入mail.txt 排除重覆的,加到mail

        Using fs As New FileStream(fileName, FileMode.Open, FileAccess.Read)
            Dim sr As New StreamReader(fileName, Encoding.GetEncoding("big5"))
            ary = Split(sr.ReadToEnd, vbCrLf)
            For Each i As String In ary.Distinct.ToArray()
                mail.Add(i)
            Next

            sr.Close()
        End Using
        mail.Sort() '再排序

        ListBox1.DataSource = mail
        ListBox1.DisplayMember = "tostring()"
        Return True



    End Function
End Class


如有錯誤 歡迎指正