Version 2.4.2.2 - Remove Independentsoft Email, Replace with Limilabs.Mail, Remove manual Email Data Exctraction, Support Eml Files
This commit is contained in:
@@ -1,106 +1,105 @@
|
||||
Imports Independentsoft
|
||||
Imports Limilabs.Mail
|
||||
Imports Limilabs.Mail
|
||||
Imports Limilabs.Mail.MSG
|
||||
Imports System.Text.RegularExpressions
|
||||
|
||||
Public Class ClassEmailHeaderExtractor
|
||||
''' <summary>
|
||||
''' Extrahiert die Headerinformationen aus einem msg Objekt mithilfe der MSG.NET Klasse
|
||||
''' </summary>
|
||||
''' <param name="msg">Eine Email vom Typ Msg.Message</param>
|
||||
''' <returns>Headerinformationen als String oder Nothing wenn ein Fehler aufgetreten ist.</returns>
|
||||
Public Shared Function getMessageHeaders(msg As Msg.Message)
|
||||
Try
|
||||
Dim headers = msg.TransportMessageHeaders.Replace(vbCrLf, " ")
|
||||
Return headers
|
||||
Catch ex As Exception
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
'''' <summary>
|
||||
'''' Extrahiert die Headerinformationen aus einem msg Objekt mithilfe der MSG.NET Klasse
|
||||
'''' </summary>
|
||||
'''' <param name="msg">Eine Email vom Typ Msg.Message</param>
|
||||
'''' <returns>Headerinformationen als String oder Nothing wenn ein Fehler aufgetreten ist.</returns>
|
||||
'Public Shared Function getMessageHeaders(msg As Msg.Message)
|
||||
' Try
|
||||
' Dim headers = msg.TransportMessageHeaders.Replace(vbCrLf, " ")
|
||||
' Return headers
|
||||
' Catch ex As Exception
|
||||
' Return Nothing
|
||||
' End Try
|
||||
'End Function
|
||||
|
||||
''' <summary>
|
||||
''' Extrahiert aus den Headerinformationen anhand einer Liste von Regular Expressions eine Absenderadresse.
|
||||
''' </summary>
|
||||
''' <param name="messageHeaders">Headerinformationen die von getMessageHeaders erzeugt wurden.</param>
|
||||
''' <param name="RegexList">Eine Liste von Regular Expressions</param>
|
||||
''' <param name="RegexGroup">Die Ergebnisgruppe, die die Adresse enthält</param>
|
||||
''' <returns>Eine Emailadresse oder Nothing, wenn keine der Regular Expressions ein Ergebnis lieferte.</returns>
|
||||
Public Shared Function extractFromAddress(messageHeaders As String, RegexList As List(Of Regex), Optional RegexGroup As Integer = 1)
|
||||
If IsNothing(messageHeaders) Then
|
||||
Return Nothing
|
||||
End If
|
||||
'''' <summary>
|
||||
'''' Extrahiert aus den Headerinformationen anhand einer Liste von Regular Expressions eine Absenderadresse.
|
||||
'''' </summary>
|
||||
'''' <param name="messageHeaders">Headerinformationen die von getMessageHeaders erzeugt wurden.</param>
|
||||
'''' <param name="RegexList">Eine Liste von Regular Expressions</param>
|
||||
'''' <param name="RegexGroup">Die Ergebnisgruppe, die die Adresse enthält</param>
|
||||
'''' <returns>Eine Emailadresse oder Nothing, wenn keine der Regular Expressions ein Ergebnis lieferte.</returns>
|
||||
'Public Shared Function extractFromAddress(messageHeaders As String, RegexList As List(Of Regex), Optional RegexGroup As Integer = 1)
|
||||
' If IsNothing(messageHeaders) Then
|
||||
' Return Nothing
|
||||
' End If
|
||||
|
||||
For Each rx In RegexList
|
||||
Dim match As Match = rx.Match(messageHeaders)
|
||||
Dim email As String = match.Groups(RegexGroup).Value
|
||||
' For Each rx In RegexList
|
||||
' Dim match As Match = rx.Match(messageHeaders)
|
||||
' Dim email As String = match.Groups(RegexGroup).Value
|
||||
|
||||
If Not String.IsNullOrWhiteSpace(email) Then
|
||||
Return email
|
||||
End If
|
||||
Next
|
||||
' If Not String.IsNullOrWhiteSpace(email) Then
|
||||
' Return email
|
||||
' End If
|
||||
' Next
|
||||
|
||||
Return Nothing
|
||||
End Function
|
||||
Public Shared Function extractFromHeader(messageHeaders As String, Regex As String)
|
||||
Try
|
||||
Dim result = Nothing
|
||||
Dim i As Integer = 0
|
||||
If IsNothing(messageHeaders) Then
|
||||
Return Nothing
|
||||
End If
|
||||
' einen Regulären Ausdruck laden
|
||||
Dim strRegex As String = Regex
|
||||
Dim myRegex As New Regex(strRegex, RegexOptions.IgnorePatternWhitespace Or RegexOptions.IgnoreCase)
|
||||
Dim strTargetString As String = messageHeaders.Trim
|
||||
' die Vorkommen im String auslesen
|
||||
For Each myMatch As Match In myRegex.Matches(strTargetString)
|
||||
If myMatch.Success Then
|
||||
LOGGER.Debug("Match success. Matched Value: [{0}]", myMatch.Value)
|
||||
' Return Nothing
|
||||
'End Function
|
||||
'Public Shared Function extractFromHeader(messageHeaders As String, Regex As String)
|
||||
' Try
|
||||
' Dim result = Nothing
|
||||
' Dim i As Integer = 0
|
||||
' If IsNothing(messageHeaders) Then
|
||||
' Return Nothing
|
||||
' End If
|
||||
' ' einen Regulären Ausdruck laden
|
||||
' Dim strRegex As String = Regex
|
||||
' Dim myRegex As New Regex(strRegex, RegexOptions.IgnorePatternWhitespace Or RegexOptions.IgnoreCase)
|
||||
' Dim strTargetString As String = messageHeaders.Trim
|
||||
' ' die Vorkommen im String auslesen
|
||||
' For Each myMatch As Match In myRegex.Matches(strTargetString)
|
||||
' If myMatch.Success Then
|
||||
' LOGGER.Debug("Match success. Matched Value: [{0}]", myMatch.Value)
|
||||
|
||||
If myMatch.Value <> "" Then
|
||||
If i = 0 Then
|
||||
result = myMatch.Value.ToString
|
||||
Else
|
||||
result = result & ";" & myMatch.Value.ToString
|
||||
End If
|
||||
i += 1
|
||||
End If
|
||||
Else
|
||||
LOGGER.Debug("Match failed!")
|
||||
End If
|
||||
Next
|
||||
' If myMatch.Value <> "" Then
|
||||
' If i = 0 Then
|
||||
' result = myMatch.Value.ToString
|
||||
' Else
|
||||
' result = result & ";" & myMatch.Value.ToString
|
||||
' End If
|
||||
' i += 1
|
||||
' End If
|
||||
' Else
|
||||
' LOGGER.Debug("Match failed!")
|
||||
' End If
|
||||
' Next
|
||||
|
||||
LOGGER.Debug("Extracted value: [{0}]", result)
|
||||
' LOGGER.Debug("Extracted value: [{0}]", result)
|
||||
|
||||
Return result
|
||||
Catch ex As Exception
|
||||
LOGGER.Error(ex)
|
||||
MsgBox("Unexpected Error in extractFromHeader: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
' Return result
|
||||
' Catch ex As Exception
|
||||
' LOGGER.Error(ex)
|
||||
' MsgBox("Unexpected Error in extractFromHeader: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
|
||||
' Return Nothing
|
||||
' End Try
|
||||
'End Function
|
||||
|
||||
''' <summary>
|
||||
''' Extrahiert aus den Headerinformationen anhand einer Liste von Regular Expressions eine Empfängeradresse.
|
||||
''' </summary>
|
||||
''' <param name="messageHeaders">Headerinformationen die von getMessageHeaders erzeugt wurden.</param>
|
||||
''' <param name="RegexList">Eine Liste von Regular Expressions</param>
|
||||
''' <param name="RegexGroup">Die Ergebnisgruppe, die die Adresse enthält</param>
|
||||
''' <returns>Eine Emailadresse oder Nothing, wenn keine der Regular Expressions ein Ergebnis lieferte.</returns>
|
||||
Public Shared Function extractToAddress(messageHeaders As String, RegexList As List(Of Regex), Optional RegexGroup As Integer = 1)
|
||||
If IsNothing(messageHeaders) Then
|
||||
Return Nothing
|
||||
End If
|
||||
'''' <summary>
|
||||
'''' Extrahiert aus den Headerinformationen anhand einer Liste von Regular Expressions eine Empfängeradresse.
|
||||
'''' </summary>
|
||||
'''' <param name="messageHeaders">Headerinformationen die von getMessageHeaders erzeugt wurden.</param>
|
||||
'''' <param name="RegexList">Eine Liste von Regular Expressions</param>
|
||||
'''' <param name="RegexGroup">Die Ergebnisgruppe, die die Adresse enthält</param>
|
||||
'''' <returns>Eine Emailadresse oder Nothing, wenn keine der Regular Expressions ein Ergebnis lieferte.</returns>
|
||||
'Public Shared Function extractToAddress(messageHeaders As String, RegexList As List(Of Regex), Optional RegexGroup As Integer = 1)
|
||||
' If IsNothing(messageHeaders) Then
|
||||
' Return Nothing
|
||||
' End If
|
||||
|
||||
For Each rx In RegexList
|
||||
Dim match As Match = rx.Match(messageHeaders)
|
||||
Dim email As String = match.Groups(RegexGroup).Value
|
||||
' For Each rx In RegexList
|
||||
' Dim match As Match = rx.Match(messageHeaders)
|
||||
' Dim email As String = match.Groups(RegexGroup).Value
|
||||
|
||||
If Not String.IsNullOrWhiteSpace(email) Then
|
||||
Return email
|
||||
End If
|
||||
Next
|
||||
' If Not String.IsNullOrWhiteSpace(email) Then
|
||||
' Return email
|
||||
' End If
|
||||
' Next
|
||||
|
||||
Return Nothing
|
||||
End Function
|
||||
' Return Nothing
|
||||
'End Function
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user