mailr/app/helpers/messages_helper.rb

114 lines
3.3 KiB
Ruby
Raw Normal View History

2011-07-22 22:57:36 +02:00
module MessagesHelper
2011-07-27 20:34:30 +02:00
2011-08-02 23:12:17 +02:00
def size_formatter(size)
if size <= 2**10
2011-09-09 22:10:25 +02:00
"#{size} #{t(:bytes,:scope=>:common)}"
2011-08-02 23:12:17 +02:00
elsif size <= 2**20
2011-09-09 22:10:25 +02:00
sprintf("%.1f #{t(:kbytes,:scope=>:common)}",size.to_f/2**10)
2011-08-02 23:12:17 +02:00
else
2011-09-09 22:10:25 +02:00
sprintf("%.1f #{t(:mbytes,:scope=>:common)}",size.to_f/2**20)
2011-08-02 23:12:17 +02:00
end
end
def date_formatter(date)
2011-09-09 23:44:51 +02:00
date.nil? ? t(:no_date,:scope=>:message) : date.strftime("%Y-%m-%d %H:%M")
2011-08-02 23:12:17 +02:00
end
2011-09-10 20:31:55 +02:00
def address_formatter(addr,op)
2011-08-26 22:59:43 +02:00
s = ""
2011-09-10 13:49:42 +02:00
return s if addr.nil?
2011-08-26 22:59:43 +02:00
length = $defaults["msg_address_length"].to_i
2011-09-10 20:31:55 +02:00
case op
2011-09-03 13:07:40 +02:00
when :index
2011-09-09 22:10:25 +02:00
fs = addr.gsub(/\"/,"").split(/</)
2011-09-03 13:07:40 +02:00
fs[0].size.zero? ? s = fs[1] : s = fs[0]
s.length >= length ? s = s[0,length]+"..." : s
return h(s)
2011-09-09 22:10:25 +02:00
when :show
2011-09-10 13:49:42 +02:00
#addr = addr[0].charseted.gsub(/\"/,"")
2011-09-10 20:31:55 +02:00
return h(addr.gsub(/\"/,""))
2011-09-03 13:07:40 +02:00
when :raw
2011-09-09 22:10:25 +02:00
#fs = addr.gsub(/\"/,"").split(/</)
#fs[0].size.zero? ? s = fs[1] : s << fs[0] + " <" + fs[1] + ">"
2011-09-10 13:49:42 +02:00
s = h(addr)
return s
2011-09-10 20:31:55 +02:00
when :reply
return h(addr)
2011-09-03 13:07:40 +02:00
end
end
2011-08-26 22:59:43 +02:00
2011-09-10 20:31:55 +02:00
def body_formatter(body,op)
case op
when :reply
s = "\n\n\n"
body.gsub(/^\s+/,"").split(/\n/).each do |line|
s += ">" + line + "\n"
end
s
when :edit
return body
end
end
2011-09-03 13:07:40 +02:00
2011-09-10 20:31:55 +02:00
def subject_formatter(message,op)
case op
2011-09-10 13:49:42 +02:00
when :index
if message.subject.nil? or message.subject.size.zero?
s = t(:no_subject,:scope=>:message)
else
length = $defaults["msg_subject_length"].to_i
message.subject.length >= length ? s = message.subject[0,length]+"..." : s = message.subject
end
link_to s,{:controller => 'messages', :action => 'show', :id => message.uid} , :title => message.subject
when :show
if message.subject.nil? or message.subject.size.zero?
t(:no_subject,:scope=>:message)
else
message.subject
end
2011-09-10 20:31:55 +02:00
when :reply
if message.nil? or message.size.zero?
t(:reply_string,:scope=>:show)
else
t(:reply_string,:scope=>:show) + " " + message
end
2011-09-10 13:49:42 +02:00
end
2011-08-02 23:12:17 +02:00
end
def attachment_formatter(message)
2011-09-09 22:10:25 +02:00
message.content_type =~ /^text\/plain/ ? "" : image_tag(current_theme_image_path('star.png'))
2011-08-02 23:12:17 +02:00
end
2011-08-16 20:05:58 +02:00
def headers_links
2011-09-03 13:07:40 +02:00
#if @current_folder.hasFullName?(@folder_sent_name) || @current_folder.hasFullName?(@folder_drafts_name)
if @current_folder == @sent_folder || @current_folder == @drafts_folder
2011-08-16 20:05:58 +02:00
fields = $defaults["msgs_sent_view_fields"]
else
fields = $defaults["msgs_inbox_view_fields"]
end
html = ""
fields.each do |f|
html << "<th>"
if params[:sort_field] == f
params[:sort_dir].nil? ? dir = 'desc' : dir = nil
end
html << link_to(Message.human_attribute_name(f), {:controller => 'messages',:action => 'index',:sort_field => f,:sort_dir => dir}, {:class=>"header"})
html << "</th>"
end
html
end
2011-08-24 19:20:13 +02:00
def content_text_plain_for_render(text)
2011-08-26 22:59:43 +02:00
html = "<pre>"
2011-09-03 13:07:40 +02:00
#html << text.gsub!(/\r\n/,"\n")
2011-08-26 22:59:43 +02:00
html << h(text)
html << "</pre>"
2011-08-24 19:20:13 +02:00
html
end
2011-07-22 22:57:36 +02:00
end
2011-07-27 20:34:30 +02:00