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

View file

@ -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 = "<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
# 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
logout: Wyloguj
download: Pobierz
version: Wersja

View file

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