Revision 9615a42b
Added by Marc Dequènes almost 14 years ago
- ID 9615a42b5b8876a2df40b0a7346754ed4b737a0e
lib/tmail_extra.rb | ||
---|---|---|
end
|
||
end
|
||
end
|
||
|
||
###
|
||
# default Content-Type is: text/plain; charset=us-ascii
|
||
# (see http://tools.ietf.org/html/rfc2045#section-5.2)
|
||
|
||
class ContentTypeHeader
|
||
def set( args )
|
||
@main, @sub, @params = *args
|
||
|
||
if @main.blank?
|
||
@main = 'text'
|
||
@sub = 'plain'
|
||
@params = {'charset' => 'us-ascii'}
|
||
end
|
||
end
|
||
end
|
||
|
||
# don't break compatibility, but ensure RFC is respected when
|
||
# no specific 'default' argument is specified
|
||
class Mail
|
||
def content_type( default = nil )
|
||
rfc_default = 'text/plain'
|
||
if h = @header['content-type']
|
||
h.content_type || default || rfc_default
|
||
else
|
||
default || rfc_default
|
||
end
|
||
end
|
||
|
||
def main_type( default = nil )
|
||
rfc_default = 'text'
|
||
if h = @header['content-type']
|
||
h.main_type || default || rfc_default
|
||
else
|
||
default || rfc_default
|
||
end
|
||
end
|
||
|
||
def sub_type( default = nil )
|
||
rfc_default = 'plain'
|
||
if h = @header['content-type']
|
||
h.sub_type || default || rfc_default
|
||
else
|
||
default || rfc_default
|
||
end
|
||
end
|
||
|
||
def type_param( name, default = nil )
|
||
v = if h = @header['content-type']
|
||
h[name] || default
|
||
else
|
||
default
|
||
end
|
||
|
||
name == 'charset' ? v || 'us-ascii' : v
|
||
end
|
||
|
||
def charset( default = nil )
|
||
rfc_default = 'us-ascii'
|
||
if h = @header['content-type']
|
||
h['charset'] or default or rfc_default
|
||
else
|
||
default or rfc_default
|
||
end
|
||
end
|
||
end
|
||
#
|
||
###
|
||
end
|
Also available in: Unified diff
[workaround] TMail does not respect RFC2045 §5.2