I generate a CSV file as one string with semicolons as field separator and chr(13) chr(10) as line separator. I append this to an email with the cfmailparam tag using disposition="attachment" and the content attribute contains the said string. The attachment of the mail seems to be encoded in UTF8 which Excel does not like, so my Umlauts are destroyed. Is there a possibility to provide the cfmailparam tag with a charset attribute to ensure the file is attached/sent Windows1252 encoded?
Is it better to store the string with the cffile tag and the Windows1252 encoding and appending it to the mail with the cfmailparam file attribute?
<cfset arrTitel = [
"Titel"
, "Geschäftsbereich"
]>
<cfsavecontent variable="csv"><cfoutput><cfloop from="1" to="#ArrayLen( arrTitel )#" index="spaltentitel"><cfif spaltentitel gt 1>;</cfif>"#arrTitel[spaltentitel]#</cfloop>#chr(13)##chr(10)#</cfoutput></cfsavecontent>
<cfmail from="#mail#" to="#mailempf#" subject="subj" type="text/html">
<cfmailparam
content="#csv#"
disposition="attachment"
file="Report.csv"
>
</cfmail>
This is what it basically looks like.
Please don't advise to change the encoding of the cfm file. Other values containing Umlauts are not hard coded but come from a database.
Related
In Groovy, using the following snippet i am parsing an xml file which contains Unicode text. But the full text is not copied to JCR nodes, only part of the characters are recognized and copied to the target JCR nodes / another file system and the remaining characters are displaying in an unrecognized format.
FileReader fr = new FileReader("$currentFileLocation")
def inputSource = new InputSource(fr)
inputSource.setEncoding('UTF-8')
def obj = new XmlSlurper().parse(inputSource)
def HtmlContent = obj."Widget-HTML"."HtmlContent".getBody().text()
Expected should be written to the target system as :
サービス事例のサポート ツールセットである
But it is copied as in this format :
サービス事例�?�サ�?ート ツールセット�?��?�る
Assuming below arbitrary xml file which includes the characters mentioned by the author of this question.
xml file, say testutf.xml. Note that the file is saved with utf-8 character encoding.
<?xml version="1.0" encoding="UTF-8"?>
<records>
<record>
<name>サービス事例のサポート ツールセットである</name>
</record>
</records>
Here is script which reads that reads the xml file in the same encoding. Comments added appropriately in-line.
import groovy.xml.*
//Chang the xml file path as per your environment
def fileName = '/absolute/path/of/the/testutf.xml'
//Read file with utf-8 encoding
def contents = new File(fileName).getText('utf-8')
//parsed object
def parsedContents = new XmlSlurper().parseText(contents)
//Read the data
def nameData = parsedContents.record.name
println "Record name : $nameData"
Output
Record name : サービス事例のサポート ツールセットである
And I believe that you should be able to apply the same for your own xml instead of the above sample xml.
You could try the encoding as Shift_JIS they handle the specifics of the Japanese characters.
Refer to a discussion here on Japanese Encoding with UTF-8, UTF-16 and Shift_JS
I'm using use Mail::IMAPClient to retrieve mail headers from an imap server. It works great. But when the header contains any character other that [a-z|A-Z|0-9] I'm served with strings that look like this :
Subject : Un message en =?UTF-8?B?ZnJhbsOnYWlzIMOgIGxhIGNvbg==?= (original string : "Un message en français à la con")
Body :
=C3=A9aeio=C3=B9=C3=A8=C3=A8 (original string : éaeioùèè)
What is this strange format ? Is that the famous "perl string
internal" format ?
what is the safest way of handling human idioms
coming from IMAP servers ?
The body encoding is Quoted-Printable; the header (subject) encoding is MIME "encoded-word" encoding ("B" type for base64). The best way to deal with both of them is to pass the email into a module that's capable of dealing with MIME, such as Email::MIME or the older and buggier MIME::Lite.
For example:
# $message was retrieved from IMAP
my $mime = Email::MIME->new($message);
my $subject = $mime->header('Subject'); # automatically decoded
my $body = $mime->body_str; # also automatically decoded
However if you need to deal with them outside of the context of an entire message, there are also modules like Encode::MIME::Header and MIME::QuotedPrint.
It is quoted-printable coded. It is a standard encoding used in email. It has nothing to do with Perl's internal string format.
Set out to write a simple procmail recipie that would forward the mail to me if it found the text "Unprovisioned" in the subject.
:0:
* ^Subject:.*Unprovisioned.*
! me#test.com
Unfortunately the subject field in the mail message coming from the mail server was in MIME encoded-word syntax.
The form is: "=?charset?encoding?encoded text?=".
Subject: =?UTF-8?B?QURWSVNPUlk6IEJNRFMgMTg0NSwgTkVXIFlPUksgLSBVbnByb3Zpc2lvbmVkIENvbm4gQQ==?=
=?UTF-8?B?bGVydA==?=
The above subject is utf-8 charset, base64 encoding with text folded to two lines. So was wondering if there are any mechanisms/scripts/utilities to parse this and convert to string format so that I could apply my procmail filter. Ofcourse I can write a perl script to parse this an perform the required validations, but looking to avoid it if possible.
Encode::MIME::Header, which ships with Perl, accessed directly through Encode:
use Encode qw(encode decode);
my $header_text = decode('MIME-Header', $header);
The HTTP Accept-Encoding header contains atoms of acceptable character sets, and the charset= field in a MIME Content-Type header contains an atom of the character set for the following data.
My question is the following: must these atoms match the preferred MIME encoding name or charset name, or can they match any alias of a charset?
Alias and preferred MIME encoding as used by http://www.iana.org/assignments/character-sets.
I'm planning on using iconv to convert to platform-native wide UTF, and I don't want to make the entry in the form of an array of fields in the form of (iconv_alias, { list-of-aliases }) per charset. Rather, a simple (alias, iconv_alias) 2-tuple.
i'm using vbscript to extract data from db2 and write to file.
Writing to file like:
Set objTextFile = objFSO.CreateTextFile(sFilePath, True, True)
that creates file in unicode. But that is xml file and it uses UTF-8.
So when i open xml file with MS XML Notepad it throws error:
'hexadecimal value 0x00 is an invalid character'
So i opening this text file with TextPad and saving in UTF-8. After that XML opens without any problems.
Can i convert file from Unicode to UTF-8 by vbScript?
Using the Stream object to save your file with the utf-8 charset might work better for you; here's a simple .vbs function you could test out on your data:
Option Explicit
Sub Save2File (sText, sFile)
Dim oStream
Set oStream = CreateObject("ADODB.Stream")
With oStream
.Open
.CharSet = "utf-8"
.WriteText sText
.SaveToFile sFile, 2
End With
Set oStream = Nothing
End Sub
' Example usage: '
Save2File "The data I want in utf-8", "c:\test.txt"
Well, in some cases, we need to do this in WSH in a machine without ADO. In this case, keep in your mind that WSH don't create file in UTF-8 format (CreateTextFile method not work with UTF-8), but is completely possible to manipulate an UTF-8 file (appending data). Thinking this, I found an non-orthodoxal solution. Follow this steps:
1) Open a blank NOTEPAD, click FILE > SAVE AS, type a name for the file (like UTF8FileFormat.txt, per example), change the field "Encoding" to UTF-8 and click in [Save]. Leave NOTEPAD.
2) In your WSH you will use the UTF8FileFormat.txt to create your UTF8 text file. To do this, after your FileSystemObject declaration, use the CopyFile method to copy the UTF8FileFormat.txt to a new file (remember to use the Overwrite option) and, then, use the OpenTextFile method to open your new file with ForAppending and NoCreate options. After this, you will can write in this file normally (as in CreateTextFile method). Your new file will be in UTF-8 format. Below follow an example:
'### START
' ### REMEMBER: You need to create the UTF8FileFormat.txt file in a blank
' ### NOTEPAD with UTF-8 Encoding first.
Unicode=-1 : ForAppending=8 : NoCreate=False : Overwrite=True
set fs = CreateObject("Scripting.FileSystemObject")
fs.CopyFile "UTF8FileFormat.txt","MyNewUTF8File.txt",Overwrite
set UTF8 = fs.OpenTextFile("MyNewUTF8File.txt", ForAppending, NoCreate)
UTF8.writeline "My data can be writed in UTF-8 format now"
UTF8.close
set UTF8 = nothing
'### END