Attribute VB_Name = "Mail"
Public Type sMail
    Receiver As String
    Sender As String
    Message As String
    Date As String
    Time As String
End Type

Public Function Add_Mail(Receiver$, Sender$, Message$)
    Dim strMail$
    strMail$ = App.Path & "\Mail.ini"
    Open strMail$ For Append As #1
        Print #1, Receiver$ & "|" & Sender$ & "|" & Message$ & "|" & Date & "|" & Time
    Close #1
End Function

Public Function Get_Mail(Receiver$) As sMail
    Dim i&, strMail$, strContents$()
    Dim strFields$(), lCtr&, lTop&, lBottom&
    strMail$ = App.Path & "\Mail.ini"
    Open strMail$ For Append As #1: Close #1 'Create file
    Open strMail$ For Binary As #1
        strContents$() = Split(Input(LOF(1), #1), vbCrLf) 'Get all lines and split by return
    Close #1
    'Loop through contents
    For i = 0 To UBound(strContents)
        If Len(strContents(i)) > 0 And InStr(strContents(i), "|") <> 0 Then
            strFields$() = Split(strContents(i), "|")
                If UBound(strFields) <> 0 Then
                    If LCase(strFields(0)) = LCase(Receiver) Then
                            Dim sMailData As sMail
                            With sMailData
                                .Receiver = strFields(0)
                                .Sender = strFields(1)
                                .Message = strFields(2)
                                .Date = strFields(3)
                                .Time = strFields(4)
                            End With
                        'Return the mail data
                        Get_Mail = sMailData
                        
                        'Proceed to remove the mail
                        lTop = UBound(strContents$)
                        lBottom = LBound(strContents$)
                            For lCtr = i To lTop - 1
                                strContents(lCtr) = strContents(lCtr + 1)
                            Next
                        On Error Resume Next
                        ReDim Preserve strContents(lBottom To lTop - 1)
                    Exit For
                End If
            End If
        End If
    Next
    Open strMail$ For Output As #1
        For i = 0 To UBound(strContents)
            If Len(strContents(i)) <> 0 Then
                Print #1, strContents(i)
            End If
        Next
    Close #1
End Function
