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

@@ -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)