works but need some cleanup

This commit is contained in:
Wojciech Todryk 2011-06-24 23:48:08 +02:00
parent 0ec83db287
commit e40a859b7d
752 changed files with 4866 additions and 27923 deletions

43
app/controllers/application_controller.rb Normal file → Executable file
View file

@ -1,34 +1,43 @@
# The filters added to this controller will be run for all controllers in the application.
# Likewise will all the methods added be available for all controllers.
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :user_login_filter
before_filter :add_scripts
#before_filter :localize
filter_parameter_logging :password
#filter_parameter_logging :password #upgrade to Rails3
protected
def secure_user?() true end
def secure_cust?() false end
def additional_scripts() "" end
def onload_function() "" end
private
def add_scripts
@additional_scripts = additional_scripts()
@onload_function = onload_function()
end
def user_login_filter
if (secure_user? or secure_cust? )and logged_user.nil?
session["return_to"] = request.request_uri
#upgrade Rails 3
#session["return_to"] = request.request_uri
logger.debug "*** return_to => #{request.fullpath}"
session["return_to"] = request.fullpath
redirect_to :controller=>"/login", :action => "index"
return false
end
end
alias login_required user_login_filter
alias login_required user_login_filter
def logged_user # returns customer id
session['user']
end
@ -36,7 +45,7 @@ class ApplicationController < ActionController::Base
def logged_customer
session['user']
end
def localize
# We will use instance vars for the locale so we can make use of them in
# the templates.
@ -65,7 +74,7 @@ class ApplicationController < ActionController::Base
end
public
def include_tinymce(mode="textareas",elements="")
tinymce=''
tinymce << '
@ -76,11 +85,11 @@ class ApplicationController < ActionController::Base
tinymce << mode << '",'
if mode == "exact"
tinymce << 'elements : "' << elements << '",
'
'
end
tinymce << '
theme : "advanced",
cleanup : true,
cleanup : true,
width: "100%",
remove_linebreaks : false,
entity_encoding : "named",
@ -142,25 +151,25 @@ class ApplicationController < ActionController::Base
</script>'
tinymce
end
helper_method :include_tinymce
def include_simple_tinymce(mode="textareas",elements="")
tinymce = ''
tinymce << '<script language="javascript" type="text/javascript" src="/tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
<script language="javascript" type="text/javascript">
tinyMCE.init({
mode : "'
tinymce << mode << '",'
if mode == "exact"
tinymce << 'elements : "' << elements << '",
'
'
end
tinymce << '
theme : "default",
width : "100%",
auto_reset_designmode : true
});
});
</script>'
tinymce
end
@ -168,7 +177,7 @@ class ApplicationController < ActionController::Base
def _(text)
t text
end
helper_method :include_simple_tinymce, :_

0
app/controllers/contact_groups_controller.rb Normal file → Executable file
View file

0
app/controllers/contacts_controller.rb Normal file → Executable file
View file

0
app/controllers/folders_controller.rb Normal file → Executable file
View file

38
app/controllers/login_controller.rb Normal file → Executable file
View file

@ -1,14 +1,16 @@
require 'ezcrypto'
require 'imapmailbox'
class LoginController < ApplicationController
def index
if not(logged_user.nil?)
redirect_to :controller =>"webmail", :action=>"index"
redirect_to :controller =>"webmail", :action=>"index"
else
@login_user = Customer.new
end
end
end
def authenticate
if user = auth(params['login_user']["email"], params['login_user']["password"])
session["user"] = user.id
@ -17,26 +19,27 @@ class LoginController < ApplicationController
else
# dont use crypt
session["wmp"] = params['login_user']["password"]
end
end
if session["return_to"]
redirect_to(session["return_to"])
session["return_to"] = nil
else
redirect_to :action=>"index"
redirect_to :action=>"index"
end
else
logger.debug "*** Not logged"
@login_user = Customer.new
flash["error"] = t :wrong_email_or_password
redirect_to :action => "index"
redirect_to :action => "index"
end
end
def logout
reset_session
flash["status"] = t(:user_logged_out)
redirect_to :action => "index"
redirect_to :action => "index"
end
protected
def need_subdomain?() true end
@ -45,12 +48,15 @@ class LoginController < ApplicationController
private
def auth(email, password)
mailbox = IMAPMailbox.new
mailbox = IMAPMailbox.new(Rails.logger)
logger.info "*** mailbox #{mailbox.inspect}"
begin
mailbox.connect(email, password)
rescue
return nil
mailbox.connect(email, password)
rescue Exception => exc
logger.debug "*** auth/Mailbox Object => #{exc.message}"
return nil
end
mailbox.disconnect
mailbox = nil
if user = Customer.find_by_email(email)
@ -60,6 +66,6 @@ class LoginController < ApplicationController
user = Customer.create("email"=>email)
MailPref.create('customer_id' => user.id)
return user
end
end
end
end
end

