Update attachment filename to fix length and character errors in windream

This commit is contained in:
Jonathan Jenne
2023-07-28 10:21:13 +02:00
parent aa5a268e14
commit 3eebd74549
7 changed files with 140 additions and 84 deletions

View File

@@ -21,52 +21,69 @@ Public Class ClassConfig
End Sub
Private Function GetConfigTable() As DataTable
Dim oSQL As String = "SELECT * FROM TBEMLP_CONFIG"
Dim oTable As DataTable = Database.GetDatatable(oSQL)
Return oTable
Try
Logger.Debug("Getting Config Table..")
Dim oSQL As String = "SELECT * FROM TBEMLP_CONFIG"
Dim oTable As DataTable = Database.GetDatatable(oSQL)
Return oTable
Catch ex As Exception
Logger.Error(ex)
Return Nothing
End Try
End Function
Private Function GetBaseConfigTable() As DataTable
Dim oSQL As String = "SELECT * FROM TBDD_BASECONFIG"
Dim oTable As DataTable = Database.GetDatatable(oSQL)
Return oTable
Try
Logger.Debug("Getting Base Config Table..")
Dim oSQL As String = "SELECT * FROM TBDD_BASECONFIG"
Dim oTable As DataTable = Database.GetDatatable(oSQL)
Return oTable
Catch ex As Exception
Logger.Error(ex)
Return Nothing
End Try
End Function
Public Function GetConfig() As Config
Dim oConfigTable = GetConfigTable()
Dim oBaseTable = GetBaseConfigTable()
Try
Dim oConfigTable = GetConfigTable()
Dim oBaseTable = GetBaseConfigTable()
If oBaseTable Is Nothing Then
Logger.Warn("Config from TBDD_BASECONFIG could not be loaded!")
If oBaseTable Is Nothing Then
Logger.Warn("Config from TBDD_BASECONFIG could not be loaded!")
Return Nothing
End If
If oBaseTable.Rows.Count = 0 Then
Logger.Warn("Config from TBDD_BASECONFIG could not be loaded!")
Return Nothing
End If
If oConfigTable Is Nothing Then
Logger.Warn("Config from TBEMLP_CONFIG could not be loaded!")
Return Nothing
End If
If oConfigTable.Rows.Count = 0 Then
Logger.Warn("Config from TBEMLP_CONFIG is empty!")
Return Nothing
End If
Dim oRow As DataRow = oConfigTable.Rows.Item(0)
Dim oConfig As New Config With {
.PathAttachments = oRow.ItemEx("PATH_EMAIL_TEMP", ""),
.PathError = oRow.ItemEx("PATH_EMAIL_ERRORS", ""),
.BodyFont = oRow.ItemEx("FONT_BODY", "Arial"),
.TimerInterval = oRow.ItemEx("CHECK_INTERVALL_MINUTES", 5),
.WindreamConnectionString = oRow.ItemEx("WM_CON_STRING", ""),
.WindreamDrive = oRow.ItemEx("WM_DRIVE", "W")
}
Return oConfig
Catch ex As Exception
Logger.Error(ex)
Return Nothing
End If
If oBaseTable.Rows.Count = 0 Then
Logger.Warn("Config from TBDD_BASECONFIG could not be loaded!")
Return Nothing
End If
If oConfigTable Is Nothing Then
Logger.Warn("Config from TBEMLP_CONFIG could not be loaded!")
Return Nothing
End If
If oConfigTable.Rows.Count = 0 Then
Logger.Warn("Config from TBEMLP_CONFIG is empty!")
Return Nothing
End If
Dim oRow As DataRow = oConfigTable.Rows.Item(0)
Dim oConfig As New Config With {
.PathAttachments = oRow.ItemEx("PATH_EMAIL_TEMP", ""),
.PathError = oRow.ItemEx("PATH_EMAIL_ERRORS", ""),
.BodyFont = oRow.ItemEx("FONT_BODY", "Arial"),
.TimerInterval = oRow.ItemEx("CHECK_INTERVALL_MINUTES", 5),
.WindreamConnectionString = oRow.ItemEx("WM_CON_STRING", ""),
.WindreamDrive = oRow.ItemEx("WM_DRIVE", "W")
}
Return oConfig
End Try
End Function
End Class

View File

@@ -15,7 +15,7 @@ Public Class clsWorkEmail
Private Const SUBJECT_MAX_LENGTH = 25
Private Const MESSAGE_ID_MAX_LENGTH = 100
Private CurrentMail As IMail = Nothing
Private CurrentMail As MailContainer = Nothing
Private CURRENT_TEMP_MAIL_PATH As String
Private CURRENT_MAIL_BODY_ALL As String
@@ -98,8 +98,10 @@ Public Class clsWorkEmail
' The MessageID is now replaced by a SHA256 Hash of the MessageID
' The reason is that MessageIDs can be very long,
' which results in the final filepath exceeding the Windream/Windows maximum of 255 chars.
'CURRENT_MAIL_MESSAGE_ID = RemoveIllegalFileNameChars(pMailMessage.MessageID)
CURRENT_MAIL_MESSAGE_ID = StringEx.GetHash(pMailMessage.MessageID)
' 28.07.23
' The SHA256 Hash is now truncated to half the size
' which should be a good balance between uniqueness and length
CURRENT_MAIL_MESSAGE_ID = StringEx.GetShortHash(pMailMessage.MessageID)
'If String.IsNullOrEmpty(CURRENT_MAIL_MESSAGE_ID) Then
' CURRENT_MAIL_MESSAGE_ID = Guid.NewGuid.ToString()
@@ -414,7 +416,7 @@ Public Class clsWorkEmail
End Try
End Function
Private Function SAVE2TEMP(pCurrentMail As IMail) As Boolean
Private Function SAVE2TEMP(pCurrentMail As MailContainer) As Boolean
Dim oTempFilename As String
Try
Dim oTempPath As String = Path.Combine(Path.GetTempPath, "DD_EmailProfiler")
@@ -685,8 +687,12 @@ Public Class clsWorkEmail
'05.06.23
'The filename of attachments will be HASH~DOMAIN~SUBJECT(0,25) from now on
'oAttachmentFileString = Path.Combine(PATH_TEMP, $"{CURRENT_MAIL_MESSAGE_ID}~{oFilename}")
'28.07.23
'The original filename part will now be slugified to prevent errors
'when opening the file in windream
Dim oAttachmentFileName = $"{CURRENT_MAIL_MESSAGE_ID}~{pCurrentMail.SenderDomain}~{oAttachment.SafeFileName}"
Dim oFilename = StringEx.ConvertTextToSlug(oAttachment.SafeFileName)
Dim oAttachmentFileName = $"{CURRENT_MAIL_MESSAGE_ID}~{pCurrentMail.SenderDomain}~{oFilename}"
_Logger.Debug("Final Filename for Attachment: [{0}]", oAttachmentFileName)
oAttachmentFilePath = Path.Combine(pExtractPath, oAttachmentFileName)