

'------------------------------------------------------------------------------
'
'
'          Mail Checker   Ver:1.10
'                         Cre:Hidetaka Oda      Dat:2003/02/04
'                                               Upd:    /02/14
'                                               Upd:    /03/20
'
'
'------------------------------------------------------------------------------


    Option Explicit

    '/*  ϐ錾  */

    ' Mް
    Private Mes As String

    ' ʐM
    Private Reply As String * 4

    ' ݏ
    Private MailStep As String

    ' MҰِ
    Private Mail_n As String

    ' ݏf
    Private StepFlg As String


' update start 2003/03/20


    ' ݕωf
    Private IconFlg As String


' update end


    ' ϰp
    Private Timer_Flg As Integer
    Private Timer_Cycle As Integer
    Private Timer_Unit As Integer
    Private Timer_Reg As String * 1


'------------------------------------------------------------------------------


    '/*  ݂ڲ֕\  */
    Private Type NOTIFYICONDATA


        ' NOTIFYCONDATA̻
        cbSize As Long

        ' ޳
        hWnd As Long

        ' ID
        UID As Long

        ' ׸
        uFlags As Long

        ' ү
        uCallbackMessage As Long

        ' ݂
        hIcon As Long

        ' ToolTip÷
        szTip As String * 64


    End Type


