Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Decrypt quoted printable strings
#2
Member function str.QuotedPrintableEncoding
Code:
Copy      Help
;/
function$ action [$charset] ;;action: 0 encode, 1 decode

;Encodes or decodes text of this variable using quoted-printable encoding.
;Returns self.
;Error if fails. For example, if charset does not exist.

;charset - character set of encoded data. Eg "windows-1252". Default: "utf-8".

;NOTES
;Slow, especially first time.
;On Windows 2000 may incorrectly encode Unicode characters when using utf-8 charset (default).

;EXAMPLE
;str s="aaa=bbb []ą"
;out s.QuotedPrintableEncoding(0)
;out s.QuotedPrintableEncoding(1)


if(!this.len) ret this
if(empty(charset)) charset="utf-8"

IDispatch m._create("CDO.Message") b(m.BodyPart) s
b.ContentTransferEncoding="quoted-printable"

sel action
,case 0
,s=b.GetDecodedContentStream
,s.charset=charset
,s.WriteText(this); s.Flush
,s=b.GetEncodedContentStream
,
,case 1
,s=b.GetEncodedContentStream
,s.charset="windows-1252" ;;encoded data is ascii
,s.WriteText(this); s.Flush
,s=b.GetDecodedContentStream
,s.charset=charset
,
,case else ret this

this=s.ReadText
if(action=0 and !StrCompare(charset "utf-8" 1)) this.get(this 9) ;;BOM

err+ end _error
ret this

this also can be useful
Member function str.GetCharset
Code:
Copy      Help
function$ [codepage]

;Gets charset (character set) string for current or specified ANSI code page.
;Returns self.
;Error if fails.

;codepage - code page identifier. If 0, uses code page of current user (GetACP()).

;EXAMPLE
;out _s.GetCharset


if(!codepage) codepage=GetACP
_s.from("MIME\Database\Codepage\" codepage)
if(!rget(this "WebCharset" _s HKEY_CLASSES_ROOT) and !rget(this "BodyCharset" _s HKEY_CLASSES_ROOT)) end "failed"
ret this


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)