devel
This commit is contained in:
parent
cead4d9d74
commit
961e9d6f4b
|
@ -57,6 +57,41 @@ class ApplicationController < ActionController::Base
|
||||||
@current_folder = @current_user.folders.find_by_full_name(@selected_folder)
|
@current_folder = @current_user.folders.find_by_full_name(@selected_folder)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.decode_quoted(text,unknown_charset = $defaults["msg_unknown_charset"])
|
||||||
|
begin
|
||||||
|
if text.=~(/=\?/).nil?
|
||||||
|
after = Iconv.conv('UTF-8',unknown_charset,text)
|
||||||
|
#after = text
|
||||||
|
else
|
||||||
|
# TODO support multiple showing of =?xxx?=
|
||||||
|
text =~ /(=\?.+\?=)/
|
||||||
|
after = text
|
||||||
|
match = $1
|
||||||
|
f = match.split(/\?/)
|
||||||
|
case f[2].downcase
|
||||||
|
when 'q':
|
||||||
|
replace = f[3].gsub(/_/," ").unpack("M").first
|
||||||
|
when 'b':
|
||||||
|
replace = f[3].gsub(/_/," ").unpack("m").first
|
||||||
|
else
|
||||||
|
replace = match
|
||||||
|
end
|
||||||
|
match.gsub!(/\?/,'\?')
|
||||||
|
match.gsub!(/\)/,'\)')
|
||||||
|
after = text.gsub(/#{match}/,replace)
|
||||||
|
|
||||||
|
if f[1].downcase != 'utf-8'
|
||||||
|
after = Iconv.conv('UTF-8',f[1],after)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
return after
|
||||||
|
rescue Exception => e
|
||||||
|
logger.error("Class Message: #{e.to_s}: T: #{text} M: #{match} R: #{replace} A: #{after}")
|
||||||
|
return text
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
##################################### private section ##########################################
|
##################################### private section ##########################################
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -21,7 +21,7 @@ class Attachment
|
||||||
key = fields[0]
|
key = fields[0]
|
||||||
value = fields[1]
|
value = fields[1]
|
||||||
if Attachment.attribute_method?(key) == true
|
if Attachment.attribute_method?(key) == true
|
||||||
send("#{key}=", value)
|
send("#{key}=", ApplicationController.decode_quoted(value))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -33,23 +33,8 @@ class Attachment
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.fromMultiParts(attachments,id,parts)
|
def self.fromMultiParts(attachments,id,parts)
|
||||||
cid = ''
|
|
||||||
parts.each do |part|
|
parts.each do |part|
|
||||||
if not part.content_id.nil?
|
a = build(id,part)
|
||||||
part.content_id =~ /\<(\S+)\>/
|
|
||||||
cid = $1
|
|
||||||
else
|
|
||||||
cid = ''
|
|
||||||
end
|
|
||||||
a = Attachment.new( :message_id => id,
|
|
||||||
:description => part.content_description,
|
|
||||||
:type => part.content_type,
|
|
||||||
:content => part.body.raw_source,
|
|
||||||
:encoding => part.content_transfer_encoding,
|
|
||||||
:size => part.body.raw_source.size,
|
|
||||||
:multipart => part.multipart?,
|
|
||||||
:cid => cid
|
|
||||||
)
|
|
||||||
if a.multipart?
|
if a.multipart?
|
||||||
fromMultiParts(attachments,id,part.parts)
|
fromMultiParts(attachments,id,part.parts)
|
||||||
else
|
else
|
||||||
|
@ -59,15 +44,29 @@ class Attachment
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.fromSinglePart(attachments,id,part)
|
def self.fromSinglePart(attachments,id,part)
|
||||||
|
a = build(id,part)
|
||||||
|
attachments << a
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.build(id,part)
|
||||||
|
cid = ''
|
||||||
|
if not part.content_id.nil?
|
||||||
|
part.content_id =~ /\<(\S+)\>/
|
||||||
|
cid = $1
|
||||||
|
else
|
||||||
|
cid = ''
|
||||||
|
end
|
||||||
a = Attachment.new( :message_id => id,
|
a = Attachment.new( :message_id => id,
|
||||||
:description => part.content_description,
|
:description => part.content_description,
|
||||||
:type => part.content_type,
|
:type => part.content_type,
|
||||||
:encoding => part.body.encoding,
|
|
||||||
:content => part.body.raw_source,
|
:content => part.body.raw_source,
|
||||||
|
:encoding => part.body.encoding,
|
||||||
:size => part.body.raw_source.size,
|
:size => part.body.raw_source.size,
|
||||||
:charset => part.body.charset
|
:charset => part.body.charset,
|
||||||
|
:multipart => part.multipart?,
|
||||||
|
:cid => cid
|
||||||
)
|
)
|
||||||
attachments << a
|
return a
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -137,7 +136,7 @@ class Attachment
|
||||||
end
|
end
|
||||||
|
|
||||||
def decode
|
def decode
|
||||||
|
begin
|
||||||
case @encoding
|
case @encoding
|
||||||
when /quoted-printable/
|
when /quoted-printable/
|
||||||
#decoded = @content.gsub(/_/," ").unpack("M").first
|
#decoded = @content.gsub(/_/," ").unpack("M").first
|
||||||
|
@ -157,20 +156,26 @@ class Attachment
|
||||||
else
|
else
|
||||||
decoded = @content
|
decoded = @content
|
||||||
end
|
end
|
||||||
|
rescue
|
||||||
|
@content
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def decode_and_charset
|
def decode_and_charset
|
||||||
|
begin
|
||||||
decoded = decode
|
decoded = decode
|
||||||
|
|
||||||
if not @charset == 'UTF-8'
|
if not @charset == 'UTF-8'
|
||||||
@charset.nil? ? charset = $defaults["msg_unknown_encoding"] : charset = @charset
|
@charset.nil? ? charset = $defaults["msg_unknown_charset"] : charset = @charset
|
||||||
charseted = Iconv.iconv("UTF-8",charset,decoded).first
|
charseted = Iconv.iconv("UTF-8",charset,decoded).first
|
||||||
else
|
else
|
||||||
charseted = decoded
|
charseted = decoded
|
||||||
end
|
end
|
||||||
|
|
||||||
charseted
|
charseted
|
||||||
|
rescue
|
||||||
|
decoded
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,48 +8,10 @@ class Message < ActiveRecord::Base
|
||||||
set_primary_key :uid
|
set_primary_key :uid
|
||||||
attr_accessible :unseen, :to_addr, :size, :content_type, :folder_id, :subject, :date, :uid, :from_addr, :user_id, :msg_id
|
attr_accessible :unseen, :to_addr, :size, :content_type, :folder_id, :subject, :date, :uid, :from_addr, :user_id, :msg_id
|
||||||
|
|
||||||
def self.decode(text,unknown_encoding = $defaults["msg_unknown_encoding"])
|
|
||||||
begin
|
|
||||||
if text.=~(/=\?/).nil?
|
|
||||||
after = Iconv.conv('UTF-8',unknown_encoding,text)
|
|
||||||
else
|
|
||||||
# TODO support multiple showing of =?xxx?=
|
|
||||||
text =~ /(=\?\S+\?=)/
|
|
||||||
after = text
|
|
||||||
match = $1
|
|
||||||
logger.custom('match',match)
|
|
||||||
f = match.split(/\?/)
|
|
||||||
case f[2].downcase
|
|
||||||
when 'q':
|
|
||||||
replace = f[3].gsub(/_/," ").unpack("M").first
|
|
||||||
when 'b':
|
|
||||||
replace = f[3].gsub(/_/," ").unpack("m").first
|
|
||||||
else
|
|
||||||
replace = match
|
|
||||||
end
|
|
||||||
logger.custom('replace',replace)
|
|
||||||
match.gsub!(/\?/,'\?')
|
|
||||||
match.gsub!(/\)/,'\)')
|
|
||||||
after = text.gsub(/#{match}/,replace)
|
|
||||||
|
|
||||||
logger.custom('after',after)
|
|
||||||
|
|
||||||
if f[1].downcase != 'utf-8'
|
|
||||||
after = Iconv.conv('UTF-8',f[1],after)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
return after
|
|
||||||
rescue
|
|
||||||
logger.error("Class Message: String decode error: #{text}")
|
|
||||||
return text
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.addr_to_db(addr)
|
def self.addr_to_db(addr)
|
||||||
ret = ""
|
ret = ""
|
||||||
name = addr.name
|
name = addr.name
|
||||||
name.nil? ? ret : ret << decode(name)
|
name.nil? ? ret : ret << ApplicationController.decode_quoted(name)
|
||||||
ret << "<" + addr.mailbox + "@" + addr.host
|
ret << "<" + addr.mailbox + "@" + addr.host
|
||||||
ret
|
ret
|
||||||
end
|
end
|
||||||
|
@ -74,7 +36,7 @@ class Message < ActiveRecord::Base
|
||||||
from = addr_to_db(envelope.from[0])
|
from = addr_to_db(envelope.from[0])
|
||||||
to = addr_to_db(envelope.to[0])
|
to = addr_to_db(envelope.to[0])
|
||||||
|
|
||||||
envelope.subject.nil? ? subject = "" : subject = decode(envelope.subject)
|
envelope.subject.nil? ? subject = "" : subject = ApplicationController.decode_quoted(envelope.subject)
|
||||||
|
|
||||||
create(
|
create(
|
||||||
:user_id => user.id,
|
:user_id => user.id,
|
||||||
|
|
|
@ -21,7 +21,7 @@ msg_address_length: 35
|
||||||
msg_search_fields: [subject, from, to]
|
msg_search_fields: [subject, from, to]
|
||||||
|
|
||||||
# if encoding can not be get from data
|
# if encoding can not be get from data
|
||||||
msg_unknown_encoding: ISO-8859-2
|
msg_unknown_charset: ISO-8859-2
|
||||||
|
|
||||||
imap_debug: false
|
imap_debug: false
|
||||||
imap_use_ssl: 'false'
|
imap_use_ssl: 'false'
|
||||||
|
|
Loading…
Reference in a new issue