some fix for locale,new polish locale

This commit is contained in:
Wojciech Todryk 2011-06-18 13:27:44 +02:00
parent 83088930fe
commit 7145c6486d
5 changed files with 206 additions and 122 deletions

23
README
View file

@ -2,7 +2,7 @@
Installation Guide Installation Guide
Requirements Requirements
* Ruby 1.8.7 * Ruby 1.8.7
* Rails 2.3.2 * Rails 2.3.2
Installation Installation
@ -14,18 +14,21 @@ Installation
LOCALCONFIG = { LOCALCONFIG = {
:imap_server => 'your.imap.server' :imap_server => 'your.imap.server'
} }
end end
3. Configure SMTP settings 3. Configure SMTP settings
# initializers/smtp_settings.rb # initializers/smtp_settings.rb
ActionMailer::Base.smtp_settings = { ActionMailer::Base.smtp_settings = {
:address => "mail.example.com.py", :address => "mail.example.com.py",
:port => 26, :port => 26,
:authentication => :plain, :authentication => :plain,
:enable_starttls_auto => true, :enable_starttls_auto => true,
:user_name => "emilio@example.com.py", :user_name => "emilio@example.com.py",
:password => "yourpass" :password => "yourpass"
} }
4 Use it 4. Prepare config/database.yml file (see config/database.yml.example)
5. Migrate database (rake db:migrate)
6. Use it

View file

