Files
EmailProfiler/App/DigitalData.EMLProfiler/clsWorkEmail.vb
Digital Data - Marlon Schreiber 79d864c676 Bodyauswertung
2019-01-23 17:59:18 +01:00

727 lines
32 KiB
VB.net

Imports Independentsoft.Email.Mime
Imports System.Text.RegularExpressions
Imports WINDREAMLib
Imports DigitalData.EMLProfiler.ClassCurrent
Imports System.IO
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Database
Imports System.Threading
Public Class clsWorkEmail
Private Shared Logger As Logger
Private MyLogger As LogConfig
Private _email As clsEmail
Private _Database As clsDatabase
Private _windream As clsWindream_allgemein
Private _windream_index As clsWindream_Index
Private _firebird As Firebird
Private _worked_email As Boolean = False
Sub New(LogConf As LogConfig, ConStr As String, FB_DATASOURCE As String, FB_DATABASE As String, FB_USER As String, FB_PW As String)
Try
Logger = LogConf.GetLogger
MyLogger = LogConf
If LogConf.Debug = False Then
Logger.Info("Detail-Log is on")
End If
_email = New clsEmail(LogConf)
_Database = New clsDatabase(LogConf, ConStr)
_windream = New clsWindream_allgemein(LogConf)
_windream_index = New clsWindream_Index(LogConf)
If FB_DATASOURCE <> String.Empty Then
_firebird = New Firebird(LogConf, FB_DATASOURCE, FB_DATABASE, FB_USER, FB_PW)
End If
Catch ex As Exception
Logger.Error(ex)
End Try
End Sub
Public Function WORK_MAIL(msg As Message)
Try
CURRENT_MAIL_BODY_ALL = ""
CURRENT_MAIL_BODY_ANSWER1 = ""
CURRENT_MAIL_BODY_Substr2 = ""
CURRENT_MAIL_MESSAGE = msg
CURRENT_MAIL_SUBJECT = msg.Subject.ToUpper
If IsNothing(CURRENT_MAIL_SUBJECT) Then
CURRENT_MAIL_SUBJECT = ""
End If
Dim oTempMailExists As Boolean = SAVE2TEMP()
'Checking wether Mail can be opened
Dim oTempMailAccessible As Boolean = False
If oTempMailExists = True Then
Try
Dim oFS As FileStream = File.OpenRead(CURRENT_TEMP_MAIL_PATH)
oTempMailAccessible = True
Catch ex As Exception
Logger.Warn($"Could not read the Temp-Mail. Insufficient rights? Message: {ex.Message}")
End Try
If oTempMailAccessible = True Then
If CURRENT_MAIL_SUBJECT.Contains("[PROCESSMANAGER]") Then
PROCESS_MANAGER_IN()
ElseIf msg.Subject.Contains("[ADDI]") Then
Else
Logger.Debug(String.Format("No relation configured for this email - Subject[{0}]", msg.Subject))
COMMON_EMAIL_IN()
End If
INSERT_HISTORY()
End If
End If
Catch ex As Exception
Logger.Error(ex)
'clsLogger.Add("Unexpected Error in WORK_MAIL: " & ex.Message & "MESSAGE_ID: " & msg.MessageID)
Return False
End Try
End Function
Private Function PROCESS_MANAGER_IN() As Boolean
Try
Dim oDel_email As Boolean = False
Logger.Info(String.Format("PM-related message found....[{0}]", CURRENT_MAIL_MESSAGE.Subject))
Logger.Debug(String.Format("PM-related message found....[{0}]", CURRENT_MAIL_MESSAGE.Subject))
Dim oExpression = "PROCESS_NAME = 'ProcessManager'"
'Filter the rows using Select() method of DataTable
Dim TEMP_PROCESS_PROFILE_DT As DataTable = DT_POLL_PROCESS
Dim PM_ROW As DataRow() = TEMP_PROCESS_PROFILE_DT.Select(oExpression)
For Each row As DataRow In PM_ROW
WM_REFERENCE_INDEX = row("WM_REFERENCE_INDEX")
WM_VECTOR_LOG = row("WM_VECTOR_LOG")
WM_OBJEKTTYPE = row("WM_OBJEKTTYPE")
WM_IDX_BODY_TEXT = row("WM_IDX_BODY_TEXT")
WM_IDX_BODY_SUBSTR_LENGTH = row("WM_IDX_BODY_SUBSTR_LENGTH")
oDel_email = row("DELETE_MAIL")
COPY2HDD(row("COPY_2_HDD"), row("PATH_EMAIL_TEMP"), row("PATH_EMAIL_ERRORS"), False)
EXTRACT_BODY()
Next
If CURRENT_MAIL_SUBJECT.Contains("[PROCESSMANAGER][EA]") Then
Logger.Info(String.Format("Message referencing to EASY-APPROVAL...."))
Logger.Debug(String.Format("Message referencing to EASY-APPROVAL...."))
CURRENT_MAIL_PROCESS_NAME = "DD EasyApproval via Mail"
If CURRENT_MAIL_BODY_ANSWER1 <> "" Then
MessageError = False
If GET_WMDOC_INFO() = True Then
If DT_STEPS.Rows.Count > 0 Then
WORK_POLL_STEPS()
Else
Logger.Info("No steps configured for this Profile ....")
End If
End If
End If
If ClassCurrent.CURRENT_DEBUG_LOCAL_EMAIL = "" Then
EMAIL_DELETE(oDel_email)
End If
End If
Return True
Catch ex As Exception
Logger.Error(ex)
'Logger.Debug("Unexpected Error in PROCESS_MANAGER_IN: " & ex.Message & "MESSAGE_ID: " & CURRENT_MAIL_MESSAGE.MessageID)
Return False
End Try
End Function
Function COMMON_EMAIL_IN()
Try
Dim oDel_email As Boolean = False
Logger.Info(String.Format("COMMON_EMAIL_IN...Subject [{0}]", CURRENT_MAIL_MESSAGE.Subject))
Logger.Debug(String.Format("COMMON_EMAIL_IN...Subject [{0}]", CURRENT_MAIL_MESSAGE.Subject))
Dim oExpression = "PROCESS_NAME = 'Attachment Sniffer'"
CURRENT_MAIL_PROCESS_NAME = "Attachment Sniffer"
'Filter the rows using Select() method of DataTable
Dim TEMP_PROCESS_PROFILE_DT As DataTable = DT_POLL_PROCESS
Dim PM_ROW As DataRow() = TEMP_PROCESS_PROFILE_DT.Select(oExpression)
For Each row As DataRow In PM_ROW
Try
WM_REFERENCE_INDEX = row("WM_REFERENCE_INDEX")
Catch ex As Exception
WM_REFERENCE_INDEX = Nothing
End Try
Try
WM_VECTOR_LOG = row("WM_VECTOR_LOG")
Catch ex As Exception
WM_VECTOR_LOG = Nothing
End Try
WM_OBJEKTTYPE = row("WM_OBJEKTTYPE")
WM_IDX_BODY_TEXT = row("WM_IDX_BODY_TEXT")
WM_IDX_BODY_SUBSTR_LENGTH = row("WM_IDX_BODY_SUBSTR_LENGTH")
COPY2HDD(row("COPY_2_HDD"), row("PATH_EMAIL_TEMP"), row("PATH_EMAIL_ERRORS"), True)
EXTRACT_ATTACHMENTS(row("PATH_EMAIL_TEMP"), row("PATH_EMAIL_ERRORS"))
EXTRACT_BODY()
oDel_email = row("DELETE_MAIL")
Next
If ClassCurrent.CURRENT_DEBUG_LOCAL_EMAIL = "" Then
EMAIL_DELETE(oDel_email)
End If
Return True
Catch ex As Exception
Logger.Error(ex)
'Logger.Debug("Unexpected Error in PROCESS_MANAGER_IN: " & ex.Message & "MESSAGE_ID: " & CURRENT_MAIL_MESSAGE.MessageID)
Return False
End Try
End Function
Private Function SAVE2TEMP()
Try
Dim oTempPath As String = Path.Combine(Path.GetTempPath, "DD_EmailProfiler")
If Directory.Exists(oTempPath) = False Then
Directory.CreateDirectory(oTempPath)
End If
Dim oFileEntries As String() = Directory.GetFiles(oTempPath)
' Process the list of files found in the directory.
Dim oFileName As String
For Each oFileName In oFileEntries
Try
File.Delete(oFileName)
Catch ex As Exception
End Try
Next oFileName
Dim oResult As Boolean = False
Dim oTempFilename As String = Path.Combine(oTempPath, CURRENT_MAIL_MESSAGE.GetFileName)
Dim oCounter As Integer = 1
If File.Exists(oTempFilename) = True Then
Do While File.Exists(oTempFilename)
oCounter += 1
oTempFilename = Path.Combine(oTempPath, oCounter & "_" & CURRENT_MAIL_MESSAGE.GetFileName)
Loop
End If
CURRENT_MAIL_MESSAGE.Save(oTempFilename, True)
CURRENT_TEMP_MAIL_PATH = oTempFilename
Logger.Debug($"Email saved to Temppath {CURRENT_TEMP_MAIL_PATH}")
oCounter = 0
Dim oCancel As Boolean
Do While File.Exists(CURRENT_TEMP_MAIL_PATH) = False
Thread.Sleep(1000)
oCounter += 1
If oCounter > 10 Then
Logger.Warn("It took to long to save the mail to Temppath!")
oCancel = True
Exit Do
End If
Loop
If oCancel = True Then
oResult = False
Else
If File.Exists(CURRENT_TEMP_MAIL_PATH) Then
oResult = True
End If
End If
'Datei in Array zum Templöschen speichern
TEMP_FILES.Add(oTempFilename)
Return oResult
Catch ex As Exception
Logger.Error(ex)
CURRENT_TEMP_MAIL_PATH = Nothing
'clsLogger.Add("Unexpected Error in COPY2HDD: " & ex.Message & "MESSAGE_ID: " & CURRENT_MAIL_MESSAGE.MessageID, True)
Return False
End Try
End Function
Private Function COPY2HDD(copy_2_hdd As Boolean, pathemailtemp As String, pathemail_errors As String, messageid As Boolean)
Try
If copy_2_hdd = True Then
Logger.Debug("COPY_2_HDD is ACTIVE!")
PATH_TEMP = pathemailtemp
PATH_ERROR = pathemail_errors
If Directory.Exists(PATH_TEMP) Then
Dim oTempFilename = PATH_TEMP
If messageid = True Then
oTempFilename &= "\" & CURRENT_MAIL_MESSAGE.MessageID & ".eml"
Else
oTempFilename &= "\" & CURRENT_MAIL_MESSAGE.GetFileName
End If
Dim cleanPath As String = String.Join("", oTempFilename.Split(Path.GetInvalidPathChars()))
If System.IO.File.Exists(cleanPath) = False Then
CURRENT_MAIL_MESSAGE.Save(cleanPath, True)
Else
Logger.Info("EMail (" & CURRENT_MAIL_MESSAGE.Subject & ") already existing!", False, "RUN_THREAD.COPY_2_HDD")
End If
End If
End If
Catch ex As Exception
Logger.Error(ex)
'clsLogger.Add("Unexpected Error in COPY2HDD: " & ex.Message & "MESSAGE_ID: " & CURRENT_MAIL_MESSAGE.MessageID, True)
Return False
End Try
End Function
Private Function EXTRACT_BODY()
TEMP_HTML_RESULTS.Clear()
Dim oDTFunctionRegex As DataTable = _Database.Return_Datatable("SELECT * FROM TBDD_FUNCTION_REGEX WHERE FUNCTION_NAME IN ('EMAIL_PROFILER - RemoveHTMLText','EMAIL_PROFILER - BODY REMOVE NewLine','EMAIL_PROFILER - BODY_ANSWER_GROUP')")
Dim msg_email As New Independentsoft.Email.Mime.Message(CURRENT_TEMP_MAIL_PATH)
If IsNothing(msg_email.Body) Then
Dim oAllBodyParts As New BodyPartCollection()
oAllBodyParts.Add(msg_email.BodyParts)
oAllBodyParts.Add(GetChildren(msg_email.BodyParts))
For Each bodyPart As BodyPart In oAllBodyParts
If bodyPart.ContentType IsNot Nothing AndAlso bodyPart.ContentType.Type = "text" AndAlso bodyPart.ContentType.SubType = "plain" Then
Logger.Debug(String.Format("BODY1-Text is....#{0}", bodyPart.Body))
If CURRENT_MAIL_BODY_ALL <> bodyPart.Body Then
CURRENT_MAIL_BODY_ALL = bodyPart.Body
End If
ElseIf bodyPart.ContentType IsNot Nothing AndAlso bodyPart.ContentType.Type = "text" AndAlso bodyPart.ContentType.SubType = "html" Then
Logger.Debug(String.Format("bodyhtml....#{0}", bodyPart.Body))
If CURRENT_MAIL_BODY_ALL = "" Then
CURRENT_MAIL_BODY_ALL = bodyPart.Body
Logger.Debug(String.Format("bodyhtml....#{0}", bodyPart.Body))
End If
End If
Next
Else
CURRENT_MAIL_BODY_ALL = msg_email.Body
End If
If CURRENT_MAIL_BODY_ALL.StartsWith("<html") Then
Try
Dim pattern1 As String = ""
For Each oRow As DataRow In oDTFunctionRegex.Rows
If oRow.Item("FUNCTION_NAME") = "EMAIL_PROFILER - RemoveHTMLText" Then
pattern1 = oRow.Item("REGEX")
End If
Next
If pattern1 = String.Empty Then
Exit Try
End If
' Instantiate the regular expression object.
Dim r As Regex = New Regex(pattern1, RegexOptions.Multiline)
' Match the regular expression pattern against a text string.
Dim m As Match = r.Match(CURRENT_MAIL_BODY_ALL)
Dim oClearedBodyText = CURRENT_MAIL_BODY_ALL
Do While m.Success
oClearedBodyText = oClearedBodyText.Replace(m.Value, "")
'Dim g As Group = m.Groups(1)
'If g.ToString.StartsWith("&") = False Then
' TEMP_HTML_RESULTS.Add(g.ToString())
'End If
m = m.NextMatch()
Loop
Logger.Info($"Cleared bodytext is: {oClearedBodyText}")
CURRENT_MAIL_BODY_ALL = Trim(oClearedBodyText)
Catch ex As Exception
End Try
'If TEMP_HTML_RESULTS.Count = 0 Then
' Logger.Warn("HTML Recognition via Regex could not create a match within this mail - So the answer will interpreted as empty!")
'End If
End If
Try
If CURRENT_MAIL_BODY_ALL = String.Empty Then
Logger.Warn("Mailbody is empty. Email can not be processed! - Please check the html-structure")
Logger.Info("EXCEPTION - Mailbody is empty.Email can not be processed! - Please check the html-structure")
MessageError = True
Return False
Else
Logger.Debug($"Length of Body is [{CURRENT_MAIL_BODY_ALL.Length}] - Body Text is [{CURRENT_MAIL_BODY_ALL}]")
End If
CURRENT_MAIL_BODY_ALL = CURRENT_MAIL_BODY_ALL.Replace(vbLf, "")
Dim oSplit = CURRENT_MAIL_BODY_ALL.Split(Environment.NewLine)
Dim oCount As Integer = 0
Dim oReadLength As Integer = 0
Dim oAnswer2 As String
For Each ostr As String In oSplit
ostr = ostr.Replace(vbCrLf, "")
If ostr = String.Empty Then
Continue For
End If
oCount += 1
If oCount = 1 Then
CURRENT_MAIL_BODY_ANSWER1 = ostr
Else
If oCount = 2 Then
CURRENT_MAIL_BODY_Substr2 = ostr
Else
If ((oReadLength + ostr.Length) >= WM_IDX_BODY_SUBSTR_LENGTH) Or ostr.StartsWith("##") Then
Exit For
End If
CURRENT_MAIL_BODY_Substr2 = CURRENT_MAIL_BODY_Substr2 & vbNewLine & ostr
End If
oReadLength += ostr.Length
End If
Next
'Dim oFirstindex = CURRENT_MAIL_BODY_ALL.IndexOf(Chr(13))
'If IsNothing(oFirstindex) Then
' oFirstindex = CURRENT_MAIL_BODY_ALL.IndexOf(Chr(10))
'End If
'Logger.Debug(String.Format("firstindex....[{0}]", oFirstindex))
'If oFirstindex = -1 Then
' Logger.Warn("Could not find the first carriage-return in Mail-Body. Email can not be processed!")
' MessageError = True
' Return False
'End If
'If CURRENT_MAIL_BODY_ALL.StartsWith("<html") Then
' If TEMP_HTML_RESULTS.Count > 0 Then
' End If
'Else
' Try
' CURRENT_MAIL_BODY_ANSWER1 = CURRENT_MAIL_BODY_ALL.Substring(0, oFirstindex)
' CURRENT_MAIL_BODY_ANSWER1 = RTrim(LTrim(CURRENT_MAIL_BODY_ANSWER1))
' Catch ex As Exception
' Logger.Warn("Error in Substring 144: " & ex.Message)
' Logger.Warn("CURRENT_MAIL_BODY: " & CURRENT_MAIL_BODY_ALL)
' Logger.Warn("oFirstindex: " & oFirstindex)
' CURRENT_MAIL_BODY_ANSWER1 = ""
' End Try
'End If
Logger.Debug(String.Format("MailBody-ANSWER1:...[{0}]", CURRENT_MAIL_BODY_ANSWER1))
Logger.Debug(String.Format("MailBody-ANSWER2:...[{0}]", CURRENT_MAIL_BODY_Substr2))
'now trying to get the text before Masterline
'If WM_IDX_BODY_TEXT <> String.Empty And WM_IDX_BODY_SUBSTR_LENGTH <> 0 And oDTFunctionRegex.Rows.Count >= 1 Then
' If CURRENT_MAIL_BODY_ALL.StartsWith("<html") Then
' Dim oTempBodyString As String = ""
' oCount = 0
' For Each _oAnswer1 In TEMP_HTML_RESULTS
' If oCount = 0 Then
' oTempBodyString = _oAnswer1
' Else
' oTempBodyString &= vbNewLine & _oAnswer1
' End If
' oCount += 1
' Next
' CURRENT_MAIL_BODY_Substr2 = oTempBodyString
' Else
' Dim pattern As String = oDTFunctionRegex.Rows(0).Item("REGEX")
' ' Instantiate the regular expression object.
' Dim r As Regex = New Regex(pattern, RegexOptions.Multiline)
' ' Match the regular expression pattern against a text string.
' Dim m As Match = r.Match(CURRENT_MAIL_BODY_ALL)
' If m.Success Then
' If Not IsNothing(m.Value) Then
' If m.Value.Length > WM_IDX_BODY_SUBSTR_LENGTH Then
' Try
' Logger.Debug($"Getting the Substring of body - Length: {WM_IDX_BODY_SUBSTR_LENGTH}...")
' CURRENT_MAIL_BODY_Substr2 = m.Value.Substring(0, WM_IDX_BODY_SUBSTR_LENGTH)
' Catch ex As Exception
' Logger.Warn("Error in Substring 168: " & ex.Message)
' Logger.Warn("m.Value: " & m.Value)
' Logger.Warn("WM_IDX_BODY_SUBSTR_LENGTH: " & WM_IDX_BODY_SUBSTR_LENGTH.ToString)
' CURRENT_MAIL_BODY_Substr2 = ""
' End Try
' Else
' Logger.Info($"m.Value.Length [{m.Value.Length}] < WM_IDX_BODY_SUBSTR_LENGTH [{WM_IDX_BODY_SUBSTR_LENGTH}], so simply m.Value [{m.Value}] will be taken...")
' CURRENT_MAIL_BODY_Substr2 = m.Value
' End If
' End If
' End If
' Logger.Debug(String.Format("MailBody-Substring After RecognizeString:...[{0}]", CURRENT_MAIL_BODY_Substr2))
' End If
'End If
If CURRENT_MAIL_BODY_ANSWER1 = String.Empty Then
Logger.Warn("CURRENT_MAIL_BODY_ANSWER1 is String.Empty: So the answer will interpreted as empty!")
End If
Catch ex As Exception
Logger.Error(ex)
'clsLogger.Add("Unexpected Error in COPY2HDD: " & ex.Message & "MESSAGE_ID: " & CURRENT_MAIL_MESSAGE.MessageID, True)
MessageError = True
Return False
End Try
End Function
Private Function EXTRACT_ATTACHMENTS(pathemailtemp As String, pathemail_errors As String)
PATH_TEMP = pathemailtemp
PATH_ERROR = pathemail_errors
Try
If CURRENT_TEMP_MAIL_PATH <> Nothing Then
If File.Exists(CURRENT_TEMP_MAIL_PATH) Then
Dim msg_email As New Independentsoft.Email.Mime.Message(CURRENT_TEMP_MAIL_PATH)
For Each attachment As Attachment In msg_email.GetAttachments
If Path.GetExtension(attachment.GetFileName).ToUpper.Contains("PDF") Then
Dim sGUID = System.Guid.NewGuid.ToString()
Dim oAttachmentFilename
Try
oAttachmentFilename = Path.Combine(PATH_TEMP, $"{sGUID}{Path.GetExtension(attachment.GetFileName)}")
If System.IO.File.Exists(oAttachmentFilename) = False Then
attachment.Save(oAttachmentFilename)
INSERT_HISTORY_FB(sGUID, attachment.GetFileName)
Else
Logger.Info("Attachment (" & oAttachmentFilename & ") already existing!", False, "EXTRACT_ATTACHMENTS")
End If
Catch ex As Exception
Logger.Warn($"Error while creating and saving attachment-name: {ex.Message} - AttachmentName: {oAttachmentFilename}")
MessageError = True
Return False
End Try
End If
Next
Else
Logger.Warn($"If cause 2 EXTRACT_ATTACHMENTS: {CURRENT_TEMP_MAIL_PATH} not existing")
End If
Else
Logger.Warn($"EXTRACT_ATTACHMENTSIf cause 1: CURRENT_TEMP_MAIL_PATH is NOTHING")
End If
Catch ex As Exception
Logger.Error(ex)
'clsLogger.Add("Unexpected Error in COPY2HDD: " & ex.Message & "MESSAGE_ID: " & CURRENT_MAIL_MESSAGE.MessageID, True)
MessageError = True
Return False
End Try
End Function
Private Function INSERT_HISTORY()
If MessageError = False Then
Dim ins = $"INSERT INTO TBEMLP_HISTORY (WORK_PROCESS,EMAIL_MSGID,EMAIL_SUBJECT,EMAIL_DATE,EMAIL_BODY,EMAIL_SUBSTRING1,EMAIL_SUBSTRING2) VALUES " &
$"('{CURRENT_MAIL_PROCESS_NAME}'," &
$"'{CURRENT_MAIL_MESSAGE.MessageID.Replace("<", "").Replace(">", "")}'," &
$"'{CURRENT_MAIL_MESSAGE.Subject}'," &
$"'{CURRENT_MAIL_MESSAGE.Date}'," &
$"'{CURRENT_MAIL_BODY_ALL}'," &
$"'{CURRENT_MAIL_BODY_ANSWER1}'," &
$"'{CURRENT_MAIL_BODY_Substr2}')"
_Database.Execute_non_Query(ins)
End If
End Function
Private Function INSERT_HISTORY_FB(oGUID As String, ATTMT1 As String)
If MessageError = False Then
Dim ins = $"INSERT INTO TBEDM_EMAIL_PROFILER_HISTORY (WORK_PROCESS,EMAIL_MSGID,EMAIL_FROM,EMAIL_SUBJECT,EMAIL_DATETIME,EMAIL_BODY,EMAIL_SUBSTRING1,EMAIL_SUBSTRING2,EMAIL_ATTMT1) VALUES " &
$"('{CURRENT_MAIL_PROCESS_NAME}'," &
$"'{oGUID}'," &
$"'{CURRENT_MAIL_MESSAGE.From.EmailAddress}'," &
$"'{CURRENT_MAIL_MESSAGE.Subject}'," &
$"'{CURRENT_MAIL_MESSAGE.Date}'," &
$"'{CURRENT_MAIL_BODY_ALL}'," &
$"'{CURRENT_MAIL_BODY_ANSWER1}'," &
$"'{CURRENT_MAIL_BODY_Substr2}'," &
$"'{ATTMT1}')"
_firebird.ExecuteNonQuery(ins)
End If
End Function
Private Function GetChildren(ByVal bodyParts As BodyPartCollection) As BodyPartCollection
Dim children As New BodyPartCollection()
For i As Integer = 0 To bodyParts.Count - 1
children.Add(GetChildren(bodyParts(i).BodyParts))
children.Add(bodyParts(i))
Next
Return children
End Function
Private Function EMAIL_DELETE(del As Boolean)
If del = True And MessageError = False Then
_email.DELETE_EMAIL(CURRENT_MAIL_MESSAGE.MessageID)
Else
If MessageError = True Then
Logger.Warn($"Could not delete Message {CURRENT_MAIL_MESSAGE.MessageID} as there was an MessageError!")
End If
End If
End Function
Private Function WORK_POLL_STEPS() As Boolean
Try
_worked_email = False
For Each row As DataRow In DT_STEPS.Rows
POLL_STEP_GUID = row.Item("GUID")
POLL_STEP_PROCESS_ID = row.Item("PROCESS_ID")
POLL_KEYWORDS = row.Item("KEYWORDS_BODY")
KEYWORDS_SPLIT = POLL_KEYWORDS.Split(";")
For Each str As String In KEYWORDS_SPLIT
If CURRENT_MAIL_BODY_ANSWER1.ToUpper = str.ToUpper Then
_worked_email = True
Logger.Info(String.Format("Found Keyword '{0}' in MessageBody", str))
Dim sql As String = String.Format("SELECT * FROM TBEMLP_POLL_INDEXING_STEPS WHERE STEP_ID = {0} AND ACTIVE = 1", POLL_STEP_GUID)
DT_INDEXING_STEPS = _Database.Return_Datatable(sql)
If DT_INDEXING_STEPS.Rows.Count > 0 Then
WORK_INDEXING_STEPS()
Else
Logger.Info("No Indexing Steps found?! - SQL: " & sql)
End If
End If
Next
Next
If _worked_email = False Then
Dim sql As String = String.Format("SELECT * FROM TBEMLP_POLL_INDEXING_STEPS WHERE STEP_ID = {0} AND ACTIVE = 1 AND USE_FOR_DIRECT_ANSWER = 1", POLL_STEP_GUID)
DT_INDEXING_STEPS = _Database.Return_Datatable(sql)
WORK_INDEXING_STEPS()
_worked_email = True
End If
'Now indexing the LogIndex
If Not IsNothing(WM_VECTOR_LOG) And (Not IsDBNull(WM_VECTOR_LOG)) And (WM_VECTOR_LOG <> "") Then
Dim msg = Now.ToString & " - " & CURRENT_MAIL_PROCESS_NAME
IndexFile(WM_VECTOR_LOG, msg, False)
End If
'Now indexing the Body-Message Index
If CURRENT_MAIL_BODY_Substr2 <> String.Empty And WM_IDX_BODY_TEXT <> String.Empty Then
IndexFile(WM_IDX_BODY_TEXT, CURRENT_MAIL_BODY_Substr2, True)
End If
Return True
Catch ex As Exception
MessageError = True
Logger.Error(ex)
'clsLogger.Add("Unexpected Error in WORK_POLL_STEPS: " & ex.Message & "MESSAGE_ID: " & CURRENT_MAIL_MESSAGE.MessageID, True)
Return False
End Try
End Function
Private Function WORK_INDEXING_STEPS()
Try
For Each row As DataRow In DT_INDEXING_STEPS.Rows
Dim INDEXNAME As String = row.Item("INDEXNAME")
Dim INDEXVALUE As String = row.Item("INDEXVALUE")
IndexFile(INDEXNAME, INDEXVALUE, False)
Next
Catch ex As Exception
MessageError = True
Logger.Error(ex)
'clsLogger.Add("Unexpected Error in WORK_INDEXING_STEPS: " & ex.Message & "MESSAGE_ID: " & CURRENT_MAIL_MESSAGE.MessageID, True)
Return False
End Try
End Function
Private Function IndexFile(oidxname As String, oidxvalue As String, oConcat_act_Value As Boolean)
Dim OArrIndex() As String
ReDim Preserve OArrIndex(0)
OArrIndex(0) = oidxname
If oConcat_act_Value = True Then
Dim oActValue = _windream_index.GetValueforIndex_WMFile(CURRENT_WM_DOC, oidxname)
If Not IsNothing(oActValue) Then
If oActValue.ToString.Length > 0 Then
If oActValue <> oidxvalue Then
oidxvalue = oActValue & vbNewLine & oidxvalue
End If
End If
End If
End If
Dim oArrValue() As String
Dim oMyArray()
ReDim oMyArray(0)
oMyArray(0) = oidxvalue
Dim oVektorArray()
oVektorArray = _windream_index.GetVektorArray(CURRENT_WM_DOC, oidxname, oMyArray, True)
If oVektorArray Is Nothing = False Then
'Zielindex ist ein Vektorindex
ReDim oArrValue(oVektorArray.Length - 1)
Array.Copy(oVektorArray, oArrValue, oVektorArray.Length)
If oArrValue Is Nothing Then
Logger.Warn($"arrValue from vektor for index {oidxname} is nothing! Value: {oidxvalue} - no indexing!")
Logger.Info($"arrValue from vektor for index {oidxname} is nothing! Value: {oidxvalue} - no indexing!")
Return False
End If
Else
'Es handelt sich um einen Einfachindex
ReDim oArrValue(0)
oArrValue(0) = oidxvalue
End If
If oArrValue Is Nothing = False Then
Return _windream_index.RunIndexing(CURRENT_WM_DOC, OArrIndex, oArrValue, WM_OBJEKTTYPE)
Else
Logger.Warn($"arrValue for index {oidxname} is nothing! Value: {oidxvalue} - no indexing!")
Logger.Info($"arrValue for index {oidxname} is nothing! Value: {oidxvalue} - no indexing!")
Return False
End If
End Function
Private Function GET_WMDOC_INFO()
Try
Dim oDOC_ID = REGEX_CHECK_DOC_ID(CURRENT_MAIL_SUBJECT.Replace("10636", "133092").Replace("10644", "133092"))
If Not IsNothing(oDOC_ID) Then
Dim oDT_BASE_ATTR As DataTable = _Database.Return_DatatableCS("SELECT * FROM BaseAttributes WHERE dwDocID = " & oDOC_ID, WM_CON_STRING)
If Not IsNothing(oDT_BASE_ATTR) Then
If oDT_BASE_ATTR.Rows.Count = 1 Then
CURRENT_DOC_ID = oDOC_ID
Dim oSql = String.Format("Select[dbo].[FNDD_GET_WINDREAM_FILE_PATH]({0},'{1}')", CURRENT_DOC_ID, WM_DRIVE)
CURRENT_DOC_PATH = _Database.Execute_Scalar(oSql)
Logger.Debug("CURRENT_DOC_PATH is: " & CURRENT_DOC_PATH)
CURRENT_WM_DOC = Nothing
Dim oWMDOC As WMObject
Try
oWMDOC = _windream.oSession.GetWMObjectByPath(WMEntity.WMEntityDocument, CURRENT_DOC_PATH.Substring(2))
CURRENT_WM_DOC = oWMDOC
Return True
Catch ex As Exception
Logger.Warn("error while creating WMObject in (GET_DOC_INFO): " & ex.Message)
Return False
End Try
Else
Logger.Warn("No record found for dwDocID " & oDOC_ID)
Return False
End If
Else
Logger.Warn("DT_BASE_ATTR is nothing")
Return False
End If
Else
Logger.Warn("Could not get a DOC-ID via regex!")
Return False
End If
Catch ex As Exception
Logger.Error(ex)
'clsLogger.Add("Unexpected Error in GET_DOC_INFO: " & ex.Message & "MESSAGE_ID: " & CURRENT_MAIL_MESSAGE.MessageID)
MessageError = True
Return False
End Try
End Function
Public Function REGEX_CHECK_DOC_ID(SearchString As String)
Try
Dim regex As Regex = New Regex("\[DID#{1}([0-9]+)]{1}")
Logger.Debug("REGEX_String before replacing: '" & SearchString & "'")
' Regulären Ausdruck zum Auslesen der windream-Indexe definieren
Dim elements As MatchCollection = regex.Matches(SearchString)
Dim result = ""
For Each element As Match In elements
result = element.Groups(1).Value
Logger.Debug(String.Format("Found Regex(0) {0} in SearchString", element.Groups(0).Value))
Logger.Debug(String.Format("Found Regex(1) {0} in SearchString", element.Groups(1).Value))
Next
Return result
Catch ex As Exception
MessageError = True
Logger.Error(ex)
'clsLogger.AddError("Unexpected error: " & ex.Message, "REGEX_CHECK_DOC_ID")
Return Nothing
End Try
End Function
End Class