'Constants for search strings in the body immediately preceding and following the failed e-mail address
Public Const RTN_S1 = "----- The following addresses had permanent fatal errors -----"
Public Const RTN_FTAG1 = "<"
Public Const RTN_ETAG1 = ">"
'and so on...
Public Const RTN_S11 = "message was addressed"
Public Const RTN_FTAG11 = ", "
Public Const RTN_ETAG11 = ","
Public Const RTN_S12 = "The user(s) account is disabled"
Public Const RTN_FTAG12 = "<"
Public Const RTN_ETAG12 = ">"
Public Type RTN_EMAIL
intNum As Integer 'Number of occurence of search string
strTgt As String 'Search string
strFTag As String 'Tag preceding e-mail address
strETAg As String 'Tag following e-mail address
End Type
'_________________________
Public Function fParseRtnEmail(Byval strText As String) As String
'--- Given the text of an e-mail return notification,
' parses the failed e-mail address
'--- Parameters
' [In]
' strText: the string to parse
'--- Return value
' returns the e-mail address else an empty string if the parsing was unsuccessful
Dim intC1 As Integer 'Counter
Dim intC2 As Integer 'Counter
Dim intTmp 'Temp position
Dim intP1 As Integer 'Position of first character after the search string
Dim intP2 As Integer 'Position of tag preceding the e-mail address
Dim intP3 As Integer 'Position of tag following the e-mail address
Dim intFlag As Integer 'True if the e-mail address was parsed from Text
Dim audtTags() As RTN_EMAIL 'Tags to search for e-mail address
Dim strData As String 'Current value parsed from Text
'Check strText isn't empty
If Len(strText) = 0 Then
Exit Function
End If
'Load the search tags in the udt array
Redim audtTags(0 To 12)
audtTags(0).intNum = 2
audtTags(0).strTgt = RTN_S1
audtTags(0).strFTag = RTN_FTAG1
audtTags(0).strETag = RTN_ETAG1
audtTags(1).intNum = 1
audtTags(1).strTgt = RTN_S2
audtTags(1).strFTag = RTN_FTAG2
audtTags(1).strETag = RTN_ETAG2
audtTags(2).intNum = 1
audtTags(2).strTgt = RTN_S3
audtTags(2).strFTag = RTN_FTAG3
audtTags(2).strETag = RTN_ETAG13
audtTags(3).intNum = 1
audtTags(3).strTgt = RTN_S4
audtTags(3).strFTag = RTN_FTAG4
audtTags(3).strETag = RTN_ETAG4
audtTags(4).intNum = 1
audtTags(4).strTgt = RTN_S5
audtTags(4).strFTag = RTN_FTAG5
audtTags(4).strETag = RTN_ETAG5
audtTags(5).intNum = 1
audtTags(5).strTgt = RTN_S6
audtTags(5).strFTag = RTN_FTAG6
audtTags(5).strETag = RTN_ETAG6
audtTags(6).intNum = 1
audtTags(6).strTgt = RTN_S7
audtTags(6).strFTag = RTN_FTAG7
audtTags(6).strETag = RTN_ETAG7
audtTags(7).intNum = 1
audtTags(7).strTgt = RTN_S8
audtTags(7).strFTag = RTN_FTAG8
audtTags(7).strETag = RTN_ETAG8
audtTags(8).intNum = 2
audtTags(8).strTgt = RTN_S9
audtTags(8).strFTag = RTN_FTAG9
audtTags(8).strETag = RTN_ETAG9
audtTags(9).intNum = 1
audtTags(9).strTgt = RTN_S10
audtTags(9).strFTag = RTN_FTAG10
audtTags(9).strETag = RTN_ETAG10
audtTags(10).intNum = 1
audtTags(10).strTgt = RTN_S11
audtTags(10).strFTag = RTN_FTAG11
audtTags(10).strETag = RTN_ETAG11
audtTags(11).intNum = 1
audtTags(11).strTgt = RTN_S12
audtTags(11).strFTag = RTN_FTAG12
audtTags(11).strETag = RTN_ETAG12
audtTags(12).strTgt = RTN_S13
audtTags(12).strFTag = RTN_FTAG13
audtTags(12).strETag = RTN_ETAG13
'Move through the primary search string array and parse the failed address
intFlag = False
For intC1 = Lbound(audtTags) To Ubound(audtTags)
'Look for each search string
If Instr(1, strText, audtTags(intC1).strTgt) Then
'Store the position of the first character after the primary search string
If audtTags(intC1).intNum < 2 Then
'The string only occurs once before the e-mail address
intP1 = Instr(1, strText, audtTags(intC1).strTgt) + _
Len(audtTags(intC1).strTgt)
Else
'The string may occur more than once before the e-mail address
intTmp = 1
For intC2 = 1 To audtTags(intC1).intNum
intP1 = Instr(intTmp, strText, audtTags(intC1).strTgt)
If intP1 = 0 Then
intP1 = intTmp
Exit For
Else
intTmp = intP1 + Len(audtTags(intC1).strTgt)
End If
Next
End If
'Store the position of the tag preceeding the e-mail address
intP2 = Instr(intP1, strText, audtTags(intC1).strFTag)
If intP2 >= intP1 Then
'Store the position of the tag following the e-mail address
intP3 = Instr(intP2 + Len(audtTags(intC1).strFTag), strText, audtTags(intC1).strETag)
'Parse the data
If intP3 > intP2 + 1 Then
strData = Trim$(Mid$(strText, intP2 + Len(audtTags(intC1).strFTag), _
intP3 - intP2 - Len(audtTags(intC1).strFTag)))
If Not strData = "" Then
'Verify it is an e-mail address
If Instr(1, strData, "@") > 0 Then
fParseRtnEmail = strData
'Flag we found it
intFlag = True
End If
End If
End If
End If
End If
'Exit if we found a primary search string
If intFlag Then Exit For
Next
End Function