MS Erweiterung IMAP

This commit is contained in:
Digital Data - Marlon Schreiber
2019-03-26 16:35:05 +01:00
parent 1d07465ca5
commit 9b9ec33533
98 changed files with 2215 additions and 349688 deletions

View File

@@ -60,4 +60,6 @@ Public Class ClassCurrent
Public Shared TEMP_HTML_RESULTS As List(Of String) = New List(Of String)
Public Shared CURRENT_DEBUG_LOCAL_EMAIL As String
End Class

View File

@@ -103,6 +103,7 @@
<Compile Include="clsWindream_Index.vb" />
<Compile Include="clsWorkEmail.vb" />
<Compile Include="clsWorker.vb" />
<Compile Include="ModuleCurrent.vb" />
<Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="My Project\Application.Designer.vb">
<AutoGen>True</AutoGen>

View File

@@ -0,0 +1,5 @@
Module ModuleCurrent
Public CURRENToWMSession As Object
Public CURRENToWMSession_Created As Date = Now
Public CURRENToWMConnect As Object
End Module

View File

@@ -24,7 +24,7 @@ DigitalData.Modules.Logging
</member>
<member name="T:DigitalData.Modules.Logging.LogConfig">
<module>LogConfig</module>
<version>0.0.0.5</version>
<version>0.0.0.7</version>
<date>02.10.2018</date>
<summary>
Module that writes file-logs to different locations:
@@ -139,6 +139,13 @@ DigitalData.Modules.Logging
</summary>
<returns>An object of Logging.Logger</returns>
</member>
<member name="M:DigitalData.Modules.Logging.LogConfig.GetLogger(System.String)">
<summary>
Returns the Logger for a class specified by `ClassName`
</summary>
<param name="ClassName">The name of the class the logger belongs to</param>
<returns>An object of Logging.Logger</returns>
</member>
<member name="M:DigitalData.Modules.Logging.LogConfig.GetClassFullName">
<summary>
Gets the fully qualified name of the class invoking the calling method,

View File

@@ -17,12 +17,6 @@ Public Class clsEmailIMAP
Logger.Info(String.Format("Working on IMAP_COLLECT....."))
Logger.Debug(String.Format("Working on IMAP_COLLECT....."))
Dim oClient As New ImapClient(MAIL_SERVER, MAIL_PORT)
'If LOG_ERRORS_ONLY = False Then
' Dim emaillogger As New Independentsoft.Email.Logger(My.Application.Info.DirectoryPath & "\Log\IDSoftMailLog.txt")
' AddHandler emaillogger.WriteLog, AddressOf OnWriteLog
'client.Logger = emaillogger
'End If
oClient.ValidateRemoteCertificate = False
oClient.Connect()
oClient.Login(MAIL_USER, MAIL_USER_PW)
@@ -54,31 +48,38 @@ Public Class clsEmailIMAP
Try
Logger.Info(String.Format("Working on TEST_IMAP_COLLECT....."))
Dim client As New ImapClient(MYMAIL_SERVER, MYMAIL_PORT)
Dim oImapClient As New ImapClient(MYMAIL_SERVER, MYMAIL_PORT)
' oImapClient.ValidateRemoteCertificate = False
oImapClient.Connect()
Try
oImapClient.Login(MAIL_USER, MAIL_USER_PW)
Catch ex As Exception
MsgBox($"Unexpected error in TEST_IMAP_COLLECT (oImapClient.Login): {ex.Message}")
Logger.Info($"Unexpected error in TEST_IMAP_COLLECT - User: [{MYMAIL_USER}] PW: [{MYMAIL_USER_PW}]")
Logger.Warn(ex.StackTrace.ToString)
Logger.Warn(ex.Message)
'If LOG_ERRORS_ONLY = False Then
' Dim emaillogger As New Independentsoft.Email.Logger(My.Application.Info.DirectoryPath & "\Log\IDSoftMailLog.txt")
' AddHandler emaillogger.WriteLog, AddressOf OnWriteLog
'client.Logger = emaillogger
'End If
client.Connect()
client.Login(MYMAIL_USER, MYMAIL_USER_PW)
client.SelectFolder(INBOXNAME)
Dim envelopes As Envelope() = client.ListMessages()
Logger.Error(ex)
Return False
End Try
For i As Integer = 0 To envelopes.Length - 1
If Not IsNothing(envelopes(i).Subject) Then
oImapClient.SelectFolder(INBOXNAME)
Dim oEnvelopes As Envelope() = oImapClient.ListMessages()
For i As Integer = 0 To oEnvelopes.Length - 1
If Not IsNothing(oEnvelopes(i).Subject) Then
'If envelopes(i).Subject.ToString.ToUpper.Contains("[PROCESSMANAGER]") Or envelopes(i).Subject.ToString.ToUpper.Contains("[ADDI]") Then
MsgBox($"Working on email: UniqueID: {envelopes(i).UniqueID} - Subject:{envelopes(i).Subject} - Date {envelopes(i).Date.ToString}")
Dim message As Mime.Message = client.GetMessage(envelopes(i).UniqueID)
MsgBox($"Working on email: UniqueID: {oEnvelopes(i).UniqueID} - Subject:{oEnvelopes(i).Subject} - Date {oEnvelopes(i).Date.ToString}")
Dim message As Mime.Message = oImapClient.GetMessage(oEnvelopes(i).UniqueID)
End If
Next
client.Disconnect()
oImapClient.Disconnect()
Logger.Info("TEST_IMAP_COLLECT finished!")
Return True
Catch ex As Exception
MsgBox($"Unexpected error in TEST_IMAP_COLLECT: {ex.Message}")
Logger.Error(ex, "Unexpected Error in TEST_IMAP_COLLECT:")
Return False
End Try

