diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 28afba9..b05d8e8 100755 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -147,46 +147,14 @@ class MessagesController < ApplicationController @message_header = parts[0] @mail = Mail.new(imap_message) if @mail.multipart? -# idx = 0 -# @mail.parts.each do |part| -# a = Attachment.new( :message_id => @message.id, -# :description => part.content_description, -# :type => part.content_type, -# :content => part.body.raw_source, -# :encoding => part.content_transfer_encoding, -# :idx => idx, -# :multipart => part.multipart? -# ) -# logger.custom('a',a.to_s) -# if a.isText? -# @render_as_text << a.content_normalized -# else -# @attachments << a -# end -# -# idx += 1 -# end - Attachment.fromPart(@attachments,@message.id,@mail.parts,0) - @attachments.each do |a| - a.isText? ? @render_as_text << a.content_normalized : @render_as_text - end - + Attachment.fromMultiParts(@attachments,@message.id,@mail.parts) else - a = Attachment.new( :message_id => @message.id, - :description => @mail.content_description, - :type => @mail.content_type, - :encoding => @mail.body.encoding, - :charset => @mail.body.charset, - :content => @mail.body.raw_source, - :idx => 0 - ) - logger.custom('a',a.to_s) - if a.isText? - @render_as_text << a.content_normalized - else - @attachments << a - end - end + Attachment.fromSinglePart(@attachments,@message.id,@mail) + end + + @attachments.each do |a| + a.isText? ? @render_as_text << a.content_normalized : @render_as_text + end end def body @@ -202,27 +170,15 @@ class MessagesController < ApplicationController end def attachment - @message = @current_user.messages.find(params[:id]) - mail = Mail.new(@mailbox.fetch_body(@message.uid)) - - if mail.multipart? - part = mail.parts[params[:idx].to_i] - a = Attachment.new( :message_id => @message.id, - :description => part.content_description, - :type => part.content_type, - :content => part.body.raw_source, - :encoding => part.content_transfer_encoding, - :idx => params[:idx] - ) + 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 - a = Attachment.new( :message_id => @message.id, - :type => mail.content_type, - :encoding => mail.body.encoding, - :charset => mail.body.charset, - :content => mail.body.raw_source, - :idx => 0 - ) - end + Attachment.fromSinglePart(attachments,message.id,mail) + end + a = attachments[params[:idx].to_i] headers['Content-type'] = a.type headers['Content-Disposition'] = %(attachment; filename="#{a.name}") render :text => a.decode diff --git a/app/models/attachment.rb b/app/models/attachment.rb index affcefb..9eae108 100755 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -32,7 +32,7 @@ class Attachment multipart end - def self.fromPart(attachments,id,parts,idx) + def self.fromMultiParts(attachments,id,parts,idx=0) parts.each do |part| a = Attachment.new( :message_id => id, :description => part.content_description, @@ -43,20 +43,33 @@ class Attachment :multipart => part.multipart? ) if a.multipart? - fromPart(attachments,id,part.parts,idx) + idx += 1 + fromMultiParts(attachments,id,part.parts,idx) else attachments << a + idx += 1 end - idx += 1 + #FIXME problem with enueration of attachemnts end end + def self.fromSinglePart(attachments,id,part,idx=0) + 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 + ) + attachments << a + end + + def persisted? false end - - def name if @name.nil? case type @@ -151,33 +164,6 @@ class Attachment end end -# def to_html -# html = "" -# html << "" -# html << "#{@description.nil? ? @name : @description}" -# html << " #{@type}" -# @charset.nil? ? html : html << " #{@charset}" -# @encoding.nil? ? html : html << " #{@encoding}" -# case @type -# when /^message\/delivery-status/ -# html << "
"
-#                html << @content
-#                html << "
" -# #when /^message\/rfc822/ -# # html << "
"
-#            #    html << @content
-#            #    html << "
" -# end -# html << "
" -# end - -# def to_table -# html = "" -## @type.nil? ? html << "" : html << "#{@type}" -# @charset.nil? ? html << "" : html << "#{@charset}" -# @encoding.nil? ? html << "" : html << "#{@encoding}" - -# html -# end + diff --git a/config/defaults.yml b/config/defaults.yml index 902b34f..b924494 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: [wtodryk] +only_can_logins: [wojciech@todryk.pl] diff --git a/config/locales/pl.yml b/config/locales/pl.yml index cdbf423..6af3a9c 100755 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -139,4 +139,5 @@ pl: no_data: Brak danych logout: Wyloguj download: Pobierz + version: Wersja diff --git a/themes/olive/views/folders/_list.html.erb b/themes/olive/views/folders/_list.html.erb index d7f92d9..9ce8b2c 100755 --- a/themes/olive/views/folders/_list.html.erb +++ b/themes/olive/views/folders/_list.html.erb @@ -18,3 +18,6 @@ <%= raw form_button_value('logout','tick.png',user_logout_path) %> +

+<%= t(:version) %>: Build 20110826 +