diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 72fab77..33d8fee 100755 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -136,45 +136,56 @@ class MessagesController < ApplicationController end def show - + logger.custom('start',Time.now) @attachments = [] @render_as_text = [] @render_as_html_idx = nil @message = @current_user.messages.find_by_uid(params[:id]) @message.update_attributes(:unseen => false) + logger.custom('start_fetch',Time.now) imap_message = @mailbox.fetch_body(@message.uid) + logger.custom('stop_fetch',Time.now) parts = imap_message.split(/\r\n\r\n/) @message_header = parts[0] + logger.custom('before_parse',Time.now) @mail = Mail.new(imap_message) + logger.custom('after_parse',Time.now) if @mail.multipart? Attachment.fromMultiParts(@attachments,@message.id,@mail.parts) else Attachment.fromSinglePart(@attachments,@message.id,@mail) end + logger.custom('attach',Time.now) 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 + logger.custom('done',Time.now) end def body attachments = [] + cids = [] 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 = "ala
#{header}
#{mail.inspect}" + html = attachments[params[:idx].to_i] + + @body = html.decode_and_charset + + for idx in 0..attachments.size-1 + if not attachments[idx].cid.size.zero? + @body.gsub!(/cid:#{attachments[idx].cid}/,messages_attachment_download_path(message.uid,idx)) + end + end + render 'html_view',:layout => 'html_view' end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index de46307..c7627fd 100755 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -3,7 +3,7 @@ class Attachment include ActiveModel::Conversion extend ActiveModel::Naming - attr_accessor :type, :charset, :encoding, :name, :description, :content, :message_id, :idx, :boundary, :format, :multipart + attr_accessor :type, :charset, :encoding, :name, :description, :content, :message_id, :idx, :boundary, :format, :multipart,:size,:cid attr_reader :link def initialize(attributes = {}) @@ -33,13 +33,22 @@ class Attachment end def self.fromMultiParts(attachments,id,parts) + cid = '' parts.each do |part| + if not part.content_id.nil? + 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, - :multipart => part.multipart? + :size => part.body.raw_source.size, + :multipart => part.multipart?, + :cid => cid ) if a.multipart? fromMultiParts(attachments,id,part.parts) @@ -54,9 +63,9 @@ class Attachment :description => part.content_description, :type => part.content_type, :encoding => part.body.encoding, - :charset => part.body.charset, - :content => part.body.raw_source - + :content => part.body.raw_source, + :size => part.body.raw_source.size, + :charset => part.body.charset ) attachments << a end @@ -156,7 +165,7 @@ class Attachment if not @charset == 'UTF-8' @charset.nil? ? charset = $defaults["msg_unknown_encoding"] : charset = @charset - charseted = Iconv.iconv("UTF-8",charset,decoded) + charseted = Iconv.iconv("UTF-8",charset,decoded).first else charseted = decoded end diff --git a/config/defaults.yml b/config/defaults.yml index b924494..0183973 100755 --- a/config/defaults.yml +++ b/config/defaults.yml @@ -40,4 +40,4 @@ mailbox_sent: INBOX.sent mailbox_drafts: INBOX.drafts # array of logins which only can login to application, comment it to allow everyone to login -only_can_logins: [wojciech@todryk.pl] +only_can_logins: [some_login] diff --git a/themes/olive/views/messages/_attachment.html.erb b/themes/olive/views/messages/_attachment.html.erb index 5cb65cb..abd27f2 100755 --- a/themes/olive/views/messages/_attachment.html.erb +++ b/themes/olive/views/messages/_attachment.html.erb @@ -11,6 +11,9 @@ <%= attachment.encoding %> +<%= size_formatter(attachment.size) %> + + <%= link_to t(:download), messages_attachment_download_path(attachment.message_id,attachment.idx) %>