BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

POP3 wrong decoding filename

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock
View previous topic :: View next topic  
Author Message
Bert van der Hoeven
Guest





PostPosted: Mon Feb 06, 2006 10:02 pm    Post subject: POP3 wrong decoding filename Reply with quote



This a part of a e-mail file genarated with lotus notes, whith indy10
snapshot 6 feb. 2006 the filename is not decoded.
My question is: is the mail wrong or is indy not correct translating the
name or have i decode the filename myself?
The attechment self is ok.
thanks
Bert.

--0__=4EBBFB95DFD462628f9e8a93df938690918c4EBBFB95DFD46262
Content-Type: application/msexcel;
name="=?UTF-8?B?cGxhbm5pbmcgZmFzZSAwIHZlcnNpZSAzYi54bHM=?="
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="=?UTF-8?B?cGxhbm5pbmcgZmFzZSAwIHZlcnNpZSAzYi54bHM=?="
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Tue Feb 07, 2006 1:03 am    Post subject: Re: POP3 wrong decoding filename Reply with quote



"Bert van der Hoeven" <GDvdHoeven (AT) planet (DOT) nl> wrote:

Quote:
is the mail wrong

No.

Quote:
or is indy not correct translating the name

Indy is not trying to translate the filename at all, because it is encoded using UTF-8, which Indy does not support at this time. The Indy developers are aware of the issue, but there is not much that can be done about it under Win32 since the string would have to be decoded into a WideString, which does not fit into Indy's current decoder architecture. UTF-8 support is currently being worked on for a future release under VCL.NET, where all strings are natively WideString.

Quote:
or have i decode the filename myself?

At this point in time, yes. To decode it, look for strings that begin with '=?' and end with '?='. In between those two delimiters, there are three fields separated by '?'. The first field is the encoding used for the original data. The second field is the encoding used for transporting the data. The third field is the actual data.

So, given the string:

=?UTF-8?B?cGxhbm5pbmcgZmFzZSAwIHZlcnNpZSAzYi54bHM=?=

The data encoding is 'UTF-8'.
The transport encoding is 'B' (base64).
The data is 'cGxhbm5pbmcgZmFzZSAwIHZlcnNpZSAzYi54bHM='.

You would first decode the base64 data, and then second you would decode the resulting UTF-8 data to get the original value.


Gambit
Back to top
theo
Guest





PostPosted: Tue Feb 07, 2006 12:02 pm    Post subject: Re: POP3 wrong decoding filename Reply with quote



Bert van der Hoeven schrieb:
Quote:
This a part of a e-mail file genarated with lotus notes, whith indy10
snapshot 6 feb. 2006 the filename is not decoded.
My question is: is the mail wrong or is indy not correct translating the
name or have i decode the filename myself?


