devel
This commit is contained in:
parent
cf56c7555a
commit
0ec83db287
|
@ -6,55 +6,55 @@ require 'ezcrypto'
|
|||
|
||||
class WebmailController < ApplicationController
|
||||
include ImapUtils
|
||||
|
||||
|
||||
# Administrative functions
|
||||
before_filter :login_required
|
||||
before_filter :obtain_cookies_for_search_and_nav, :only=>[:messages]
|
||||
before_filter :load_imap_session
|
||||
after_filter :close_imap_session
|
||||
|
||||
|
||||
layout "public", :except => [:view_source, :download]
|
||||
|
||||
|
||||
# model :filter, :expression, :mail_pref, :customer
|
||||
|
||||
|
||||
BOOL_ON = "on"
|
||||
|
||||
|
||||
def index
|
||||
redirect_to(:action=>"messages")
|
||||
end
|
||||
|
||||
|
||||
def error_connection
|
||||
end
|
||||
|
||||
|
||||
def refresh
|
||||
@mailbox.reload
|
||||
@folders = @mailbox.folders
|
||||
redirect_to(:action=>'messages')
|
||||
end
|
||||
|
||||
|
||||
def messages
|
||||
session["return_to"] = nil
|
||||
@search_field = params['search_field']
|
||||
@search_value = params['search_value']
|
||||
|
||||
|
||||
# handle sorting - tsort session field contains last reverse or no for field
|
||||
# and lsort - last sort field
|
||||
if session['tsort'].nil? or session['lsort'].nil?
|
||||
session['lsort'] = "DATE"
|
||||
session['tsort'] = {"DATE" => true, "FROM" => true, "SUBJECT" => true, "TO" => false}
|
||||
end
|
||||
|
||||
|
||||
case operation_param
|
||||
when t(:copy) # copy
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
msg_ids = []
|
||||
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['tsort'][sort_query] = (session['tsort'][sort_query]? false : true)
|
||||
@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_value'] = @search_value
|
||||
when t(:show_all) # search
|
||||
when t(:show_all) # search
|
||||
session['search_field'] = @search_field = nil
|
||||
session['search_value'] = @search_value = nil
|
||||
else
|
||||
|
@ -78,7 +78,7 @@ class WebmailController < ApplicationController
|
|||
@search_field = session['search_field']
|
||||
@search_value = session['search_value']
|
||||
end
|
||||
|
||||
|
||||
sort_query = session['lsort']
|
||||
reverse_sort = session['tsort'][sort_query]
|
||||
query = ["ALL"]
|
||||
|
@ -89,50 +89,42 @@ class WebmailController < ApplicationController
|
|||
@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'))
|
||||
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
|
||||
@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
|
||||
|
||||
|
||||
def delete
|
||||
@msg_id = msg_id_param.to_i
|
||||
folder.delete(@msg_id)
|
||||
redirect_to(:action=>"messages")
|
||||
end
|
||||
|
||||
|
||||
def reply # not ready at all
|
||||
@msg_id = msg_id_param.to_i
|
||||
@imapmail = folder.message(@msg_id)
|
||||
fb = @imapmail.full_body
|
||||
@tmail = TMail::Mail.parse(fb)
|
||||
|
||||
@tmail = TMail::Mail.parse(fb)
|
||||
|
||||
@mail = prepare_mail
|
||||
@mail.reply(@tmail, fb, get_mail_prefs.mail_type)
|
||||
|
||||
|
||||
render :action => 'compose'
|
||||
end
|
||||
|
||||
|
||||
def forward
|
||||
@msg_id = msg_id_param.to_i
|
||||
@imapmail = folder.message(@msg_id)
|
||||
fb = @imapmail.full_body
|
||||
@tmail = TMail::Mail.parse(fb)
|
||||
|
||||
@tmail = TMail::Mail.parse(fb)
|
||||
|
||||
@mail = prepare_mail
|
||||
@mail.forward(@tmail, fb)
|
||||
|
||||
|
||||
render :action => 'compose'
|
||||
end
|
||||
|
||||
|
||||
def compose
|
||||
if @mail.nil?
|
||||
operation = operation_param
|
||||
|
@ -141,13 +133,13 @@ class WebmailController < ApplicationController
|
|||
encmail = @mail.send_mail
|
||||
get_imap_session
|
||||
@mailbox.message_sent(encmail)
|
||||
|
||||
|
||||
# delete temporary files (attachments)
|
||||
@mail.delete_attachments()
|
||||
render :action => :mailsent
|
||||
elsif operation == t(:add)
|
||||
@mail = create_mail
|
||||
if params['attachment']
|
||||
if params['attachment']
|
||||
attachment = CDF::Attachment.new(@mail)
|
||||
attachment.file = params['attachment']
|
||||
end
|
||||
|
@ -157,7 +149,7 @@ class WebmailController < ApplicationController
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def empty # empty trash folder (works for any one else :-))
|
||||
folder.messages(0, -1).each{ |message|
|
||||
folder.delete(message)
|
||||
|
@ -165,50 +157,50 @@ class WebmailController < ApplicationController
|
|||
folder.expunge
|
||||
redirect_to(:action=>"messages")
|
||||
end
|
||||
|
||||
|
||||
def message
|
||||
@msg_id = msg_id_param
|
||||
@imapmail = folder.message(@msg_id)
|
||||
folder.mark_read(@imapmail.uid) if @imapmail.unread
|
||||
@mail = TMail::Mail.parse(@imapmail.full_body)
|
||||
end
|
||||
|
||||
|
||||
def download
|
||||
msg_id = msg_id_param
|
||||
imapmail = folder.message(msg_id)
|
||||
mail = TMail::Mail.parse(imapmail.full_body)
|
||||
|
||||
mail = TMail::Mail.parse(imapmail.full_body)
|
||||
|
||||
if mail.multipart?
|
||||
get_parts(mail).each { |part|
|
||||
return send_part(part) if part.header and part.header['content-type']['name'] == params['ctype']
|
||||
get_parts(mail).each { |part|
|
||||
return send_part(part) if part.header and part.header['content-type']['name'] == params['ctype']
|
||||
}
|
||||
render("webmail/noattachment")
|
||||
else
|
||||
else
|
||||
render("webmail/noattachment")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def prefs
|
||||
@customer = Customer.find(logged_customer)
|
||||
@mailpref = MailPref.find_or_create_by_customer_id logged_customer
|
||||
|
||||
|
||||
if params['op'] == _('Save')
|
||||
if params['customer']
|
||||
@customer.fname = params['customer']['fname']
|
||||
@customer.lname = params['customer']['lname']
|
||||
@customer.save
|
||||
end
|
||||
@mailpref.attributes = params["mailpref"]
|
||||
@mailpref.attributes = params["mailpref"]
|
||||
@mailpref.save
|
||||
session["wmimapseskey"] = nil
|
||||
redirect_to(:action=>"messages")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Message filters management
|
||||
def filters
|
||||
end
|
||||
|
||||
|
||||
def filter
|
||||
if params['op']
|
||||
@filter = Filter.new(params['filter'])
|
||||
|
@ -217,7 +209,7 @@ class WebmailController < ApplicationController
|
|||
case params['op']
|
||||
when _('Add')
|
||||
@filter.expressions << Expression.new
|
||||
when _('Save')
|
||||
when _('Save')
|
||||
if params['filter']['id'] and params['filter']['id'] != ""
|
||||
@sf = Filter.find(params['filter']['id'])
|
||||
@sf.name, @sf.destination_folder = @filter.name, @filter.destination_folder
|
||||
|
@ -236,11 +228,11 @@ class WebmailController < ApplicationController
|
|||
@expressions = @filter.expressions
|
||||
else
|
||||
@filter = Filter.find(params["id"]) if params["id"]
|
||||
@expressions = @filter.expressions
|
||||
@expressions = @filter.expressions
|
||||
end
|
||||
@destfolders = get_to_folders
|
||||
end
|
||||
|
||||
|
||||
def filter_delete
|
||||
Filter.delete(params["id"])
|
||||
# reindex other filters
|
||||
|
@ -254,7 +246,7 @@ class WebmailController < ApplicationController
|
|||
@user.serialize_to_file
|
||||
redirect_to :action=>"filters"
|
||||
end
|
||||
|
||||
|
||||
def filter_up
|
||||
filt = @user.filters.find(params['id'])
|
||||
ufilt = @user.filters.find_all("order_num = #{filt.order_num - 1}").first
|
||||
|
@ -265,7 +257,7 @@ class WebmailController < ApplicationController
|
|||
@user.serialize_to_file
|
||||
redirect_to :action=>"filters"
|
||||
end
|
||||
|
||||
|
||||
def filter_down
|
||||
filt = Filter.find(params["id"])
|
||||
dfilt = @user.filters[filt.order_num]
|
||||
|
@ -276,7 +268,7 @@ class WebmailController < ApplicationController
|
|||
@user.serialize_to_file
|
||||
redirect_to :action=>"filters"
|
||||
end
|
||||
|
||||
|
||||
def filter_add
|
||||
@filter = Filter.new
|
||||
@filter.expressions << Expression.new
|
||||
|
@ -285,58 +277,58 @@ class WebmailController < ApplicationController
|
|||
render "filter"
|
||||
end
|
||||
# end of filters
|
||||
|
||||
|
||||
def view_source
|
||||
@msg_id = msg_id_param.to_i
|
||||
@imapmail = folder.message(@msg_id)
|
||||
@msg_source = CGI.escapeHTML(@imapmail.full_body).gsub("\n", "<br/>")
|
||||
end
|
||||
|
||||
|
||||
def auto_complete_for_mail_to
|
||||
auto_complete_responder_for_contacts params[:mail][:to]
|
||||
end
|
||||
|
||||
|
||||
def auto_complete_for_mail_cc
|
||||
auto_complete_responder_for_contacts params[:mail][:cc]
|
||||
end
|
||||
|
||||
|
||||
def auto_complete_for_mail_bcc
|
||||
auto_complete_responder_for_contacts params[:mail][:bcc]
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
||||
def auto_complete_responder_for_contacts(value)
|
||||
# first split by "," and take last name
|
||||
searchName = value.split(',').last.strip
|
||||
|
||||
|
||||
# if there are 2 names search by them
|
||||
if searchName.split.size > 1
|
||||
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 + '%']
|
||||
else
|
||||
conditions = ['customer_id = ? and LOWER(fname) LIKE ?', logged_customer, searchName.downcase + '%']
|
||||
end
|
||||
end
|
||||
@contacts = Contact.find(:all, :conditions => conditions, :order => 'fname ASC',:limit => 8)
|
||||
render :partial => 'contacts'
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
|
||||
|
||||
def additional_scripts()
|
||||
@additional_css = ["webmail/webmail"]
|
||||
@additional_js = ["webmail"]
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
||||
def get_to_folders
|
||||
res = Array.new
|
||||
@folders.each{|f| res << f unless f.name == CDF::CONFIG[:mail_sent] or f.name == CDF::CONFIG[:mail_inbox] }
|
||||
res
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
def create_mail
|
||||
m = CDF::Mail.new(user.mail_temporary_path)
|
||||
if params["mail"]
|
||||
|
@ -351,24 +343,24 @@ class WebmailController < ApplicationController
|
|||
end
|
||||
else
|
||||
m.from, m.content_type = user.friendlly_local_email, get_mail_prefs.mail_type
|
||||
end
|
||||
end
|
||||
m.customer_id = logged_customer
|
||||
m
|
||||
end
|
||||
|
||||
|
||||
def prepare_mail
|
||||
m = CDF::Mail.new(user.mail_temporary_path)
|
||||
m.from, m.content_type = user.friendlly_local_email, get_mail_prefs.mail_type
|
||||
m
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
def send_part(part)
|
||||
if part.content_type == "text/html"
|
||||
disposition = "inline"
|
||||
elsif part.content_type.include?("image/")
|
||||
disposition = "inline"
|
||||
else
|
||||
disposition = "inline"
|
||||
else
|
||||
disposition = "attachment"
|
||||
end
|
||||
headers['Content-Length'] = part.body.size
|
||||
|
@ -377,48 +369,48 @@ class WebmailController < ApplicationController
|
|||
headers['Content-Disposition'] = disposition << %(; filename="#{part.header['content-type']['name']}")
|
||||
render :text => part.body
|
||||
end
|
||||
|
||||
|
||||
def get_parts(mail)
|
||||
parts = Array.new
|
||||
parts << mail
|
||||
mail.parts.each { |part|
|
||||
mail.parts.each { |part|
|
||||
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")
|
||||
parts = parts.concat(get_parts(TMail::Mail.parse(part.body))) << part
|
||||
else
|
||||
else
|
||||
parts << part
|
||||
end
|
||||
}
|
||||
parts
|
||||
}
|
||||
parts
|
||||
end
|
||||
|
||||
|
||||
def obtain_cookies_for_search_and_nav
|
||||
@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_img_src = ((cookies['_wmlmo'] and cookies['_wmlmo'] == 'closed') ? 'closed' : 'opened')
|
||||
end
|
||||
|
||||
@ops_img_src = ((cookies['_wmlmo'] and cookies['_wmlmo'] == 'closed') ? 'closed' : 'opened')
|
||||
end
|
||||
|
||||
###################################################################
|
||||
### Some fixed parameters and session variables
|
||||
###################################################################
|
||||
def folder
|
||||
@folders[@folder_name]
|
||||
end
|
||||
|
||||
|
||||
def msg_id_param
|
||||
params["msg_id"]
|
||||
end
|
||||
|
||||
|
||||
def messages_param
|
||||
params["messages"]
|
||||
end
|
||||
|
||||
|
||||
def dst_folder
|
||||
params["cpdest"]
|
||||
end
|
||||
|
||||
|
||||
def operation_param
|
||||
params["op"]
|
||||
end
|
||||
|
|
|
@ -2,10 +2,9 @@
|
|||
|
||||
# Uncomment below to force Rails into production mode
|
||||
# (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.3' unless defined? RAILS_GEM_VERSION
|
||||
|
||||
# Bootstrap the Rails environment, frameworks, and default configuration
|
||||
require File.join(File.dirname(__FILE__), 'boot')
|
||||
|
@ -35,7 +34,7 @@ Rails::Initializer.run do |config|
|
|||
# Make Active Record use UTC-base instead of local time
|
||||
config.active_record.default_timezone = :utc
|
||||
|
||||
#config.i18n.default_locale = "en"
|
||||
config.i18n.default_locale = "en"
|
||||
|
||||
# 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)
|
||||
|
|
|
@ -45,7 +45,7 @@ pl-PL:
|
|||
add_filter: Dodaj filtr
|
||||
cc: Cc
|
||||
bcc: Bcc
|
||||
send: Wyslij
|
||||
send: Wyślij
|
||||
choose_address: Wybierz adres z kontaktów
|
||||
compose_txt: Utwórz nową wiadomość
|
||||
attachment: Załącznik
|
||||
|
|
Loading…
Reference in a new issue