'------------------------------------------------------------------------------


    Private Declare Function Shell_NotifyIconA Lib "SHELL32" _
            (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Integer


'------------------------------------------------------------------------------


    '/*  ڲ֘A̧ݸ  */
    Private Function SetNotifyIconData(hWnd As Long, ID As Long, flags As Long, _
                            CallbackMessage As Long, Icon As Long, Tip As String) As NOTIFYICONDATA


        Dim typNID As NOTIFYICONDATA


        typNID.cbSize = Len(typNID)
        typNID.hWnd = hWnd
        typNID.UID = ID
        typNID.uFlags = flags
        typNID.uCallbackMessage = CallbackMessage
        typNID.hIcon = Icon
        typNID.szTip = Tip
        SetNotifyIconData = typNID


    End Function


'------------------------------------------------------------------------------


    '/*  ̫۰  */
    Private Sub Form_Load()
  
  
        ' ꎞgpϐ
        Dim Ret As String
        Dim Inform1 As String
        Dim Inform2 As String


        ' ϐ
        Ret = ""
        Mes = ""
        Reply = ""
        MailStep = ""
        Mail_n = ""
        StepFlg = ""
        IconFlg = ""


        '--  ݒ̕  --
        ' 
        Text1.Text = GetSetting("mailchk", "setting", "19")

        ' հ
        Text2.Text = GetSetting("mailchk", "setting", "21")

        ' ߽ܰ
        Ret = GetSetting("mailchk", "setting", "16")

        ' Ұװ
        Text4.Text = GetSetting("mailchk", "setting", "13")

        ' ϰ
        Text5.Text = GetSetting("mailchk", "setting", "3")

        ' m点
        Inform1 = GetSetting("mailchk", "setting", "9")

        ' ϰP
        Inform2 = GetSetting("mailchk", "setting", "14")

        ' ϰ
        Timer_Reg = GetSetting("mailchk", "setting", "18")


        ' Í
        Call Pass_Analysis(Ret)
        Text3.Text = set_str

        Timer1.Enabled = False
        Command1.Enabled = True
        Command2.Enabled = False


        ' Oݒ肳ĂȂݒʔ\
        If Text1.Text <> "" And _
            Text2.Text <> "" And _
            Text3.Text <> "" And _
            Inform1 <> "" And _
            Timer_Reg <> "" Then


            Check1.Value = Inform1
            Timer_Unit = Inform2
            Call Command1_Click


        End If


    End Sub


'------------------------------------------------------------------------------


    '/*  ސݒ藓I  */
    Private Sub Text1_GotFocus()


        length = Len(Text1.Text)
        Text1.SelStart = str_place
        Text1.SelLength = length


    End Sub


'------------------------------------------------------------------------------


    '/*  Đݒ藓I  */
    Private Sub Text2_GotFocus()


        length = Len(Text2.Text)
        Text2.SelStart = str_place
        Text2.SelLength = length


    End Sub


'------------------------------------------------------------------------------


    '/*  ߽ܰސݒ藓I  */
    Private Sub Text3_GotFocus()


        length = Len(Text3.Text)
        Text3.SelStart = str_place
        Text3.SelLength = length


    End Sub


'------------------------------------------------------------------------------


    '/*  Ұװݒ藓I  */
    Private Sub Text4_GotFocus()


        length = Len(Text4.Text)
        Text4.SelStart = str_place
        Text4.SelLength = length


    End Sub


'------------------------------------------------------------------------------


    '/*  ϰݒ藓I  */
    Private Sub Text5_GotFocus()


        length = Len(Text5.Text)
        Text5.SelStart = str_place
        Text5.SelLength = length


    End Sub


'------------------------------------------------------------------------------
' Update start 2003/03/20


    '/*    */
    Private Sub Text5_LostFocus()


        ' bPʂ̏ꍇ
        If Timer_Unit = 0 Then


            If Text5.Text < 10 Then


                MsgBox "10bȏŐݒ肵ĉB", vbOKOnly + vbInformation, "Ұޯ"
                Text5.Text = 10


            End If


        End If
    
    
    End Sub


' Update end
'------------------------------------------------------------------------------


    '/*  Pʊm  */
    Private Sub Combo1_Click()


        Timer_Unit = Combo1.ListIndex


' Update start 2003/03/20


        ' 
        Call Text5_LostFocus


' Update end


    End Sub


'------------------------------------------------------------------------------


    '/*    */
    Private Sub Command1_Click()


        ' ϐ錾
        ' ^C}[ݒ莞gp
        Dim i As Integer
        Dim List_Count As Integer
        Dim List_Content As String


        ' ݒ
        If Text1.Text = "" Then


            MsgBox "ޖݒ肵ĉ"
            Exit Sub


        End If


        ' 
        If Not IsNumeric(Text5.Text) Then


            MsgBox "l͂ĉ", vbOKOnly + vbExclamation, "Numeric Error"
            Exit Sub


        End If


        If Text5.Text = 0 Then


            MsgBox "`FbNݒ肵ĉ(0͖ł)", vbOKOnly + vbExclamation, "Zero Error"
            Exit Sub


        ElseIf Text5.Text > 0 And Text5.Text < 10 And Timer_Unit = 0 Then


            MsgBox "`FbN10bLł", vbOKOnly + vbExclamation, "Cycle Error"
            Exit Sub


        Else


            ' ^C}[ݒ萔l擾
            Timer_Cycle = Text5.Text


            If Timer_Unit = 0 And Timer_Reg <> "1" Then


                Timer_Unit = Combo1.ListIndex


            End If


            ' ݒɕKvȐl擾
            List_Count = Combo1.ListCount
            List_Content = Combo1.Text


            ' l
            If Timer_Unit = -1 Then


                For i = 0 To List_Count Step 1


                    If List_Content = Combo1.List(i) Then


                        Timer_Unit = i
                        Exit For


                    End If


                Next i


            End If


            ' ϰ
            Select Case Timer_Unit


                Case 0
                    ' b
                    Timer1.Interval = Timer_Cycle * Timer_Interval
                    Timer_Flg = Timer_Cycle
                    Combo1.Text = "b"


                Case 1
                    ' 
                    Timer1.Interval = Timer_MaxCount * Timer_Interval
                    Timer_Flg = 0
                    Combo1.Text = ""


                Case 2
                    ' 
                    Timer1.Interval = Timer_MaxCount * Timer_Interval
                    Timer_Cycle = Timer_Cycle * Timer_MaxCount
                    Timer_Flg = 0
                    Combo1.Text = ""


            End Select


        End If


        If Text1.Text <> "" Then


' Update start 2003/03/20


            ' ꎞ۰
            Winsock1.Close


' Update end


            ' ڑJn
            Winsock1.Connect Text1.Text, 110
            MailStep = "connect"
            Timer1.Enabled = True
            Command1.Enabled = False
            Command2.Enabled = True


        End If


        ' ̫т
        Call SystemTray_In


End Sub


'------------------------------------------------------------------------------


    '/*    */
    Private Sub Command2_Click()


        ' eݒ菉
        Timer1.Enabled = False
        Winsock1.Close
        MailStep = "connect"
        StepFlg = ""
        Label5.Caption = "[`FbN~"
        Command1.Enabled = True
        Command2.Enabled = False

        ' ڲݍ폜
        Call SystemTray_Out


    End Sub


'------------------------------------------------------------------------------
' Update start 2003/03/20


    '/*  ƭ  */
    Private Sub Command3_Click()


        ' ꎞ۰
        Winsock1.Close

        ' Port:110ڑ
        Winsock1.Connect Text1.Text, 110


    End Sub


' Update end
'------------------------------------------------------------------------------


    '/*  ϰN  */
    Private Sub Timer1_Timer()


        If Timer_Flg = Timer_Cycle Then



            ' bw͏O
            If Timer_Unit <> 0 Then


                ' ϰُ
                Timer_Flg = 0


            End If


            ' ꎞ۰
            Winsock1.Close

            ' Port:110ڑ
            Winsock1.Connect Text1.Text, 110


        Else


            Timer_Flg = Timer_Flg + 1


        End If


    End Sub


'------------------------------------------------------------------------------


    '/*  Winsock۰_Ұٻސڑٰ  */
    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)


        ' ނүޓemFgp
        Dim i As Integer


        ' ްM
        Winsock1.GetData Mes
        Reply = Left(Mes, 4)


        ' ʐM󋵔f
        If StepFlg = "" Then


            StepFlg = "user"


        End If


        ' ҰٻސڑmF
        If MailStep = "connect" And Reply = "+OK " Then


            MailStep = "user"


        ElseIf Reply = "-ERR" Then


            MailStep = "connect"


        End If



        '--  ĊmF  --
        ' ĂmFς݂̏ꍇ
        If StepFlg <> "" And StepFlg = "user" And MailStep <> "connect" Then


            StepFlg = "pass"


        End If


        ' Ұٻނւ̱ĊmF
        If MailStep = "user" And Reply = "+OK " Then


            Winsock1.SendData "USER " & Text2.Text & vbCrLf
            MailStep = "pass"
            Exit Sub


        ElseIf Reply = "-ERR" Then


            MailStep = "connect"


        End If



        '--  ߽ܰފmF  --
        ' ߽ܰނmFς݂̏ꍇ
        If StepFlg <> "" And StepFlg = "pass" And MailStep <> "connect" Then


            StepFlg = "stat"


        End If


        ' Ұٻނւ߽ܰފmF
        If MailStep = "pass" And Reply = "+OK " Then


            Winsock1.SendData "PASS " & Text3.Text & vbCrLf
            MailStep = "stat"
            Exit Sub


        ElseIf Reply = "-ERR" Then


            MailStep = "connect"


        End If



        '--  ҰِmF  --
        ' ҰِmFς݂̏ꍇ
        If StepFlg <> "" And StepFlg = "stat" And MailStep <> "connect" Then


            StepFlg = "allOK"


        End If


        ' ҰٻނւҰِmF
        If MailStep = "stat" And Reply = "+OK " Then


            Winsock1.SendData "STAT" & vbCrLf
            MailStep = "allOK"
            Exit Sub


        ElseIf Reply = "-ERR" Then


            MailStep = "connect"


        End If



        '--  Ұِf  --
        ' 󋵊mFH
