eml-to-html.ps1
param (
[Parameter(Mandatory = $true, Position = 0)]
[string]$InputFile
)
if (-not (Test-Path $InputFile)) {
Write-Error "Bestand niet gevonden: $InputFile"
exit 1
}
$raw = Get-Content $InputFile -Raw
if ($raw -notmatch "Content-Type:\s*text/html") {
Write-Error "Geen HTML-part gevonden in dit EML-bestand."
exit 1
}
# Pak alles NA Content-Type: text/html
$htmlPart = ($raw -split "Content-Type:\s*text/html", 2)[1]
# Verwijder headers van de MIME-part
$htmlBody = ($htmlPart -split "\r?\n\r?\n", 2)[1]
# --- Quoted-printable decoding ---
# 1) line continuations (= aan einde regel)
$htmlBody = $htmlBody -replace "=\r?\n", ""
# 2) =XX hex decoding
$bytes = [System.Text.Encoding]::ASCII.GetBytes($htmlBody)
$decodedBytes = New-Object System.Collections.Generic.List[byte]
for ($i = 0; $i -lt $bytes.Length; $i++) {
if ($bytes[$i] -eq 61 -and $i + 2 -lt $bytes.Length) { # '='
$hex = [char]$bytes[$i + 1] + [char]$bytes[$i + 2]
if ($hex -match '^[0-9A-Fa-f]{2}$') {
$decodedBytes.Add([Convert]::ToByte($hex, 16))
$i += 2
continue
}
}
$decodedBytes.Add($bytes[$i])
}
# Charset (default utf-8)
$encoding = [System.Text.Encoding]::UTF8
$decodedHtml = $encoding.GetString($decodedBytes.ToArray())
$outputFile = [System.IO.Path]::ChangeExtension($InputFile, ".html")
$decodedHtml | Out-File $outputFile -Encoding UTF8
Write-Host "HTML geëxtraheerd naar:"
Write-Host " $outputFile"
1011600cookie-checkConvert Email (EML) to HTML