8
0
Skriptentwickung/current/DD-Core/Modules/Load-EMLFile-withLogging.psm1

105 lines
5.0 KiB
PowerShell
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Function Load-EMLFile-withLogging {
<#
.SYNOPSIS
Load EML File from FileSystem
.DESCRIPTION
This Function can load an EML E-Mail File from the FileSystem.
If load goes on successful, Function will Return a Object for the loaded Mail File.
Otherwise Function will Return $NULL - if something went wrong...
Function is not able to load MSG Files!
.REQUIREMENT General
PowerShell V3
.REQUIREMENT Assembly
<NONE>
.REQUIREMENT Variables
FileTest, ADODBStream, CDOMessage
.REQUIREMENT Variables preSet
<NONE>
.REQUIREMENT Functions
Write-LogFile
.VERSION
Number: 1.0.0.0 / Date: 08.12.2016
.PARAMETER EMLFileName
Give the full Path and Filename of the EML Mail, you want to load.
.EXAMPLE
Load-EmlFile-withLogging -EMLFileName "<Path>\E-Mail4711.eml"
#>
Param (
[Parameter(Mandatory=$True,HelpMessage='Give the full Path and Filename of the EML Mail, you want to load.')]
[ValidateNotNullOrEmpty()]
[String]$EMLFileName=$NULL
) #end param
#Clear Error Variable
$error.clear()
#Checking if "Write-LogFile" Module was loaded
IF (Get-Module -Name "Write-LogFile") {
Write-Host "DEBUG Info: Write-LogFile - Module exists."
$FileTest = Test-Path -Path "$EMLFileName" -PathType Leaf
Write-LogFile -LogLine " "
Write-LogFile -LogLine "Module Load-EMLFile-withLogging is testing File existence:"
Write-LogFile -LogLine "$EMLFileName"
IF ($FileTest -eq $True) {
Write-LogFile -LogLine "File exists. Trying to load it..."
Try {
$ADODBStream = New-Object -ComObject ADODB.Stream
$ADODBStream.Open()
$ADODBStream.LoadFromFile($EMLFileName)
$CDOMessage = New-Object -ComObject CDO.Message
$CDOMessage.DataSource.OpenObject($ADODBStream, "_Stream")
Write-LogFile -LogLine "EML Object Created!"
Return $CDOMessage
} #end try
Catch {
Write-LogFile -LogLine "Cannot read File."
Return $NULL
} #end catch
} #end if
ELSE {
Write-LogFile -LogLine "File doesnt exist, or access denied!"
Return $NULL
} #end else
} #end if
ELSE {
Write-Host ""
Write-Host "DEBUG Info: Write-LogFile - Module does not exist!"
Write-Host "DEBUG Info: Please load the Module and try again, running this Function/Module!"
Write-Host "DEBUG Info: Exiting, because of this Issue."
EXIT
} #end else
} #end function