AutomatedOutlookSignature icon indicating copy to clipboard operation
AutomatedOutlookSignature copied to clipboard

special characters are not displayed correctly in out-file

Open kleinerbub opened this issue 1 year ago • 8 comments

The script doesn't genereate the correctly encoded specials characters like german umlauts. I already tried to set the encoding for out-file to utf8, but that does only work for values from active directory. If I output some static values directly within the script (because they are not all defined in active directory), they are not displayed as they should.

I could use ü and so on, but this only works for the html-signature, not for the text-version.

kleinerbub avatar Jun 08 '23 09:06 kleinerbub

Hello.

Do you mind giving me some examples so I can take a look into this for you and see if we can get a resolution.

Thank you.

captainqwerty avatar Jun 08 '23 09:06 captainqwerty

Hi @captainqwerty , thanks for your quick answer.

I enclosed a sample script, generated files and screenshots, which can be used for testing. To test all is working well you need to have a AD-User with special characters, e.g. äöü or ß in the used attributes.

Kind regards.

example_Signature-Files.zip

kleinerbub avatar Jun 08 '23 12:06 kleinerbub

Wonderful, thank you for your effort to help this project.

I have planned in looking at this on the weekend :) Hopefully find a resolution for yourself and further improve this little project.

captainqwerty avatar Jun 08 '23 12:06 captainqwerty

Have you checked which encoding you used for the script itself? Try saving the script encoded as UTF-8 with BOM, and then run it again.

Zennate avatar Aug 15 '23 13:08 Zennate

I can confirm changing ASCII econding to UTF8 when generating output files works correctly for accented chars "ěščřžýáíé" used in Czech lang.

IMO UTF8 is relatively safe option today and should work on all major scenarios.

nocturneop15 avatar Aug 30 '23 14:08 nocturneop15

I am very sorry for the big delay in looking at this - I have been swamped recently. I will do some testing with @nocturneop15's suggestion and if that works I shall make a new release detailing it.

captainqwerty avatar Aug 30 '23 15:08 captainqwerty

I can suggest using optional "sanitize" function that can also address german "umlauts" and others. I use this one: ` function get-sanitizedUTF8Input{ Param( [String]$inputString ) $replaceTable = @{"ß"="ss";"a"="a";"á"="a";"â"="a";"a"="a";"ä"="a";"a"="a";"a"="ae";"ç"="c";"e"="e";"é"="e";"e"="e";"ë"="e";"i"="i";"í"="i";"î"="i";"i"="i";"?"="d";"n"="n";"o"="o";"ó"="o";"ô"="o";"o"="o";"ö"="o";"o"="o";"u"="u";"ú"="u";"u"="u";"ü"="u";"ý"="y";"?"="p";"y"="y";"ř"="r"}

foreach($key in $replaceTable.Keys){
    $inputString = $inputString -Replace($key,$replaceTable.$key)
}
#$inputString = $inputString -replace '[^a-zA-Z0-9]', '' # seats out spaces and non-alphanumeric
return $inputString

} `

nocturneop15 avatar Aug 30 '23 16:08 nocturneop15

Another approach would be to use System.IO.File.WriteAllText instead of Out-File System.IO.File.WriteAllText covers most of the special characters including german "umlauts" and others Original: $style + $signature | Out-File -FilePath "$file.htm" -Encoding ascii

Edited: $htmlcontent = $style + $signature $filepath = "$file.htm" [System.IO.File]::WriteAllText($filepath, $htmlcontent)

NikPPPPPP avatar Mar 14 '24 13:03 NikPPPPPP

Changing the encoding to unicode worked for me. Windows saves .txt files in Outlook with default UTF-16LE encoding.

P4lette avatar May 10 '24 08:05 P4lette

In version 5 I have added -encoding as a parameter for selecting an encoding. I hope this resolve the issue.

@NikPPPPPP - I will also take a look at using System.io.file as well in the next version. Once I have confirmation this is fixed I shall close the issue.

captainqwerty avatar May 20 '24 17:05 captainqwerty

With the new -Encoding Parameter option this should now be resolved. I have done some testing with Unicode and UTF-8 and it appears to be fine now.

captainqwerty avatar May 22 '24 19:05 captainqwerty