View File

@@ -72,7 +72,6 @@ Public Class clsEmail
For i As Integer = 0 To messageInfo.Length - 1
Dim message As Message = client.GetMessage(messageInfo(i).Index)
MsgBox(String.Format("Message [{0}] added", message.Subject))
Next
client.Disconnect()
@@ -105,22 +104,28 @@ Public Class clsEmail
client.Disconnect()
Return True
ElseIf CURRENT_POLL_TYPE = "IMAP" Then
Dim client As New ImapClient(MAIL_SERVER, MAIL_PORT)
Try
Dim oClient As New ImapClient(MAIL_SERVER, MAIL_PORT)
client.ValidateRemoteCertificate = False
client.Connect()
client.Login(MAIL_USER, MAIL_USER_PW)
oClient.ValidateRemoteCertificate = False
oClient.Connect()
oClient.Login(MAIL_USER, MAIL_USER_PW)
oClient.SelectFolder("Inbox")
Dim oEnvelopes As Envelope() = oClient.ListMessages()
For i As Integer = 0 To oEnvelopes.Length - 1
If oEnvelopes(i).MessageID = msgid Then
oClient.Delete(oEnvelopes(i).UniqueID) 'mark as deleted
End If
Next
oClient.Expunge() 'delete messages marked as deleted
oClient.Disconnect()
Return True
Catch ex As Exception
Logger.Warn("Error in IMAP Delete: " & ex.Message)
Return False
End Try
client.SelectFolder("Inbox")
Dim envelopes As Envelope() = client.ListMessages()
For i As Integer = 0 To envelopes.Length - 1
If envelopes(i).MessageID = msgid Then
client.Delete(envelopes(i).UniqueID) 'mark as deleted
End If
Next
client.Expunge() 'delete messages marked as deleted
client.Disconnect()
Return True
Else
Return False
End If
@@ -133,8 +138,6 @@ Public Class clsEmail
Public Function Email_Send_Independentsoft(ByVal mailSubject As String, ByVal mailBody As String, mailto As String,
mailfrom As String, mailsmtp As String, mailport As Integer, mailUser As String, mailPW As String,
AUTH_TYPE As String, Optional attment As String = "")
Try
Logger.Debug($"in Email_Send_Independentsoft..")
Dim empfaenger As String()

View File

