This commit is contained in:
Wojciech Todryk 2011-08-27 00:10:45 +02:00
parent 52b4c63ddb
commit 549238d734
5 changed files with 39 additions and 93 deletions

View file

@ -147,46 +147,14 @@ class MessagesController < ApplicationController
@message_header = parts[0] @message_header = parts[0]
@mail = Mail.new(imap_message) @mail = Mail.new(imap_message)
if @mail.multipart? if @mail.multipart?
# idx = 0 Attachment.fromMultiParts(@attachments,@message.id,@mail.parts)
# @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
else else
a = Attachment.new( :message_id => @message.id, Attachment.fromSinglePart(@attachments,@message.id,@mail)
:description => @mail.content_description, end
:type => @mail.content_type,
:encoding => @mail.body.encoding, @attachments.each do |a|
:charset => @mail.body.charset, a.isText? ? @render_as_text << a.content_normalized : @render_as_text
:content => @mail.body.raw_source, end
:idx => 0
)
logger.custom('a',a.to_s)
if a.isText?
@render_as_text << a.content_normalized
else
@attachments << a
end
end
end end
def body def body
@ -202,27 +170,15 @@ class MessagesController < ApplicationController
end end
def attachment def attachment
@message = @current_user.messages.find(params[:id]) attachments = []
mail = Mail.new(@mailbox.fetch_body(@message.uid)) message = @current_user.messages.find(params[:id])
mail = Mail.new(@mailbox.fetch_body(message.uid))
if mail.multipart? if mail.multipart?
part = mail.parts[params[:idx].to_i] Attachment.fromMultiParts(attachments,message.id,mail.parts)
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]
)
else else
a = Attachment.new( :message_id => @message.id, Attachment.fromSinglePart(attachments,message.id,mail)
:type => mail.content_type, end
:encoding => mail.body.encoding, a = attachments[params[:idx].to_i]
:charset => mail.body.charset,
:content => mail.body.raw_source,
:idx => 0
)
end
headers['Content-type'] = a.type headers['Content-type'] = a.type
headers['Content-Disposition'] = %(attachment; filename="#{a.name}") headers['Content-Disposition'] = %(attachment; filename="#{a.name}")
render :text => a.decode render :text => a.decode

View file

@ -32,7 +32,7 @@ class Attachment
multipart multipart
end end
def self.fromPart(attachments,id,parts,idx) def self.fromMultiParts(attachments,id,parts,idx=0)
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,
@ -43,20 +43,33 @@ class Attachment
:multipart => part.multipart? :multipart => part.multipart?
) )
if a.multipart? if a.multipart?
fromPart(attachments,id,part.parts,idx) idx += 1
fromMultiParts(attachments,id,part.parts,idx)
else else
attachments << a attachments << a
idx += 1
end end
idx += 1 #FIXME problem with enueration of attachemnts
end end
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? def persisted?
false false
end end
def name def name
if @name.nil? if @name.nil?
case type case type
@ -151,33 +164,6 @@ class Attachment
end end
end end
# def to_html
# html = "<span class=\"attachment\">"
# html << "<span class=\"title\">"
# html << "<a href=\"/messages/attachment/#{@message_id}/#{@idx}\">#{@description.nil? ? @name : @description}</a>"
# html << "</span> #{@type}"
# @charset.nil? ? html : html << " #{@charset}"
# @encoding.nil? ? html : html << " #{@encoding}"
# case @type
# when /^message\/delivery-status/
# html << "<pre>"
# html << @content
# html << "</pre>"
# #when /^message\/rfc822/
# # html << "<pre>"
# # html << @content
# # html << "</pre>"
# end
# html << "</span>"
# end
# def to_table
# html = ""
## @type.nil? ? html << "<td></td>" : html << "<td>#{@type}</td>"
# @charset.nil? ? html << "<td></td>" : html << "<td>#{@charset}</td>"
# @encoding.nil? ? html << "<td></td>" : html << "<td>#{@encoding}</td>"
# html
# end

View file

@ -40,4 +40,4 @@ mailbox_sent: INBOX.sent
mailbox_drafts: INBOX.drafts mailbox_drafts: INBOX.drafts
# array of logins which only can login to application, comment it to allow everyone to login # 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]

View file

@ -139,4 +139,5 @@ pl:
no_data: Brak danych no_data: Brak danych
logout: Wyloguj logout: Wyloguj
download: Pobierz download: Pobierz
version: Wersja

View file

@ -18,3 +18,6 @@
<%= raw form_button_value('logout','tick.png',user_logout_path) %> <%= raw form_button_value('logout','tick.png',user_logout_path) %>
</div> </div>
</div> </div>
<p>
<%= t(:version) %>: Build 20110826
</p>