'        If StepFlg <> "" And StepFlg = "allOK" And MailStep <> "connect " Then


'            StepFlg = "mail"


'        End If


        ' Ұٻނ̓e
        If MailStep = "allOK" Then


            For i = 0 To Max_Mail


                Mail_n = Mid(Mes, 5, i)


                If Right(Mail_n, 1) = " " Then


                    Mail_n = Left(Mail_n, i - 1)
                    Exit For


                End If


            Next i


            ' Ұِɂ镪
            If Not Mail_n = 0 Then


                If Check1.Value = 1 Then


                    If Form2.Visible = False Then


                        Form2.Visible = True


                    End If


                End If


                Label5.Caption = "[" & Mail_n & "ʓ͂Ă܂"
                Form2.Label1.Caption = "[" & Mail_n & "ʓ͂Ă܂"


' Update start 2003/03/20


                ' ݕωf
                If IconFlg = "" Then


                    IconFlg = "1"

                    ' ڲXV
                    Call SystemTray_Out
                    Call SystemTray_In

                End If


' Update end


            Else


                Form2.Visible = False
                Label5.Caption = "[͓͂Ă܂"
                Form2.Label1.Caption = "[͓͂Ă܂"


' Update start 2003/03/20


                ' ݕωf
                If IconFlg = "1" Then


                    IconFlg = ""

                    ' ڲXV
                    Call SystemTray_Out
                    Call SystemTray_In

                End If


