Re: MIME / Base64 problem.

Giganews Newsgroups
Subject: Re: MIME / Base64 problem.
Posted by:  Remy Lebeau \(Indy Team\) (re…@lebeausoftware.org)
Date: Mon, 12 Apr 2010

"Terry Yapt" <ya…@NOtechSPAMnovell.com> wrote in message
news:85C8C1B5D0AAE340ya…@NOtechSPAMnovell.com...

> I am trying to encode/decode an string from/to Base64 (mime)

You are telling TIdEncoderMIME to encode your source String to ISO-8591
prior to then encoding those bytes to base64.  However, you are not telling
TIdDecoderMIME that is need to interpret the decoded base64 bytes using
ISO-8591 so the extracted String is converted back to Unicode properly.  In
tonight's snapshot, DecodeString() now has new TIdTextEncoding parameter,
ie:

function DecodeBase64(const AOrigen: String):string;
begin
  iso88591 := TEncoding.GetEncoding(C_ENCODING);
  try
    buf := TIdDecoderMIME.DecodeString(AOrigen, iso88591);
  finally
    FreeAndNil(iso88591);
  end;
end;

Otherwise, use DecodeBytes() instead and then call BytesToString()
separately, ie:

function DecodeBase64(const AOrigen: String):string;
var
  buf: TIdBytes;
begin
  buf := TIdDecoderMIME.DecodeBytes(AOrigen);
  iso88591 := TEncoding.GetEncoding(C_ENCODING);
  try
    result := BytesToString(buf, iso88591);
  finally
    FreeAndNil(iso88591);
  end;
end;

--
Remy Lebeau (Indy Team)

Replies

In response to

MIME / Base64 problem. posted by Terry Yapt on Sat, 10 Apr 2010