2009-01-07 20:27:12 +01:00
|
|
|
require 'cdfutils'
|
|
|
|
require 'mail2screen'
|
|
|
|
|
2009-01-07 21:06:34 +01:00
|
|
|
module WebmailHelper
|
2009-01-07 20:27:12 +01:00
|
|
|
include Mail2Screen
|
|
|
|
def link_compose_new
|
2009-09-01 14:23:05 +02:00
|
|
|
link_to(t(:compose_txt), :controller=>"webmail", :action=>"compose")
|
2009-01-07 20:27:12 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def link_refresh
|
2009-09-01 14:23:05 +02:00
|
|
|
link_to(t(:refresh), :controller=>"webmail", :action=>"refresh")
|
2009-01-07 20:27:12 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def link_message_list
|
2009-02-05 16:55:24 +01:00
|
|
|
link_to(_('Message list'), :controller=>"webmail", :action=>"messages")
|
2009-01-07 20:27:12 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def link_reply_to_sender(msg_id)
|
2009-09-01 14:23:05 +02:00
|
|
|
link_to(t(:reply), :controller=>"webmail", :action=>"reply", :params=>{"msg_id"=>msg_id})
|
2009-01-07 20:27:12 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def link_forward_message(msg_id)
|
2009-09-01 14:23:05 +02:00
|
|
|
link_to(t(:forward), :controller=>"webmail", :action=>"forward", :params=>{"msg_id"=>msg_id})
|
2009-01-07 20:27:12 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def link_flag_for_deletion(msg_id)
|
2009-09-01 14:23:05 +02:00
|
|
|
link_to(t(:delete), :controller=>"webmail", :action=>"delete", :params=>{"msg_id"=>msg_id})
|
2009-01-07 20:27:12 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def link_view_source(msg_id)
|
2009-09-01 14:23:05 +02:00
|
|
|
link_to(t(:view_source), {:controller=>"webmail", :action=>"view_source", :params=>{"msg_id"=>msg_id}}, {'target'=>"_blank"})
|
2009-01-07 20:27:12 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def link_filter_add
|
2009-09-01 14:23:05 +02:00
|
|
|
link_to(t(:add_filter), :controller=>'webmail', :action=>'filter_add')
|
2009-01-07 20:27:12 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def folder_link(folder)
|
2009-02-07 23:14:00 +01:00
|
|
|
return folder.name if folder.attribs.include?(:Noselect)
|
2011-04-01 13:23:32 +02:00
|
|
|
folder_name = short_fn(folder)
|
|
|
|
folder_name = t(folder_name.downcase.to_sym, :default => folder_name)
|
|
|
|
title = folder.unseen > 0 ? "#{folder_name} (#{folder.unseen})" : "#{folder_name}"
|
2009-02-07 23:14:00 +01:00
|
|
|
link = link_to title, :controller => 'webmail', :action => 'messages', :folder_name => folder.name
|
|
|
|
link = content_tag('b', link) if folder.name == @folder_name
|
|
|
|
link += ' ' + empty_trash_link(folder.name) if folder.trash?
|
|
|
|
link
|
2009-01-07 20:27:12 +01:00
|
|
|
end
|
2009-02-07 23:14:00 +01:00
|
|
|
|
2009-01-07 20:27:12 +01:00
|
|
|
def message_date(datestr)
|
|
|
|
t = Time.now
|
|
|
|
begin
|
|
|
|
if datestr.kind_of?(String)
|
|
|
|
d = (Time.rfc2822(datestr) rescue Time.parse(value)).localtime
|
|
|
|
else
|
|
|
|
d = datestr
|
|
|
|
end
|
|
|
|
if d.day == t.day and d.month == t.month and d.year == t.year
|
|
|
|
d.strftime("%H:%M")
|
|
|
|
else
|
|
|
|
d.strftime("%Y-%m-%d")
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
begin
|
|
|
|
d = imap2time(datestr)
|
|
|
|
if d.day == t.day and d.month == t.month and d.year == t.year
|
|
|
|
d.strftime("%H:%M")
|
|
|
|
else
|
|
|
|
d.strftime("%Y-%m-%d")
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
datestr
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def attachment(att, index)
|
|
|
|
ret = "#{att.filename}"
|
|
|
|
# todo: add link to delete attachment
|
|
|
|
#ret <<
|
|
|
|
ret << "<input type='hidden' name='att_files[#{index}]' value='#{att.filename}'/>"
|
|
|
|
ret << "<input type='hidden' name='att_tfiles[#{index}]' value='#{att.temp_filename}'/>"
|
|
|
|
ret << "<input type='hidden' name='att_ctypes[#{index}]' value='#{att.content_type}'/>"
|
|
|
|
end
|
|
|
|
|
|
|
|
def link_filter_up(filter_id)
|
2009-02-05 16:55:24 +01:00
|
|
|
link_to(_('Up'), :controller=>"webmail", :action=>"filter_up", :id=>filter_id)
|
2009-01-07 20:27:12 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def link_filter_down(filter_id)
|
2009-02-05 16:55:24 +01:00
|
|
|
link_to(_('Down'), :controller=>"webmail", :action=>"filter_down", :id=>filter_id)
|
2009-01-07 20:27:12 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def link_filter_edit(filter_id)
|
2009-02-05 16:55:24 +01:00
|
|
|
link_to(_('Edit'), :controller=>"webmail", :action=>"filter", :id=>filter_id)
|
2009-01-07 20:27:12 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def link_filter_delete(filter_id)
|
2009-02-05 16:55:24 +01:00
|
|
|
link_to(_('Delete'), :controller=>"webmail", :action=>"filter_delete", :id=>filter_id)
|
2009-01-07 20:27:12 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def page_navigation_webmail(pages)
|
|
|
|
nav = "<p class='paginator'><small>"
|
|
|
|
|
2009-09-01 14:23:05 +02:00
|
|
|
nav << "(#{pages.length} #{t :pages}) "
|
2009-01-07 20:27:12 +01:00
|
|
|
|
|
|
|
window_pages = pages.current.window.pages
|
|
|
|
nav << "..." unless window_pages[0].first?
|
|
|
|
for page in window_pages
|
|
|
|
if pages.current == page
|
|
|
|
nav << page.number.to_s << " "
|
|
|
|
else
|
2009-02-05 16:55:24 +01:00
|
|
|
nav << link_to(page.number, :controller=>"webmail", :action=>'messages', :page=>page.number) << " "
|
2009-01-07 20:27:12 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
nav << "..." unless window_pages[-1].last?
|
|
|
|
nav << " "
|
|
|
|
|
2009-09-01 14:23:05 +02:00
|
|
|
nav << link_to(t(:first), :controller=>"webmail", :action=>'messages', :page=>@pages.first.number) << " | " unless @pages.current.first?
|
|
|
|
nav << link_to(t(:prev), :controller=>"webmail", :action=>'messages', :page=>@pages.current.previous.number) << " | " if @pages.current.previous
|
|
|
|
nav << link_to(t(:next), :controller=>"webmail", :action=>'messages', :page=>@pages.current.next.number) << " | " if @pages.current.next
|
|
|
|
nav << link_to(t(:last), :controller=>"webmail", :action=>'messages', :page=>@pages.last.number) << " | " unless @pages.current.last?
|
2009-01-07 20:27:12 +01:00
|
|
|
|
|
|
|
nav << "</small></p>"
|
|
|
|
|
|
|
|
return nav
|
|
|
|
end
|
|
|
|
|
|
|
|
def parse_subject(subject)
|
|
|
|
begin
|
|
|
|
if mime_encoded?(subject)
|
|
|
|
if mime_decode(subject) == ''
|
|
|
|
_('(No subject)')
|
|
|
|
else
|
|
|
|
mime_decode(subject)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if from_qp(subject) == ''
|
|
|
|
_('(No subject)')
|
|
|
|
else
|
|
|
|
from_qp(subject)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
rescue Exception => ex
|
|
|
|
RAILS_DEFAULT_LOGGER.debug('Exception occured - #{ex}')
|
|
|
|
return ""
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def message_size(size)
|
|
|
|
if size / (1024*1024) > 0
|
|
|
|
return "#{(size / (1024*1024)).round} MB"
|
|
|
|
elsif size / 1024 > 0
|
|
|
|
return "#{(size / (1024)).round} KB"
|
|
|
|
else
|
|
|
|
return "#{size} B"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-02-07 23:14:00 +01:00
|
|
|
private
|
|
|
|
|
|
|
|
def empty_trash_link(folder_name)
|
2009-09-01 14:23:05 +02:00
|
|
|
link_to( "(#{t :empty})",
|
2009-02-07 23:14:00 +01:00
|
|
|
{ :controller => "webmail", :action => "empty", :params=>{"folder_name"=>folder_name}},
|
2011-03-29 02:59:28 +02:00
|
|
|
:confirm => t(:want_to_empty_trash_message))
|
2009-02-07 23:14:00 +01:00
|
|
|
end
|
|
|
|
end
|