howto decode encoded mail subjects?

S

Stephan Mueller

Hi,

i need to parse mails. Some of the Mails in question use some ending
scheme to support sepcial characters which are not ASCII-7.

encoded chars look like this: =?UTF-8?Q?=20some text...?UTF-?Q?...

Is there a way to decode these subjects soemhow to real utf? Then I
could use Iconv to change the encoding as i like.

Any tips appreciated!


Cheers,

Steph.
 
B

Bertram Scharpf

Hi,

Am Dienstag, 28. Aug 2007, 00:48:39 +0900 schrieb Stephan Mueller:
i need to parse mails. Some of the Mails in question use some ending
scheme to support sepcial characters which are not ASCII-7.

encoded chars look like this: =?UTF-8?Q?=20some text...?UTF-?Q?...

Is there a way to decode these subjects soemhow to real utf? Then I
could use Iconv to change the encoding as i like.

Half a year ago I wrote me a mail filter that does much more
than only decode header fields. I post some example code for
your task below.

I use the filter every day since last December. I provide it
as open source but I think nobody else is using it. So I
cannot estimate how good the documentation and the
installation tools are.

Bertram


--------------------------------

require "bs-net/mail"
include BsNet

mb = MBox.new "~/Mail/lists/ruby-talk"

# Variant #1

froms = mb.map { |text|
mail = Mail.new text
mail.addrs( :from).map { |plain,long,group| long }
}
froms.flatten!
puts froms.uniq.sort


puts "-"*32


# Variant #2

froms = mb.map { |text|
mail = Mail.new text
mail.addrs_norm :from # plain lower case addresses
}
froms.flatten!
puts froms.uniq.sort


puts "-"*32


# Variant #3

froms = []
mb.map { |text|
mail = Mail.new text
f = mail.addrs :from
froms.concat f.to_a
}
froms.uniq.sort.each { |(plain,long,group)|
puts "#{plain} -- #{long} -- #{group}"
}
 
S

Stephan Mueller

Hi Bertram,

* Bertram Scharpf said:
I use the filter every day since last December. I provide it
as open source but I think nobody else is using it. So I
cannot estimate how good the documentation and the
installation tools are.

thanks for your examples on how to use bs-net. One question remains:
Where can i find bs-net? :)


Cheers,

Steph.
 

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

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top