Net::IMAP: Encoding problems

M

Maik Schmidt

I've used Net::IMAP for the first time and all in all it worked very
well. But I have one problem: When I download mails containing non-ASCII
characters in the subject or the body, they are encoded using the
q-encoded quoted-printable encoding scheme. How can I convert them to
normal String objects? unpack("M*") does not seem to support q-encoding.

Another question: Is it possible to dump a complete mail received via
Net::IMAP, so that I can feed it into RubyMail or TMail?

Cheers,

Maik
 
M

Martin Pirker

Maik Schmidt said:
When I download mails containing non-ASCII
characters in the subject or the body, they are encoded using the
q-encoded quoted-printable encoding scheme. How can I convert them to
normal String objects? unpack("M*") does not seem to support q-encoding.


def decodeqp(str)
str.gsub(/=\?(.+?)?\?([bq])\?(.+?)\?=/i) { |x|
m = $~
case m[2].downcase # m[2] is type of encoding
when "b" then s=m[3].unpack("m*").to_s # m[3] is encoded string
when "q" then s=m[3].unpack("M*").to_s
end
case m[1].downcase # m[1] is charset
when "iso-8859-1"
...
when "iso-8859-2"
....


you might use iconv for charset conversion then


HTH (although I was demonstrated yesterday again I'm still Ruby novice)
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top