Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Decrypt quoted printable strings
#1
I am looking for QM compatible software to decrypt quoted printable strings. Any advice welcome.
#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
#3
Dear Gintaras,

I am really indebted for your invaluable help.

Best regards
Simos
#4
Dear Gintaras,

I tried your example with greek characters. I am wondering a few of them are not decoded correctly; as an example the second character in the following example :

Macro temp14
Code:
Copy      Help
str s
s="Μπα"
out s.QuotedPrintableEncoding(0)
out s.QuotedPrintableEncoding(1)

I would kindly ask your advice.
#5
What is output?
What Windows version?
Is QM unicode mode?

I tested, and output is
=CE=9C=CF=80=CE=B1
Μπα
#6
Output :

windows-1253
=CE=9C=CF?=CE=B1
Μ?α


Windows XP - SP3

QM in Unicode

Thanks
#7
Windows bugs. I also tested on XP, worked well.

try this
Macro Macro83
Code:
Copy      Help
str s
s="Μπα"
out s.QuotedPrintableEncoding(0 "windows-1253")
out s.QuotedPrintableEncoding(1 "windows-1253")
#8
Yes, it worked!

Many thanks, Simos.
#9
However, this is another peculiar situation :

Macro temp9
Code:
Copy      Help
str s
s="ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ"
out s.QuotedPrintableEncoding(0 "utf-8")
out s.QuotedPrintableEncoding(1 "utf-8")

which it produces the following output :

=CE'=CE'=CE"=CE"=CE.=CE-=CE-=CE=98=CET=CE=9A=CE>=CE=9C=CE=9D=CE=9E=
=CE=9F=CE=A0=CE=B5=CE=A3=CE$=CEY=CE=A6=CE=A7=CE=A8=CE=A9
''"".--ΘTΚ>ΜΝΞΟΠΡΣ$YΦΧΨΩ

Could you please comment on it?
#10
I noticed this on Windows 2000. I think it is a bug in CDO (a Windows component). Need to find some other component (COM or dll) on the Internet. But I would create encryption/decryption code in QM or C. Look for quoted-printable in wikipedia, the rules are simple.
#11
Can be used MailBee component. QM uses it in email functions.

Member function str.QuotedPrintableEncoding
Code:
Copy      Help
;/
function$ action ;;action: 0 encode, 1 decode

;Encodes or decodes text of this variable using quoted-printable encoding.
;Returns self.

;NOTES
;When encoding, for Unicode characters always uses default ANSI codepage of current user, regarless of whether QM is in Unicode mode. Therefore cannot be used Unicode characters that cannot be converted to ANSI.

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


if(!this.len) ret this
MailBee.Message m._create

sel action
,case 0
,m.BodyText=this ;;does not respond to charset etc. Always uses default codepage/charset of current user.
,_s=m.RawBody
,
,case 1
,m.RawBody=_s.from(m.RawBody this)
,m.BodyEncoding=3 ;;at first encode base64, because if 0 (no encoding), wraps lines
,_s=m.RawBody
,
,case else ret this

;remove headeds
int i=find(_s "[][]")
if i>=0
,i+4
,if(action=0) this.get(_s i)
,else this.decrypt(4 _s+i); if(_unicode) this.ConvertEncoding(0 _unicode)

err+ end _error
ret this

;tested: with CDO.Message 30 times slower
#12
Once more, many thanks. It works. Yes, I had already checked with Wikipedia and I had written an arbritary code that did the job, neverthless it was slow and by no means elegant. Best Regards.


Forum Jump:


Users browsing this thread: 1 Guest(s)