Add Initial Support for OAuth2 / O365
This commit is contained in:
@@ -13,14 +13,6 @@ Public Class ClassCurrent
|
||||
Public Shared Property DTCONFIG As DataTable
|
||||
Public Shared Property DT_ECM_BASE_CONFIG As DataTable
|
||||
|
||||
Public Shared Property MAIL_FROM As String = ""
|
||||
Public Shared Property MAIL_SERVER As String = ""
|
||||
Public Shared Property MAIL_USER As String = ""
|
||||
Public Shared Property MAIL_USER_PW As String = ""
|
||||
Public Shared Property MAIL_PORT As Integer = 995
|
||||
Public Shared Property MAIL_INBOX_NAME As String = "Inbox"
|
||||
Public Shared Property MAIL_ARCHIVE_FOLDER As String = ""
|
||||
Public Shared Property MAIL_AUTHTYPE As String
|
||||
Public Shared Property DT_POLL_PROCESS As DataTable
|
||||
Public Shared Property DT_STEPS As DataTable
|
||||
Public Shared Property DT_INDEXING_STEPS As DataTable
|
||||
@@ -34,10 +26,8 @@ Public Class ClassCurrent
|
||||
Public Shared Property CURRENT_DRIVE_ISFULL As Boolean = False
|
||||
|
||||
|
||||
' Public Shared Property oCURRENT_WORKMAIL_LIST As New ArrayList()
|
||||
Public Shared Property CURRENT_WORKMAIL_UID_LIST As New List(Of Long)
|
||||
|
||||
Public Shared Property CURRENT_MAIL_MESSAGE As IMail
|
||||
Public Shared Property CURRENT_ImapObject As Imap
|
||||
Public Shared Property CURRENT_MAIL_UID As Long
|
||||
|
||||
|
||||
@@ -42,23 +42,14 @@ Public Class MailContainer
|
||||
SenderDomain = GetSenderDomain(pMail)
|
||||
End Sub
|
||||
|
||||
|
||||
Private Function GetSenderAddress(pMail As IMail)
|
||||
Dim oMailBox = pMail.From.FirstOrDefault()
|
||||
If oMailBox Is Nothing Then
|
||||
Return "InvalidSenderAddress"
|
||||
Else
|
||||
Return oMailBox.Address
|
||||
End If
|
||||
Return oMailBox?.Address
|
||||
End Function
|
||||
|
||||
Private Function GetSenderDomain(pMail As IMail)
|
||||
Dim oMailBox = pMail.From.FirstOrDefault()
|
||||
If oMailBox Is Nothing Then
|
||||
Return "InvalidSenderAddress"
|
||||
Else
|
||||
Return oMailBox.DomainPart
|
||||
End If
|
||||
Return oMailBox.DomainPart
|
||||
End Function
|
||||
|
||||
End Class
|
||||
|
||||
@@ -17,13 +17,15 @@ Public Class clsWorkEmail
|
||||
|
||||
Private CurrentMail As MailContainer = Nothing
|
||||
|
||||
Private CURRENT_TEMP_MAIL_PATH As String
|
||||
Private CurrentTempMailPath As String
|
||||
|
||||
Private CURRENT_MAIL_BODY_ALL As String
|
||||
Private CURRENT_MAIL_BODY_ANSWER1 As String = ""
|
||||
Private CURRENT_MAIL_BODY_Substr2 As String = ""
|
||||
Private CURRENT_MAIL_SUBJECT As String = ""
|
||||
Private CURRENT_MAIL_FROM As String = ""
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' Primary Mail Identifier.
|
||||
''' Is a hash of the MessageId, used to be the MessageId itself.
|
||||
@@ -85,7 +87,7 @@ Public Class clsWorkEmail
|
||||
CURRENT_MAIL_BODY_ALL = ""
|
||||
CURRENT_MAIL_BODY_ANSWER1 = ""
|
||||
CURRENT_MAIL_BODY_Substr2 = ""
|
||||
CURRENT_MAIL_MESSAGE = pMailMessage
|
||||
'CURRENT_MAIL_MESSAGE = pMailMessage
|
||||
CURRENT_MAIL_SUBJECT = pMailMessage.Subject.ToUpper.EscapeForSQL()
|
||||
|
||||
CURRENT_MAIL_UID = poUID
|
||||
@@ -136,7 +138,7 @@ Public Class clsWorkEmail
|
||||
Dim oTempMailAccessible As Boolean = False
|
||||
If oTempMailExists = True Then
|
||||
Try
|
||||
Dim oFS As FileStream = File.OpenRead(CURRENT_TEMP_MAIL_PATH)
|
||||
Dim oFS As FileStream = File.OpenRead(CurrentTempMailPath)
|
||||
oTempMailAccessible = True
|
||||
oFS.Close()
|
||||
Catch ex As Exception
|
||||
@@ -151,7 +153,7 @@ Public Class clsWorkEmail
|
||||
Else
|
||||
_Logger.Debug("CommonEmail-Process-Sniffer")
|
||||
If COMMON_EMAIL_IN(CurrentMail) = True Then
|
||||
InsertHistoryEntry()
|
||||
InsertHistoryEntry(CurrentMail)
|
||||
If CURRENT_ATTMT_COUNT = 0 Then
|
||||
_Logger.Info("### Mail contained no Attachments!! ###")
|
||||
Dim oBody = EmailStrings.EMAIL_NO_FERDS
|
||||
@@ -239,8 +241,8 @@ Public Class clsWorkEmail
|
||||
Private Function PROCESS_MANAGER_IN(pCurrentMail As MailContainer) As Boolean
|
||||
Try
|
||||
|
||||
_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))
|
||||
_Logger.Info(String.Format("PM-related message found....[{0}]", pCurrentMail.Mail.Subject))
|
||||
_Logger.Debug(String.Format("PM-related message found....[{0}]", pCurrentMail.Mail.Subject))
|
||||
Dim oExpression = "PROCESS_NAME = 'ProcessManager'"
|
||||
'Filter the rows using Select() method of DataTable
|
||||
Dim TEMP_PROCESS_PROFILE_DT As DataTable = DT_POLL_PROCESS
|
||||
@@ -260,8 +262,8 @@ Public Class clsWorkEmail
|
||||
WM_IDX_BODY_SUBSTR_LENGTH = row("WM_IDX_BODY_SUBSTR_LENGTH")
|
||||
DeleteMail = row("DELETE_MAIL")
|
||||
|
||||
If COPY2HDD(row("COPY_2_HDD"), row("PATH_ORIGINAL"), row("PATH_EMAIL_ERRORS"), False) = True Then
|
||||
EXTRACT_BODY()
|
||||
If COPY2HDD(pCurrentMail, row("COPY_2_HDD"), row("PATH_ORIGINAL"), row("PATH_EMAIL_ERRORS"), False) = True Then
|
||||
EXTRACT_BODY(pCurrentMail)
|
||||
End If
|
||||
|
||||
|
||||
@@ -330,8 +332,8 @@ Public Class clsWorkEmail
|
||||
Function COMMON_EMAIL_IN(pCurrentMail As MailContainer) As Boolean
|
||||
Try
|
||||
|
||||
_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))
|
||||
_Logger.Info(String.Format("COMMON_EMAIL_IN...Subject [{0}]", pCurrentMail.Mail.Subject))
|
||||
_Logger.Debug(String.Format("COMMON_EMAIL_IN...Subject [{0}]", pCurrentMail.Mail.Subject))
|
||||
Dim oExpression = "PROCESS_NAME = 'Attachment Sniffer' or PROCESS_NAME = 'ZugFeRD-Parser'"
|
||||
|
||||
'Filter the rows using Select() method of DataTable
|
||||
@@ -391,7 +393,7 @@ Public Class clsWorkEmail
|
||||
_Logger.Warn($"Unexpected Error in Checking RemainingTotalFreeSpace for Storage [{oExtractMainPath}]: {ex.Message}")
|
||||
End Try
|
||||
|
||||
If COPY2HDD(oRow("COPY_2_HDD"), oRow("PATH_ORIGINAL"), oRow("PATH_EMAIL_ERRORS"), True) = True Then
|
||||
If COPY2HDD(pCurrentMail, oRow("COPY_2_HDD"), oRow("PATH_ORIGINAL"), oRow("PATH_EMAIL_ERRORS"), True) = True Then
|
||||
If EXTRACT_ATTACHMENTS(pCurrentMail, oExtractMainPath, oRow("PATH_EMAIL_ERRORS")) = True Then
|
||||
|
||||
Return True
|
||||
@@ -439,12 +441,12 @@ Public Class clsWorkEmail
|
||||
'Dim oSubjectFilename = CURRENT_MAIL_MESSAGE.Subject.Truncate(SUBJECT_MAX_LENGTH) & ".eml"
|
||||
Dim oSubjectFilename = CURRENT_MAIL_MESSAGE_ID & ".eml"
|
||||
|
||||
_Logger.Debug($"oSubjectFilename (beforeclean) is: {oSubjectFilename}")
|
||||
_Logger.Debug($"Filename (beforeclean) is: {oSubjectFilename}")
|
||||
oSubjectFilename = RemoveIllegalFileNameChars(oSubjectFilename)
|
||||
oTempFilename = oTempPath & "\" & oSubjectFilename
|
||||
_Logger.Debug($"oTempFilename (afterclean) is: {oTempFilename}")
|
||||
oTempFilename = Path.Combine(oTempPath, oSubjectFilename)
|
||||
_Logger.Debug($"Filepath (afterclean) is: {oTempFilename}")
|
||||
|
||||
|
||||
Dim oCounter As Integer = 1
|
||||
'If File.Exists(oTempFilename) = True Then
|
||||
' Do While File.Exists(oTempFilename)
|
||||
' oCounter += 1
|
||||
@@ -455,12 +457,15 @@ Public Class clsWorkEmail
|
||||
' oTempFilename = oTempFilename.Replace("\", "")
|
||||
' Loop
|
||||
'End If
|
||||
CURRENT_MAIL_MESSAGE.Save(oTempFilename)
|
||||
CURRENT_TEMP_MAIL_PATH = oTempFilename
|
||||
_Logger.Debug($"Email saved to Temppath {CURRENT_TEMP_MAIL_PATH}")
|
||||
oCounter = 0
|
||||
pCurrentMail.Mail.Save(oTempFilename)
|
||||
CurrentTempMailPath = oTempFilename
|
||||
|
||||
_Logger.Debug($"Email saved to Temppath {CurrentTempMailPath}")
|
||||
|
||||
Dim oCounter As Integer = 1
|
||||
Dim oCancel As Boolean
|
||||
Do While File.Exists(CURRENT_TEMP_MAIL_PATH) = False
|
||||
Do While File.Exists(CurrentTempMailPath) = False
|
||||
_Logger.Debug("Trying to read saved mail.. ({0}/{1})", oCounter, 10)
|
||||
Thread.Sleep(1000)
|
||||
oCounter += 1
|
||||
If oCounter > 10 Then
|
||||
@@ -472,7 +477,7 @@ Public Class clsWorkEmail
|
||||
If oCancel = True Then
|
||||
oResult = False
|
||||
Else
|
||||
If File.Exists(CURRENT_TEMP_MAIL_PATH) Then
|
||||
If File.Exists(CurrentTempMailPath) Then
|
||||
oResult = True
|
||||
End If
|
||||
End If
|
||||
@@ -483,13 +488,13 @@ Public Class clsWorkEmail
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
_Logger.Info($"Unexpected error in Save2Temp [{oTempFilename}]")
|
||||
CURRENT_TEMP_MAIL_PATH = Nothing
|
||||
CurrentTempMailPath = 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(pShouldCopyToDisk As Boolean, pPathOriginal As String, pPathErrors As String, pUseMessageIdAsFilename As Boolean) As Boolean
|
||||
Private Function COPY2HDD(pCurrentMail As MailContainer, pShouldCopyToDisk As Boolean, pPathOriginal As String, pPathErrors As String, pUseMessageIdAsFilename As Boolean) As Boolean
|
||||
Try
|
||||
If pShouldCopyToDisk = True Then
|
||||
_Logger.Debug("COPY_2_HDD is ACTIVE!")
|
||||
@@ -519,7 +524,7 @@ Public Class clsWorkEmail
|
||||
Return False
|
||||
End Try
|
||||
|
||||
CURRENT_MAIL_MESSAGE.Save(oTempFilename)
|
||||
pCurrentMail.Mail.Save(oTempFilename)
|
||||
Dim oFileInfo As New FileInfo(oTempFilename)
|
||||
Dim oFileLenth As Long = oFileInfo.Length
|
||||
If oFileLenth > 0 Then
|
||||
@@ -536,7 +541,7 @@ Public Class clsWorkEmail
|
||||
End If
|
||||
|
||||
Else
|
||||
_Logger.Info("COPY2HDD (" & CURRENT_MAIL_MESSAGE.Subject & ") already existing in [{oTempFilename}]!", False, "RUN_THREAD.COPY_2_HDD")
|
||||
_Logger.Info("COPY2HDD (" & pCurrentMail.Mail.Subject & ") already existing in [{oTempFilename}]!", False, "RUN_THREAD.COPY_2_HDD")
|
||||
Return True
|
||||
End If
|
||||
Else
|
||||
@@ -551,11 +556,11 @@ Public Class clsWorkEmail
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
Private Function EXTRACT_BODY()
|
||||
Private Function EXTRACT_BODY(pCurrentMail As MailContainer)
|
||||
Dim oDTFunctionRegex As DataTable = _DB_MSSQL.GetDatatable("SELECT * FROM TBDD_FUNCTION_REGEX WHERE UPPER(FUNCTION_NAME) IN (UPPER('EMAIL_PROFILER - RemoveHTMLText'),UPPER('EMAIL_PROFILER - RemoveHTMLText1'))")
|
||||
|
||||
Dim oBodyText As String = ""
|
||||
If Not IsNothing(CURRENT_MAIL_MESSAGE.Text) Then
|
||||
If Not IsNothing(pCurrentMail.Mail.Text) Then
|
||||
CURRENT_MAIL_BODY_ALL = oBodyText
|
||||
End If
|
||||
|
||||
@@ -656,11 +661,12 @@ Public Class clsWorkEmail
|
||||
_Logger.Debug(String.Format("PATH_TEMP[{0}]", pExtractPath))
|
||||
Dim oAttachmentCount As Integer
|
||||
oAttachmentCount = 0
|
||||
Try
|
||||
If CURRENT_TEMP_MAIL_PATH <> Nothing Then
|
||||
If File.Exists(CURRENT_TEMP_MAIL_PATH) Then
|
||||
|
||||
For Each oAttachment As MimeData In CURRENT_MAIL_MESSAGE.Attachments
|
||||
Try
|
||||
If CurrentTempMailPath <> Nothing Then
|
||||
If File.Exists(CurrentTempMailPath) Then
|
||||
|
||||
For Each oAttachment As MimeData In pCurrentMail.Mail.Attachments
|
||||
Dim oATTFilename = oAttachment.SafeFileName.ToString.ToLower
|
||||
|
||||
Dim oValidExtensions = New List(Of String) From {"pdf", "xls", "xlsx", "doc", "docx", "ppt", "pptx"}
|
||||
@@ -687,28 +693,32 @@ Public Class clsWorkEmail
|
||||
'28.07.23
|
||||
'The original filename part will now be slugified to prevent errors
|
||||
'when opening the file in windream
|
||||
'05.09.23
|
||||
'The filename will now only contain a hash and a counter to prevent all errors relating to filenames and subject lines being shit
|
||||
|
||||
|
||||
Dim oFileInfo1 = New FileInfo(oAttachment.SafeFileName)
|
||||
Dim oFileInfo = New FileInfo(oAttachment.SafeFileName)
|
||||
Dim oFilenameWithoutExtension = Path.GetFileNameWithoutExtension(oAttachment.SafeFileName)
|
||||
Dim oFilename = StringEx.ConvertTextToSlug(oFilenameWithoutExtension) & oFileInfo1.Extension
|
||||
Dim oAttachmentFileName = $"{CURRENT_MAIL_MESSAGE_ID}~{pCurrentMail.SenderDomain}~{oFilename}"
|
||||
Dim oFilename = StringEx.ConvertTextToSlug(oFilenameWithoutExtension) & oFileInfo.Extension
|
||||
|
||||
'Dim oAttachmentFileName = $"{CURRENT_MAIL_MESSAGE_ID}~{pCurrentMail.SenderDomain}~{oFilename}"
|
||||
Dim oAttachmentFileName = $"{CURRENT_MAIL_MESSAGE_ID}~Attachment{oAttachmentCount}{oFileInfo.Extension}"
|
||||
|
||||
_Logger.Debug("Final Filename for Attachment: [{0}]", oAttachmentFileName)
|
||||
|
||||
oAttachmentFilePath = Path.Combine(pExtractPath, oAttachmentFileName)
|
||||
_Logger.Debug("Final Path for Attachment: [{0}]", oAttachmentFilePath)
|
||||
|
||||
If System.IO.File.Exists(oAttachmentFilePath) = False Then
|
||||
If File.Exists(oAttachmentFilePath) = False Then
|
||||
_Logger.Debug(String.Format("Trying to save attachment [{0}]", oAttachmentFilePath))
|
||||
Try
|
||||
oAttachment.Save(oAttachmentFilePath)
|
||||
'oAttachment.Save(oAttachmentFileString)
|
||||
Dim oFileInfo As New FileInfo(oAttachmentFilePath)
|
||||
Dim oFileLenth As Long = oFileInfo.Length
|
||||
Dim oFileInfo1 As New FileInfo(oAttachmentFilePath)
|
||||
Dim oFileLenth As Long = oFileInfo1.Length
|
||||
If oFileLenth > 2 Then
|
||||
_Logger.Info(String.Format("Attachment saved to [{0}]", oAttachmentFilePath))
|
||||
'INSERT_HISTORY_FB(CURRENT_MAIL_MESSAGE_ID, oAttachment.SafeFileName)
|
||||
InsertAttachmentHistoryEntry(CURRENT_MAIL_MESSAGE_ID, oAttachment.SafeFileName)
|
||||
InsertAttachmentHistoryEntry(pCurrentMail, CURRENT_MAIL_MESSAGE_ID, oAttachment.SafeFileName)
|
||||
oAttachmentCount += 1
|
||||
Else
|
||||
_Logger.Warn($"##!! oFileLenth for AttachmentObjects is <2 !!##")
|
||||
@@ -737,7 +747,7 @@ Public Class clsWorkEmail
|
||||
End Try
|
||||
Next
|
||||
Else
|
||||
_Logger.Warn($"If cause 2 EXTRACT_ATTACHMENTS: {CURRENT_TEMP_MAIL_PATH} not existing")
|
||||
_Logger.Warn($"If cause 2 EXTRACT_ATTACHMENTS: {CurrentTempMailPath} not existing")
|
||||
End If
|
||||
Else
|
||||
_Logger.Warn($"EXTRACT_ATTACHMENTSIf cause 1: CURRENT_TEMP_MAIL_PATH is NOTHING")
|
||||
@@ -755,13 +765,13 @@ Public Class clsWorkEmail
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function InsertHistoryEntry() As Boolean
|
||||
Private Function InsertHistoryEntry(pCurrentMail As MailContainer) As Boolean
|
||||
If MessageError = False Then
|
||||
Dim ins = $"INSERT INTO TBEMLP_HISTORY (WORK_PROCESS,EMAIL_MSGID,EMAIL_SUBJECT,EMAIL_DATE,EMAIL_BODY,EMAIL_SUBSTRING1,EMAIL_SUBSTRING2,EMAIL_FROM,PROFILE_ID) VALUES " &
|
||||
$"('{CurrentMailProcessName}'," &
|
||||
$"'{CURRENT_MAIL_MESSAGE_ID}'," &
|
||||
$"'{CURRENT_MAIL_SUBJECT}'," &
|
||||
$"'{CURRENT_MAIL_MESSAGE.Date}'," &
|
||||
$"'{pCurrentMail.Mail.Date}'," &
|
||||
$"'{CURRENT_MAIL_BODY_ALL}'," &
|
||||
$"'{CURRENT_MAIL_BODY_ANSWER1}'," &
|
||||
$"'{CURRENT_MAIL_BODY_Substr2}'," &
|
||||
@@ -774,7 +784,7 @@ Public Class clsWorkEmail
|
||||
End If
|
||||
End Function
|
||||
|
||||
Private Function InsertAttachmentHistoryEntry(pMessageId As String, pFileName As String) As Boolean
|
||||
Private Function InsertAttachmentHistoryEntry(pCurrentMail As MailContainer, pMessageId As String, pFileName As String) As Boolean
|
||||
If IsNothing(_DB_MSSQL) Then
|
||||
_Logger.Info("INSERT_HISTORY_FB: _DB_MSSQL is nothing ")
|
||||
Return False
|
||||
@@ -786,7 +796,7 @@ Public Class clsWorkEmail
|
||||
$"'{pMessageId}'," &
|
||||
$"'{CURRENT_MAIL_FROM}'," &
|
||||
$"'{CURRENT_MAIL_SUBJECT}'," &
|
||||
$"'{CURRENT_MAIL_MESSAGE.Date}'," &
|
||||
$"'{pCurrentMail.Mail.Date}'," &
|
||||
$"'{CURRENT_MAIL_BODY_ALL}'," &
|
||||
$"'{pFileName}')"
|
||||
_DB_MSSQL.ExecuteNonQuery(ins)
|
||||
|
||||
@@ -41,21 +41,25 @@ Public Class clsWorker
|
||||
CURRENT_DEBUG_LOCAL_EMAIL = pLocalEML
|
||||
End Sub
|
||||
|
||||
Private Sub DeleteTempFiles()
|
||||
For Each _file In TEMP_FILES
|
||||
Logger.Debug("Trying to delete temp file: [{0}]", _file)
|
||||
|
||||
If IO.File.Exists(_file) Then
|
||||
Try
|
||||
IO.File.Delete(_file)
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Logger.Warn("Could not delete the tempfile from TEMP_FILES: [{0}]", _file)
|
||||
End Try
|
||||
End If
|
||||
Next
|
||||
TEMP_FILES.Clear()
|
||||
End Sub
|
||||
|
||||
Public Sub Start_WorkingProfiles(Optional LocalEmail As Boolean = False)
|
||||
Try
|
||||
For Each _file In TEMP_FILES
|
||||
Logger.Debug("Trying to delete temp file: [{0}]", _file)
|
||||
|
||||
If IO.File.Exists(_file) Then
|
||||
Try
|
||||
IO.File.Delete(_file)
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Logger.Warn($"TempFileDelete - Could not delete the tempfile from TEMP_FILES: {ex.Message}")
|
||||
End Try
|
||||
End If
|
||||
Next
|
||||
TEMP_FILES.Clear()
|
||||
DeleteTempFiles()
|
||||
|
||||
If Database.DBInitialized = True Then
|
||||
Logger.Debug("now windream_init... ")
|
||||
@@ -98,10 +102,6 @@ Public Class clsWorker
|
||||
End If
|
||||
|
||||
CURRENT_EMAIL_GUID = 0
|
||||
MAIL_FROM = ""
|
||||
MAIL_SERVER = ""
|
||||
MAIL_USER = ""
|
||||
MAIL_USER_PW = ""
|
||||
|
||||
CURRENT_POLL_TYPE = oDR_Profile.Item("POLL_TYPE")
|
||||
Logger.Debug(String.Format("Working on profile: ({0}-{1}-{2}) ", oDR_Profile.Item("GUID"), oDR_Profile.Item("PROFILE_NAME"), CURRENT_POLL_TYPE))
|
||||
@@ -114,31 +114,30 @@ Public Class clsWorker
|
||||
Logger.Debug("Expression Filter email: " & expression)
|
||||
Logger.Debug("DT_TBDD_EMAIL.rowCount: " & DT_TBDD_EMAIL.Rows.Count)
|
||||
'Filter the rows using Select() method of DataTable
|
||||
Dim FilteredRows As DataRow() = EMAIL_PROF_TABLE.Select(expression)
|
||||
If FilteredRows.Length = 1 Then
|
||||
For Each row As DataRow In FilteredRows
|
||||
MAIL_FROM = row("EMAIL_FROM")
|
||||
MAIL_SERVER = row("EMAIL_SMTP")
|
||||
MAIL_USER = row("EMAIL_USER")
|
||||
MAIL_USER_PW = row("EMAIL_PW")
|
||||
MAIL_PORT = row("PORT_IN")
|
||||
MAIL_INBOX_NAME = "Inbox"
|
||||
MAIL_ARCHIVE_FOLDER = row("ARCHIVE_FOLDER")
|
||||
MAIL_AUTHTYPE = row("AUTH_TYPE")
|
||||
Logger.Debug(String.Format("{0}-{1}", MAIL_FROM, MAIL_SERVER))
|
||||
Dim FilteredRows As List(Of DataRow) = EMAIL_PROF_TABLE.Select(expression).ToList()
|
||||
If FilteredRows.Count = 1 Then
|
||||
Dim oRow = FilteredRows(0)
|
||||
Dim MAIL_FROM = oRow("EMAIL_FROM")
|
||||
Dim MAIL_SERVER = oRow("EMAIL_SMTP")
|
||||
Dim MAIL_USER = oRow("EMAIL_USER")
|
||||
Dim MAIL_USER_PW = oRow("EMAIL_PW")
|
||||
Dim MAIL_PORT = oRow("PORT_IN")
|
||||
Dim MAIL_INBOX_NAME = "Inbox"
|
||||
Dim MAIL_ARCHIVE_FOLDER = oRow("ARCHIVE_FOLDER")
|
||||
Dim MAIL_AUTHTYPE = oRow("AUTH_TYPE")
|
||||
Logger.Debug(String.Format("{0}-{1}", MAIL_FROM, MAIL_SERVER))
|
||||
|
||||
Dim PWPlain = Encryption.DecryptData(MAIL_USER_PW)
|
||||
If Not IsNothing(PWPlain) Then
|
||||
If PWPlain <> "" Then
|
||||
MAIL_USER_PW = PWPlain
|
||||
Else
|
||||
Logger.Warn("PWPlain is string.empty - Could not decrypt passwort")
|
||||
End If
|
||||
Dim PWPlain = Encryption.DecryptData(MAIL_USER_PW)
|
||||
If Not IsNothing(PWPlain) Then
|
||||
If PWPlain <> "" Then
|
||||
MAIL_USER_PW = PWPlain
|
||||
Else
|
||||
Logger.Warn("PWPlain is nothing - Could not decrypt passwort")
|
||||
Logger.Warn("PWPlain is string.empty - Could not decrypt passwort")
|
||||
End If
|
||||
Else
|
||||
Logger.Warn("PWPlain is nothing - Could not decrypt passwort")
|
||||
End If
|
||||
|
||||
Next
|
||||
CURRENT_WORKMAIL_UID_LIST.Clear()
|
||||
|
||||
If MAIL_SERVER <> "" Then
|
||||
@@ -148,7 +147,8 @@ Public Class clsWorker
|
||||
Else
|
||||
Select Case CURRENT_POLL_TYPE
|
||||
Case "IMAP"
|
||||
oPollResult = FetchMessages(MAIL_SERVER, MAIL_PORT, MAIL_USER, MAIL_USER_PW, MAIL_AUTHTYPE)
|
||||
' We are using 'Archive Folder' as an additional field to save the Tenant-ID for O365-OAuth2
|
||||
oPollResult = FetchMessages(MAIL_SERVER, MAIL_PORT, MAIL_USER, MAIL_USER_PW, MAIL_AUTHTYPE, MAIL_ARCHIVE_FOLDER)
|
||||
|
||||
Case Else
|
||||
Logger.Error("Poll Type [{0}] is not supported!", CURRENT_POLL_TYPE)
|
||||
@@ -161,7 +161,7 @@ Public Class clsWorker
|
||||
Logger.Info("Working with local Mail")
|
||||
Dim oEmail As IMail = New MailBuilder().CreateFromEmlFile(CURRENT_DEBUG_LOCAL_EMAIL)
|
||||
ClassWorkMail.WorkEmailMessage(oEmail, 123456789)
|
||||
CURRENT_MAIL_MESSAGE = Nothing
|
||||
'CURRENT_MAIL_MESSAGE = Nothing
|
||||
Else
|
||||
Try
|
||||
Logger.Info(String.Format("Pulled: [{0}] E-Mails", CURRENT_WORKMAIL_UID_LIST.Count()))
|
||||
@@ -199,7 +199,7 @@ Public Class clsWorker
|
||||
Logger.Info("### oEmail was nothing ###")
|
||||
End If
|
||||
|
||||
CURRENT_MAIL_MESSAGE = Nothing
|
||||
'CURRENT_MAIL_MESSAGE = Nothing
|
||||
Next
|
||||
If CURRENT_POLL_TYPE = "IMAP" And CURRENT_WORKMAIL_UID_LIST.Count > 0 Then
|
||||
If Not IsNothing(Fetcher.Client) Then
|
||||
@@ -226,24 +226,7 @@ Public Class clsWorker
|
||||
Logger.Warn("For the Email-Profile ID " & CURRENT_EMAIL_GUID & " no record could be found! Check wether Email-Profile is active!")
|
||||
End If
|
||||
Next
|
||||
Try
|
||||
'Delete all Tempfiles
|
||||
For Each _file In TEMP_FILES
|
||||
Logger.Debug("Trying to delete temp file: [{0}]", _file)
|
||||
|
||||
If System.IO.File.Exists(_file) Then
|
||||
Try
|
||||
System.IO.File.Delete(_file)
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Logger.Warn($"TempFileDelete - Could not delete the tempfile from TEMP_FILES: {ex.Message}")
|
||||
End Try
|
||||
End If
|
||||
Next
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Warn($"TempFileDelete(X) - Could not delete the tempfile from TEMP_FILES: {ex.Message}")
|
||||
End Try
|
||||
DeleteTempFiles()
|
||||
|
||||
Else
|
||||
Logger.Info("No active profiles")
|
||||
@@ -257,9 +240,19 @@ Public Class clsWorker
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Public Function FetchMessages(Server As String, Port As Integer, Username As String, Password As String, AuthType As String) As Boolean
|
||||
Public Function FetchMessages(pServer As String, pPort As Integer, pUsername As String, pPassword As String, pAuthType As String, pArchiveFolder As String) As Boolean
|
||||
Try
|
||||
Dim oSession = Fetcher.Connect(Server, Port, Username, Password, AuthType)
|
||||
Dim oSession As MailSession.SessionInfo
|
||||
|
||||
If pAuthType = MailSession.AUTH_OAUTH2 Then
|
||||
Dim oClientId As String = pServer
|
||||
Dim oClientSecret As String = pPassword
|
||||
Dim oTenantId As String = pArchiveFolder
|
||||
oSession = Fetcher.ConnectToO365(pUsername, oClientId, oTenantId, oClientSecret)
|
||||
Else
|
||||
|
||||
oSession = Fetcher.Connect(pServer, pPort, pUsername, pPassword, pAuthType)
|
||||
End If
|
||||
|
||||
|
||||
If oSession.Connected = False AndAlso oSession.Error IsNot Nothing Then
|
||||
|
||||
Reference in New Issue
Block a user