175
app/controllers/webmail_controller.rb Normal file → Executable file
View file

@ -3,58 +3,63 @@ require 'net/smtp'
require 'net/imap'
require 'mail2screen'
require 'ezcrypto'
require 'imapmailbox'
require 'imap_utils'
class WebmailController < ApplicationController
include ImapUtils
logger.info "*** WebmailController #{logger.inspect}"
# 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 +72,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 +83,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"]
@ -92,39 +97,39 @@ class WebmailController < ApplicationController
@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'))
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
@ -133,13 +138,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
@ -149,7 +154,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)
@ -157,50 +162,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'])
@ -209,7 +214,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
@ -228,11 +233,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
@ -246,7 +251,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
@ -257,7 +262,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]
@ -268,7 +273,7 @@ class WebmailController < ApplicationController
@user.serialize_to_file
redirect_to :action=>"filters"
end
def filter_add
@filter = Filter.new
@filter.expressions << Expression.new
@ -277,58 +282,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"]
@ -343,24 +348,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
@ -369,48 +374,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

0
app/helpers/application_helper.rb Normal file → Executable file
View file

0
app/helpers/contact_group_helper.rb Normal file → Executable file
View file

0
app/helpers/contacts_helper.rb Normal file → Executable file
View file

0
app/helpers/folders_helper.rb Normal file → Executable file
View file

0
app/helpers/navigation_helper.rb Normal file → Executable file
View file

63
app/helpers/webmail_helper.rb Normal file → Executable file
View file