' Update start 2003/03/20


            End If


            ' ԏ
            StepFlg = ""
            MailStep = "connect"


        End If


        '--  Error  --
        If Reply <> "+OK " Then


            Select Case StepFlg


                Case "pass"
                    MsgBox "[UhcɌ肪܂", vbOKOnly + vbExclamation, "User Error"
                    StepFlg = ""

                
                Case "stat"
                    MsgBox "pX[hɌ肪܂", vbOKOnly + vbExclamation, "Pass Error"
                    StepFlg = ""


                Case "allOK"
                    MsgBox "rs`sɌ肪܂", vbOKOnly + vbExclamation, "Stat Error"
                    StepFlg = ""


                Case Else
                    MsgBox "OIȃG[܂", vbOKOnly + vbExclamation, "Exception Error"


            End Select


            Winsock1.Close
            Visible = True
            Command1.Enabled = True
            Command2.Enabled = False
            Timer1.Enabled = False
            Label5.Caption = "G["
            Form2.Label1.Caption = "G["


        End If


    End Sub


'------------------------------------------------------------------------------


    '/*  ̫тɂķ޳  */
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)


        '--݂̺۰ٖ
        Dim ActiveName As String


        '--݂̺۰ٖ擾
        ActiveName = ActiveControl.Name


        '--f
        Select Case KeyCode


            '--Q
            Case Key_Q


                '--+Ctrl
                If Shift = Key_Ctrl Then


                    Call SystemTray_In


                End If


            Case Else


        End Select


    End Sub


'------------------------------------------------------------------------------


    '/*  ݂ڲɕ\A̫э폜  */
    Public Sub SystemTray_In()


        ' ϐ錾
        Dim intRet    As Integer
        Dim strTip    As String
        Dim typNID    As NOTIFYICONDATA
        Dim IconType  As Long

        ' ToolTip÷(݂ϳ킹\)
        If Mail_n = "" Or Mail_n = "0" Then


            IconType = Icon
            strTip = "[͓͂Ă܂" & Chr$(0)


        Else


            IconType = Form2.Icon
            strTip = "[" & Mail_n & "ʓ͂Ă܂" & Chr$(0)


        End If


        ' \̾
        typNID = SetNotifyIconData(hWnd, vbNull, NIF_MESSAGE Or NIF_ICON Or NIF_TIP, _
                                    MouseMove, IconType, strTip)

        ' ڲݕ\
        intRet = Shell_NotifyIconA(NIM_ADD, typNID)

        WindowState = vbMinimized
        Visible = False


    End Sub


'------------------------------------------------------------------------------


    '/*  ڲ籲ݏ  */
    Public Sub SystemTray_Out()


        ' ڲ폜
        Dim intRet As Integer
        Dim typNID As NOTIFYICONDATA


        ' \̾
        typNID = SetNotifyIconData(hWnd, vbNull, NIF_MESSAGE Or NIF_ICON Or NIF_TIP, _
                                                                        vbNull, Icon, "")

        ' ڲݍ폜
        intRet = Shell_NotifyIconA(NIM_DELETE, typNID)


    End Sub


'------------------------------------------------------------------------------


    '/*  ݲ  */
    Public Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, y As Single)


        ' ݔfϐ
        Dim sx As Integer


        ' ݔfϐɑ
        sx = X \ Screen.TwipsPerPixelX


        Select Case sx


            Case L_DblClick
                ' ٸد
                If Not Visible Then


                    Visible = True
                    WindowState = vbNormal
                    SetFocus

                    ' ڲݏ
                    Call SystemTray_Out


                End If


            Case R_DblClick
                ' Eٸد
                Form2.Visible = True
                Form2.WindowState = vbNormal
                Form2.SetFocus


            Case Else


        End Select


    End Sub


'------------------------------------------------------------------------------


    '/*  I  */
    Private Sub Form_Unload(Cancel As Integer)


        '--  ݒ̕ۑ  --
        ' 
        SaveSetting "mailchk", "setting", "19", Text1.Text

        ' հ
        SaveSetting "mailchk", "setting", "21", Text2.Text

        ' Ұװ
        SaveSetting "mailchk", "setting", "13", Text4.Text

        ' m点
        SaveSetting "mailchk", "setting", "9", Check1.Value

        ' ϰ
        SaveSetting "mailchk", "setting", "3", Text5.Text

        ' ϰP
        SaveSetting "mailchk", "setting", "14", Timer_Unit

        ' ϰ
        SaveSetting "mailchk", "setting", "18", 1


        ' ߽ܰވÍ
        Call Pass_Change(Text3.Text)
        SaveSetting "mailchk", "setting", "16", set_str


        ' I
        End


    End Sub


'------------------------------------------------------------------------------