With Synapse (http://www.ararat.cz/synapse/), this filenmame is
automatically decoded to "planning fase 0 versie 3b.xls"
Back to top
Bert van der Hoeven
Guest





PostPosted: Tue Feb 07, 2006 9:02 pm    Post subject: Re: POP3 wrong decoding filename Reply with quote

Thanks for this helpful information.
To pitty indy do not support this.

Can I use the Indy base64 decoder to decode the string?
and how can i decode UTF-8 to a delphi string?

"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> schreef in bericht
news:43e7e12a$1 (AT) newsgroups (DOT) borland.com...
Quote:

"Bert van der Hoeven" <GDvdHoeven (AT) planet (DOT) nl> wrote:

is the mail wrong

No.

or is indy not correct translating the name

Indy is not trying to translate the filename at all, because it is encoded
using UTF-8, which Indy does not support at this time. The Indy
developers are aware of the issue, but there is not much that can be done
about it under Win32 since the string would have to be decoded into a
WideString, which does not fit into Indy's current decoder architecture.
UTF-8 support is currently being worked on for a future release under
VCL.NET, where all strings are natively WideString.

or have i decode the filename myself?

At this point in time, yes. To decode it, look for strings that begin
with '=?' and end with '?='. In between those two delimiters, there are
three fields separated by '?'. The first field is the encoding used for
the original data. The second field is the encoding used for transporting
the data. The third field is the actual data.

So, given the string:

=?UTF-8?B?cGxhbm5pbmcgZmFzZSAwIHZlcnNpZSAzYi54bHM=?=

The data encoding is 'UTF-8'.
The transport encoding is 'B' (base64).
The data is 'cGxhbm5pbmcgZmFzZSAwIHZlcnNpZSAzYi54bHM='.

You would first decode the base64 data, and then second you would decode
the resulting UTF-8 data to get the original value.


Gambit
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Feb 08, 2006 12:04 am    Post subject: Re: POP3 wrong decoding filename Reply with quote

"Bert van der Hoeven" <GDvdHoeven (AT) planet (DOT) nl> wrote in message
news:43e8fb20$1 (AT) newsgroups (DOT) borland.com...

Quote:
To pitty indy do not support this.

It is not Indy's fault. Decoding UTF-8 strings almost always requires the
data to be placed into a WideString. The current architecture under Win32
is based on AnsiString instead of WideString.

Quote:
Can I use the Indy base64 decoder to decode the string?

Yes.

Quote:
how can i decode UTF-8 to a delphi string?

If you are using D6+, then the VCL has its own UTF-8 support functions, such
as UTF8Decode().

Alternatively, Indy 10 does have an IdUTF8 unit in the Protocols package.
You can use its UTF8ToUnicode() function.


Gambit
Back to top
Bert van der Hoeven
Guest





PostPosted: Wed Feb 08, 2006 9:05 pm    Post subject: Re: POP3 wrong decoding filename Reply with quote

Decoding works fine! Thanks to TeamB.

There is someting strange.
The filename starts with "=?UTF...... loking in then mail file (or
properties outlook express)
While debugging the code i found out that the file name starts with
"=_UTF......
The ? changed in _ underscore.
It is not a problem but i do no way this happens and if it can effect my
program.
Do anayone no?

Thanks
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Feb 08, 2006 10:05 pm    Post subject: Re: POP3 wrong decoding filename Reply with quote

"Bert van der Hoeven" <GDvdHoeven (AT) planet (DOT) nl> wrote in message
news:43ea4bce$1 (AT) newsgroups (DOT) borland.com...

Quote:
While debugging the code i found out that the file name
starts with "=_UTF......
The ? changed in _ underscore.

At what point exactly? Please provide more details.


Gambit
Back to top
Bert van der Hoeven
Guest





PostPosted: Sat Feb 11, 2006 11:03 am    Post subject: Re: POP3 wrong decoding filename Reply with quote

Quote:
At what point exactly? Please provide more details.

The message is loaded from a file in a TIdMessage.
MsgPart.loadfromfile......
loking directly in the file gives:
--0__=4EBBFB95DFD462628f9e8a93df938690918c4EBBFB95DFD46262
Content-Type: application/msexcel;
name="=?UTF-8?B?cGxhbm5pbmcgZmFzZSAwIHZlcnNpZSAzYi54bHM=?="
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="=?UTF-8?B?cGxhbm5pbmcgZmFzZSAwIHZlcnNpZSAzYi54bHM=?="

Here is a snip from my code:
DS : string; //can this be the problem?

if (MsgPart.MessageParts.Items[intIndex] is TIdAttachmentFile) then
begin //general attachment
if TIdAttachmentFile(MsgPart.MessageParts.Items[intIndex]).ParentPart<0
then
begin //alleen zelfstandige bijlagen als parentpart<0
li := lvMessageParts.Items.Add;
if
uppercase(TIdAttachmentFile(MsgPart.MessageParts.Items[intIndex]).ContentType)='MESSAGE/RFC822'
then
begin
li.ImageIndex := 5;
li.Caption := 'E-mail bericht';
end
else
begin
li.ImageIndex := 8;
if
uppercase(TIdAttachmentFile(MsgPart.MessageParts.Items[intIndex]).ContentTransfer)='BASE64'
then
begin
//opdelen in juiste stukken.
DS:=TIdAttachmentFile(MsgPart.MessageParts.Items[intIndex]).Filename;
li.Caption:=DecodeBase64Data(DS);
//IdDecoderMIME1.Encode(TIdAttachmentFile(MsgPart.MessageParts.Items[intIndex]).Filename);
end
else li.Caption :=
TIdAttachmentFile(MsgPart.MessageParts.Items[intIndex]).Filename;



