#-- # rbmh/header.rb : rbmhshow 0.4.2 # # Copyright (C) 2004--2005 Merlin Hughes # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # #++ # Header decoding module RBMH class Header end # http://www.ietf.org/rfc/rfc2047.txt # I don't follow the rules for spacing of words # and I am slack with [^?] instead of [^ ?] because # of some erroneous implementations # I just ignore charset for now... assume iso-8859-1 # TODO: Do this better, use it for all appropriate headers def Header.nationalize(value) value.gsub(InternationalRE) { charset, encoding, string = $1, $2[0], $3 if encoding == 66 or encoding == 98 # `B' or `b' string.unpack("m*") else string.tr('_', ' ').unpack("M*") end } end InternationalRE = /=\?(.*)\?([bBqQ])\?(([^?]|\?[^=])*)\?=/ # $1: charset, $2: encoding, $3: string end # module RBMH