html view almost done

This commit is contained in:
Wojciech Todryk 2011-08-27 22:00:06 +02:00
parent 549238d734
commit 19aef7a5ed
15 changed files with 68 additions and 37 deletions

View file

@ -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

View file

@ -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

View file

@ -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(/\?/)
# 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':
after = f[3].gsub(/_/," ").unpack("M").first
replace = f[3].gsub(/_/," ").unpack("M").first
when 'b':
after = f[3].gsub(/_/," ").unpack("m").first
replace = f[3].gsub(/_/," ").unpack("m").first
else
return text
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)

View file

@ -139,5 +139,6 @@ pl:
no_data: Brak danych
logout: Wyloguj
download: Pobierz
view: Pokaż
version: Wersja

View file

@ -35,7 +35,7 @@ Mailr::Application.routes.draw do
match "messages/reply/:id" => 'messages#reply'
post "messages/sendout"
match "messages/show/:id" => 'messages#show'
match "messages/body/:id" => 'messages#body' , :as => :messages_body
match "messages/body/:id/:idx" => 'messages#body' , :as => :messages_part_body
match "messages/attachment/:id/:idx" => 'messages#attachment', :as => :messages_attachment_download
get "user/logout"

View file

@ -444,7 +444,7 @@ div.msg_header {
iframe {
width: 937px;
height: 600px;
height: 800px;
margin-top: 10px;
}
@ -495,6 +495,7 @@ div.render_text span{
}
div.render_text pre {
font-size: 12px;
background-color: #EFF3E4;
padding: 5px;
border: 1px solid #5E634E;

View file

@ -0,0 +1 @@
<%= yield %>

View file

@ -13,3 +13,6 @@
<td>
<%= link_to t(:download), messages_attachment_download_path(attachment.message_id,attachment.idx) %>
</td>
<td>
<%= link_to t(:view), messages_part_body_path(attachment.message_id,attachment.idx) %>
</td>

View file

@ -3,9 +3,10 @@
<table class="table">
<% trclass = :even %>
<% @attachments.each do |a| %>
<% for idx in 0..@attachments.size-1 %>
<% @attachments[idx].idx = idx %>
<tr class="<%= trclass.to_s %>">
<%= render :partial => 'attachment', :object => a %>
<%= render :partial => 'attachment', :object => @attachments[idx] %>
</tr>
<% trclass == :even ? trclass = :odd : trclass = :even %>
<% end %>

View file

@ -1,3 +0,0 @@
<iframe frameborder="0" src="<%= messages_body_path(@message.uid) %>">
</iframe>

View file

@ -0,0 +1,3 @@
<iframe frameborder="0" src="<%= messages_part_body_path(@message.uid,@render_as_html_idx) %>">
</iframe>

View file

@ -0,0 +1,2 @@
<%= raw @body -%>

View file

@ -19,8 +19,8 @@
<%= render :partial => 'attachments' %>
<% end %>
<% if not @render_rich.nil? %>
<%= render :partial => 'body' ,:object => @render_body %>
<% if not @render_as_html_idx.nil? %>
<%= render :partial => 'html_part' %>
<% else %>
<div class="render_text">
<span><%= t(:content,:scope=>:message) %></span>