function SplitUTF8string(InDS : string;
var part1, part2: string;
var partData : string):Boolean;
var
DS,
UTF1,
UTF2 : string;
UTFData : string;
N : integer;
IPart : integer;
begin
DS:=InDS;
if (length(DS)>2) and (copy(DS,1,2)='=_') then
begin
IPart:=1;
UTF1:='';
UTF2:='';
UTFDATA:='';
for N:=3 to length(DS) do
begin
case IPart of
1 : begin
if DS[N]<>'_' then
UTF1:=UTF1+DS[N]
else
IPart:=2;
end;
2 : begin
if DS[N]<>'_' then
UTF2:=UTF2+DS[N]
else
IPart:=3;
end;
3 : begin
if DS[N]<>'_' then
UTFData:=UTFData+DS[N]
else
IPart:=4;
end;
end;
end;
Part1:=UTF1;
Part2:=UTF2;
PartData:=UTFData;
Result:=True;
end
else result:=False;
end;

function DecodeBase64Data(InData : string):string;
var
UTF1,
UTF2 : string;
UTFData : string;
DecoderMime : TIdDecoderMIME;
DS : string;
DUTF8 : UTF8String;
begin
Result:='';
if SplitUTF8string(InData,UTF1,UTF2,UTFData) then
begin
DecoderMime := TIdDecoderMIME.Create;
try
DUTF8:=DecoderMime.DecodeString(UTFData);
DS:=UTF8Decode(DUTF8);
Result:=DS;
finally
DecoderMime.Free;
end;
end
else result:=InData;
end;

I hope this gives the backgrount information.

Thanks,
Bert.


"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> schreef in bericht
news:43ea5d6d$1 (AT) newsgroups (DOT) borland.com...
Quote:

"Bert van der Hoeven" <GDvdHoeven (AT) planet (DOT) nl> wrote in message
news:43ea4bce$1 (AT) newsgroups (DOT) borland.com...

While debugging the code i found out that the file name
starts with "=_UTF......
The ? changed in _ underscore.

At what point exactly? Please provide more details.


Gambit

Back to top
Ciaran Costelloe
Guest





PostPosted: Sat Feb 11, 2006 11:03 pm    Post subject: Re: POP3 wrong decoding filename Reply with quote

Bert van der Hoeven wrote:

Quote:
Decoding works fine! Thanks to TeamB.

There is someting strange.
The filename starts with "=?UTF...... loking in then mail file (or
properties outlook express)
While debugging the code i found out that the file name starts with
"=_UTF......
The ? changed in _ underscore.

With attachment filenames, Indy replaces any characters that are not
valid for a Windows filename with underscores. This is to avoid
problems with TIdAttachment's SaveToFile function. The ? is not valid
in a Windows filename since it is a DOS wild character.

Ciaran
Back to top
Bert van der Hoeven
Guest





PostPosted: Wed Feb 15, 2006 7:03 pm    Post subject: Re: POP3 wrong decoding filename Reply with quote

This make's sense. Thanks!


"Ciaran Costelloe" <ccostelloe (AT) flogas (DOT) ie> schreef in bericht
news:43ee6017$1 (AT) newsgroups (DOT) borland.com...
Quote:
Bert van der Hoeven wrote:

Decoding works fine! Thanks to TeamB.

There is someting strange.
The filename starts with "=?UTF...... loking in then mail file (or
properties outlook express)
While debugging the code i found out that the file name starts with
"=_UTF......
The ? changed in _ underscore.

With attachment filenames, Indy replaces any characters that are not
valid for a Windows filename with underscores. This is to avoid
problems with TIdAttachment's SaveToFile function. The ? is not valid
in a Windows filename since it is a DOS wild character.

Ciaran
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.