@ -6,35 +6,35 @@ module WebmailHelper
def link_compose_new
link_to(t(:compose_txt), :controller=>"webmail", :action=>"compose")
end
def link_refresh
link_to(t(:refresh), :controller=>"webmail", :action=>"refresh")
end
def link_message_list
link_to(_('Message list'), :controller=>"webmail", :action=>"messages")
end
def link_reply_to_sender(msg_id)
link_to(t(:reply), :controller=>"webmail", :action=>"reply", :params=>{"msg_id"=>msg_id})
end
def link_forward_message(msg_id)
link_to(t(:forward), :controller=>"webmail", :action=>"forward", :params=>{"msg_id"=>msg_id})
end
def link_flag_for_deletion(msg_id)
link_to(t(:delete), :controller=>"webmail", :action=>"delete", :params=>{"msg_id"=>msg_id})
end
def link_view_source(msg_id)
link_to(t(:view_source), {:controller=>"webmail", :action=>"view_source", :params=>{"msg_id"=>msg_id}}, {'target'=>"_blank"})
end
def link_filter_add
link_to(t(:add_filter), :controller=>'webmail', :action=>'filter_add')
end
def folder_link(folder)
return folder.name if folder.attribs.include?(:Noselect)
folder_name = short_fn(folder)
@ -42,7 +42,8 @@ module WebmailHelper
title = folder.unseen > 0 ? "#{folder_name} (#{folder.unseen})" : "#{folder_name}"
link = link_to title, :controller => 'webmail', :action => 'messages', :folder_name => folder.name
link = content_tag('b', link) if folder.name == @folder_name
link += '&nbsp;' + empty_trash_link(folder.name) if folder.trash?
link += raw('&nbsp;' + empty_trash_link(folder.name)) if folder.trash?
logger.info link
link
end
@ -58,7 +59,7 @@ module WebmailHelper
d.strftime("%H:%M")
else
d.strftime("%Y-%m-%d")
end
end
rescue
begin
d = imap2time(datestr)
@ -66,43 +67,43 @@ module WebmailHelper
d.strftime("%H:%M")
else
d.strftime("%Y-%m-%d")
end
end
rescue
datestr
end
end
end
def attachment(att, index)
ret = "#{att.filename}"
# todo: add link to delete attachment
#ret <<
#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)
link_to(_('Up'), :controller=>"webmail", :action=>"filter_up", :id=>filter_id)
end
def link_filter_down(filter_id)
link_to(_('Down'), :controller=>"webmail", :action=>"filter_down", :id=>filter_id)
end
def link_filter_edit(filter_id)
link_to(_('Edit'), :controller=>"webmail", :action=>"filter", :id=>filter_id)
end
def link_filter_delete(filter_id)
link_to(_('Delete'), :controller=>"webmail", :action=>"filter_delete", :id=>filter_id)
end
def page_navigation_webmail(pages)
nav = "<p class='paginator'><small>"
nav << "(#{pages.length} #{t :pages}) &nbsp; "
window_pages = pages.current.window.pages
nav << "..." unless window_pages[0].first?
for page in window_pages
@ -114,27 +115,27 @@ module WebmailHelper
end
nav << "..." unless window_pages[-1].last?
nav << " &nbsp; "
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?
nav << "</small></p>"
return nav
end
def parse_subject(subject)
begin
if mime_encoded?(subject)
if mime_decode(subject) == ''
if mime_decode(subject) == ''
_('(No subject)')
else
mime_decode(subject)
end
else
if from_qp(subject) == ''
if from_qp(subject) == ''
_('(No subject)')
else
from_qp(subject)
@ -143,17 +144,17 @@ module WebmailHelper
rescue Exception => ex
RAILS_DEFAULT_LOGGER.debug('Exception occured - #{ex}')
return ""
end
end
end
def message_size(size)
def message_size(size)
if size / (1024*1024) > 0
return "#{(size / (1024*1024)).round}&nbsp;MB"
elsif size / 1024 > 0
elsif size / 1024 > 0
return "#{(size / (1024)).round}&nbsp;KB"
else
return "#{size}&nbsp;B"
end
end
end
private
@ -161,6 +162,6 @@ module WebmailHelper
def empty_trash_link(folder_name)
link_to( "(#{t :empty})",
{ :controller => "webmail", :action => "empty", :params=>{"folder_name"=>folder_name}},
:confirm => t(:want_to_empty_trash_message))
:confirm => t(:want_to_empty_trash_message))
end
end

71
app/models/contact.rb Normal file → Executable file
View file

@ -1,34 +1,37 @@
require 'cdfutils'
require_association 'contact_group'
class Contact < ActiveRecord::Base
class Contact < ActiveRecord::Base
validate :check_fname_and_lname, :check_mail_cannot_be_changed
validate :check_email, :on => :create
has_and_belongs_to_many :groups, :class_name => "ContactGroup", :join_table => "contact_contact_groups", :association_foreign_key => "contact_group_id", :foreign_key => "contact_id"
# Finder methods follow
def Contact.find_by_user(user_id)
find(:all, :conditions => ["customer_id = ?", user_id], :order => "fname asc", :limit => 10)
end
def Contact.find_by_user_email(user_id, email)
find(:first, :conditions => ["customer_id = #{user_id} and email = ?", email])
end
def Contact.find_by_group_user(user_id, grp_id)
result = Array.new
find(:all, :conditions => ["customer_id = ?", user_id], :order => "fname asc").each { |c|
begin
begin
c.groups.find(grp_id)
result << c
result << c
rescue ActiveRecord::RecordNotFound
end
}
result
end
named_scope :for_customer, lambda{ |customer_id| {:conditions => {:customer_id => customer_id}} }
named_scope :letter, lambda{ |letter| {:conditions => ["contacts.fname LIKE ?", "#{letter}%"]} }
scope :for_customer, lambda{ |customer_id| {:conditions => {:customer_id => customer_id}} }
scope :letter, lambda{ |letter| {:conditions => ["contacts.fname LIKE ?", "#{letter}%"]} }
def Contact.find_by_user_letter(user_id, letter)
find_by_sql("select * from contacts where customer_id=#{user_id} and substr(UPPER(fname),1,1) = '#{letter}' order by fname")
end
@ -36,36 +39,38 @@ class Contact < ActiveRecord::Base
def full_name
"#{fname}&nbsp;#{lname}"
end
def show_name
"#{fname} #{lname}"
end
def full_address
"#{fname} #{lname}<#{email}>"
end
protected
def validate
errors.add 'fname', I18n.t(:validate_fname_error) unless self.fname =~ /^.{2,20}$/i
errors.add 'lname', I18n.t(:validate_lname_error) unless self.lname =~ /^.{2,20}$/i
# Contact e-mail cannot be changed
unless self.new_record?
protected
def check_fname_and_lname
errors.add 'fname', t(:validate_fname_error) unless self.fname =~ /^.{2,20}$/i
errors.add 'lname', t(:validate_lname_error) unless self.lname =~ /^.{2,20}$/i
end
def check_mail_cannot_be_changed
# Contact e-mail cannot be changed
unless self.new_record?
old_record = Contact.find(self.id)
errors.add 'email', I18n.t(:contacto_cannot_be_changed) unless old_record.email == self.email
errors.add 'email', t(:contact_cannot_be_changed) unless old_record.email == self.email
end
end
def check_mail
# Contact e-mail cannot be changed, so we only need to validate it on create
errors.add 'email', t(:validate_email_error) unless valid_email?(self.email)
# Already existing e-mail in contacts for this user is not allowed
if self.new_record?
if Contact.find :first, :conditions => {:email => email, :customer_id => customer_id}
errors.add('email', I18n.t(:email_exists))
end
end
end
def validate_on_create
# Contact e-mail cannot be changed, so we only need to validate it on create
errors.add 'email', I18n.t(:validate_email_error) unless valid_email?(self.email)
# Already existing e-mail in contacts for this user is not allowed
if self.new_record?
if Contact.find :first, :conditions => {:email => email, :customer_id => customer_id}
errors.add('email', I18n.t(:email_exists))
end
end
end
end

43
app/models/contact_group.rb Normal file → Executable file
View file

@ -1,25 +1,30 @@
class ContactGroup < ActiveRecord::Base
has_and_belongs_to_many :contacts, :class_name => "Contact", :join_table => "contact_contact_groups", :association_foreign_key => "contact_id", :foreign_key => "contact_group_id"
has_and_belongs_to_many :contacts, :class_name => "Contact", :join_table => "contact_contact_groups", :association_foreign_key => "contact_id", :foreign_key => "contact_group_id"
validate :check_group_name
validate :check_group_id, :on => :create
validate :check_group_uniqness, :on => :update
def ContactGroup.find_by_user(user_id)
find_by_sql("select * from contact_groups where customer_id = #{user_id} order by name asc")
end
protected
def validate
errors.add('name', :contactgroup_name_invalid) unless self.name =~ /^.{1,50}$/i
def ContactGroup.find_by_user(user_id)
find_by_sql("select * from contact_groups where customer_id = #{user_id} order by name asc")
end
def validate_on_create
if ContactGroup.find_first(["name = '#{name}' and customer_id = #{user_id}"])
errors.add("name", _('Please enter group name (1 to 50 characters)'))
end
protected
def check_group_name
errors.add('name', t(:contactgroup_name_invalid)) unless self.name =~ /^.{1,50}$/i
end
def check_group_id
if ContactGroup.find_first(["name = '#{name}' and customer_id = #{user_id}"])
errors.add("name", _('Please enter group name (1 to 50 characters)'))
end
end
def validate_on_update
if ContactGroup.find_first(["name = '#{name}' and customer_id = #{user_id} and id <> #{id}"])
errors.add("name", _('You already have contact group with this name'))
end
def check_group_uniqness
if ContactGroup.find_first(["name = '#{name}' and customer_id = #{user_id} and id <> #{id}"])
errors.add("name", _('You already have contact group with this name'))
end
end
end

0
app/models/customer.rb Normal file → Executable file
View file

0
app/models/mail_pref.rb Normal file → Executable file
View file

0
app/views/contact_groups/index.html.erb Normal file → Executable file
View file

View file

0
app/views/contacts/index.html.erb Normal file → Executable file
View file

20
app/views/contacts/new.html.erb Normal file → Executable file
View file

@ -20,24 +20,24 @@
<div id="tab_content">
<% form_tag( contacts_path, 'method' => 'post', 'class' => 'two_columns') do %>
<%= form_tag( contacts_path, 'method' => 'post', 'class' => 'two_columns') do %>
<%= form_input(:hidden_field, 'contact', 'id') %>
<%= form_input(:hidden_field, 'contact', 'customer_id') %>
<table>
<%= form_input(:text_field, 'contact', 'fname', t(:first_name), 'class'=>'two_columns') %>
<%= form_input(:text_field, 'contact', 'lname', t(:last_name), 'class'=>'two_columns') %>
<%= form_input((@contact.new_record? ? :text_field : :read_only_field), 'contact', 'email', t(:email), 'class'=>'two_columns')%>
</table>
<% for group in @contactgroups %>
<input id="groups[<%=group.id%>]" type="hidden" name="groups[<%=group.id%>]" value="<%=@groups[group.id]%>">
<% end %>
<% end %>
<% if not(@contactgroups.empty?) %>
<%=_('Contact belong to these groups')%>:
<table class="list">
<tr>
<%
<%
end
col = 1
for group in @contactgroups %>
@ -57,17 +57,17 @@
<% end %>
<% if not(@contactgroups.empty?) %>
</tr>
</table>
</table>
<% end %>
<table class="edit">
<table class="edit">
<tr>
<td colspan=2 class="buttonBar">
<input type="submit" name="paction" value="<%=t(:save)%>"/>
<input type="submit" name="paction" value="<%=t(:save_and_add_another)%>"/>
</td>
</tr>
</table>
</tr>
</table>
<% end %>
</div>
</div>

8
app/views/folders/index.html.erb Normal file → Executable file
View file

@ -15,18 +15,18 @@
<div id="tab_main">
<div id="tab_content">
<% content_for('sidebar') { %>
<% content_for('sidebar') { %>
<div id="folders">
<h4><%= t :add_folder %></h4>
<hr/>
<% form_tag folders_path, :id => 'new_folder' do %>
<%= form_tag folders_path, :id => 'new_folder' do %>
<ul>
<li><label for='folder'><%= t :name %>:</label></li>
<li><%= text_field_tag 'folder', '', :size => 18 %></li>
<li><%= submit_tag t(:add_folder) %></li>
</ul>
<% end %>
</div>
</div>
<% } %>
<div id="messages">
@ -45,4 +45,4 @@
</div>
</div>
</div>
</div>
</div>

0
app/views/layouts/chooser.html.erb Normal file → Executable file
View file

0
app/views/layouts/login.html.erb Normal file → Executable file
View file

5
app/views/layouts/public.html.erb Normal file → Executable file
View file

@ -14,7 +14,10 @@
<div id="wholepage">
<div id="container">
<div id="sidebar_outer">
<div id="sidebar"><%= yield :sidebar %></div>
<div id="logo"></div>
<div id="sidebar">
<%= yield :sidebar %>
</div>
</div>
<div id="content"><%= yield %></div>
<br class="clear"/>

0
app/views/login/index.rhtml Normal file → Executable file
View file

4
app/views/shared/_folders.html.erb Normal file → Executable file
View file

@ -3,8 +3,8 @@
<hr/>
<ul>
<% @folders.each do |folder| -%>
<li><%= folder_link(folder) %></li>
<% end -%>
<li><%= raw folder_link(folder) %></li>
<% end -%>
</ul>
</div>
<div style="text-align: center; padding: 10px;">

View file

View file

View file

View file

View file

View file

View file

View file

View file

@ -15,9 +15,9 @@
<div id="tab_main">
<div id="tab_content">
<% content_for('sidebar') { %>
<%= render :partial => 'shared/folders' %>
<% } %>
<% content_for :sidebar do %>
<%= render :partial => 'shared/folders' %>
<% end %>
<div id="messages">
<div id="msglist">
@ -25,11 +25,11 @@
<%= form_tag({:controller=>'webmail', :action=>'messages'})%>
<div class='notviscode'><input type="submit" name="op" value="<%= t :search %>" /></div>
<input type="hidden" name="page" value="<%=@page%>"/>
<a href='#' onclick='toggle_msg_operations(true);'>
<%=t :operations%><img id='img_msgops' alt='open' src='../images/list_<%=@ops_img_src%>.gif'/>
</a>
<div id="msgops" class='<%=@ops_class%>'>
<h4><%= t :operations_txt %></h4>
<span id="opch">

View file