html view almost done
This commit is contained in:
parent
549238d734
commit
19aef7a5ed
15 changed files with 68 additions and 37 deletions
|
@ -139,6 +139,7 @@ class MessagesController < ApplicationController
|
|||
|
||||
@attachments = []
|
||||
@render_as_text = []
|
||||
@render_as_html_idx = nil
|
||||
|
||||
@message = @current_user.messages.find_by_uid(params[:id])
|
||||
@message.update_attributes(:unseen => false)
|
||||
|
@ -152,21 +153,29 @@ class MessagesController < ApplicationController
|
|||
Attachment.fromSinglePart(@attachments,@message.id,@mail)
|
||||
end
|
||||
|
||||
@attachments.each do |a|
|
||||
a.isText? ? @render_as_text << a.content_normalized : @render_as_text
|
||||
for idx in 0..@attachments.size-1
|
||||
@attachments[idx].isText? ? @render_as_text << @attachments[idx].decode_and_charset : @render_as_text
|
||||
@attachments[idx].isHtml? ? @render_as_html_idx ||= idx : @render_as_html_idx
|
||||
end
|
||||
end
|
||||
|
||||
def body
|
||||
message = @mailbox.fetch_body(params[:id].to_i)
|
||||
mail = Mail.new(message)
|
||||
@title = ''
|
||||
@body = ''
|
||||
attachments = []
|
||||
message = @current_user.messages.find(params[:id])
|
||||
mail = Mail.new(@mailbox.fetch_body(message.uid))
|
||||
if mail.multipart?
|
||||
Attachment.fromMultiParts(attachments,message.id,mail.parts)
|
||||
else
|
||||
Attachment.fromSinglePart(attachments,message.id,mail)
|
||||
end
|
||||
a = attachments[params[:idx].to_i]
|
||||
@title = 'aaaaa'
|
||||
@body = a.decode_and_charset
|
||||
#
|
||||
#header = parts[0]
|
||||
#body = parts[1]
|
||||
#@body = "<html><head><title>ala</title><body><pre>#{header}</pre>#{mail.inspect}</body></html>"
|
||||
render 'mail_view',:layout => 'mail_view'
|
||||
render 'html_view',:layout => 'html_view'
|
||||
end
|
||||
|
||||
def attachment
|
||||
|
|
|
@ -32,35 +32,31 @@ class Attachment
|
|||
multipart
|
||||
end
|
||||
|
||||
def self.fromMultiParts(attachments,id,parts,idx=0)
|
||||
def self.fromMultiParts(attachments,id,parts)
|
||||
parts.each do |part|
|
||||
a = Attachment.new( :message_id => id,
|
||||
:description => part.content_description,
|
||||
:type => part.content_type,
|
||||
:content => part.body.raw_source,
|
||||
:encoding => part.content_transfer_encoding,
|
||||
:idx => idx,
|
||||
:multipart => part.multipart?
|
||||
)
|
||||
if a.multipart?
|
||||
idx += 1
|
||||
fromMultiParts(attachments,id,part.parts,idx)
|
||||
fromMultiParts(attachments,id,part.parts)
|
||||
else
|
||||
attachments << a
|
||||
idx += 1
|
||||
end
|
||||
#FIXME problem with enueration of attachemnts
|
||||
end
|
||||
end
|
||||
|
||||
def self.fromSinglePart(attachments,id,part,idx=0)
|
||||
def self.fromSinglePart(attachments,id,part)
|
||||
a = Attachment.new( :message_id => id,
|
||||
:description => part.content_description,
|
||||
:type => part.content_type,
|
||||
:encoding => part.body.encoding,
|
||||
:charset => part.body.charset,
|
||||
:content => part.body.raw_source,
|
||||
:idx => idx
|
||||
:content => part.body.raw_source
|
||||
|
||||
)
|
||||
attachments << a
|
||||
end
|
||||
|
@ -103,6 +99,10 @@ class Attachment
|
|||
@type.nil? or @type =~ /^text\/plain/
|
||||
end
|
||||
|
||||
def isHtml?
|
||||
@type =~ /^text\/html/
|
||||
end
|
||||
|
||||
def title
|
||||
@description.nil? ? name : @description
|
||||
end
|
||||
|
@ -128,9 +128,11 @@ class Attachment
|
|||
end
|
||||
|
||||
def decode
|
||||
|
||||
case @encoding
|
||||
when /quoted-printable/
|
||||
decoded = @content.gsub(/_/," ").unpack("M").first
|
||||
#decoded = @content.gsub(/_/," ").unpack("M").first
|
||||
decoded = @content.unpack("M").first
|
||||
when /base64/
|
||||
decoded = @content.unpack("m").first
|
||||
when /uuencode/
|
||||
|
@ -148,7 +150,7 @@ class Attachment
|
|||
end
|
||||
end
|
||||
|
||||
def content_normalized
|
||||
def decode_and_charset
|
||||
|
||||
decoded = decode
|
||||
|
||||
|
|
|
@ -10,18 +10,29 @@ class Message < ActiveRecord::Base
|
|||
|
||||
def self.decode(text,unknown_encoding = $defaults["msg_unknown_encoding"])
|
||||
begin
|
||||
if text.=~(/^=\?/).nil?
|
||||
if text.=~(/=\?/).nil?
|
||||
after = Iconv.conv('UTF-8',unknown_encoding,text)
|
||||
else
|
||||
f = text.split(/\?/)
|
||||
case f[2].downcase
|
||||
when 'q':
|
||||
after = f[3].gsub(/_/," ").unpack("M").first
|
||||
when 'b':
|
||||
after = f[3].gsub(/_/," ").unpack("m").first
|
||||
else
|
||||
return text
|
||||
end
|
||||
# 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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue