Unicode to quoted-printable conversion

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
snm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 253
Joined: Fri Dec 09, 2011 11:17 am

Unicode to quoted-printable conversion

Post by snm » Sat Aug 11, 2012 9:21 pm

Does it exist any function or external which converts unicode text to "quoted-printable" format?
It should substitute non latin and some special chars to "=XX", "=" to "=3D" etc, as well as split long lines to max 70 chars per line with "=" at the end.

Marek

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Unicode to quoted-printable conversion

Post by Mark » Sun Aug 12, 2012 11:05 am

Hi,

It is quite simple to write such a function in LiveCode. Wikipedia contains all the info you need.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: Unicode to quoted-printable conversion

Post by shaosean » Sun Aug 12, 2012 11:56 am

I got one, will post in a couple of days if you can wait for me to find it..

snm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 253
Joined: Fri Dec 09, 2011 11:17 am

Re: Unicode to quoted-printable conversion

Post by snm » Sun Aug 12, 2012 12:30 pm

Thanks a lot Shaosean. I can wait few days, as it's only small part of my project.

Marek

snm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 253
Joined: Fri Dec 09, 2011 11:17 am

Re: Unicode to quoted-printable conversion

Post by snm » Tue Aug 14, 2012 11:25 am

Hi Saosean,

Did you find it?

Marek

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: Unicode to quoted-printable conversion

Post by shaosean » Tue Aug 14, 2012 11:38 am

Few more terabytes to search through.. I should really sort/catalogue my files better, but this gives me a bit of a challenge I guess ;-)

snm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 253
Joined: Fri Dec 09, 2011 11:17 am

Re: Unicode to quoted-printable conversion

Post by snm » Tue Aug 14, 2012 1:55 pm

Please try to give it some priority if it's possible. I count on your help very much.

Marek.

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: Unicode to quoted-printable conversion

Post by shaosean » Wed Aug 15, 2012 5:41 am

It does not split the lines though, but should be easy enough to do, just make sure to do it at the equal sign so as not to split an encoded char..

Code: Select all

on mouseUp
  put quotedPrintableFromUnicode(the unicodeText of field 1)
end mouseUp


function quotedPrintableFromUnicode pData
  local tFirstByteFlag          -- bool, flag if we're on the first or second byte of a two byte char
  local tOneByteChar            -- char, repeat loop var, current one-byte character in the saBody["text"] variable
  local tOneByteChar2           -- char, repeat loop var, current one-byte character in the tTwoByteCharDecoded variable
  local tTwoByteChar            -- char, current two-byte character (created by placing two tOneByteChar vars together)
  local tTwoByteCharDecoded     -- str, conversion of tTwoByteChar to UTF8
  local tOneByteCharConverted   -- str, conversion of tOneByteChar2 to quoted-printable
  local tDataOut                -- str, encoded data
  local tDataInLine
  local tDataInLine2
  
  --- encode the plain text body part
  put TRUE into tFirstByteFlag
  repeat for each char tOneByteChar in pData
    if (tFirstByteFlag) then
      put tOneByteChar into tTwoByteChar
      put FALSE into tFirstByteFlag
      next repeat
    else
      put tOneByteChar after tTwoByteChar
      put TRUE into tFirstByteFlag
    end if
    
    set the useUnicode to TRUE
    if (charToNum(tTwoByteChar) > 127) then
      put uniDecode(tTwoByteChar, "UTF8") into tTwoByteCharDecoded
      repeat for each char tOneByteChar2 in tTwoByteCharDecoded   # v101: changed tOneByteChar to tOneByteChar2 to lessen confusion: Jan Decroos
        get binaryDecode("H2", tOneByteChar2, tOneByteCharConverted)   # v101: changed tOneByteChar to tOneByteChar2 to lessen confusion: Jan Decroos
        put "=" & toUpper(tOneByteCharConverted) after tDataOut
      end repeat
    else
      put uniDecode(tTwoByteChar, "UTF8") after tDataOut
    end if
  end repeat
  return tDataOut
end quotedPrintableFromUnicode

snm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 253
Joined: Fri Dec 09, 2011 11:17 am

Re: Unicode to quoted-printable conversion

Post by snm » Wed Aug 15, 2012 9:59 am

Thanks a lo Saosean. It's working great. You helped me much.
I owe you few hours of work or some beer in next future.

Marek

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: Unicode to quoted-printable conversion

Post by shaosean » Wed Aug 15, 2012 10:27 am

I take PayPal as well as bags of cash left at the door ;-)

snm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 253
Joined: Fri Dec 09, 2011 11:17 am

Re: Unicode to quoted-printable conversion

Post by snm » Wed Aug 15, 2012 11:22 am

So I'm starting to collect cash. What kind of bag do you prefer?

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: Unicode to quoted-printable conversion

Post by shaosean » Wed Aug 15, 2012 11:51 am

Not too picky, I usually just use the bags afterwards to make beds for all the stray cats that live in my bedroom ;-)

Post Reply