@@ -65,7 +65,7 @@ Public Class clsWindream_Index
End Function
Public Function GetIndex_Type(idxName) As String
Try
Dim oAttribute = oSession.GetWMObjectByName(WINDREAMLib.WMEntity.WMEntityAttribute, idxName)
Dim oAttribute = oWMSession.GetWMObjectByName(WINDREAMLib.WMEntity.WMEntityAttribute, idxName)
'den Variablentyp (String, Integer, ...) auslesen
Dim vType = oAttribute.getVariableValue("dwAttrType")
Dim Type As String
@@ -131,7 +131,7 @@ Public Class clsWindream_Index
'VEKTORFELDER, ALSO ÜBERPRÜFEN OB ERGEBNIS-ARRAY GEFÜLLT IST
Logger.Debug("RunIndexing_Vektor: VEKTORFELD-Indexierung: Vorbereiten des Arrays")
' das entsprechende Attribut aus windream auslesen
Dim oAttribute = oSession.GetWMObjectByName(WINDREAMLib.WMEntity.WMEntityAttribute, indexname)
Dim oAttribute = oWMSession.GetWMObjectByName(WINDREAMLib.WMEntity.WMEntityAttribute, indexname)
' den Variablentyp (String, Integer, ...) auslesen
Dim vType = oAttribute.getVariableValue("dwAttrType")
Select Case (vType)
@@ -256,7 +256,7 @@ Public Class clsWindream_Index
' wenn der Datei noch kein Dokumenttyp zugewiesen wurde
If oDocument.aObjectType.aName <> Objekttyp Then
' ihr den entsprechenden Dokumenttyp zuweisen
oDocument.aObjectType = oSession.GetWMObjectByName(WINDREAMLib.WMEntity.WMEntityObjectType, Objekttyp)
oDocument.aObjectType = oWMSession.GetWMObjectByName(WINDREAMLib.WMEntity.WMEntityObjectType, Objekttyp)
' WMObject.aObjectType = selectedProfile.Dokumenttyp
Logger.Debug("Objekttyp war Standard und wurde in '" & Objekttyp & "' geändert.")
Else
@@ -275,7 +275,7 @@ Public Class clsWindream_Index
For Each aName As String In Indizes
indexname = aName
' das entsprechende Attribut aus windream auslesen
Dim oAttribute = oSession.GetWMObjectByName(WINDREAMLib.WMEntity.WMEntityAttribute, Indizes(i))
Dim oAttribute = oWMSession.GetWMObjectByName(WINDREAMLib.WMEntity.WMEntityAttribute, Indizes(i))
' den Variablentyp (String, Integer, ...) auslesen
Dim vType = oAttribute.getVariableValue("dwAttrType")
' wenn in aValues an Position i ein Wert steht
@@ -611,101 +611,101 @@ Public Class clsWindream_Index
Return Nothing
End If
Dim missing As Boolean = False
Dim Anzahl As Integer = 0
Dim ValueArray()
'Jeden Wert des Vektorfeldes durchlaufen
Dim wertWD = oDocument.GetVariableValue(oIndexName)
If wertWD Is Nothing = False Then
'Nochmals prüfen ob wirklich Array
If wertWD.GetType.ToString.Contains("System.Object") Then
'Keine Duplikatprüfung also einfach neues Array füllen
If CheckDuplikat = False Then
For Each value As Object In wertWD
'Das Array anpassen
ReDim Preserve ValueArray(Anzahl)
'Den Wert im Array speichern
ValueArray(Anzahl) = value.ToString
Anzahl += 1
Next
'Und jetzt den/die Neuen Wert(e) anfügen
For Each NewValue As Object In NIIndexe
If NewValue Is Nothing = False Then
'Das Array anpassen
ReDim Preserve ValueArray(Anzahl)
'Den Wert im Array speichern
ValueArray(Anzahl) = NewValue.ToString
Anzahl += 1
End If
Next
Else
Logger.Debug("Duplikatprüfung soll durchgeführt werden.")
'Duplikat Prüfung an, also nur anhängen wenn Wert <>
For Each WDValue As Object In wertWD
If WDValue Is Nothing = False Then
'Erst einmal die ALten Werte schreiben
ReDim Preserve ValueArray(Anzahl)
'Den Wert im Array speichern
ValueArray(Anzahl) = WDValue.ToString
Logger.Debug("Value (" & Anzahl & ") " & WDValue.ToString)
Anzahl += 1
End If
Next
'Jetzt die Neuen Werte auf Duplikate überprüfen
For Each NewValue As Object In NIIndexe
If NewValue Is Nothing = False Then
If ValueArray.Contains(NewValue) = False Then
Logger.Debug("New Value (" & Anzahl & ") " & NewValue.ToString)
'Das Array anpassen
ReDim Preserve ValueArray(Anzahl)
'Den Wert im Array speichern
ValueArray(Anzahl) = NewValue.ToString
Anzahl += 1
Else
Logger.Debug("Value '" & NewValue.ToString & "' bereits in Vektorfeld enthalten")
End If
End If
Next
End If
End If
Else
Logger.Debug("Vektorfeld ist noch leer....")
'Den/die Neuen Wert(e) anfügen
For Each NewValue As Object In NIIndexe
If NewValue Is Nothing = False Then
If CheckDuplikat = True Then
If ValueArray Is Nothing = False Then
If ValueArray.Contains(NewValue) = False Then
'Das Array anpassen
ReDim Preserve ValueArray(Anzahl)
'Den Wert im Array speichern
ValueArray(Anzahl) = NewValue.ToString
Anzahl += 1
Else
Logger.Debug("Value '" & NewValue.ToString & "' bereits in Array enthalten")
End If
Else 'Dererste Wert, also hinzufügen
'Das Array anpassen
ReDim Preserve ValueArray(Anzahl)
'Den Wert im Array speichern
ValueArray(Anzahl) = NewValue.ToString
Anzahl += 1
End If
Else
Dim Anzahl As Integer = 0
Dim ValueArray()
'Jeden Wert des Vektorfeldes durchlaufen
Dim wertWD = oDocument.GetVariableValue(oIndexName)
If wertWD Is Nothing = False Then
'Nochmals prüfen ob wirklich Array
If wertWD.GetType.ToString.Contains("System.Object") Then
'Keine Duplikatprüfung also einfach neues Array füllen
If CheckDuplikat = False Then
For Each value As Object In wertWD
'Das Array anpassen
ReDim Preserve ValueArray(Anzahl)
'Den Wert im Array speichern
ValueArray(Anzahl) = value.ToString
Anzahl += 1
Next
'Und jetzt den/die Neuen Wert(e) anfügen
For Each NewValue As Object In NIIndexe
If NewValue Is Nothing = False Then
'Das Array anpassen
ReDim Preserve ValueArray(Anzahl)
'Den Wert im Array speichern
ValueArray(Anzahl) = NewValue.ToString
Anzahl += 1
End If
End If
Next
End If
Logger.Debug("Return ValueArray: length " & ValueArray.Length)
Return ValueArray
End If
Next
Else
Logger.Debug("Duplikatprüfung soll durchgeführt werden.")
'Duplikat Prüfung an, also nur anhängen wenn Wert <>
For Each WDValue As Object In wertWD
If WDValue Is Nothing = False Then
'Erst einmal die ALten Werte schreiben
ReDim Preserve ValueArray(Anzahl)
'Den Wert im Array speichern
ValueArray(Anzahl) = WDValue.ToString
Logger.Debug("Value (" & Anzahl & ") " & WDValue.ToString)
Anzahl += 1
End If
Next
'Jetzt die Neuen Werte auf Duplikate überprüfen
For Each NewValue As Object In NIIndexe
If NewValue Is Nothing = False Then
If ValueArray.Contains(NewValue) = False Then
Logger.Debug("New Value (" & Anzahl & ") " & NewValue.ToString)
'Das Array anpassen
ReDim Preserve ValueArray(Anzahl)
'Den Wert im Array speichern
ValueArray(Anzahl) = NewValue.ToString
Anzahl += 1
Else
Logger.Debug("Value '" & NewValue.ToString & "' bereits in Vektorfeld enthalten")
End If
End If
Next
End If
End If
Else
Logger.Debug("Vektorfeld ist noch leer....")
'Den/die Neuen Wert(e) anfügen
For Each NewValue As Object In NIIndexe
If NewValue Is Nothing = False Then
If CheckDuplikat = True Then
If ValueArray Is Nothing = False Then
If ValueArray.Contains(NewValue) = False Then
'Das Array anpassen
ReDim Preserve ValueArray(Anzahl)
'Den Wert im Array speichern
ValueArray(Anzahl) = NewValue.ToString
Anzahl += 1
Else
Logger.Debug("Value '" & NewValue.ToString & "' bereits in Array enthalten")
End If
Else 'Dererste Wert, also hinzufügen
'Das Array anpassen
ReDim Preserve ValueArray(Anzahl)
'Den Wert im Array speichern
ValueArray(Anzahl) = NewValue.ToString
Anzahl += 1
End If
Else
'Das Array anpassen
ReDim Preserve ValueArray(Anzahl)
'Den Wert im Array speichern
ValueArray(Anzahl) = NewValue.ToString
Anzahl += 1
End If
End If
Next
End If
Logger.Debug("Return ValueArray: length " & ValueArray.Length)
Return ValueArray
Catch ex As Exception
Logger.Error(ex)
ClassCurrent.MessageError = True
@@ -716,7 +716,7 @@ Public Class clsWindream_Index
#Region "+++++ Allgemeine Funktionen die Informationen zurückliefern +++++"
Public Function GetCheckIsVector(oIndexname As String)
Dim oAttribute = oSession.GetWMObjectByName(WINDREAMLib.WMEntity.WMEntityAttribute, oIndexname)
Dim oAttribute = oWMSession.GetWMObjectByName(WINDREAMLib.WMEntity.WMEntityAttribute, oIndexname)
' den Variablentyp (String, Integer, ...) auslesen
Dim vType = oAttribute.getVariableValue("dwAttrType")
Select Case (vType)
@@ -791,7 +791,7 @@ Public Class clsWindream_Index
Dim IndexwertAusWindream As Object = Nothing
Dim _dok As WINDREAMLib.WMObject
_dok = Nothing
_dok = oSession.GetWMObjectByPath(WMEntityDocument, _fullfilepath) 'WINDREAMLib.WMEntity.WMEntityDocument
_dok = oWMSession.GetWMObjectByPath(WMEntityDocument, _fullfilepath) 'WINDREAMLib.WMEntity.WMEntityDocument
IndexwertAusWindream = _dok.GetVariableValue(_indexname)
Return IndexwertAusWindream.ToString
Catch ex As Exception

