[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

howto decode encoded mail subjects?

Stephan Mueller

8/27/2007 3:49:00 PM

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.

5 Answers

Bertram Scharpf

8/27/2007 7:17:00 PM

0

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}"
}


--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-...

Stephan Mueller

8/28/2007 5:18:00 AM

0

Hi Bertram,

* Bertram Scharpf <lists@bertram-scharpf.de> [27.08.2007]:

> 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.

Bertram Scharpf

8/28/2007 8:51:00 AM

0

Hi,

Am Dienstag, 28. Aug 2007, 14:18:10 +0900 schrieb Stephan Mueller:
> * Bertram Scharpf <lists@bertram-scharpf.de> [27.08.2007]:
>
> > 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? :)

Oops. I just forgot the link:

<http://opensource.bertram-scharpf.de/sites/cr...

Bertram


--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-...

Stephan Mueller

8/29/2007 8:14:00 AM

0

Hi,

* Bertram Scharpf <lists@bertram-scharpf.de> [28.08.2007]:

> Oops. I just forgot the link:
>
> <http://opensource.bertram-scharpf.de/sites/cr...

thank you for providing the link. Maybe you should announce cropmail on
rubyforge to gain more users. I guess nowadays most people look on
rubyforge first when looking for ruby-related stuff.


Cheers,

Steph.

The Peeler

2/19/2011 12:26:00 PM

0

On Sat, 19 Feb 2011 10:44:47 +0100, Dumb Heini, the Dutch resident Nazi
troll of sci and scj, wrote:

>>> Convicted for denigration of the teachings of a legally recognized
>>> religion.
>>>
>>> Punishment: 120 day fines for a total of 480 euros.
>>
>> How can one demonise demons? The woman is being persecuted by leftists
>> and goat humping savades..
>>
>
> the austrians have lost it completely too. the woman gets a fine and in
> germany you get 5 years if you raise you right hand.it is an insane
> continent

"Insane continent"? The irony! This from one of the most stupid and twisted
posters ever seen on Usenet! LOL


--
Dumb Heini about himself: "i was diagnozed with the syndromeof asperger, no
idea what it means but i am feelingperfectly oke"
MID: <7u8b41FjtnU1@mid.individual.net>