@ -6,55 +6,55 @@ require 'ezcrypto'
class WebmailController < ApplicationController class WebmailController < ApplicationController
include ImapUtils include ImapUtils
# Administrative functions # Administrative functions
before_filter :login_required before_filter :login_required
before_filter :obtain_cookies_for_search_and_nav, :only=>[:messages] before_filter :obtain_cookies_for_search_and_nav, :only=>[:messages]
before_filter :load_imap_session before_filter :load_imap_session
after_filter :close_imap_session after_filter :close_imap_session
layout "public", :except => [:view_source, :download] layout "public", :except => [:view_source, :download]
# model :filter, :expression, :mail_pref, :customer # model :filter, :expression, :mail_pref, :customer
BOOL_ON = "on" BOOL_ON = "on"
def index def index
redirect_to(:action=>"messages") redirect_to(:action=>"messages")
end end
def error_connection def error_connection
end end
def refresh def refresh
@mailbox.reload @mailbox.reload
@folders = @mailbox.folders @folders = @mailbox.folders
redirect_to(:action=>'messages') redirect_to(:action=>'messages')
end end
def messages def messages
session["return_to"] = nil session["return_to"] = nil
@search_field = params['search_field'] @search_field = params['search_field']
@search_value = params['search_value'] @search_value = params['search_value']
# handle sorting - tsort session field contains last reverse or no for field # handle sorting - tsort session field contains last reverse or no for field
# and lsort - last sort field # and lsort - last sort field
if session['tsort'].nil? or session['lsort'].nil? if session['tsort'].nil? or session['lsort'].nil?
session['lsort'] = "DATE" session['lsort'] = "DATE"
session['tsort'] = {"DATE" => true, "FROM" => true, "SUBJECT" => true, "TO" => false} session['tsort'] = {"DATE" => true, "FROM" => true, "SUBJECT" => true, "TO" => false}
end end
case operation_param case operation_param
when t(:copy) # copy when t(:copy) # copy
msg_ids = [] msg_ids = []
messages_param.each { |msg_id, bool| messages_param.each { |msg_id, bool|
msg_ids << msg_id.to_i if bool == BOOL_ON and dst_folder != @folder_name } if messages_param msg_ids << msg_id.to_i if bool == BOOL_ON and dst_folder != @folder_name } if messages_param
folder.copy_multiple(msg_ids, dst_folder) if msg_ids.size > 0 folder.copy_multiple(msg_ids, dst_folder) if msg_ids.size > 0
when t(:move) # move when t(:move) # move
msg_ids = [] msg_ids = []
messages_param.each { |msg_id, bool| messages_param.each { |msg_id, bool|
msg_ids << msg_id.to_i if bool == BOOL_ON and dst_folder != @folder_name } if messages_param msg_ids << msg_id.to_i if bool == BOOL_ON and dst_folder != @folder_name } if messages_param
folder.move_multiple(msg_ids, dst_folder) if msg_ids.size > 0 folder.move_multiple(msg_ids, dst_folder) if msg_ids.size > 0
when t(:delete) # delete when t(:delete) # delete
msg_ids = [] msg_ids = []
messages_param.each { |msg_id, bool| msg_ids << msg_id.to_i if bool == BOOL_ON } if messages_param messages_param.each { |msg_id, bool| msg_ids << msg_id.to_i if bool == BOOL_ON } if messages_param
@ -67,10 +67,10 @@ class WebmailController < ApplicationController
session['lsort'] = sort_query = params["scc"] session['lsort'] = sort_query = params["scc"]
session['tsort'][sort_query] = (session['tsort'][sort_query]? false : true) session['tsort'][sort_query] = (session['tsort'][sort_query]? false : true)
@search_field, @search_value = session['search_field'], session['search_value'] @search_field, @search_value = session['search_field'], session['search_value']
when t(:search) # search when t(:search) # search
session['search_field'] = @search_field session['search_field'] = @search_field
session['search_value'] = @search_value session['search_value'] = @search_value
when t(:show_all) # search when t(:show_all) # search
session['search_field'] = @search_field = nil session['search_field'] = @search_field = nil
session['search_value'] = @search_value = nil session['search_value'] = @search_value = nil
else else
@ -78,7 +78,7 @@ class WebmailController < ApplicationController
@search_field = session['search_field'] @search_field = session['search_field']
@search_value = session['search_value'] @search_value = session['search_value']
end end
sort_query = session['lsort'] sort_query = session['lsort']
reverse_sort = session['tsort'][sort_query] reverse_sort = session['tsort'][sort_query]
query = ["ALL"] query = ["ALL"]
@ -89,42 +89,50 @@ class WebmailController < ApplicationController
@pages = Paginator.new self, 0, get_mail_prefs.wm_rows, @page @pages = Paginator.new self, 0, get_mail_prefs.wm_rows, @page
@messages = folder.messages_search([@search_field, @search_value], sort_query + (reverse_sort ? ' desc' : ' asc')) @messages = folder.messages_search([@search_field, @search_value], sort_query + (reverse_sort ? ' desc' : ' asc'))
else else
logger.info "total #{folder.total}"
logger.info "prews #{get_mail_prefs.wm_rows}"
logger.info "@page #{@page.inspect}"
logger.info "========================folder #{folder.messages.count}"
@pages = Paginator.new self, folder.total, get_mail_prefs.wm_rows, @page @pages = Paginator.new self, folder.total, get_mail_prefs.wm_rows, @page
@messages = folder.messages(@pages.current.first_item - 1, get_mail_prefs.wm_rows, sort_query + (reverse_sort ? ' desc' : ' asc')) @messages = folder.messages(@pages.current.first_item - 1, get_mail_prefs.wm_rows, sort_query + (reverse_sort ? ' desc' : ' asc'))
logger.info "========================folder after #{folder.messages.count}"
end end
end end
def delete def delete
@msg_id = msg_id_param.to_i @msg_id = msg_id_param.to_i
folder.delete(@msg_id) folder.delete(@msg_id)
redirect_to(:action=>"messages") redirect_to(:action=>"messages")
end end
def reply # not ready at all def reply # not ready at all
@msg_id = msg_id_param.to_i @msg_id = msg_id_param.to_i
@imapmail = folder.message(@msg_id) @imapmail = folder.message(@msg_id)
fb = @imapmail.full_body fb = @imapmail.full_body
@tmail = TMail::Mail.parse(fb) @tmail = TMail::Mail.parse(fb)
@mail = prepare_mail @mail = prepare_mail
@mail.reply(@tmail, fb, get_mail_prefs.mail_type) @mail.reply(@tmail, fb, get_mail_prefs.mail_type)
render :action => 'compose' render :action => 'compose'
end end
def forward def forward
@msg_id = msg_id_param.to_i @msg_id = msg_id_param.to_i
@imapmail = folder.message(@msg_id) @imapmail = folder.message(@msg_id)
fb = @imapmail.full_body fb = @imapmail.full_body
@tmail = TMail::Mail.parse(fb) @tmail = TMail::Mail.parse(fb)
@mail = prepare_mail @mail = prepare_mail
@mail.forward(@tmail, fb) @mail.forward(@tmail, fb)
render :action => 'compose' render :action => 'compose'
end end
def compose def compose
if @mail.nil? if @mail.nil?
operation = operation_param operation = operation_param
@ -133,13 +141,13 @@ class WebmailController < ApplicationController
encmail = @mail.send_mail encmail = @mail.send_mail
get_imap_session get_imap_session
@mailbox.message_sent(encmail) @mailbox.message_sent(encmail)
# delete temporary files (attachments) # delete temporary files (attachments)
@mail.delete_attachments() @mail.delete_attachments()
render :action => :mailsent render :action => :mailsent
elsif operation == t(:add) elsif operation == t(:add)
@mail = create_mail @mail = create_mail
if params['attachment'] if params['attachment']
attachment = CDF::Attachment.new(@mail) attachment = CDF::Attachment.new(@mail)
attachment.file = params['attachment'] attachment.file = params['attachment']
end end
@ -149,7 +157,7 @@ class WebmailController < ApplicationController
end end
end end
end end
def empty # empty trash folder (works for any one else :-)) def empty # empty trash folder (works for any one else :-))
folder.messages(0, -1).each{ |message| folder.messages(0, -1).each{ |message|
folder.delete(message) folder.delete(message)
@ -157,50 +165,50 @@ class WebmailController < ApplicationController
folder.expunge folder.expunge
redirect_to(:action=>"messages") redirect_to(:action=>"messages")
end end
def message def message
@msg_id = msg_id_param @msg_id = msg_id_param
@imapmail = folder.message(@msg_id) @imapmail = folder.message(@msg_id)
folder.mark_read(@imapmail.uid) if @imapmail.unread folder.mark_read(@imapmail.uid) if @imapmail.unread
@mail = TMail::Mail.parse(@imapmail.full_body) @mail = TMail::Mail.parse(@imapmail.full_body)
end end
def download def download
msg_id = msg_id_param msg_id = msg_id_param
imapmail = folder.message(msg_id) imapmail = folder.message(msg_id)
mail = TMail::Mail.parse(imapmail.full_body) mail = TMail::Mail.parse(imapmail.full_body)
if mail.multipart? if mail.multipart?
get_parts(mail).each { |part| get_parts(mail).each { |part|
return send_part(part) if part.header and part.header['content-type']['name'] == params['ctype'] return send_part(part) if part.header and part.header['content-type']['name'] == params['ctype']
} }
render("webmail/noattachment") render("webmail/noattachment")
else else
render("webmail/noattachment") render("webmail/noattachment")
end end
end end
def prefs def prefs
@customer = Customer.find(logged_customer) @customer = Customer.find(logged_customer)
@mailpref = MailPref.find_or_create_by_customer_id logged_customer @mailpref = MailPref.find_or_create_by_customer_id logged_customer
if params['op'] == _('Save') if params['op'] == _('Save')
if params['customer'] if params['customer']
@customer.fname = params['customer']['fname'] @customer.fname = params['customer']['fname']
@customer.lname = params['customer']['lname'] @customer.lname = params['customer']['lname']
@customer.save @customer.save
end end
@mailpref.attributes = params["mailpref"] @mailpref.attributes = params["mailpref"]
@mailpref.save @mailpref.save
session["wmimapseskey"] = nil session["wmimapseskey"] = nil
redirect_to(:action=>"messages") redirect_to(:action=>"messages")
end end
end end
# Message filters management # Message filters management
def filters def filters
end end
def filter def filter
if params['op'] if params['op']
@filter = Filter.new(params['filter']) @filter = Filter.new(params['filter'])
@ -209,7 +217,7 @@ class WebmailController < ApplicationController
case params['op'] case params['op']
when _('Add') when _('Add')
@filter.expressions << Expression.new @filter.expressions << Expression.new
when _('Save') when _('Save')
if params['filter']['id'] and params['filter']['id'] != "" if params['filter']['id'] and params['filter']['id'] != ""
@sf = Filter.find(params['filter']['id']) @sf = Filter.find(params['filter']['id'])
@sf.name, @sf.destination_folder = @filter.name, @filter.destination_folder @sf.name, @sf.destination_folder = @filter.name, @filter.destination_folder
@ -228,11 +236,11 @@ class WebmailController < ApplicationController
@expressions = @filter.expressions @expressions = @filter.expressions
else else
@filter = Filter.find(params["id"]) if params["id"] @filter = Filter.find(params["id"]) if params["id"]
@expressions = @filter.expressions @expressions = @filter.expressions
end end
@destfolders = get_to_folders @destfolders = get_to_folders
end end
def filter_delete def filter_delete
Filter.delete(params["id"]) Filter.delete(params["id"])
# reindex other filters # reindex other filters
@ -246,7 +254,7 @@ class WebmailController < ApplicationController
@user.serialize_to_file @user.serialize_to_file
redirect_to :action=>"filters" redirect_to :action=>"filters"
end end
def filter_up def filter_up
filt = @user.filters.find(params['id']) filt = @user.filters.find(params['id'])
ufilt = @user.filters.find_all("order_num = #{filt.order_num - 1}").first ufilt = @user.filters.find_all("order_num = #{filt.order_num - 1}").first
@ -257,7 +265,7 @@ class WebmailController < ApplicationController
@user.serialize_to_file @user.serialize_to_file
redirect_to :action=>"filters" redirect_to :action=>"filters"
end end
def filter_down def filter_down
filt = Filter.find(params["id"]) filt = Filter.find(params["id"])
dfilt = @user.filters[filt.order_num] dfilt = @user.filters[filt.order_num]
@ -268,7 +276,7 @@ class WebmailController < ApplicationController
@user.serialize_to_file @user.serialize_to_file
redirect_to :action=>"filters" redirect_to :action=>"filters"
end end
def filter_add def filter_add
@filter = Filter.new @filter = Filter.new
@filter.expressions << Expression.new @filter.expressions << Expression.new
@ -277,58 +285,58 @@ class WebmailController < ApplicationController
render "filter" render "filter"
end end
# end of filters # end of filters
def view_source def view_source
@msg_id = msg_id_param.to_i @msg_id = msg_id_param.to_i
@imapmail = folder.message(@msg_id) @imapmail = folder.message(@msg_id)
@msg_source = CGI.escapeHTML(@imapmail.full_body).gsub("\n", "<br/>") @msg_source = CGI.escapeHTML(@imapmail.full_body).gsub("\n", "<br/>")
end end
def auto_complete_for_mail_to def auto_complete_for_mail_to
auto_complete_responder_for_contacts params[:mail][:to] auto_complete_responder_for_contacts params[:mail][:to]
end end
def auto_complete_for_mail_cc def auto_complete_for_mail_cc
auto_complete_responder_for_contacts params[:mail][:cc] auto_complete_responder_for_contacts params[:mail][:cc]
end end
def auto_complete_for_mail_bcc def auto_complete_for_mail_bcc
auto_complete_responder_for_contacts params[:mail][:bcc] auto_complete_responder_for_contacts params[:mail][:bcc]
end end
private private
def auto_complete_responder_for_contacts(value) def auto_complete_responder_for_contacts(value)
# first split by "," and take last name # first split by "," and take last name
searchName = value.split(',').last.strip searchName = value.split(',').last.strip
# if there are 2 names search by them # if there are 2 names search by them
if searchName.split.size > 1 if searchName.split.size > 1
fname, lname = searchName.split.first, searchName.split.last fname, lname = searchName.split.first, searchName.split.last
conditions = ['customer_id = ? and LOWER(fname) LIKE ? and LOWER(lname) like ?', logged_customer, fname.downcase + '%', lname.downcase + '%'] conditions = ['customer_id = ? and LOWER(fname) LIKE ? and LOWER(lname) like ?', logged_customer, fname.downcase + '%', lname.downcase + '%']
else else
conditions = ['customer_id = ? and LOWER(fname) LIKE ?', logged_customer, searchName.downcase + '%'] conditions = ['customer_id = ? and LOWER(fname) LIKE ?', logged_customer, searchName.downcase + '%']
end end
@contacts = Contact.find(:all, :conditions => conditions, :order => 'fname ASC',:limit => 8) @contacts = Contact.find(:all, :conditions => conditions, :order => 'fname ASC',:limit => 8)
render :partial => 'contacts' render :partial => 'contacts'
end end
protected protected
def additional_scripts() def additional_scripts()
@additional_css = ["webmail/webmail"] @additional_css = ["webmail/webmail"]
@additional_js = ["webmail"] @additional_js = ["webmail"]
end end
private private
def get_to_folders def get_to_folders
res = Array.new res = Array.new
@folders.each{|f| res << f unless f.name == CDF::CONFIG[:mail_sent] or f.name == CDF::CONFIG[:mail_inbox] } @folders.each{|f| res << f unless f.name == CDF::CONFIG[:mail_sent] or f.name == CDF::CONFIG[:mail_inbox] }
res res
end end
def create_mail def create_mail
m = CDF::Mail.new(user.mail_temporary_path) m = CDF::Mail.new(user.mail_temporary_path)
if params["mail"] if params["mail"]
@ -343,24 +351,24 @@ class WebmailController < ApplicationController
end end
else else
m.from, m.content_type = user.friendlly_local_email, get_mail_prefs.mail_type m.from, m.content_type = user.friendlly_local_email, get_mail_prefs.mail_type
end end
m.customer_id = logged_customer m.customer_id = logged_customer
m m
end end
def prepare_mail def prepare_mail
m = CDF::Mail.new(user.mail_temporary_path) m = CDF::Mail.new(user.mail_temporary_path)
m.from, m.content_type = user.friendlly_local_email, get_mail_prefs.mail_type m.from, m.content_type = user.friendlly_local_email, get_mail_prefs.mail_type
m m
end end
def send_part(part) def send_part(part)
if part.content_type == "text/html" if part.content_type == "text/html"
disposition = "inline" disposition = "inline"
elsif part.content_type.include?("image/") elsif part.content_type.include?("image/")
disposition = "inline" disposition = "inline"
else else
disposition = "attachment" disposition = "attachment"
end end
headers['Content-Length'] = part.body.size headers['Content-Length'] = part.body.size
@ -369,48 +377,48 @@ class WebmailController < ApplicationController
headers['Content-Disposition'] = disposition << %(; filename="#{part.header['content-type']['name']}") headers['Content-Disposition'] = disposition << %(; filename="#{part.header['content-type']['name']}")
render :text => part.body render :text => part.body
end end
def get_parts(mail) def get_parts(mail)
parts = Array.new parts = Array.new
parts << mail parts << mail
mail.parts.each { |part| mail.parts.each { |part|
if part.multipart? if part.multipart?
parts = parts.concat(get_parts(part)) parts = parts.concat(get_parts(part))
elsif part.content_type and part.content_type.include?("rfc822") elsif part.content_type and part.content_type.include?("rfc822")
parts = parts.concat(get_parts(TMail::Mail.parse(part.body))) << part parts = parts.concat(get_parts(TMail::Mail.parse(part.body))) << part
else else
parts << part parts << part
end end
} }
parts parts
end end
def obtain_cookies_for_search_and_nav def obtain_cookies_for_search_and_nav
@srch_class = ((cookies['_wmlms'] and cookies['_wmlms'] == 'closed') ? 'closed' : 'open') @srch_class = ((cookies['_wmlms'] and cookies['_wmlms'] == 'closed') ? 'closed' : 'open')
@srch_img_src = ((cookies['_wmlms'] and cookies['_wmlms'] == 'closed') ? 'closed' : 'opened') @srch_img_src = ((cookies['_wmlms'] and cookies['_wmlms'] == 'closed') ? 'closed' : 'opened')
@ops_class = ((cookies['_wmlmo'] and cookies['_wmlmo'] == 'closed') ? 'closed' : 'open') @ops_class = ((cookies['_wmlmo'] and cookies['_wmlmo'] == 'closed') ? 'closed' : 'open')
@ops_img_src = ((cookies['_wmlmo'] and cookies['_wmlmo'] == 'closed') ? 'closed' : 'opened') @ops_img_src = ((cookies['_wmlmo'] and cookies['_wmlmo'] == 'closed') ? 'closed' : 'opened')
end end
################################################################### ###################################################################
### Some fixed parameters and session variables ### Some fixed parameters and session variables
################################################################### ###################################################################
def folder def folder
@folders[@folder_name] @folders[@folder_name]
end end
def msg_id_param def msg_id_param
params["msg_id"] params["msg_id"]
end end
def messages_param def messages_param
params["messages"] params["messages"]
end end
def dst_folder def dst_folder
params["cpdest"] params["cpdest"]
end end
def operation_param def operation_param
params["op"] params["op"]
end end

View file

@ -4,7 +4,7 @@
# (Use only when you can't set environment variables through your web/app server) # (Use only when you can't set environment variables through your web/app server)
# ENV['RAILS_ENV'] = 'production' # ENV['RAILS_ENV'] = 'production'
RAILS_GEM_VERSION = '2.3.11' unless defined? RAILS_GEM_VERSION #RAILS_GEM_VERSION = '2.3.11' unless defined? RAILS_GEM_VERSION
# Bootstrap the Rails environment, frameworks, and default configuration # Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot') require File.join(File.dirname(__FILE__), 'boot')
@ -34,7 +34,7 @@ Rails::Initializer.run do |config|
# Make Active Record use UTC-base instead of local time # Make Active Record use UTC-base instead of local time
config.active_record.default_timezone = :utc config.active_record.default_timezone = :utc
config.i18n.default_locale = "es-ES" #config.i18n.default_locale = "en"
# Use Active Record's schema dumper instead of SQL when creating the test database # Use Active Record's schema dumper instead of SQL when creating the test database
# (enables use of different database adapters for development and test environments) # (enables use of different database adapters for development and test environments)
@ -65,6 +65,9 @@ rescue LoadError
STDERR.puts 'WARNING: config/site.rb not found, using default settings from ' + default_config_path STDERR.puts 'WARNING: config/site.rb not found, using default settings from ' + default_config_path
end end
#if CONFIG[:locale] is nil then I18n.default_locale will be used
I18n.default_locale = CDF::CONFIG[:locale]
require 'tmail_patch' require 'tmail_patch'
$KCODE = 'u' $KCODE = 'u'
require 'jcode' require 'jcode'

70
config/locales/pl-PL.yml Normal file
View file

@ -0,0 +1,70 @@
pl-PL:
mailr: Mailr
email: E-mail
password: Hasło
log_in: Zaloguj
wrong_email_or_password: Podano nieprawidłowy login lub hasło.
mailbox: Poczta
folders: Foldery
folder: Folder
empty: Pusty
logout: Wyloguj
compose: Nowa wiadomość
preferences: Ustawienia
filters: Filtry
contacts: Kontakty
search: Szukaj
search_txt: Szukaj w polu wiadomości
refresh: Odśwież
operations: Akcje
operations_txt: Akcje na zaznaczonych wiadomościach
delete: Usuń
copy: Skopiuj
move: Przenieś
mark_read: Zaznacz jako przeczytane
mark_unread: Zaznacz jako nieprzeczytane
destination_txt: Miejsce docelowe dla akcji
for: ciągu znaków
to: Do
subject: Temat
date: Data
size: Rozmiar
from: Od
show_all: Pokaż wszystkie
pages: Strony
first: Pierwsza
prev: Poprzednia
next: Następna
last: Ostatnia
back_to_list: Powrót do listy
back_to_message: Powrót do wiadomości
reply: Odpowiedz
forward: Przekaż
delete: Usuń
view_source: Pokaż źródło
add_filter: Dodaj filtr
cc: Cc
bcc: Bcc
send: Wyslij
choose_address: Wybierz adres z kontaktów
compose_txt: Utwórz nową wiadomość
attachment: Załącznik
add: Dodaj
first_name: Imię
last_name: Nazwisko
send_type: Format wiadomości wychodzącej
messages_per_page: Ilość wiadomości na stronie
check_external_mail: Check external mail?
check_external_mail_txt: Note that by selecting this option webmail system will try to log you using your original email on a local server.
save: Zapisz
cancel: Anuluj
add_one_contact: Dodaj jeden kontakt
add_multiple: Dodaj wiele
name: Nazwa
add_folder: Dodaj folder
total_messages: Total messages
unseen: Unseen
add_edit_folder: Zarządzanie folderami
user_logged_out: Użytkownik został wylogowany
please_login: Logowanie
add_to_contacts: Dodaj do kontaktów

View file

@ -3,7 +3,7 @@ module Mail2Screen
def mail2html(mail, msg_id) def mail2html(mail, msg_id)
footer = "" footer = ""
parsed_body = create_body(mail, msg_id, footer) parsed_body = create_body(mail, msg_id, footer)
ret = "<table class='messageheader' border='0' cellpadding='0' cellspacing='0' >\n" ret = "<table class='messageheader' border='0' cellpadding='0' cellspacing='0' >\n"
ret << "<tbody>\n" ret << "<tbody>\n"
ret << " <tr><td class='label' nowrap='nowrap'>#{t :from}:</td><td>#{address(mail.from_addrs, @msg_id)}</td></tr>\n" ret << " <tr><td class='label' nowrap='nowrap'>#{t :from}:</td><td>#{address(mail.from_addrs, @msg_id)}</td></tr>\n"
@ -14,7 +14,7 @@ module Mail2Screen
if @mail.bcc_addrs if @mail.bcc_addrs
ret << " <tr><td class='label' nowrap='nowrap'>#{t :bcc}:</td><td>#{address(mail.bcc_addrs, @msg_id)}</td></tr>\n" ret << " <tr><td class='label' nowrap='nowrap'>#{t :bcc}:</td><td>#{address(mail.bcc_addrs, @msg_id)}</td></tr>\n"
end end
ret << " <tr><td class='label' nowrap='nowrap'>#{t :subject}:</td><td>#{h(mime_encoded?(mail.subject) ? mime_decode(mail.subject) : mail.subject)}</dd>\n" ret << " <tr><td class='label' nowrap='nowrap'>#{t :subject}:</td><td>#{h(mime_encoded?(mail.subject) ? mime_decode(mail.subject) : mail.subject)}</dd>\n"
ret << " <tr><td class='label' nowrap='nowrap'>#{t :date}:</td><td>#{h message_date(mail.date)}</td></tr>\n" ret << " <tr><td class='label' nowrap='nowrap'>#{t :date}:</td><td>#{h message_date(mail.date)}</td></tr>\n"
if footer != '' if footer != ''
ret << " <tr><td class='label' nowrap='nowrap'>#{image_tag('attachment.png')}</td><td>#{footer}</td></tr>\n" ret << " <tr><td class='label' nowrap='nowrap'>#{image_tag('attachment.png')}</td><td>#{footer}</td></tr>\n"
@ -26,7 +26,7 @@ module Mail2Screen
ret << parsed_body ret << parsed_body
ret << "</div>\n" ret << "</div>\n"
end end
def create_body(mail, msg_id, footer) def create_body(mail, msg_id, footer)
charset = (mail.charset.nil? ? 'iso-8859-1' : mail.charset) charset = (mail.charset.nil? ? 'iso-8859-1' : mail.charset)
if mail.multipart? if mail.multipart?
@ -38,7 +38,7 @@ module Mail2Screen
ret << create_body(part, msg_id, footer) ret << create_body(part, msg_id, footer)
end end
} }
return ret return ret
else else
mail.parts.each { |part| mail.parts.each { |part|
if part.multipart? if part.multipart?
@ -55,13 +55,13 @@ module Mail2Screen
elsif part.content_type.include?("image/") elsif part.content_type.include?("image/")
ctype = part.header['content-type'] ctype = part.header['content-type']
ret << add_image(ctype, msg_id) ret << add_image(ctype, msg_id)
elsif part.content_type.include?("message/rfc822") elsif part.content_type.include?("message/rfc822")
ret << "<br/>#{_('Follows attached message')}:<hr/>" << mail2html(TMail::Mail.parse(part.body), msg_id) ret << "<br/>#{_('Follows attached message')}:<hr/>" << mail2html(TMail::Mail.parse(part.body), msg_id)
end end
end end
} }
return ret return ret
end end
else else
ret = "" ret = ""
if mail.content_type == "text/plain" or mail.content_type.nil? if mail.content_type == "text/plain" or mail.content_type.nil?
@ -72,24 +72,24 @@ module Mail2Screen
return ret return ret
end end
end end
def add_text(part, encoding, charset) def add_text(part, encoding, charset)
CGI.escapeHTML(decode_part_text("#{part}", encoding, charset)).gsub(/\r\n/,"<br/>").gsub(/\r/, "<br/>").gsub(/\n/,"<br/>") CGI.escapeHTML(decode_part_text("#{part}", encoding, charset)).gsub(/\r\n/,"<br/>").gsub(/\r/, "<br/>").gsub(/\n/,"<br/>")
end end
def add_html(part, encoding, charset) def add_html(part, encoding, charset)
strip_html(decode_part_text("#{part}", encoding, charset)) strip_html(decode_part_text("#{part}", encoding, charset))
end end
def decode_part_text(part_str, encoding, charset) def decode_part_text(part_str, encoding, charset)
# Parse mail # Parse mail
header, text = "", "" header, text = "", ""
# Get header and body # Get header and body
#Content-type: text/plain; charset="ISO-8859-1" #Content-type: text/plain; charset="ISO-8859-1"
#Content-transfer-encoding: quoted-printable #Content-transfer-encoding: quoted-printable
isBody = false isBody = false
part_str.each_line { |line| part_str.each_line { |line|
if isBody if isBody
text << line text << line
else else
@ -105,7 +105,7 @@ module Mail2Screen
ret = from_qp(text) ret = from_qp(text)
elsif not(encoding.nil?) and encoding.downcase == "base64" elsif not(encoding.nil?) and encoding.downcase == "base64"
ret = "#{text.unpack("m")}" ret = "#{text.unpack("m")}"
else else
ret = text ret = text
end end
# manage charset # manage charset
@ -118,9 +118,9 @@ module Mail2Screen
RAILS_DEFAULT_LOGGER.debug("Exception occured #{ex}\n#{ex.backtrace.join('\n')}") RAILS_DEFAULT_LOGGER.debug("Exception occured #{ex}\n#{ex.backtrace.join('\n')}")
return ret return ret
end end
end end
end end
def add_attachment(content_type, msg_id) def add_attachment(content_type, msg_id)
filename = (content_type.nil? or content_type['name'].nil? ? "" : content_type['name']) filename = (content_type.nil? or content_type['name'].nil? ? "" : content_type['name'])
if filename == "" if filename == ""
@ -129,28 +129,28 @@ module Mail2Screen
"<span class='attachment'>&nbsp;<a href='/webmail/download?msg_id=#{msg_id}&ctype=" << CGI.escape(filename) << "'>#{filename}</a></span>" "<span class='attachment'>&nbsp;<a href='/webmail/download?msg_id=#{msg_id}&ctype=" << CGI.escape(filename) << "'>#{filename}</a></span>"
end end
end end
def add_image(content_type, msg_id) def add_image(content_type, msg_id)
filename = (content_type.nil? or content_type['name'].nil? ? "" : content_type['name']) filename = (content_type.nil? or content_type['name'].nil? ? "" : content_type['name'])
"<hr/><span class='attachment'><br/><img src='/webmail/download?msg_id=#{msg_id}&ctype=" << CGI.escape(filename) << "' alt='#{filename}'/></span>" "<hr/><span class='attachment'><br/><img src='/webmail/download?msg_id=#{msg_id}&ctype=" << CGI.escape(filename) << "' alt='#{filename}'/></span>"
end end
def friendly_address(addr) def friendly_address(addr)
addr.kind_of?(Net::IMAP::Address) ? ((addr.name.nil? or addr.name.strip == "") ? "#{addr.mailbox}@#{addr.host}" : "#{(mime_encoded?(addr.name.strip) ? mime_decode(addr.name.to_s): addr.name.to_s)}<#{addr.mailbox}@#{addr.host}>") : ((addr.name.nil? or addr.name.strip == "") ? "#{addr.spec}" : "#{(mime_encoded?(addr.name.strip) ? mime_decode(addr.name.to_s): addr.name.to_s)}<#{addr.spec}>") addr.kind_of?(Net::IMAP::Address) ? ((addr.name.nil? or addr.name.strip == "") ? "#{addr.mailbox}@#{addr.host}" : "#{(mime_encoded?(addr.name.strip) ? mime_decode(addr.name.to_s): addr.name.to_s)}<#{addr.mailbox}@#{addr.host}>") : ((addr.name.nil? or addr.name.strip == "") ? "#{addr.spec}" : "#{(mime_encoded?(addr.name.strip) ? mime_decode(addr.name.to_s): addr.name.to_s)}<#{addr.spec}>")
end end
def friendly_address_or_name(addr) def friendly_address_or_name(addr)
if addr.kind_of?(Net::IMAP::Address) if addr.kind_of?(Net::IMAP::Address)
((addr.name.nil? or addr.name.to_s == "") ? "#{addr.mailbox}@#{addr.host}" : (mime_encoded?(addr.name.to_s) ? mime_decode(addr.name.to_s): addr.name.to_s)) ((addr.name.nil? or addr.name.to_s == "") ? "#{addr.mailbox}@#{addr.host}" : (mime_encoded?(addr.name.to_s) ? mime_decode(addr.name.to_s): addr.name.to_s))
else else
((addr.nil? or addr.to_s == "") ? "#{addr.to_s}" : (mime_encoded?(addr.to_s) ? mime_decode(addr.to_s): addr.to_s)) ((addr.nil? or addr.to_s == "") ? "#{addr.to_s}" : (mime_encoded?(addr.to_s) ? mime_decode(addr.to_s): addr.to_s))
end end
end end
def add_to_contact(addr, msg_id) def add_to_contact(addr, msg_id)
"&nbsp;<a href='/contact/add_from_mail?cstr=#{CGI.escape(friendly_address(addr))}&retmsg=#{msg_id}'>Agregar a contactos</a>" "&nbsp;<a href='/contact/add_from_mail?cstr=#{CGI.escape(friendly_address(addr))}&retmsg=#{msg_id}'>"+t(:add_to_contacts)
end end
def short_address(addresses) def short_address(addresses)
ret = "" ret = ""
addresses.each { |addr| #split(/,\s*/) addresses.each { |addr| #split(/,\s*/)
@ -159,7 +159,7 @@ module Mail2Screen
} unless addresses.nil? } unless addresses.nil?
ret ret
end end
def address(addresses, msg_id) def address(addresses, msg_id)
ret = "" ret = ""
addresses.each { |addr| #split(/,\s*/) addresses.each { |addr| #split(/,\s*/)