mailr/lib/mail_plugin_extension.rb

149 lines
3.7 KiB
Ruby
Raw Normal View History

2012-03-10 18:08:39 +01:00
require 'iconv'
module Mail
2012-03-24 13:23:34 +01:00
class Message
attr_accessor :idx,:parent_id
2012-03-24 18:09:31 +01:00
def decoded_and_charseted
begin
if not charset.upcase == 'UTF-8'
charset.nil? ? source_charset = $defaults["msg_unknown_charset"] : source_charset = charset
charseted = Iconv.iconv("UTF-8",source_charset,decoded).first
else
charseted = decoded
end
rescue
decoded
end
2012-03-24 13:23:34 +01:00
2012-03-24 18:09:31 +01:00
end
2012-03-24 13:23:34 +01:00
2012-03-10 18:08:39 +01:00
def isImage?
not (content_type =~ /^image/).nil?
end
def isText?
not (content_type =~ /^text\/plain/).nil?
end
def isHtml?
not (content_type =~ /^text\/html/).nil?
end
def getSize
body.raw_source.size
end
2012-03-24 13:23:34 +01:00
2012-03-10 18:08:39 +01:00
def filename_charseted
begin
if content_type =~ /\=\?([\w\-]+)\?/
source_charset = $1
if source_charset.upcase == 'UTF-8'
return filename
end
else
source_charset = $defaults["msg_unknown_charset"]
end
Iconv.iconv("UTF-8",source_charset,filename).first
rescue
filename
end
end
2012-03-24 13:23:34 +01:00
end
class Part
attr_accessor :idx,:parent_id
2012-03-24 18:09:31 +01:00
def isImage?
not (content_type =~ /^image/).nil?
end
2012-03-24 13:23:34 +01:00
2012-03-24 18:09:31 +01:00
def isText?
not (content_type =~ /^text\/plain/).nil?
end
2012-03-24 13:23:34 +01:00
2012-03-24 18:09:31 +01:00
def isHtml?
not (content_type =~ /^text\/html/).nil?
end
2012-03-24 13:23:34 +01:00
2012-03-24 18:09:31 +01:00
def getSize
body.raw_source.size
end
2012-03-24 13:23:34 +01:00
2012-03-24 18:09:31 +01:00
def decoded_and_charseted
begin
if not charset.upcase == 'UTF-8'
charset.nil? ? source_charset = $defaults["msg_unknown_charset"] : source_charset = charset
charseted = Iconv.iconv("UTF-8",source_charset,decoded).first
else
charseted = decoded
end
rescue
decoded
end
2012-03-24 13:23:34 +01:00
2012-03-24 18:09:31 +01:00
end
2012-03-24 13:23:34 +01:00
2012-03-10 18:08:39 +01:00
end
2012-03-24 18:09:31 +01:00
class Field
def charseted
begin
if value =~ /\=\?([\w\-]+)\?/
source_charset = $1
if source_charset.upcase == 'UTF-8'
return decoded
end
else
source_charset = $defaults["msg_unknown_charset"]
end
Iconv.iconv("UTF-8",source_charset,decoded).first
rescue
decoded
end
end
end
2012-03-24 13:23:34 +01:00
2012-03-24 18:09:31 +01:00
class Address
def charseted
begin
if value =~ /\=\?([\w\-]+)\?/
source_charset = $1
if source_charset.upcase == 'UTF-8'
return decoded
end
else
source_charset = $defaults["msg_unknown_charset"]
end
Iconv.iconv("UTF-8",source_charset,decoded).first
rescue
decoded
end
end
end
2012-03-24 13:23:34 +01:00
#class Part
#def filename_charseted
#begin
#if content_type =~ /\=\?([\w\-]+)\?/
#source_charset = $1
#if source_charset.upcase == 'UTF-8'
#return filename
#end
#else
#source_charset = $defaults["msg_unknown_charset"]
#end
#Iconv.iconv("UTF-8",source_charset,filename).first
#rescue
#filename
#end
#end
#end
2012-03-10 18:08:39 +01:00
end