View File

@@ -21,7 +21,7 @@ Public Class clsWindream_allgemein
#Region "+++++ Variablen +++++"
Public Shared oConnect ' der Typ darf nicht festgelegt werden (warum auch immer... geht sonst nicht)
Public Shared oSession 'As WINDREAMLib.WMSession ' der Typ darf nicht festgelegt werden (warum auch immer... geht sonst nicht)
Public Shared oWMSession 'As WINDREAMLib.WMSession ' der Typ darf nicht festgelegt werden (warum auch immer... geht sonst nicht)
Public Shared oBrowser As New WMOBRWSLib.ServerBrowser
Public Shared oDokumentTypen As WINDREAMLib.WMObjects
Private Shared oController As New WMOSearchController
@@ -56,11 +56,22 @@ Public Class clsWindream_allgemein
Try
Try
' Session-Objekt instanziieren und mit dem im Client ausgewählten Server belegen
oSession = CreateObject("Windream.WMSession", GetCurrentServer)
' Connection-Objekt instanziieren
oConnect = CreateObject("Windream.WMConnect")
'MsgBox("windrem init 'ed")
Dim oHourDifference As Integer
oHourDifference = CInt(DateDiff(DateInterval.Hour, CURRENToWMSession_Created, Now))
If IsNothing(CURRENToWMSession) Or oHourDifference >= 2 Then
' Session-Objekt instanziieren und mit dem im Client ausgewählten Server belegen
oWMSession = CreateObject("Windream.WMSession", GetCurrentServer)
' Connection-Objekt instanziieren
oConnect = CreateObject("Windream.WMConnect")
CURRENToWMConnect = oConnect
Else
Logger.Debug("WMSession already created!")
oWMSession = CURRENToWMSession
Return True
End If
Catch ex As Exception
Return False
End Try
@@ -82,11 +93,11 @@ Public Class clsWindream_allgemein
'oConnect.Password = "pw"
' Verbindung mit Session-Objekt (und dem ausgewählten Server) aufbauen
oConnect.LoginSession(oSession)
oConnect.LoginSession(oWMSession)
Logger.Debug("windream-Server: '" & GetCurrentServer() & "'")
Logger.Debug("windream-UserName: '" & oConnect.UserName & "'")
If oSession.aLoggedin = False Then
If oWMSession.aLoggedin = False Then
Logger.Warn("Es konnte keine Verbindung mit dem windream-Server hergestellt werden")
Return False
End If
@@ -107,16 +118,17 @@ Public Class clsWindream_allgemein
'MsgBox(WMCtrl.WMServerName)
Try
oSession.SwitchEvents(WMCOMEventWMSessionNeedIndex, False)
oWMSession.SwitchEvents(WMCOMEventWMSessionNeedIndex, False)
' der Parameter WMEntityDocument definiert, dass nur Dokumenttypen und keine
' Ordnertypen ausgelesen werden
oDokumentTypen = oSession.GetWMObjectTypes(WINDREAMLib.WMEntity.WMEntityDocument)
oDokumentTypen = oWMSession.GetWMObjectTypes(WINDREAMLib.WMEntity.WMEntityDocument)
Catch ex As Exception
Logger.Error(ex)
Return False
End Try
End If
CURRENToWMSession = oWMSession
CURRENToWMSession_Created = Now
Logger.Debug("Alles OK - Erfolgreich angemeldet und Session aufgebaut")
Return True
@@ -194,7 +206,7 @@ Public Class clsWindream_allgemein
Dim oRelProperties As WMObjectRelationClass
' den Objekttyp laden
oObjectType = oSession.GetWMObjectByName(WMEntityObjectType, name)
oObjectType = oWMSession.GetWMObjectByName(WMEntityObjectType, name)
' Beziehung zu Indizes des Objekttyp auslesen
oIndexAttributes = oObjectType.GetWMObjectRelationByName("TypeAttributes")
@@ -235,7 +247,7 @@ Public Class clsWindream_allgemein
Public Function GetObjecttypeByName(ByVal objekttypName As String) As WMObject
Try
' alle Objekttypen auslesen
Dim oObjectTypes As WMObjects = oSession.GetWMObjectTypes(WINDREAMLib.WMEntity.WMEntityDocument)
Dim oObjectTypes As WMObjects = oWMSession.GetWMObjectTypes(WINDREAMLib.WMEntity.WMEntityDocument)
' alle Objekttypen durchlaufen und nach dem mit dem angegebenen Namen suchen
For Each oObjectType As WMObject In oObjectTypes
@@ -287,7 +299,7 @@ Public Class clsWindream_allgemein
''' <remarks></remarks>
Public Function IsLoggedIn() As Boolean
Try
Return oSession.aLoggedin
Return oWMSession.aLoggedin
Catch ex As Exception
Logger.Error(ex)
End Try
@@ -352,7 +364,7 @@ Public Class clsWindream_allgemein
''' <remarks></remarks>
Public Function GetTypeOfIndexAsIntByName(ByVal indexname As String) As Integer
Try
Dim oAttribute = oSession.GetWMObjectByName(WINDREAMLib.WMEntity.WMEntityAttribute, indexname)
Dim oAttribute = oWMSession.GetWMObjectByName(WINDREAMLib.WMEntity.WMEntityAttribute, indexname)
Dim vType = oAttribute.getVariableValue("dwAttrType")
Return vType
Catch ex As Exception
@@ -364,7 +376,7 @@ Public Class clsWindream_allgemein
'Dim oAttribute = oSession.GetWMObjectByName(WINDREAMLib.WMEntity.WMEntityAttribute, indexname)
'Dim vType = oAttribute.getVariableValue("vItems")
'Return vType
Dim oChoiceList = oSession.GetWMObjectByName(WMEntityChoiceList, indexname)
Dim oChoiceList = oWMSession.GetWMObjectByName(WMEntityChoiceList, indexname)
If Err.Number = 0 And TypeName(oChoiceList) <> "Nothing" Then
Dim Values = oChoiceList
Values = oChoiceList.GetVariableValue("vItems")
@@ -397,7 +409,7 @@ Public Class clsWindream_allgemein
Public Function WDObject_exists(wdobj_location As String)
Dim WDObject As WMObject
Try
WDObject = oSession.GetWMObjectByPath(WINDREAMLib.WMEntity.WMEntityDocument, wdobj_location.Substring(2))
WDObject = oWMSession.GetWMObjectByPath(WINDREAMLib.WMEntity.WMEntityDocument, wdobj_location.Substring(2))
If WDObject Is Nothing Then
Return False
Else

