VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "CMailAddress"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
'programmed by ShareVB
'gestion d'une addresse mail au format Mail MIME

Option Explicit
Option Compare Text

Private mvarDisplayName As String 'copie locale
Private mvarAddress As String 'copie locale

'==================================================
'propriétés
'==================================================

Public Property Let Address(ByVal vData As String)
Attribute Address.VB_HelpID = 158
'utilisé lors de l'affectation d'une valeur à la propriété, du coté gauche de l'affectation.
'Syntax: X.Address = 5
    mvarAddress = vData
End Property

Public Property Get Address() As String
'utilisé lors de la lecture de la valeur de la propriété, du coté droit de l'instruction.
'Syntax: Debug.Print X.Address
    Address = mvarAddress
End Property

Public Property Let DisplayName(ByVal vData As String)
Attribute DisplayName.VB_HelpID = 156
'utilisé lors de l'affectation d'une valeur à la propriété, du coté gauche de l'affectation.
'Syntax: X.DisplayName = 5
    mvarDisplayName = vData
End Property

Public Property Get DisplayName() As String
'utilisé lors de la lecture de la valeur de la propriété, du coté droit de l'instruction.
'Syntax: Debug.Print X.DisplayName
    DisplayName = mvarDisplayName
End Property

'==================================================
'méthodes publiques
'==================================================

Public Function Parse(ByVal szAddress As String) As Boolean
    Dim posdeb As Long, posfin As Long
    
    szAddress = Trim$(szAddress)
    posdeb = InStr(szAddress, "<")
    If posdeb > 0 Then
        posfin = InStr(posdeb + 1, szAddress, ">")
        mvarDisplayName = Trim$(Mid$(szAddress, 1, posdeb - 1))
        mvarAddress = Trim$(Mid$(szAddress, posdeb + 1, posfin - posdeb - 1))
    Else
        mvarAddress = Trim$(szAddress)
    End If
    mvarAddress = Replace(mvarAddress, """", "")
    mvarDisplayName = Replace(mvarDisplayName, """", "")
End Function

Public Function Make() As String
    If Len(mvarDisplayName) Then
        Make = """" & mvarDisplayName & """ <" & mvarAddress & ">"
    Else
        Make = mvarAddress
    End If
End Function

'renvoie l'adresse tel que l'attend la commande smtp RCPT TO ou MAIL FROM
Public Function MakeSMTP() As String
    MakeSMTP = "<" & mvarAddress & ">"
End Function
