Welcome to Dream.In.Code
Become a C# Expert!

Join 150,413 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,018 people online right now. Registration is fast and FREE... Join Now!




How to decode quoted-printable encoded string?

 
Reply to this topicStart new topic

How to decode quoted-printable encoded string?

cygnusX
3 Apr, 2008 - 03:20 AM
Post #1

D.I.C Head
**

Joined: 19 May, 2007
Posts: 159



Thanked: 2 times
My Contributions
Here is decoding of base-64 encoded text but what about quoted-printable?

CODE

            Match match = Regex.Match(header, @"=\?(?<charset>.*?)\?(?<encoding>[qQbB])\?(?<value>.*?)\?=");

            if (match.Success)
            {
                string charSet = match.Groups["charset"].Value;
                string encoding = match.Groups["encoding"].Value.ToUpper();
                string value = match.Groups["value"].Value;

                byte[] bytes;

                if (encoding.ToLower().Equals("b")) //if the string is base-64
                    bytes = Convert.FromBase64String(value);
               else //if the string is quoted-printable ???
                    

                return Encoding.GetEncoding(charSet).GetString(bytes);
            }
            return header;

User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: How To Decode Quoted-printable Encoded String?
3 Apr, 2008 - 04:39 AM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
What do you mean by "quoted printable"?
User is offlineProfile CardPM
+Quote Post

cygnusX
RE: How To Decode Quoted-printable Encoded String?
3 Apr, 2008 - 05:42 AM
Post #3

D.I.C Head
**

Joined: 19 May, 2007
Posts: 159



Thanked: 2 times
My Contributions
This is taken from MIME(Multipurpose Internet Mail Extensions) specification.

"The Quoted-Printable encoding is intended to represent data that largely consists of octets that correspond to printable characters in the US-ASCII character set.It encodes the data in such a way that the resulting octets are unlikely to be modified by mail transport.If the data being encoded are mostly US-ASCII text, the encoded form
of the data remains largely recognizable by humans. A body which is entirely US-ASCII may also be encoded in Quoted-Printable to ensure the integrity of the data should the message pass through a character-translating, and/or line-wrapping gateway...blah blah"

Hm,actually i need to decode text encoded in "Q" encoding,not in "quoted-printable".

The "Q" encoding is similar to the "Quoted-Printable" content-
transfer-encoding defined in RFC 2045. It is designed to allow text
containing mostly ASCII characters to be decipherable on an ASCII
terminal without decoding.

(1) Any 8-bit value may be represented by a "=" followed by two
hexadecimal digits. For example, if the character set in use
were ISO-8859-1, the "=" character would thus be encoded as
"=3D", and a SPACE by "=20". (Upper case should be used for
hexadecimal digits "A" through "F".)

(2) The 8-bit hexadecimal value 20 (e.g., ISO-8859-1 SPACE) may be
represented as "_" (underscore, ASCII 95.). (This character may
not pass through some internetwork mail gateways, but its use
will greatly enhance readability of "Q" encoded data with mail
readers that do not support this encoding.) Note that the "_"
always represents hexadecimal 20, even if the SPACE character
occupies a different code position in the character set in use.

(3) 8-bit values which correspond to printable ASCII characters other
than "=", "?", and "_" (underscore), MAY be represented as those
characters. (But see section 5 for restrictions.) In
particular, SPACE and TAB MUST NOT be represented as themselves
within encoded words.


This post has been edited by cygnusX: 3 Apr, 2008 - 05:50 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 07:58PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month