View File

@@ -96,7 +96,7 @@ Public Class clsWorkEmail
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)
COPY2HDD(row("COPY_2_HDD"), row("PATH_ORIGINAL"), row("PATH_EMAIL_ERRORS"), False)
EXTRACT_BODY()
Next
@@ -107,6 +107,10 @@ Public Class clsWorkEmail
CURRENT_MAIL_PROCESS_NAME = "DD EasyApproval via Mail"
If CURRENT_MAIL_BODY_ANSWER1 <> "" Then
If CURRENT_MAIL_BODY_ANSWER1.EndsWith(":") Then
Logger.Info(String.Format("Keyword contained a : at end...removing it..."))
CURRENT_MAIL_BODY_ANSWER1 = CURRENT_MAIL_BODY_ANSWER1.Replace(":", "")
End If
MessageError = False
If GET_WMDOC_INFO() = True Then
If DT_STEPS.Rows.Count > 0 Then
@@ -139,26 +143,26 @@ Public Class clsWorkEmail
'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
For Each oDataRow As DataRow In PM_ROW
Try
WM_REFERENCE_INDEX = row("WM_REFERENCE_INDEX")
WM_REFERENCE_INDEX = oDataRow("WM_REFERENCE_INDEX")
Catch ex As Exception
WM_REFERENCE_INDEX = Nothing
End Try
Try
WM_VECTOR_LOG = row("WM_VECTOR_LOG")
WM_VECTOR_LOG = oDataRow("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")
WM_OBJEKTTYPE = oDataRow("WM_OBJEKTTYPE")
WM_IDX_BODY_TEXT = oDataRow("WM_IDX_BODY_TEXT")
WM_IDX_BODY_SUBSTR_LENGTH = oDataRow("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")
COPY2HDD(oDataRow("COPY_2_HDD"), oDataRow("PATH_ORIGINAL"), oDataRow("PATH_EMAIL_ERRORS"), True)
EXTRACT_ATTACHMENTS(oDataRow("PATH_EMAIL_TEMP"), oDataRow("PATH_EMAIL_ERRORS"))
'EXTRACT_BODY()
oDel_email = oDataRow("DELETE_MAIL")
Next
If ClassCurrent.CURRENT_DEBUG_LOCAL_EMAIL = "" Then
EMAIL_DELETE(oDel_email)
@@ -228,14 +232,13 @@ Public Class clsWorkEmail
Return False
End Try
End Function
Private Function COPY2HDD(copy_2_hdd As Boolean, pathemailtemp As String, pathemail_errors As String, messageid As Boolean)
Private Function COPY2HDD(copy_2_hdd As Boolean, pathOriginal 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 Directory.Exists(pathOriginal) Then
Dim oTempFilename = pathOriginal
If messageid = True Then
oTempFilename &= "\" & CURRENT_MAIL_MESSAGE.MessageID & ".eml"
Else
@@ -259,69 +262,122 @@ Public Class clsWorkEmail
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 oDTFunctionRegex As DataTable = _Database.Return_Datatable("SELECT * FROM TBDD_FUNCTION_REGEX WHERE UPPER(FUNCTION_NAME) IN (UPPER('EMAIL_PROFILER - RemoveHTMLText'),UPPER('EMAIL_PROFILER - RemoveHTMLText1'))")
Dim msg_email As New Independentsoft.Email.Mime.Message(CURRENT_TEMP_MAIL_PATH)
If IsNothing(msg_email.Body) Then
Dim oMsg_email As New Independentsoft.Email.Mime.Message(CURRENT_TEMP_MAIL_PATH)
Dim oBodyText As String = ""
If IsNothing(oMsg_email.Body) Then
Dim oAllBodyParts As New BodyPartCollection()
oAllBodyParts.Add(msg_email.BodyParts)
oAllBodyParts.Add(GetChildren(msg_email.BodyParts))
oAllBodyParts.Add(oMsg_email.BodyParts)
oAllBodyParts.Add(GetChildren(oMsg_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
If oBodyText = String.Empty Then
Logger.Debug(String.Format("BODY1-Text is....#{0}", bodyPart.Body))
oBodyText = bodyPart.Body
Else
Continue For
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
If oBodyText = String.Empty Then
oBodyText = bodyPart.Body
Logger.Debug(String.Format("bodyhtml....#{0}", bodyPart.Body))
Else
Continue For
End If
Logger.Debug(String.Format("bodyhtml....#{0}", bodyPart.Body))
End If
Next
If oBodyText = "" Then
Else
CURRENT_MAIL_BODY_ALL = oBodyText
End If
Else
CURRENT_MAIL_BODY_ALL = msg_email.Body
CURRENT_MAIL_BODY_ALL = oMsg_email.Body
End If
If CURRENT_MAIL_BODY_ALL.StartsWith("<html") Then
If Not IsNothing(CURRENT_MAIL_BODY_ALL) Then
' CURRENT_MAIL_BODY_ALL = oMsg_email.Body
Dim oPattern1 As String
Dim oPattern2 As String
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)
oPattern1 = oDTFunctionRegex.Rows(0).Item("REGEX")
Catch ex As Exception
oPattern1 = ""
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
Try
oPattern2 = oDTFunctionRegex.Rows(1).Item("REGEX")
Catch ex As Exception
oPattern2 = ""
End Try
Dim oReg As Regex = New Regex(oPattern1, RegexOptions.IgnoreCase)
Dim oMatch As Match = oReg.Match(CURRENT_MAIL_BODY_ALL)
Dim oClearedBodyText = CURRENT_MAIL_BODY_ALL
Do While oMatch.Success
oClearedBodyText = oClearedBodyText.Replace(oMatch.Value, "")
oMatch = oMatch.NextMatch()
Loop
Logger.Info($"Cleared bodytext after Regex1 is: {oClearedBodyText}")
Dim oReg2 As Regex = New Regex(oPattern2, RegexOptions.IgnoreCase)
Dim oMatch2 As Match = oReg2.Match(oClearedBodyText)
Do While oMatch2.Success
oClearedBodyText = oClearedBodyText.Replace(oMatch2.Value, "")
'Dim g As Group = m.Groups(1)
'If g.ToString.StartsWith("&") = False Then
' TEMP_HTML_RESULTS.Add(g.ToString())
'End If
oMatch2 = oMatch2.NextMatch()
Loop
Logger.Info($"Cleared bodytext after Regex2 is: {oClearedBodyText}")
CURRENT_MAIL_BODY_ALL = oClearedBodyText
Else
Logger.Info($"Mailbody still is nothing after bodyExtraction!!")
End If
'Try
' Dim pattern1 As String = ""
' For Each oRow As DataRow In oDTFunctionRegex.Rows
' If oRow.Item("FUNCTION_NAME").ToString.ToUpper = "EMAIL_PROFILER - RemoveHTMLText".ToUpper 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
Try
If CURRENT_MAIL_BODY_ALL = String.Empty Then
Logger.Warn("Mailbody is empty. Email can not be processed! - Please check the html-structure")
@@ -345,7 +401,9 @@ Public Class clsWorkEmail
If oCount = 1 Then
CURRENT_MAIL_BODY_ANSWER1 = ostr
Else
If oCount = 2 Then
If ostr.StartsWith("##") Then
Exit For
ElseIf oCount = 2 Then
CURRENT_MAIL_BODY_Substr2 = ostr
Else
If ((oReadLength + ostr.Length) >= WM_IDX_BODY_SUBSTR_LENGTH) Or ostr.StartsWith("##") Then
@@ -389,8 +447,8 @@ Public Class clsWorkEmail
Logger.Debug(String.Format("MailBody-ANSWER1:...[{0}]", CURRENT_MAIL_BODY_ANSWER1))
Logger.Debug(String.Format("MailBody-ANSWER2:...[{0}]", CURRENT_MAIL_BODY_Substr2))
Logger.Info(String.Format("MailBody-ANSWER1:...[{0}]", CURRENT_MAIL_BODY_ANSWER1))
Logger.Info(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
@@ -450,33 +508,43 @@ Public Class clsWorkEmail
End Try
End Function
Private Function EXTRACT_ATTACHMENTS(pathemailtemp As String, pathemail_errors As String)
Logger.Debug("In EXTRACT_ATTACHMENTS...")
PATH_TEMP = pathemailtemp
PATH_ERROR = pathemail_errors
Logger.Debug(String.Format("PATH_TEMP[{0}]", PATH_TEMP))
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
Dim oCurrentMail As New Independentsoft.Email.Mime.Message(CURRENT_TEMP_MAIL_PATH)
Dim oMSGID = oCurrentMail.MessageID
If IsNothing(oMSGID) Then
oMSGID = System.Guid.NewGuid.ToString()
End If
oMSGID = oMSGID.Replace(">", "").Replace("<", "")
For Each oAttachment As Attachment In oCurrentMail.GetAttachments
Dim oAttachmentFileString
Logger.Debug(String.Format("Working on Attachment [{0}]", oAttachment.GetFileName))
Try
Dim oFilename = oAttachment.GetFileName
oFilename = CleanInput(oFilename)
If oFilename = String.Empty Then
oFilename = oAttachment.GetFileName
End If
oAttachmentFileString = Path.Combine(PATH_TEMP, $"{oMSGID}~{oFilename}")
If System.IO.File.Exists(oAttachmentFileString) = False Then
Logger.Debug(String.Format("Trying to save attachment [{0}]", oAttachmentFileString))
oAttachment.Save(oAttachmentFileString)
INSERT_HISTORY_FB(oMSGID, oAttachment.GetFileName)
Else
Logger.Info("Attachment (" & oAttachmentFileString & ") already existing!", False, "EXTRACT_ATTACHMENTS")
End If
Catch ex As Exception
Logger.Warn($"Error while creating and saving attachment-name: {ex.Message} - AttachmentName: {oAttachmentFileString}")
MessageError = True
Return False
End Try
Next
Else
Logger.Warn($"If cause 2 EXTRACT_ATTACHMENTS: {CURRENT_TEMP_MAIL_PATH} not existing")
@@ -492,6 +560,29 @@ Public Class clsWorkEmail
Return False
End Try
End Function
Private Function CleanInput(strIn As String) As String
' Replace invalid characters with empty strings.
Try
Return Regex.Replace(strIn, "[^\w\.@-]", "")
' If we timeout when replacing invalid characters,
' we should return String.Empty.
Catch ex As Exception
Logger.Error(ex)
Return String.Empty
End Try
End Function
Private Function RemoveCharacter(ByVal stringToCleanUp)
Dim characterToRemove As String = ""
characterToRemove = Chr(34) + "#$%&'()*+,-./\~"
Dim firstThree As Char() = characterToRemove.Take(16).ToArray()
For index = 1 To firstThree.Length - 1
stringToCleanUp = stringToCleanUp.ToString.Replace(firstThree(index), "")
Next
Return stringToCleanUp
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 " &
@@ -543,6 +634,7 @@ Public Class clsWorkEmail
End Function
Private Function WORK_POLL_STEPS() As Boolean
Try
Dim oFoundSomething As Boolean = False
_worked_email = False
For Each row As DataRow In DT_STEPS.Rows
POLL_STEP_GUID = row.Item("GUID")
@@ -550,10 +642,12 @@ Public Class clsWorkEmail
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
For Each oKeyWord As String In KEYWORDS_SPLIT
If CURRENT_MAIL_BODY_ANSWER1.ToUpper = oKeyWord.ToUpper Then
_worked_email = True
Logger.Info(String.Format("Found Keyword '{0}' in MessageBody", str))
Logger.Info(String.Format("Found Keyword '{0}' in MessageBody", oKeyWord))
oFoundSomething = True
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
@@ -566,9 +660,15 @@ Public Class clsWorkEmail
Next
Next
If _worked_email = False Then
If oFoundSomething = False Then
Logger.Info($"None of the keywords was found...Keyword after Regex is '{0}'")
End If
If _worked_email = False And oFoundSomething = 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)
If DT_INDEXING_STEPS.Rows.Count >= 1 Then
Logger.Info($"An index for direct answer was configured. Therefore it will be used...")
End If
WORK_INDEXING_STEPS()
_worked_email = True
End If
@@ -674,7 +774,7 @@ Public Class clsWorkEmail
CURRENT_WM_DOC = Nothing
Dim oWMDOC As WMObject
Try
oWMDOC = _windream.oSession.GetWMObjectByPath(WMEntity.WMEntityDocument, CURRENT_DOC_PATH.Substring(2))
oWMDOC = _windream.oWMSession.GetWMObjectByPath(WMEntity.WMEntityDocument, CURRENT_DOC_PATH.Substring(2))
CURRENT_WM_DOC = oWMDOC
Return True
Catch ex As Exception

View File

@@ -1 +1 @@
75ca9606c59e96beda488f8b876cf3665b773d22
9c16fe2374e1e996b351d980c60514ee4e15bd53

View File

@@ -17,6 +17,7 @@ E:\SchreiberM\Visual Studio\GIT\DD_EmailProfiler\App\DigitalData.EMLProfiler\bin
E:\SchreiberM\Visual Studio\GIT\DD_EmailProfiler\App\DigitalData.EMLProfiler\bin\Debug\Independentsoft.Email.xml
E:\SchreiberM\Visual Studio\GIT\DD_EmailProfiler\App\DigitalData.EMLProfiler\bin\Debug\NLog.xml
E:\SchreiberM\Visual Studio\GIT\DD_EmailProfiler\App\DigitalData.EMLProfiler\bin\Debug\FirebirdSql.Data.FirebirdClient.pdb
E:\SchreiberM\Visual Studio\GIT\DD_EmailProfiler\App\DigitalData.EMLProfiler\obj\Debug\DigitalData.EMLProfiler.vbprojAssemblyReference.cache
E:\SchreiberM\Visual Studio\GIT\DD_EmailProfiler\App\DigitalData.EMLProfiler\obj\Debug\DigitalData.EMLProfiler.Resources.resources
E:\SchreiberM\Visual Studio\GIT\DD_EmailProfiler\App\DigitalData.EMLProfiler\obj\Debug\DigitalData.EMLProfiler.vbproj.GenerateResource.cache
E:\SchreiberM\Visual Studio\GIT\DD_EmailProfiler\App\DigitalData.EMLProfiler\obj\Debug\DigitalData.EMLProfiler.vbproj.CoreCompileInputs.cache