Thread View: borland.public.cppbuilder.internet.web
9 messages
9 total messages
Started by Hans Galema
Mon, 30 Jan 2006 14:36
utf-8 in filename of Content-Disposition: attachment;
Author: Hans Galema
Date: Mon, 30 Jan 2006 14:36
Date: Mon, 30 Jan 2006 14:36
31 lines
1914 bytes
1914 bytes
In a mailfolderfile I see the following attachment: <from mail> Content-Type: image/pjpeg; name="=?UTF-8?B?c2FtZW4gbWV0IEFuZHLDqSBraWprZW4gbmFhciBQYXNjYWwuanBn?=" content-transfer-encoding: base64 Content-Disposition: attachment; filename="=?UTF-8?B?c2FtZW4gbWV0IEFuZHLDqSBraWprZW4gbmFhciBQYXNjYWwuanBn?=" <\from mail> This has to do with an utf-8 encoded filename. But also it looks as yet more encoded. The filename decodes to: samen met Andr� kijken naar Pascal.jpg Is c2FtZW4gbWV0IEFuZHLDqSBraWprZW4gbmFhciBQYXNjYWwuanBn the piece that represents this? I googled a bit and read: <quote> > Is there any method or API to convert a file from UTF-8 to Ascii or Ansi ? Load the contents of the file, translate it to Unicode with MultiByteToWideChar(CP_UTF8, ...), and convert it to your required code page with WideCharToMultiByte. </quote> In my bcb5 I cannot find these functions. How to tackle this ? Hans.
Re: utf-8 in filename of Content-Disposition: attachment;
Author: Steve Aletto
Date: Mon, 30 Jan 2006 14:46
Date: Mon, 30 Jan 2006 14:46
12 lines
1384 bytes
1384 bytes
> Load the contents of the file, translate it to Unicode with > MultiByteToWideChar(CP_UTF8, ...), and convert it to your > required > code page with WideCharToMultiByte. > </quote> > > In my bcb5 I cannot find these functions. Strange. They are part of the Win32 API (library Kernel32.lib). Are you sure you can't use them? Steve.
Re: utf-8 in filename of Content-Disposition: attachment;
Author: Hans Galema
Date: Mon, 30 Jan 2006 15:08
Date: Mon, 30 Jan 2006 15:08
13 lines
1457 bytes
1457 bytes
Steve Aletto wrote: > Strange. They are part of the Win32 API (library Kernel32.lib). > Are you sure you can't use them? Mmm.. F1 did not find them and searching BCB's include directory gave nothing. But indeed they are in win32.hlp. One has to #include <winnls> But then my filename is more than utf-8 encoded I think. What has been done more ? I don't know where to start now. Hans.
Re: utf-8 in filename of Content-Disposition: attachment;
Author: Steve Aletto
Date: Mon, 30 Jan 2006 15:33
Date: Mon, 30 Jan 2006 15:33
11 lines
1502 bytes
1502 bytes
> But then my filename is more than utf-8 encoded I think. > What has been done more ? I don't know where to start now. It's base64. Go to http://makcoder.sourceforge.net/demo/base64.php, past c2FtZW4gbWV0IEFuZHLDqSBraWprZW4gbmFhciBQYXNjYWwuanBn and decode. Probably your next question is how to decode it by code. If I'm not mistaken one way could be Indy IdDecoderMIME. Steve.
Re: utf-8 in filename of Content-Disposition: attachment;
Author: Hans Galema
Date: Mon, 30 Jan 2006 15:59
Date: Mon, 30 Jan 2006 15:59
24 lines
1673 bytes
1673 bytes
Steve Aletto wrote: > It's base64. Go to > http://makcoder.sourceforge.net/demo/base64.php, past > c2FtZW4gbWV0IEFuZHLDqSBraWprZW4gbmFhciBQYXNjYWwuanBn and decode. A ha. Indeed it gives: samen met André kijken naar Pascal.jpg It should be: samen met Andr� kijken naar Pascal.jpg Nearly ok. Now I only have to find a way to make an � of that é. That looks like a multibyte ? > Probably your next question is how to decode it by code. No. No problem. My base64 decoder gives also: samen met André kijken naar Pascal.jpg Thanks. Hans.
Re: utf-8 in filename of Content-Disposition: attachment;
Author: Steve Aletto
Date: Mon, 30 Jan 2006 16:51
Date: Mon, 30 Jan 2006 16:51
27 lines
2126 bytes
2126 bytes
> A ha. Indeed it gives:
> samen met André kijken naar Pascal.jpg
>
> It should be:
> samen met Andr� kijken naar Pascal.jpg
Because you need to decode UTF-8 after the base64.
Put Edit1, Edit2 and IdDecoderMIME1 on a form. Past the text to
be decoded to Edit1. Then:
Edit2->Text = IdDecoderMIME1->DecodeToString(Edit1->Text);
int needed = MultiByteToWideChar(CP_UTF8, 0,
Edit2->Text.c_str(), -1, NULL, 0);
if (needed)
{
WCHAR *wc = new WCHAR[needed];
MultiByteToWideChar(CP_UTF8, 0, Edit2->Text.c_str(), -1,
wc, needed);
Edit2->Text = String(wc);
delete[] wc;
}
Please notice I wrote this code only for test. It must be
checked _very_ deeply.
Steve.
Re: utf-8 in filename of Content-Disposition: attachment;
Author: Remy Lebeau (TeamB)
Date: Mon, 30 Jan 2006 18:07
Date: Mon, 30 Jan 2006 18:07
29 lines
2032 bytes
2032 bytes
"Hans Galema" <notused@notused.nl> wrote in message
news:43de245b$1@newsgroups.borland.com...
> The filename decodes to: samen met Andr� kijken naar Pascal.jpg
>
> Is c2FtZW4gbWV0IEFuZHLDqSBraWprZW4gbmFhciBQYXNjYWwuanBn the piece that
represents this?
It is part of it. The fields used to describe the encoding are separated by
'?', where the encoding begins with '=?' and ends with '?='. So, the
encoding breaks down into three fields as follows:
UTF-8
B
c2FtZW4gbWV0IEFuZHLDqSBraWprZW4gbmFhciBQYXNjYWwuanBn
The 'UTF-8' is the encoding used for the original data. The 'B' is the
transmission encoding for the encoded data. In this case, 'B' means that
base64 is used. So, to get the original filename, you have to first decode
the contents of the third field with base64, and then decode the resulting
data with UTF-8 to get the original value.
> In my bcb5 I cannot find these functions.
They are in the Win32 API.
Gambit
Re: utf-8 in filename of Content-Disposition: attachment;
Author: Hans Galema
Date: Mon, 30 Jan 2006 20:38
Date: Mon, 30 Jan 2006 20:38
25 lines
1860 bytes
1860 bytes
Steve Aletto wrote:
> Because you need to decode UTF-8 after the base64.
> int needed = MultiByteToWideChar(CP_UTF8, 0,
> Edit2->Text.c_str(), -1, NULL, 0);
> if (needed)
> {
> WCHAR *wc = new WCHAR[needed];
> MultiByteToWideChar(CP_UTF8, 0, Edit2->Text.c_str(), -1,
> wc, needed);
> Edit2->Text = String(wc);
> delete[] wc;
> }
This works very well.
> Please notice I wrote this code only for test. It must be
> checked _very_ deeply.
I trust it blind.
Thanks so much.
Hans.
Re: utf-8 in filename of Content-Disposition: attachment;
Author: Hans Galema
Date: Mon, 30 Jan 2006 20:41
Date: Mon, 30 Jan 2006 20:41
19 lines
1638 bytes
1638 bytes
Remy Lebeau (TeamB) wrote: > UTF-8 > B > c2FtZW4gbWV0IEFuZHLDqSBraWprZW4gbmFhciBQYXNjYWwuanBn > > The 'UTF-8' is the encoding used for the original data. The 'B' is the > transmission encoding for the encoded data. In this case, 'B' means that > base64 is used. So, to get the original filename, you have to first decode > the contents of the third field with base64, and then decode the resulting > data with UTF-8 to get the original value. B == base64. Very good info. Thank you. Hans.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads