diff --git a/App/EmailProfiler.Common/clsWorkEmail.vb b/App/EmailProfiler.Common/clsWorkEmail.vb index e934921..202c473 100644 --- a/App/EmailProfiler.Common/clsWorkEmail.vb +++ b/App/EmailProfiler.Common/clsWorkEmail.vb @@ -13,7 +13,6 @@ Imports MailBox = Limilabs.Mail.Headers.MailBox Imports DigitalData.Modules.Patterns Imports System.Data.SqlClient Imports GdPicture14 -Imports System.Net.WebRequestMethods Imports Limilabs.Client.IMAP Public Class clsWorkEmail @@ -132,7 +131,7 @@ Public Class clsWorkEmail Return True End If - Dim oTempMailExists As Boolean = SAVE2TEMP(CurrentMail) + Dim oTempMailExists As Boolean = Save2TempDirectory(CurrentMail) 'Checking wether Mail can be opened Dim oTempMailAccessible As Boolean = False @@ -143,7 +142,7 @@ Public Class clsWorkEmail End If Try - Dim oFS As FileStream = System.IO.File.OpenRead(CurrentTempMailPath) + Dim oFS As FileStream = File.OpenRead(CurrentTempMailPath) oTempMailAccessible = True oFS.Close() Catch ex As Exception @@ -610,7 +609,7 @@ Public Class clsWorkEmail End Try End Function - Private Function SAVE2TEMP(pCurrentMail As MailContainer) As Boolean + Private Function Save2TempDirectory(pCurrentMail As MailContainer) As Boolean Dim oTempFilename As String = "" Try @@ -624,7 +623,7 @@ Public Class clsWorkEmail Dim oFileName As String For Each oFileName In oFileEntries Try - System.IO.File.Delete(oFileName) + File.Delete(oFileName) Catch ex As Exception End Try Next oFileName @@ -646,7 +645,7 @@ Public Class clsWorkEmail Dim oCounter As Integer = 1 Dim oCancel As Boolean - Do While System.IO.File.Exists(CurrentTempMailPath) = False + Do While File.Exists(CurrentTempMailPath) = False _Logger.Debug("Trying to read saved mail.. ({0}/{1})", oCounter, 10) Thread.Sleep(1000) oCounter += 1 @@ -659,7 +658,7 @@ Public Class clsWorkEmail If oCancel = True Then oResult = False Else - If System.IO.File.Exists(CurrentTempMailPath) Then + If File.Exists(CurrentTempMailPath) Then oResult = True End If End If @@ -684,7 +683,7 @@ Public Class clsWorkEmail If Directory.Exists(pDestination) Then Dim oTempFilename = Path.Combine(pDestination, $"{pCurrentMail.MessageId}.eml") - If System.IO.File.Exists(oTempFilename) = False Then + If File.Exists(oTempFilename) = False Then pCurrentMail.Mail.Save(oTempFilename) @@ -697,7 +696,7 @@ Public Class clsWorkEmail Else _Logger.Warn("FileLenth of file [{0}] is 0! File will be deleted.", oTempFilename) Try - System.IO.File.Delete(oTempFilename) + File.Delete(oTempFilename) Catch ex As Exception _Logger.Error(ex) End Try @@ -832,7 +831,7 @@ Public Class clsWorkEmail Try If CurrentTempMailPath <> Nothing Then - If System.IO.File.Exists(CurrentTempMailPath) Then + If File.Exists(CurrentTempMailPath) Then Dim oATTFilename = "" For Each oAttachment As MimeData In pCurrentMail.Mail.Attachments oATTFilename = oAttachment.SafeFileName.ToString.ToLower @@ -868,12 +867,17 @@ Public Class clsWorkEmail _Logger.Debug("Final Filename for Attachment: [{0}]", oAttachmentFileName) - oAttachmentFilePath = Path.Combine(pExtractPath, "Temp", oAttachmentFileName) + Dim oExtractTempPath = Path.Combine(pExtractPath, "Temp") + If Directory.Exists(oExtractTempPath) = False Then + Directory.CreateDirectory(oExtractTempPath) + End If + + oAttachmentFilePath = Path.Combine(oExtractTempPath, oAttachmentFileName) _Logger.Debug("Final Path for Attachment: [{0}]", oAttachmentFilePath) - If System.IO.File.Exists(oAttachmentFilePath) Then + If File.Exists(oAttachmentFilePath) Then _Logger.Warn("File [{0}] already exists!", oAttachmentFilePath) - System.IO.File.Delete(oAttachmentFilePath) + File.Delete(oAttachmentFilePath) End If _Logger.Debug(String.Format("Trying to save attachment [{0}]", oAttachmentFilePath)) @@ -892,7 +896,7 @@ Public Class clsWorkEmail AddTrackingStatusMSSQL(CurrentMail.MessageId, oResult, "PDF CONSISTENCY NOT OK", "Info GUI", "EML_PROF_EXTR_ATT2") AddToEmailQueueMSSQL(CurrentMail.MessageId, oResult, "PDF CONSISTENCY NOT OK", _EmailAccountID, _InfoTemplateId, ErrorCode.PDFStructureCorrupt, oATTFilename, "") - System.IO.File.Delete(oAttachmentFilePath) + File.Delete(oAttachmentFilePath) Continue For Else Dim embeddedFileCount As Integer = oGdPicturePDF.GetEmbeddedFileCount() @@ -950,7 +954,7 @@ Public Class clsWorkEmail AddToEmailQueueMSSQL(CurrentMail.MessageId, oResult, "CONSISTENCY ATTACHED FILE NOT OK", _EmailAccountID, _InfoTemplateId, ErrorCode.PDFStructureCorrupt, oAttachment.SafeFileName, "") Try - System.IO.File.Delete(oAttachmentFilePath) + File.Delete(oAttachmentFilePath) Catch ex As Exception _Logger.Error(ex) End Try @@ -994,18 +998,18 @@ Public Class clsWorkEmail End Function Private Sub WorkTempFiles(pACT As String) For Each _file In TEMP_WORK_FILES - _Logger.Debug("Working on temp work file: [{0}]", _file) + _Logger.Debug("Working ({0}) on temp work file: [{1}]", pACT, _file) - If IO.File.Exists(_file) Then + If File.Exists(_file) Then If pACT = "Delete" Then Try - IO.File.Delete(_file) + File.Delete(_file) Catch ex As Exception _Logger.Error(ex) _Logger.Warn("Could not delete the tempworkfile : [{0}]", _file) End Try ElseIf pACT = "move" Then - IO.File.Move(_file, _file.Replace("\Temp", "")) + File.Move(_file, _file.Replace("\Temp", "")) End If End If @@ -1017,7 +1021,7 @@ Public Class clsWorkEmail If MESSAGE_ERROR = False Then Return InsertHistoryEntryWithStatus(pCurrentMail, String.Empty, String.Empty) Else - _Logger.Info("! No INSERT_HISTORY as MessageError = True") + _Logger.Info("No INSERT_HISTORY as MessageError = True") Return False End If End Function