html view almost done
This commit is contained in:
parent
549238d734
commit
19aef7a5ed
|
@ -139,6 +139,7 @@ class MessagesController < ApplicationController
|
||||||
|
|
||||||
@attachments = []
|
@attachments = []
|
||||||
@render_as_text = []
|
@render_as_text = []
|
||||||
|
@render_as_html_idx = nil
|
||||||
|
|
||||||
@message = @current_user.messages.find_by_uid(params[:id])
|
@message = @current_user.messages.find_by_uid(params[:id])
|
||||||
@message.update_attributes(:unseen => false)
|
@message.update_attributes(:unseen => false)
|
||||||
|
@ -152,21 +153,29 @@ class MessagesController < ApplicationController
|
||||||
Attachment.fromSinglePart(@attachments,@message.id,@mail)
|
Attachment.fromSinglePart(@attachments,@message.id,@mail)
|
||||||
end
|
end
|
||||||
|
|
||||||
@attachments.each do |a|
|
for idx in 0..@attachments.size-1
|
||||||
a.isText? ? @render_as_text << a.content_normalized : @render_as_text
|
@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
|
||||||
end
|
end
|
||||||
|
|
||||||
def body
|
def body
|
||||||
message = @mailbox.fetch_body(params[:id].to_i)
|
attachments = []
|
||||||
mail = Mail.new(message)
|
message = @current_user.messages.find(params[:id])
|
||||||
@title = ''
|
mail = Mail.new(@mailbox.fetch_body(message.uid))
|
||||||
@body = ''
|
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]
|
#header = parts[0]
|
||||||
#body = parts[1]
|
#body = parts[1]
|
||||||
#@body = "<html><head><title>ala</title><body><pre>#{header}</pre>#{mail.inspect}</body></html>"
|
#@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
|
end
|
||||||
|
|
||||||
def attachment
|
def attachment
|
||||||
|
|
|
@ -32,35 +32,31 @@ class Attachment
|
||||||
multipart
|
multipart
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.fromMultiParts(attachments,id,parts,idx=0)
|
def self.fromMultiParts(attachments,id,parts)
|
||||||
parts.each do |part|
|
parts.each do |part|
|
||||||
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,
|
||||||
:content => part.body.raw_source,
|
:content => part.body.raw_source,
|
||||||
:encoding => part.content_transfer_encoding,
|
:encoding => part.content_transfer_encoding,
|
||||||
:idx => idx,
|
|
||||||
:multipart => part.multipart?
|
:multipart => part.multipart?
|
||||||
)
|
)
|
||||||
if a.multipart?
|
if a.multipart?
|
||||||
idx += 1
|
fromMultiParts(attachments,id,part.parts)
|
||||||
fromMultiParts(attachments,id,part.parts,idx)
|
|
||||||
else
|
else
|
||||||
attachments << a
|
attachments << a
|
||||||
idx += 1
|
|
||||||
end
|
end
|
||||||
#FIXME problem with enueration of attachemnts
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.fromSinglePart(attachments,id,part,idx=0)
|
def self.fromSinglePart(attachments,id,part)
|
||||||
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,
|
:encoding => part.body.encoding,
|
||||||
:charset => part.body.charset,
|
:charset => part.body.charset,
|
||||||
:content => part.body.raw_source,
|
:content => part.body.raw_source
|
||||||
:idx => idx
|
|
||||||
)
|
)
|
||||||
attachments << a
|
attachments << a
|
||||||
end
|
end
|
||||||
|
@ -103,6 +99,10 @@ class Attachment
|
||||||
@type.nil? or @type =~ /^text\/plain/
|
@type.nil? or @type =~ /^text\/plain/
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def isHtml?
|
||||||
|
@type =~ /^text\/html/
|
||||||
|
end
|
||||||
|
|
||||||
def title
|
def title
|
||||||
@description.nil? ? name : @description
|
@description.nil? ? name : @description
|
||||||
end
|
end
|
||||||
|
@ -128,9 +128,11 @@ class Attachment
|
||||||
end
|
end
|
||||||
|
|
||||||
def decode
|
def decode
|
||||||
|
|
||||||
case @encoding
|
case @encoding
|
||||||
when /quoted-printable/
|
when /quoted-printable/
|
||||||
decoded = @content.gsub(/_/," ").unpack("M").first
|
#decoded = @content.gsub(/_/," ").unpack("M").first
|
||||||
|
decoded = @content.unpack("M").first
|
||||||
when /base64/
|
when /base64/
|
||||||
decoded = @content.unpack("m").first
|
decoded = @content.unpack("m").first
|
||||||
when /uuencode/
|
when /uuencode/
|
||||||
|
@ -148,7 +150,7 @@ class Attachment
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def content_normalized
|
def decode_and_charset
|
||||||
|
|
||||||
decoded = decode
|
decoded = decode
|
||||||
|
|
||||||
|
|
|
@ -10,18 +10,29 @@ class Message < ActiveRecord::Base
|
||||||
|
|
||||||
def self.decode(text,unknown_encoding = $defaults["msg_unknown_encoding"])
|
def self.decode(text,unknown_encoding = $defaults["msg_unknown_encoding"])
|
||||||
begin
|
begin
|
||||||
if text.=~(/^=\?/).nil?
|
if text.=~(/=\?/).nil?
|
||||||
after = Iconv.conv('UTF-8',unknown_encoding,text)
|
after = Iconv.conv('UTF-8',unknown_encoding,text)
|
||||||
else
|
else
|
||||||
f = text.split(/\?/)
|
# TODO support multiple showing of =?xxx?=
|
||||||
case f[2].downcase
|
text =~ /(=\?\S+\?=)/
|
||||||
when 'q':
|
after = text
|
||||||
after = f[3].gsub(/_/," ").unpack("M").first
|
match = $1
|
||||||
when 'b':
|
logger.custom('match',match)
|
||||||
after = f[3].gsub(/_/," ").unpack("m").first
|
f = match.split(/\?/)
|
||||||
else
|
case f[2].downcase
|
||||||
return text
|
when 'q':
|
||||||
end
|
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'
|
if f[1].downcase != 'utf-8'
|
||||||
after = Iconv.conv('UTF-8',f[1],after)
|
after = Iconv.conv('UTF-8',f[1],after)
|
||||||
|
|
|
@ -139,5 +139,6 @@ pl:
|
||||||
no_data: Brak danych
|
no_data: Brak danych
|
||||||
logout: Wyloguj
|
logout: Wyloguj
|
||||||
download: Pobierz
|
download: Pobierz
|
||||||
|
view: Pokaż
|
||||||
version: Wersja
|
version: Wersja
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ Mailr::Application.routes.draw do
|
||||||
match "messages/reply/:id" => 'messages#reply'
|
match "messages/reply/:id" => 'messages#reply'
|
||||||
post "messages/sendout"
|
post "messages/sendout"
|
||||||
match "messages/show/:id" => 'messages#show'
|
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
|
match "messages/attachment/:id/:idx" => 'messages#attachment', :as => :messages_attachment_download
|
||||||
|
|
||||||
get "user/logout"
|
get "user/logout"
|
||||||
|
|
|
@ -444,7 +444,7 @@ div.msg_header {
|
||||||
|
|
||||||
iframe {
|
iframe {
|
||||||
width: 937px;
|
width: 937px;
|
||||||
height: 600px;
|
height: 800px;
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -495,6 +495,7 @@ div.render_text span{
|
||||||
}
|
}
|
||||||
|
|
||||||
div.render_text pre {
|
div.render_text pre {
|
||||||
|
font-size: 12px;
|
||||||
background-color: #EFF3E4;
|
background-color: #EFF3E4;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
border: 1px solid #5E634E;
|
border: 1px solid #5E634E;
|
||||||
|
|
1
themes/olive/views/layouts/html_view.erb
Executable file
1
themes/olive/views/layouts/html_view.erb
Executable file
|
@ -0,0 +1 @@
|
||||||
|
<%= yield %>
|
|
@ -13,3 +13,6 @@
|
||||||
<td>
|
<td>
|
||||||
<%= link_to t(:download), messages_attachment_download_path(attachment.message_id,attachment.idx) %>
|
<%= link_to t(:download), messages_attachment_download_path(attachment.message_id,attachment.idx) %>
|
||||||
</td>
|
</td>
|
||||||
|
<td>
|
||||||
|
<%= link_to t(:view), messages_part_body_path(attachment.message_id,attachment.idx) %>
|
||||||
|
</td>
|
||||||
|
|
|
@ -3,9 +3,10 @@
|
||||||
<table class="table">
|
<table class="table">
|
||||||
|
|
||||||
<% trclass = :even %>
|
<% trclass = :even %>
|
||||||
<% @attachments.each do |a| %>
|
<% for idx in 0..@attachments.size-1 %>
|
||||||
|
<% @attachments[idx].idx = idx %>
|
||||||
<tr class="<%= trclass.to_s %>">
|
<tr class="<%= trclass.to_s %>">
|
||||||
<%= render :partial => 'attachment', :object => a %>
|
<%= render :partial => 'attachment', :object => @attachments[idx] %>
|
||||||
</tr>
|
</tr>
|
||||||
<% trclass == :even ? trclass = :odd : trclass = :even %>
|
<% trclass == :even ? trclass = :odd : trclass = :even %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
<iframe frameborder="0" src="<%= messages_body_path(@message.uid) %>">
|
|
||||||
</iframe>
|
|
||||||
|
|
3
themes/olive/views/messages/_html_part.html.erb
Executable file
3
themes/olive/views/messages/_html_part.html.erb
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
<iframe frameborder="0" src="<%= messages_part_body_path(@message.uid,@render_as_html_idx) %>">
|
||||||
|
</iframe>
|
||||||
|
|
2
themes/olive/views/messages/html_view.html.erb
Executable file
2
themes/olive/views/messages/html_view.html.erb
Executable file
|
@ -0,0 +1,2 @@
|
||||||
|
<%= raw @body -%>
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
<%= render :partial => 'attachments' %>
|
<%= render :partial => 'attachments' %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if not @render_rich.nil? %>
|
<% if not @render_as_html_idx.nil? %>
|
||||||
<%= render :partial => 'body' ,:object => @render_body %>
|
<%= render :partial => 'html_part' %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<div class="render_text">
|
<div class="render_text">
|
||||||
<span><%= t(:content,:scope=>:message) %></span>
|
<span><%= t(:content,:scope=>:message) %></span>
|
||||||
|
|
Loading…
Reference in a new issue