start to switch to rails 3.2.2
This commit is contained in:
parent
244942a78f
commit
74c23fa0d1
253 changed files with 648 additions and 17155 deletions
BIN
app/assets/images/rails.png
Normal file
BIN
app/assets/images/rails.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.5 KiB |
15
app/assets/javascripts/application.js
Normal file
15
app/assets/javascripts/application.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
||||
// listed below.
|
||||
//
|
||||
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
||||
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
||||
//
|
||||
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
||||
// the compiled file.
|
||||
//
|
||||
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
||||
// GO AFTER THE REQUIRES BELOW.
|
||||
//
|
||||
//= require jquery
|
||||
//= require jquery_ujs
|
||||
//= require_tree .
|
13
app/assets/stylesheets/application.css
Normal file
13
app/assets/stylesheets/application.css
Normal file
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
||||
* listed below.
|
||||
*
|
||||
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
||||
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
||||
*
|
||||
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
||||
* compiled file, but it's generally better to create a new file per style scope.
|
||||
*
|
||||
*= require_self
|
||||
*= require_tree .
|
||||
*/
|
98
app/controllers/application_controller.rb
Executable file → Normal file
98
app/controllers/application_controller.rb
Executable file → Normal file
|
@ -1,99 +1,3 @@
|
|||
require 'yaml'
|
||||
|
||||
class ApplicationController < ActionController::Base
|
||||
|
||||
protect_from_forgery
|
||||
|
||||
before_filter :load_defaults,:current_user,:set_locale
|
||||
before_filter :plugins_configuration
|
||||
|
||||
def load_defaults
|
||||
$defaults ||= YAML::load(File.open(Rails.root.join('config','defaults.yml')))
|
||||
end
|
||||
|
||||
################################# protected section ###########################################
|
||||
|
||||
protected
|
||||
|
||||
def theme_resolver
|
||||
if @current_user.nil?
|
||||
$defaults['theme']
|
||||
else
|
||||
@current_user.prefs.theme || $defaults['theme']
|
||||
end
|
||||
end
|
||||
|
||||
def set_locale
|
||||
if @current_user.nil?
|
||||
I18n.locale = $defaults['locale'] || I18n.default_locale
|
||||
else
|
||||
I18n.locale = @current_user.prefs.locale.to_sym || I18n.default_locale
|
||||
end
|
||||
end
|
||||
|
||||
def current_user
|
||||
@current_user ||= User.find(session[:user_id]) if session[:user_id]
|
||||
end
|
||||
|
||||
def check_current_user
|
||||
if @current_user.nil?
|
||||
session["return_to"] = request.fullpath
|
||||
redirect_to :controller => 'user', :action => 'login'
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
def selected_folder
|
||||
if session[:selected_folder]
|
||||
@selected_folder = session[:selected_folder]
|
||||
else
|
||||
folder = @current_user.folders.inbox.first
|
||||
if not folder.nil?
|
||||
@selected_folder = folder.full_name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def get_current_folders
|
||||
@folders_shown = @current_user.folders.shown.order("name asc")
|
||||
if not @selected_folder.nil?
|
||||
@current_folder = @current_user.folders.find_by_full_name(@selected_folder)
|
||||
end
|
||||
end
|
||||
|
||||
def prepare_compose_buttons
|
||||
@buttons = []
|
||||
@buttons << {:text => 'sendout',:scope=>:compose,:image => 'email.png'}
|
||||
@buttons << {:text => 'save',:scope=>:compose,:image => 'save.png'}
|
||||
end
|
||||
|
||||
def create_message_with_params
|
||||
@message = Message.new(params[:message])
|
||||
# if params[:message]
|
||||
# @message.update_attributes(params[:message])
|
||||
# end
|
||||
files = Dir.glob(File.join($defaults["msg_upload_dir"],@current_user.username + "*"))
|
||||
@attachments = []
|
||||
files.each do |f|
|
||||
@attachments << {:name => File.basename(f).gsub!(/#{@current_user.username}_/,"") , :size => File.stat(f).size }
|
||||
end
|
||||
end
|
||||
|
||||
def get_system_folders
|
||||
@drafts_folder = @current_user.folders.drafts.first
|
||||
@sent_folder = @current_user.folders.sent.first
|
||||
@inbox_folder = @current_user.folders.inbox.first
|
||||
@trash_folder = @current_user.folders.trash.first
|
||||
end
|
||||
|
||||
##################################### private section ##########################################
|
||||
|
||||
private
|
||||
|
||||
def plugins_configuration
|
||||
WillPaginate::ViewHelpers.pagination_options[:previous_label] = t(:previous_page,:scope=>:common)
|
||||
WillPaginate::ViewHelpers.pagination_options[:next_label] = t(:next_page,:scope=>:common)
|
||||
end
|
||||
|
||||
protect_from_forgery
|
||||
end
|
||||
|
||||
|
|
|
@ -1,135 +0,0 @@
|
|||
require 'tempfile'
|
||||
|
||||
class ContactsController < ApplicationController
|
||||
|
||||
before_filter :check_current_user,:selected_folder, :get_current_folders
|
||||
|
||||
before_filter :get_contacts, :only => [:index]
|
||||
|
||||
before_filter :prepare_ops_buttons, :prepare_export_import_buttons,:only => [:index]
|
||||
|
||||
theme :theme_resolver
|
||||
|
||||
def index
|
||||
|
||||
end
|
||||
|
||||
def ops
|
||||
if params["create_new"]
|
||||
redirect_to(new_contact_path)
|
||||
return
|
||||
end
|
||||
if !params["cids"]
|
||||
flash[:warning] = t(:no_selected,:scope=>:contact)
|
||||
else
|
||||
if params["delete_selected"]
|
||||
params["cids"].each do |id|
|
||||
@current_user.contacts.find_by_id(id).destroy
|
||||
end
|
||||
elsif params["compose_to_selected"]
|
||||
redirect_to :controller=>'messages',:action=>'compose',:cids=>params["cids"]
|
||||
return
|
||||
end
|
||||
end
|
||||
redirect_to(contacts_path)
|
||||
end
|
||||
|
||||
#problem http://binary10ve.blogspot.com/2011/05/migrating-to-rails-3-got-stuck-with.html
|
||||
#def destroy
|
||||
# @current_user.contacts.find(params[:id]).destroy
|
||||
# redirect_to(contacts_path)
|
||||
#end
|
||||
|
||||
def new
|
||||
@contact = Contact.new
|
||||
end
|
||||
|
||||
def edit
|
||||
@contact = @current_user.contacts.find(params[:id])
|
||||
render 'edit'
|
||||
end
|
||||
|
||||
def create
|
||||
@contact = @current_user.contacts.build(params[:contact])
|
||||
if @contact.valid?
|
||||
@contact.save
|
||||
flash[:notice] = t(:was_created,:scope=>:contact)
|
||||
redirect_to(contacts_path)
|
||||
else
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@contact = @current_user.contacts.find(params[:id])
|
||||
if @contact.update_attributes(params[:contact])
|
||||
redirect_to(contacts_path)
|
||||
else
|
||||
render 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def external
|
||||
if params["export"]
|
||||
redirect_to :action => 'export'
|
||||
return
|
||||
elsif params["import"]
|
||||
begin
|
||||
raise t(:no_file_chosen,:scope=>:common) if not params[:upload]
|
||||
raise t(:no_tmp_dir,:scope=>:common) if not File.exists?($defaults["msg_upload_dir"])
|
||||
tmp_file = Tempfile.new($defaults["contact_tmp_filename"],$defaults["msg_upload_dir"])
|
||||
tmp_file.write(params[:upload][:datafile].read)
|
||||
tmp_file.flush
|
||||
tmp_file.rewind
|
||||
tmp_file.readlines.each do |line|
|
||||
next if line =~ /^#/
|
||||
Contact.import(@current_user,line)
|
||||
end
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
flash[:error] = {:title => e.to_s,:info => e.record.inspect + e.record.errors.inspect}
|
||||
rescue Exception => e
|
||||
flash[:error] = e.to_s
|
||||
else
|
||||
flash[:notice] = t(:were_imported,:scope=>:contact)
|
||||
end
|
||||
end
|
||||
redirect_to :action => 'index'
|
||||
end
|
||||
|
||||
def export
|
||||
contacts = @current_user.contacts
|
||||
s = ""
|
||||
contacts.each do |c|
|
||||
s += c.export + "\r\n"
|
||||
end
|
||||
headers['Content-type'] = "text/csv"
|
||||
headers['Content-Disposition'] = %(attachment; filename="contacts.csv")
|
||||
render :text => s
|
||||
end
|
||||
|
||||
####################################### protected section ################################
|
||||
|
||||
protected
|
||||
|
||||
def prepare_ops_buttons
|
||||
@buttons = []
|
||||
@buttons << {:text => 'compose_to_selected',:scope=> 'contact', :image => 'email.png'}
|
||||
@buttons << {:text => 'create_new',:scope=> 'contact', :image => 'plus.png'}
|
||||
@buttons << {:text => 'delete_selected',:scope=>'contact',:image => 'minus.png'}
|
||||
end
|
||||
|
||||
def prepare_export_import_buttons
|
||||
@ei_buttons = []
|
||||
@ei_buttons << {:text => 'import',:scope=>'contact',:image => 'right.png'}
|
||||
@ei_buttons << {:text => 'export',:scope=>'contact',:image => 'left.png'}
|
||||
end
|
||||
|
||||
####################################### private section ##################################
|
||||
|
||||
private
|
||||
|
||||
def get_contacts
|
||||
@contacts = Contact.getPageForUser(@current_user,params[:page],params[:sort_field],params[:sort_dir])
|
||||
end
|
||||
|
||||
end
|
|
@ -1,172 +0,0 @@
|
|||
require 'imap_mailbox'
|
||||
require 'imap_session'
|
||||
|
||||
class FoldersController < ApplicationController
|
||||
|
||||
include ImapMailboxModule
|
||||
include ImapSessionModule
|
||||
|
||||
before_filter :check_current_user,:selected_folder, :get_current_folders
|
||||
|
||||
before_filter :open_imap_session, :except => [:index,:show_hide,:system]
|
||||
after_filter :close_imap_session, :except => [:index,:show_hide,:system]
|
||||
|
||||
before_filter :get_folders
|
||||
before_filter :prepare_buttons_to_folders
|
||||
|
||||
theme :theme_resolver
|
||||
|
||||
def index
|
||||
#before_filter
|
||||
end
|
||||
|
||||
def create
|
||||
if params[:folder][:target].empty?
|
||||
flash[:warning] = t(:to_create_empty,:scope=>:folder)
|
||||
render "index"
|
||||
else
|
||||
begin
|
||||
#TODO recreate local copy of folders
|
||||
if params[:folder][:parent].empty?
|
||||
@mailbox.create_folder(params[:folder][:target])
|
||||
else
|
||||
parent_folder = @current_user.folders.find(params[:folder][:parent])
|
||||
if parent_folder.depth >= $defaults["mailbox_max_parent_folder_depth"].to_i
|
||||
raise Exception, t(:max_depth,:scope=>:folder)
|
||||
end
|
||||
@mailbox.create_folder(parent_folder.full_name + parent_folder.delim + params[:folder][:target])
|
||||
end
|
||||
rescue Exception => e
|
||||
flash[:error] = t(:can_not_create,:scope=>:folder) + ' (' + e.to_s + ')'
|
||||
render 'index'
|
||||
return
|
||||
end
|
||||
flash[:notice] = t(:was_created,:scope=>:folder)
|
||||
redirect_to :action => 'index'
|
||||
end
|
||||
end
|
||||
|
||||
def delete
|
||||
if params[:folder][:delete].empty?
|
||||
flash[:warning] = t(:to_delete_empty,:scope=>:folder)
|
||||
render "index"
|
||||
else
|
||||
begin
|
||||
folder = @current_user.folders.find(params[:folder][:delete])
|
||||
if @folders_system.include?(folder)
|
||||
raise Exception, t(:system,:scope=>:folder)
|
||||
end
|
||||
@mailbox.delete_folder(folder.full_name)
|
||||
if @current_folder.eql? folder
|
||||
session[:selected_folder] = nil
|
||||
end
|
||||
folder.destroy
|
||||
rescue Exception => e
|
||||
flash[:error] = t(:can_not_delete,:scope=>:folder) + ' (' + e.to_s + ')'
|
||||
render 'index'
|
||||
return
|
||||
end
|
||||
flash[:notice] = t(:was_deleted,:scope=>:folder)
|
||||
redirect_to :action => 'index'
|
||||
end
|
||||
end
|
||||
|
||||
def system
|
||||
logger.custom('sss',params[:folder].inspect)
|
||||
@folders.each do |f|
|
||||
logger.custom('s',f.inspect)
|
||||
if f.isSystem?
|
||||
f.setNone
|
||||
end
|
||||
if f.id == params[:folder][:mailbox_inbox].to_i
|
||||
f.setInbox
|
||||
end
|
||||
if f.id == params[:folder][:mailbox_sent].to_i
|
||||
f.setSent
|
||||
end
|
||||
if f.id == params[:folder][:mailbox_trash].to_i
|
||||
f.setTrash
|
||||
end
|
||||
if f.id == params[:folder][:mailbox_drafts].to_i
|
||||
f.setDrafts
|
||||
end
|
||||
end
|
||||
redirect_to :action => 'index'
|
||||
end
|
||||
|
||||
def refresh
|
||||
# TODO save system folders
|
||||
if params[:refresh]
|
||||
Folder.refresh(@mailbox,@current_user)
|
||||
flash.keep
|
||||
elsif params[:show_hide]
|
||||
if !params["folders_to_show"].nil?
|
||||
@folders.each do |f|
|
||||
if params["folders_to_show"].include?(f.id.to_s)
|
||||
f.shown = true
|
||||
f.save
|
||||
else
|
||||
f.shown = false
|
||||
f.save
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
redirect_to :action => 'index'
|
||||
end
|
||||
|
||||
def select
|
||||
session[:selected_folder] = params[:id]
|
||||
redirect_to :controller => 'messages', :action => 'index'
|
||||
end
|
||||
|
||||
def refresh_status
|
||||
@folders_shown.each do |f|
|
||||
@mailbox.set_folder(f.full_name)
|
||||
folder_status = @mailbox.status
|
||||
f.update_attributes(:total => folder_status['MESSAGES'], :unseen => folder_status['UNSEEN'])
|
||||
end
|
||||
redirect_to :controller=> 'messages', :action => 'index'
|
||||
end
|
||||
|
||||
def emptybin
|
||||
begin
|
||||
trash_folder = @current_user.folders.trash.first
|
||||
if trash_folder.nil?
|
||||
raise Exception, t(:not_configured_trash,:scope=>:folder)
|
||||
end
|
||||
@mailbox.set_folder(trash_folder.full_name)
|
||||
trash_folder.messages.each do |m|
|
||||
@mailbox.delete_message(m.uid)
|
||||
end
|
||||
@mailbox.expunge
|
||||
trash_folder.messages.destroy_all
|
||||
trash_folder.update_attributes(:unseen => 0, :total => 0)
|
||||
rescue Exception => e
|
||||
flash[:error] = "#{t(:imap_error,:scope=>:common)} (#{e.to_s})"
|
||||
end
|
||||
redirect_to :controller => 'messages', :action => 'index'
|
||||
end
|
||||
|
||||
|
||||
############################################# protected section #######################################
|
||||
|
||||
protected
|
||||
|
||||
def prepare_buttons_to_folders
|
||||
@buttons = []
|
||||
@buttons << {:text => 'show_hide',:scope=>'folder',:image => 'flag.png'}
|
||||
@buttons << {:text => 'refresh',:scope=>'folder',:image => 'refresh.png'}
|
||||
end
|
||||
|
||||
def get_folders
|
||||
@folders = @current_user.folders
|
||||
@folders_shown = @current_user.folders.shown
|
||||
#@folders_system = @current_user.folders.sys
|
||||
@current_user.folders.inbox.first.nil? ? @folder_inbox = "" : @folder_inbox = @current_user.folders.inbox.first.id
|
||||
@current_user.folders.drafts.first.nil? ? @folder_drafts = "" : @folder_drafts = @current_user.folders.drafts.first.id
|
||||
@current_user.folders.sent.first.nil? ? @folder_sent = "" : @folder_sent = @current_user.folders.sent.first.id
|
||||
@current_user.folders.trash.first.nil? ? @folder_trash = "" : @folder_trash = @current_user.folders.trash.first.id
|
||||
end
|
||||
|
||||
end
|
|
@ -1,53 +0,0 @@
|
|||
class InternalController < ApplicationController
|
||||
|
||||
before_filter :check_current_user ,:selected_folder, :get_current_folders, :only => [:about]
|
||||
|
||||
theme :theme_resolver
|
||||
layout "simple"
|
||||
|
||||
|
||||
ERRORS = [
|
||||
:internal_server_error,
|
||||
:not_found,
|
||||
:unprocessable_entity
|
||||
].freeze
|
||||
|
||||
ERRORS.each do |e|
|
||||
define_method e do
|
||||
@title = t(e,:scope=>:internal)
|
||||
@error = t(e,:scope=>:internal)
|
||||
render 'error'
|
||||
end
|
||||
end
|
||||
|
||||
def error
|
||||
@title = t(:unspecified_error,:scope=>:internal)
|
||||
@error = params[:error] || t(:unspecified_error,:scope=>:internal)
|
||||
end
|
||||
|
||||
def imaperror
|
||||
@title = t(:imap_error,:scope => :internal)
|
||||
@error = params[:error] || t(:unspecified_error, :scope => :internal)
|
||||
logger.error "!!! InternalControllerImapError: " + @error
|
||||
render 'error'
|
||||
end
|
||||
|
||||
def loginfailure
|
||||
reset_session
|
||||
flash[:error] = t(:login_failure,:scope=>:user)
|
||||
@current_user = nil
|
||||
redirect_to :controller=>'user', :action => 'login'
|
||||
end
|
||||
|
||||
def onlycanlogins
|
||||
reset_session
|
||||
flash[:error] = t(:only_can_logins,:scope=>:user)
|
||||
@current_user = nil
|
||||
redirect_to :controller=>'user', :action => 'login'
|
||||
end
|
||||
|
||||
def about
|
||||
render 'internal/about', :layout => 'application'
|
||||
end
|
||||
|
||||
end
|
|
@ -1,133 +0,0 @@
|
|||
require 'tempfile'
|
||||
|
||||
class LinksController < ApplicationController
|
||||
|
||||
before_filter :check_current_user,:selected_folder, :get_current_folders
|
||||
|
||||
before_filter :get_links, :only => [:index]
|
||||
|
||||
before_filter :prepare_ops_buttons, :only => [:index]
|
||||
|
||||
#, :prepare_export_import_buttons,:only => [:index]
|
||||
|
||||
theme :theme_resolver
|
||||
|
||||
def index
|
||||
|
||||
end
|
||||
|
||||
def ops
|
||||
if params["create_new"]
|
||||
redirect_to(new_link_path)
|
||||
return
|
||||
end
|
||||
if !params["ids"]
|
||||
flash[:warning] = t(:no_selected,:scope=>:link)
|
||||
else
|
||||
if params["delete_selected"]
|
||||
params["ids"].each do |id|
|
||||
@current_user.links.find_by_id(id).destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
redirect_to(links_path)
|
||||
end
|
||||
|
||||
#problem http://binary10ve.blogspot.com/2011/05/migrating-to-rails-3-got-stuck-with.html
|
||||
#def destroy
|
||||
# @current_user.contacts.find(params[:id]).destroy
|
||||
# redirect_to(contacts_path)
|
||||
#end
|
||||
|
||||
def new
|
||||
@link = Link.new
|
||||
end
|
||||
|
||||
def edit
|
||||
@link = @current_user.links.find(params[:id])
|
||||
render 'edit'
|
||||
end
|
||||
|
||||
def create
|
||||
@link = @current_user.links.build(params[:link])
|
||||
if @link.valid?
|
||||
@link.save
|
||||
flash[:notice] = t(:was_created,:scope=>:link)
|
||||
redirect_to(links_path)
|
||||
else
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@link = @current_user.links.find(params[:id])
|
||||
if @link.update_attributes(params[:link])
|
||||
redirect_to(links_path)
|
||||
else
|
||||
render 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def external
|
||||
if params["export"]
|
||||
redirect_to :action => 'export'
|
||||
return
|
||||
elsif params["import"]
|
||||
begin
|
||||
raise t(:no_file_chosen,:scope=>:common) if not params[:upload]
|
||||
raise t(:no_tmp_dir,:scope=>:common) if not File.exists?($defaults["msg_upload_dir"])
|
||||
tmp_file = Tempfile.new($defaults["contact_tmp_filename"],$defaults["msg_upload_dir"])
|
||||
tmp_file.write(params[:upload][:datafile].read)
|
||||
tmp_file.flush
|
||||
tmp_file.rewind
|
||||
tmp_file.readlines.each do |line|
|
||||
next if line =~ /^#/
|
||||
Contact.import(@current_user,line)
|
||||
end
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
flash[:error] = {:title => e.to_s,:info => e.record.inspect + e.record.errors.inspect}
|
||||
rescue Exception => e
|
||||
flash[:error] = e.to_s
|
||||
else
|
||||
flash[:notice] = t(:were_imported,:scope=>:contact)
|
||||
end
|
||||
end
|
||||
redirect_to :action => 'index'
|
||||
end
|
||||
|
||||
def export
|
||||
contacts = @current_user.contacts
|
||||
s = ""
|
||||
contacts.each do |c|
|
||||
s += c.export + "\r\n"
|
||||
end
|
||||
headers['Content-type'] = "text/csv"
|
||||
headers['Content-Disposition'] = %(attachment; filename="contacts.csv")
|
||||
render :text => s
|
||||
end
|
||||
|
||||
####################################### protected section ################################
|
||||
|
||||
protected
|
||||
|
||||
def prepare_ops_buttons
|
||||
@buttons = []
|
||||
@buttons << {:text => 'create_new',:scope=> 'link', :image => 'plus.png'}
|
||||
@buttons << {:text => 'delete_selected',:scope=>'link',:image => 'minus.png'}
|
||||
end
|
||||
|
||||
def prepare_export_import_buttons
|
||||
@ei_buttons = []
|
||||
@ei_buttons << {:text => 'import',:scope=>'link',:image => 'right.png'}
|
||||
@ei_buttons << {:text => 'export',:scope=>'link',:image => 'left.png'}
|
||||
end
|
||||
|
||||
####################################### private section ##################################
|
||||
|
||||
private
|
||||
|
||||
def get_links
|
||||
@links = Link.getPageForUser(@current_user,params[:page],params[:sort_field],params[:sort_dir])
|
||||
end
|
||||
|
||||
end
|
|
@ -1,210 +0,0 @@
|
|||
require 'imap_session'
|
||||
require 'imap_mailbox'
|
||||
require 'imap_message'
|
||||
require 'mail'
|
||||
require 'mail_plugin_extension'
|
||||
|
||||
class MessagesController < ApplicationController
|
||||
|
||||
include ImapMailboxModule
|
||||
include ImapSessionModule
|
||||
include ImapMessageModule
|
||||
include MessagesHelper
|
||||
|
||||
before_filter :check_current_user ,:selected_folder,:get_current_folders
|
||||
before_filter :open_imap_session, :select_imap_folder
|
||||
before_filter :prepare_compose_buttons, :only => [:compose]
|
||||
before_filter :get_system_folders, :only => [:index]
|
||||
before_filter :create_message_with_params, :only => [:compose]
|
||||
before_filter :prepare_multi1_buttons, :only => [:index,:show]
|
||||
before_filter :prepare_multi2_buttons, :only => [:index]
|
||||
before_filter :prepare_multi3_buttons, :only => [:show]
|
||||
after_filter :close_imap_session
|
||||
|
||||
theme :theme_resolver
|
||||
|
||||
def index
|
||||
|
||||
if @sent_folder.nil? || @drafts_folder.nil? || @inbox_folder.nil? || @trash_folder.nil?
|
||||
flash[:warning] = t(:not_all_configured,:scope => :folder)
|
||||
end
|
||||
|
||||
if @current_folder.nil?
|
||||
flash[:warning] = t(:no_selected,:scope => :folder)
|
||||
redirect_to :controller => 'folders', :action => 'index'
|
||||
return
|
||||
end
|
||||
|
||||
@messages = []
|
||||
|
||||
folder_status = @mailbox.status
|
||||
@current_folder.update_attributes(:total => folder_status['MESSAGES'], :unseen => folder_status['UNSEEN'])
|
||||
|
||||
folder_status['MESSAGES'].zero? ? uids_remote = [] : uids_remote = @mailbox.fetch_uids
|
||||
uids_local = @current_user.messages.where(:folder_id => @current_folder).collect(&:uid)
|
||||
|
||||
logger.custom('current_folder',@current_folder.inspect)
|
||||
logger.custom('uids_local',uids_local.join(","))
|
||||
logger.custom('uids_remote',uids_remote.join(","))
|
||||
logger.custom('to_delete',(uids_local-uids_remote).join(","))
|
||||
logger.custom('to_fetch',(uids_remote-uids_local).join(","))
|
||||
|
||||
(uids_local-uids_remote).each do |uid|
|
||||
@current_folder.messages.find_by_uid(uid).destroy
|
||||
end
|
||||
|
||||
(uids_remote-uids_local).each_slice($defaults["imap_fetch_slice"].to_i) do |slice|
|
||||
messages = @mailbox.uid_fetch(slice, ImapMessageModule::IMAPMessage.fetch_attr)
|
||||
messages.each do |m|
|
||||
Message.createForUser(@current_user,@current_folder,m)
|
||||
end
|
||||
end
|
||||
|
||||
@messages = Message.getPageForUser(@current_user,@current_folder,params[:page],params[:sort_field],params[:sort_dir])
|
||||
|
||||
end
|
||||
|
||||
def compose
|
||||
#before filter :prepare_compose_buttons, :create_message_with_params
|
||||
@operation = :new
|
||||
if params["cid"].present?
|
||||
contact = @current_user.contacts.find_by_id(params["cid"])
|
||||
if not contact.nil?
|
||||
@message.to_addr = contact.email
|
||||
end
|
||||
elsif params["cids"].present?
|
||||
contacts = []
|
||||
params["cids"].each do |c|
|
||||
contact = @current_user.contacts.find_by_id(c)
|
||||
if not contact.nil?
|
||||
contacts << contact.email
|
||||
end
|
||||
end
|
||||
@message.to_addr = contacts.join(';')
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@images = []
|
||||
@attachments = []
|
||||
@text_part = nil
|
||||
@html_part = nil
|
||||
|
||||
@message = @current_user.messages.where('folder_id = ? and uid = ?',@current_folder,params[:id]).first
|
||||
@message.update_attributes(:unseen => false)
|
||||
imap_message = @mailbox.fetch_body(@message.uid)
|
||||
|
||||
mail = Mail.new(imap_message)
|
||||
@plain_header = mail.header.to_s
|
||||
|
||||
|
||||
# FIXME missing fields and support arrays
|
||||
#@from = mail.From.addrs.presence
|
||||
#@to = mail.To.addrs.presence
|
||||
@from = @message.from_addr
|
||||
@to = @message.to_addr
|
||||
@cc = mail.Cc.presence
|
||||
@bcc = mail.Bcc.presence
|
||||
#@subject = mail.Subject
|
||||
@date = mail.date.presence
|
||||
|
||||
if mail.multipart? == true
|
||||
if not mail.text_part.nil?
|
||||
@text_part = mail.text_part.decoded_and_charseted
|
||||
end
|
||||
if not mail.html_part.nil?
|
||||
@html_part = mail.html_part.decoded_and_charseted
|
||||
end
|
||||
attachments = mail.attachments
|
||||
if not attachments.size.zero?
|
||||
for idx in 0..attachments.size - 1
|
||||
a = attachments[idx]
|
||||
a.idx = idx
|
||||
a.parent_id = @message.uid
|
||||
if a.isImage? and @current_user.prefs.msg_image_view_as.to_sym.eql?(:thumbnail)
|
||||
@images << a
|
||||
else
|
||||
@attachments << a
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
part = Mail::Part.new(mail)
|
||||
part.idx = 0
|
||||
part.parent_id = @message.uid
|
||||
if part.isText?
|
||||
@text_part = part.decoded_and_charseted
|
||||
elsif part.isImage? and @current_user.prefs.msg_image_view_as.to_sym.eql?(:thumbnail)
|
||||
@images << part
|
||||
elsif part.isHtml?
|
||||
@html_part = part.decoded_and_charseted
|
||||
else
|
||||
@attachments << part
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def html_body
|
||||
message = @current_user.messages.where('folder_id = ? and uid = ?',@current_folder,params[:id]).first
|
||||
mail = Mail.new(@mailbox.fetch_body(message.uid))
|
||||
if mail.multipart?
|
||||
@body = mail.html_part.decoded_and_charseted
|
||||
else
|
||||
@body = mail.decoded_and_charseted
|
||||
end
|
||||
|
||||
if @body.nil?
|
||||
@body = t(:no_body,:scope=>:message)
|
||||
else
|
||||
if @body=~/cid:([\w@\.]+)/
|
||||
attachments = mail.attachments
|
||||
if not attachments.size.zero?
|
||||
for idx in 0..attachments.size - 1
|
||||
@body.gsub!(/cid:#{attachments[idx].cid}/,attachment_download_path(message.uid,idx))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
render 'html_body',:layout => 'html_body'
|
||||
end
|
||||
|
||||
def attachment
|
||||
attachments = []
|
||||
message = @current_user.messages.where('folder_id = ? and uid = ?',@current_folder,params[:id]).first
|
||||
mail = Mail.new(@mailbox.fetch_body(message.uid))
|
||||
if mail.multipart? == true
|
||||
attachments = mail.attachments
|
||||
else
|
||||
attachments << Mail::Part.new(mail)
|
||||
end
|
||||
a = attachments[params[:idx].to_i]
|
||||
headers['Content-type'] = a.main_type + "/" + a.sub_type
|
||||
headers['Content-Disposition'] = %(attachment; filename="#{a.filename}")
|
||||
render :text => a.decoded
|
||||
end
|
||||
|
||||
|
||||
############################################# protected section ##########################################
|
||||
|
||||
protected
|
||||
|
||||
def prepare_multi2_buttons
|
||||
@multi2_buttons = []
|
||||
@multi2_buttons << {:text => 'trash',:scope=>:message,:image => 'trash.png'}
|
||||
@multi2_buttons << {:text => 'set_unread',:scope=>:message,:image => 'unseen.png'}
|
||||
@multi2_buttons << {:text => 'set_read',:scope=>:message,:image => 'seen.png'}
|
||||
end
|
||||
|
||||
def prepare_multi1_buttons
|
||||
@multi1_buttons = []
|
||||
@multi1_buttons << {:text => 'copy',:scope=>:message,:image => 'copy.png'}
|
||||
@multi1_buttons << {:text => 'move',:scope=>:message,:image => 'move.png'}
|
||||
end
|
||||
|
||||
def prepare_multi3_buttons
|
||||
@multi3_buttons = []
|
||||
@multi3_buttons << {:text => 'show_header',:scope=>:show,:image => 'zoom.png'}
|
||||
@multi3_buttons << {:text => 'trash',:scope=>:show,:image => 'trash.png'}
|
||||
@multi3_buttons << {:text => 'reply',:scope=>:show,:image => 'reply.png'}
|
||||
end
|
||||
end
|
|
@ -1,354 +0,0 @@
|
|||
require 'imap_session'
|
||||
require 'imap_mailbox'
|
||||
require 'imap_message'
|
||||
require 'mail'
|
||||
require 'mail_plugin_extension'
|
||||
require 'net/smtp'
|
||||
|
||||
class MessagesOpsController < ApplicationController
|
||||
|
||||
include ImapMailboxModule
|
||||
include ImapSessionModule
|
||||
include ImapMessageModule
|
||||
include MessagesHelper
|
||||
|
||||
before_filter :check_current_user ,:selected_folder,:get_current_folders
|
||||
before_filter :open_imap_session, :select_imap_folder
|
||||
before_filter :prepare_compose_buttons
|
||||
before_filter :get_system_folders, :only => [:composed,:single,:multi]
|
||||
before_filter :prepare_composed , :only => [:composed]
|
||||
before_filter :create_message_with_params, :only=> [:composed,:single,:multi]
|
||||
after_filter :close_imap_session
|
||||
theme :theme_resolver
|
||||
|
||||
|
||||
############################################### single #####################################
|
||||
|
||||
def single
|
||||
if params[:reply]
|
||||
reply
|
||||
return
|
||||
elsif params[:trash]
|
||||
trash
|
||||
elsif params[:move]
|
||||
move
|
||||
elsif params[:copy]
|
||||
copy
|
||||
end
|
||||
redirect_to :controller => 'messages', :action => 'index'
|
||||
end
|
||||
|
||||
############################################### multi ######################################
|
||||
|
||||
def multi
|
||||
begin
|
||||
if !params[:uids]
|
||||
flash[:warning] = t(:no_selected,:scope=>:message)
|
||||
elsif params[:set_unread]
|
||||
set_unread
|
||||
elsif params[:set_read]
|
||||
set_read
|
||||
elsif params[:trash]
|
||||
trash
|
||||
elsif params[:copy]
|
||||
copy
|
||||
elsif params[:move]
|
||||
move
|
||||
end
|
||||
rescue Exception => e
|
||||
flash[:error] = "#{t(:imap_error,:scope=>:internal)} (#{e.to_s})"
|
||||
end
|
||||
redirect_to :controller => 'messages', :action => 'index'
|
||||
end
|
||||
|
||||
############################################### ################################################
|
||||
|
||||
|
||||
def set_unread
|
||||
params["uids"].each do |uid|
|
||||
@mailbox.set_unread(uid)
|
||||
@current_user.messages.where('folder_id = ? and uid = ?',@current_folder,uid).first.update_attributes(:unseen => 1)
|
||||
end
|
||||
end
|
||||
|
||||
def set_read
|
||||
params["uids"].each do |uid|
|
||||
@mailbox.set_read(uid)
|
||||
@current_user.messages.where('folder_id = ? and uid = ?',@current_folder,uid).first.update_attributes(:unseen => 0)
|
||||
end
|
||||
end
|
||||
|
||||
def trash
|
||||
if @trash_folder.nil?
|
||||
flash[:warning] = t(:not_configured_trash, :scope=>:folder)
|
||||
else
|
||||
params["uids"].each do |uid|
|
||||
@mailbox.move_message(uid,@trash_folder.full_name)
|
||||
message = @current_folder.messages.find_by_uid(uid)
|
||||
message.change_folder(@trash_folder)
|
||||
end
|
||||
@mailbox.expunge
|
||||
@trash_folder.update_stats
|
||||
@current_folder.update_stats
|
||||
end
|
||||
end
|
||||
|
||||
def copy
|
||||
if params[:folder][:target].empty?
|
||||
flash[:warning] = t(:no_selected,:scope=>:folder)
|
||||
else
|
||||
dest_folder = @current_user.folders.find(params[:folder][:target])
|
||||
params["uids"].each do |uid|
|
||||
@mailbox.copy_message(uid,dest_folder.full_name)
|
||||
message = @current_folder.messages.find_by_uid(uid)
|
||||
new_message = message.clone
|
||||
new_message.folder_id = dest_folder.id
|
||||
new_message.save
|
||||
end
|
||||
dest_folder.update_stats
|
||||
@current_folder.update_stats
|
||||
end
|
||||
end
|
||||
|
||||
def move
|
||||
if params[:folder][:target].empty?
|
||||
flash[:warning] = t(:no_selected,:scope=>:folder)
|
||||
else
|
||||
dest_folder = @current_user.folders.find(params[:folder][:target])
|
||||
logger.info "DEST: "+dest_folder.inspect
|
||||
params["uids"].each do |uid|
|
||||
logger.info "UID: "+uid
|
||||
logger.info "DEST_FULL: "+dest_folder.full_name
|
||||
@mailbox.move_message(uid,dest_folder.full_name)
|
||||
message = @current_folder.messages.find_by_uid(uid)
|
||||
logger.info "M: "+message.inspect
|
||||
logger.info "UPDATE_DEST_BEFORE1: "+dest_folder.inspect
|
||||
message.change_folder(dest_folder)
|
||||
logger.info "UPDATE_DEST_BEFORE2: "+dest_folder.inspect
|
||||
end
|
||||
logger.info "UPDATE_DEST_BEFORE: "+dest_folder.inspect
|
||||
@mailbox.expunge
|
||||
dest_folder.update_stats
|
||||
logger.info "UPDATE_DEST: "+dest_folder.inspect
|
||||
@current_folder.update_stats
|
||||
logger.info "UPDATE_CUT: "+@current_folder.inspect
|
||||
end
|
||||
end
|
||||
|
||||
def upload
|
||||
begin
|
||||
raise MailrException.new :cause=>:no_tmp_dir,:scope=>:common if not File.exists?($defaults["msg_upload_dir"])
|
||||
raise MailrException.new :cause=>:no_file_chosen,:scope=>:common if not params[:upload]
|
||||
@operation = :upload
|
||||
name = params[:file][:data].original_filename
|
||||
upload_dir = $defaults["msg_upload_dir"]
|
||||
path = File.join(upload_dir, @current_user.username + "_" + name)
|
||||
File.open(path, "wb") { |f| f.write(params[:file][:data].read) }
|
||||
rescue MailrException => e
|
||||
flash[:error] = t(e.message[:cause],:scope => e.message[:scope])
|
||||
rescue Exception => e
|
||||
flash[:error] = t(:general_error,:scope=>:internal) + " (" + e.class.name + " " + e.to_s + ")"
|
||||
end
|
||||
create_message_with_params
|
||||
render 'messages/compose'
|
||||
end
|
||||
|
||||
# Files uploaded from Internet Explorer:
|
||||
#
|
||||
#Internet Explorer includes the entire path of a file in the filename sent, so the original_filename routine will return something like:
|
||||
#
|
||||
#C:\Documents and Files\user_name\Pictures\My File.jpg
|
||||
#
|
||||
#instead of just:
|
||||
#
|
||||
#My File.jpg
|
||||
#
|
||||
#This is easily handled by File.basename, which strips out everything before the filename.
|
||||
#
|
||||
#def sanitize_filename(file_name)
|
||||
# # get only the filename, not the whole path (from IE)
|
||||
# just_filename = File.basename(file_name)
|
||||
# # replace all none alphanumeric, underscore or perioids
|
||||
# # with underscore
|
||||
# just_filename.sub(/[^\w\.\-]/,'_')
|
||||
#end
|
||||
#
|
||||
#Deleting an existing File:
|
||||
#
|
||||
#If you want to delete any existing file then its simple and need to write following code:
|
||||
#
|
||||
# def cleanup
|
||||
# File.delete("#{RAILS_ROOT}/dirname/#{@filename}")
|
||||
# if File.exist?("#{RAILS_ROOT}/dirname/#{@filename}")
|
||||
# end
|
||||
|
||||
def composed
|
||||
if params[:delete_marked] and params[:files]
|
||||
params[:files].each do |filename|
|
||||
path = File.join(Rails.root,$defaults["msg_upload_dir"],@current_user.username + "_" +filename)
|
||||
File.delete(path) if File.exist?(path)
|
||||
end
|
||||
create_message_with_params
|
||||
@operation = :new
|
||||
render 'messages/compose'
|
||||
return
|
||||
elsif params[:upload]
|
||||
upload
|
||||
elsif params[:save]
|
||||
save
|
||||
elsif params[:sendout]
|
||||
sendout
|
||||
else
|
||||
redirect_to :controller => 'messages', :action => 'index'
|
||||
end
|
||||
end
|
||||
|
||||
def sendout
|
||||
begin
|
||||
smtp_server = @current_user.servers.primary_for_smtp
|
||||
raise MailrException.new :cause=>:not_configured_smtp,:scope => :compose if smtp_server.nil?
|
||||
raise MailrException.new :cause=>:has_no_domain,:scope=>:user if @current_user.has_domain?.nil?
|
||||
raise MailrException.new :cause=>:not_configured_sent,:scope=>:compose if @sent_folder.nil?
|
||||
send_mail_message( smtp_server,
|
||||
@current_user.has_domain?,
|
||||
@current_user.login,
|
||||
@current_user.get_cached_password(session),
|
||||
@mail.to_s,
|
||||
@current_user.email,
|
||||
params[:message][:to_addr]
|
||||
)
|
||||
@mailbox.append(@sent_folder.full_name,@mail.to_s,[:Seen])
|
||||
upload_dir = $defaults["msg_upload_dir"]
|
||||
@attachments.each do |file|
|
||||
path = File.join(upload_dir, @current_user.username + "_" + file[:name])
|
||||
File.delete(path) if File.exist?(path)
|
||||
end
|
||||
rescue MailrException => e
|
||||
flash[:error] = t(e.message[:cause],:scope => e.message[:scope])
|
||||
rescue Exception => e
|
||||
flash[:error] = t(:general_error,:scope=>:internal) + " (" + e.class.name + " " + e.to_s + ")"
|
||||
else
|
||||
flash[:notice] = t(:was_sent,:scope => :compose)
|
||||
redirect_to :controller => 'messages', :action => 'index'
|
||||
return
|
||||
end
|
||||
@operation = :new
|
||||
render 'messages/compose'
|
||||
end
|
||||
|
||||
def save
|
||||
begin
|
||||
raise MailrException.new :cause=>:not_configured_drafts,:scope=>:folder if @drafts_folder.nil?
|
||||
@mailbox.append(@drafts_folder.full_name,@mail.to_s,[:Seen])
|
||||
if params[:olduid].present?
|
||||
@mailbox.move_message(params[:olduid],@trash_folder.full_name)
|
||||
@mailbox.expunge
|
||||
end
|
||||
rescue MailrException => e
|
||||
flash[:error] = t(e.message[:cause],:scope => e.message[:scope])
|
||||
rescue Exception => e
|
||||
flash[:error] = t(:general_error,:scope=>:internal) + " (" + e.class.name + " " + e.to_s + ")"
|
||||
else
|
||||
@attachments.each do |filename|
|
||||
path = File.join(Rails.root,filename)
|
||||
File.delete(path) if File.exist?(path)
|
||||
end
|
||||
flash[:notice] = t(:was_saved,:scope => :compose)
|
||||
end
|
||||
redirect_to :controller => 'messages', :action => 'index'
|
||||
end
|
||||
|
||||
#FIXME edit does not support attachments
|
||||
def edit
|
||||
old_message = @current_user.messages.where('folder_id = ? and uid = ?',@current_folder,params[:uids].first).first
|
||||
@message = Message.new
|
||||
@message.to_addr = old_message.to_addr
|
||||
@message.subject = old_message.subject
|
||||
|
||||
imap_message = @mailbox.fetch_body(old_message.uid)
|
||||
mail = Mail.new(imap_message)
|
||||
if mail.multipart?
|
||||
@message.body = mail.text_part.nil? ? "" : mail.text_part.decoded_and_charseted.gsub(/<\/?[^>]*>/, "")
|
||||
else
|
||||
@message.body = mail.decoded_and_charseted.gsub(/<\/?[^>]*>/, "")
|
||||
end
|
||||
@attachments = []
|
||||
@operation = :edit
|
||||
@olduid = old_message.uid
|
||||
render 'messages/compose'
|
||||
end
|
||||
|
||||
def reply
|
||||
old_message = @current_user.messages.where('folder_id = ? and uid = ?',@current_folder,params[:uids].first).first
|
||||
@message = Message.new
|
||||
@message.to_addr = old_message.from_addr
|
||||
@message.subject = old_message.subject
|
||||
|
||||
imap_message = @mailbox.fetch_body(old_message.uid)
|
||||
mail = Mail.new(imap_message)
|
||||
if mail.multipart?
|
||||
@message.body = mail.text_part.nil? ? "" : mail.text_part.decoded_and_charseted.gsub(/<\/?[^>]*>/, "")
|
||||
else
|
||||
@message.body = mail.decoded_and_charseted.gsub(/<\/?[^>]*>/, "")
|
||||
end
|
||||
@attachments = []
|
||||
@operation = :reply
|
||||
render 'messages/compose'
|
||||
end
|
||||
###################################### protected section #######################################
|
||||
|
||||
protected
|
||||
|
||||
def send_mail_message(smtp_server,domain,username,password,msgstr,from,to)
|
||||
if smtp_server.auth.nil?
|
||||
smtp = Net::SMTP.start(smtp_server.name, smtp_server.port, domain)
|
||||
else
|
||||
smtp = Net::SMTP.start(smtp_server.name, smtp_server.port, domain, username, password, smtp_server.auth)
|
||||
end
|
||||
smtp.send_message msgstr, from, to
|
||||
smtp.finish
|
||||
end
|
||||
|
||||
def prepare_composed
|
||||
@mail = Mail.new
|
||||
@mail.subject = params[:message][:subject]
|
||||
@mail.from = @current_user.full_id
|
||||
#TODO check if email address is valid if not get address from contacts
|
||||
@mail.to = params[:message][:to_addr]
|
||||
@mail.body = params[:message][:body]
|
||||
@attachments = Dir.glob(File.join($defaults["msg_upload_dir"],@current_user.username + "*"))
|
||||
@attachments.each do |a|
|
||||
@mail.add_file :filename => File.basename(a.gsub(/#{@current_user.username}_/,"")), :content => File.read(a)
|
||||
end
|
||||
end
|
||||
|
||||
############################################ set_mail_defaults ####################################
|
||||
|
||||
def set_mail_defaults(user,server,session)
|
||||
if server.auth.nil? or server.auth == 'none'
|
||||
password = nil
|
||||
authentication = nil
|
||||
enable_starttls_auto = nil
|
||||
openssl_verify_mode = nil
|
||||
user_name = nil
|
||||
else
|
||||
password = user.get_cached_password(session)
|
||||
authentication = server.auth
|
||||
enable_starttls_auto = server.use_tls
|
||||
openssl_verify_mode = OpenSSL::SSL::VERIFY_NONE
|
||||
user_name = user.login
|
||||
end
|
||||
Mail.defaults do
|
||||
delivery_method :smtp, {:address => server.name,
|
||||
:port => server.port,
|
||||
:domain => user.domain,
|
||||
:user_name => user_name,
|
||||
:password => password,
|
||||
:authentication => authentication,
|
||||
:enable_starttls_auto => enable_starttls_auto,
|
||||
:openssl_verify_mode => openssl_verify_mode
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,55 +0,0 @@
|
|||
class PrefsController < ApplicationController
|
||||
|
||||
before_filter :check_current_user,:selected_folder
|
||||
|
||||
before_filter :get_current_folders
|
||||
|
||||
before_filter :get_prefs, :only => [:look,:update_look]
|
||||
|
||||
theme :theme_resolver
|
||||
|
||||
def update_look
|
||||
if params[:prefs]
|
||||
@prefs.update_attributes(params[:prefs])
|
||||
end
|
||||
flash[:notice] = t(:were_saved,:scope=>:prefs)
|
||||
redirect_to :action => 'look'
|
||||
end
|
||||
|
||||
def update_servers
|
||||
|
||||
redirect_to :action => 'servers'
|
||||
end
|
||||
|
||||
def update_identity
|
||||
if params[:user]
|
||||
@current_user.first_name = params[:user][:first_name]
|
||||
@current_user.last_name = params[:user][:last_name]
|
||||
@current_user.domain = params[:user][:domain]
|
||||
if @current_user.valid?
|
||||
@current_user.save
|
||||
flash[:notice] = t(:were_saved,:scope=>:prefs)
|
||||
redirect_to :action => 'identity'
|
||||
else
|
||||
render 'prefs/identity'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def look
|
||||
|
||||
end
|
||||
|
||||
def identity
|
||||
end
|
||||
|
||||
def servers
|
||||
@servers = @current_user.servers
|
||||
end
|
||||
|
||||
############################# protected section ##################################
|
||||
|
||||
def get_prefs
|
||||
@prefs = @current_user.prefs
|
||||
end
|
||||
end
|
|
@ -1,75 +0,0 @@
|
|||
class UserController < ApplicationController
|
||||
|
||||
theme :theme_resolver
|
||||
layout "simple"
|
||||
|
||||
def login
|
||||
end
|
||||
|
||||
def logout
|
||||
reset_session
|
||||
flash[:notice] = t(:logged_out,:scope=>:user)
|
||||
redirect_to :action => "login"
|
||||
end
|
||||
|
||||
def authenticate
|
||||
|
||||
if not $defaults["only_can_logins"].nil?
|
||||
if not $defaults["only_can_logins"].include?(params[:user][:login])
|
||||
redirect_to :controller => 'internal', :action => 'onlycanlogins'
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
user = User.find_by_login(params[:user][:login])
|
||||
if user.nil?
|
||||
redirect_to :action => 'unknown' ,:login=> params[:user][:login]
|
||||
else
|
||||
session[:user_id] = user.id
|
||||
user.set_cached_password(session,params[:user][:password])
|
||||
|
||||
if session["return_to"]
|
||||
redirect_to(session["return_to"])
|
||||
session["return_to"] = nil
|
||||
else
|
||||
redirect_to :controller=> 'messages', :action=> 'index'
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
def loginfailure
|
||||
end
|
||||
|
||||
def setup
|
||||
@user = User.new
|
||||
@server = Server.new
|
||||
end
|
||||
|
||||
def unknown
|
||||
end
|
||||
|
||||
def create
|
||||
|
||||
@user = User.new
|
||||
@user.login = params[:user][:login]
|
||||
@user.first_name = params[:user][:first_name]
|
||||
@user.last_name = params[:user][:last_name]
|
||||
|
||||
@server = Server.new
|
||||
@server.name = params[:server][:name]
|
||||
|
||||
if @user.valid? and @server.valid?
|
||||
@user.save
|
||||
#@server.user_id = @user.id
|
||||
#@server.save
|
||||
Prefs.create_default(@user)
|
||||
Server.create_defaults(@user)
|
||||
flash[:notice] = t(:setup_done,:scope=>:user)
|
||||
redirect_to :action => 'login'
|
||||
else
|
||||
render "setup"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
332
app/helpers/application_helper.rb
Executable file → Normal file
332
app/helpers/application_helper.rb
Executable file → Normal file
|
@ -1,334 +1,2 @@
|
|||
require 'iconv'
|
||||
|
||||
module ApplicationHelper
|
||||
|
||||
def form_field(object,field,flabel,example,val)
|
||||
model_name = eval(object.class.model_name)
|
||||
html = ""
|
||||
html << "<div class=\"param_group\">"
|
||||
if not object.errors[field.to_sym].empty?
|
||||
html << "<div class=\"fieldWithErrors\">"
|
||||
|
||||
end
|
||||
|
||||
html << "<label class=\"label\">"
|
||||
flabel.nil? ? html << model_name.human_attribute_name(field) : html << t(flabel.to_sym)
|
||||
html << "</label>"
|
||||
|
||||
if not object.errors[field.to_sym].empty?
|
||||
html << "<span class=\"error\"> "
|
||||
html << object.errors[field.to_sym].to_s
|
||||
html << "</span>"
|
||||
html << "</div>"
|
||||
end
|
||||
html << "<input id=\""
|
||||
html << object.class.name.downcase+"_"+field
|
||||
html << "\""
|
||||
html << " name=\"#{object.class.name.downcase}[#{field}]\""
|
||||
html << " type=\"text\" class=\"text_field\" value=\""
|
||||
value = val || object.instance_eval(field) || ""
|
||||
html << value
|
||||
html << "\"/>"
|
||||
html << "<span class=\"description\">"
|
||||
html << t(:example,:scope=>:common)
|
||||
html << ": "
|
||||
html << example
|
||||
html << "</span>"
|
||||
html << "</div>"
|
||||
|
||||
end
|
||||
|
||||
def show_param_view(object,field,value)
|
||||
model_name = eval(object.class.model_name)
|
||||
html = ""
|
||||
html << "<div class=\"group clearfix\">"
|
||||
html << "<label class=\"label\">#{model_name.human_attribute_name(field)}: </label>"
|
||||
html << value
|
||||
html << "</div>"
|
||||
html
|
||||
end
|
||||
|
||||
def area_field(object,field,flabel,example,val,cols,rows)
|
||||
model_name = eval(object.class.model_name)
|
||||
html = ""
|
||||
html << "<div class=\"group\">"
|
||||
|
||||
if not object.errors[field.to_sym].empty?
|
||||
html << "<div class=\"fieldWithErrors\">"
|
||||
end
|
||||
|
||||
html << "<label class=\"label\">"
|
||||
flabel.nil? ? html << model_name.human_attribute_name(field) : html << t(flabel.to_sym)
|
||||
html << "</label>"
|
||||
|
||||
if not object.errors[field.to_sym].empty?
|
||||
html << "<span class=\"error\">"
|
||||
html << object.errors[field.to_sym].to_s
|
||||
html << "</span>"
|
||||
html << "</div>"
|
||||
end
|
||||
|
||||
name = object.class.name.downcase + '[' + field + ']'
|
||||
id = object.class.name.downcase+"_"+field
|
||||
value = val || object.instance_eval(field) || ""
|
||||
html << "<textarea id=\"#{id}\" name=\"#{name}\" class=\"text_area\" cols=\"#{cols}\" rows=\"#{rows}\">#{value}</textarea>"
|
||||
|
||||
desc = t(:example,:scope=>:common) + ": " + example
|
||||
html << "<span class=\"description\">#{desc}</span>"
|
||||
|
||||
html << "</div>"
|
||||
end
|
||||
|
||||
def form_button(text,image)
|
||||
html = ""
|
||||
html << "<div class=\"group\">"
|
||||
html << "<button class=\"button\" type=\"submit\">"
|
||||
html << "<img src=\""
|
||||
html << current_theme_image_path(image)
|
||||
html << "\" alt=\""
|
||||
html << t(text.to_sym)
|
||||
html << "\" />"
|
||||
html << t(text.to_sym)
|
||||
html << "</button></div>"
|
||||
end
|
||||
|
||||
def single_action(text,scope,image)
|
||||
html = ""
|
||||
html << "<div class=\"actiongroup clearfix\">"
|
||||
html << "<button class=\"button\" name=\"#{text}\" type=\"submit\">"
|
||||
html << "<img src=\""
|
||||
html << current_theme_image_path(image)
|
||||
html << "\" alt=\""
|
||||
html << t(text.to_sym, :scope => scope.to_sym)
|
||||
html << "\" />"
|
||||
html << t(text.to_sym, :scope => scope.to_sym)
|
||||
html << "</button></div>"
|
||||
end
|
||||
|
||||
def single_action_onclick(text,scope,image,onclick)
|
||||
html = ""
|
||||
html << "<div class=\"actiongroup clearfix\">"
|
||||
html << "<button class=\"button\" type=\"submit\" onclick=\"window.location='"
|
||||
html << onclick
|
||||
html << "'\">"
|
||||
html << "<img src=\""
|
||||
html << current_theme_image_path(image)
|
||||
html << "\" alt=\""
|
||||
html << t(text.to_sym, :scope => scope.to_sym)
|
||||
html << "\" />"
|
||||
html << t(text.to_sym, :scope => scope.to_sym)
|
||||
html << "</button>"
|
||||
html << "</div>"
|
||||
end
|
||||
|
||||
def group_action(buttons)
|
||||
html = ""
|
||||
html << "<div class=\"actiongroup clearfix\">"
|
||||
buttons.each do |b|
|
||||
html << "<button class=\"button\" type=\"submit\" name=\"#{b[:text]}\">"
|
||||
html << "<img src=\""
|
||||
html << current_theme_image_path(b[:image])
|
||||
html << "\" alt=\""
|
||||
html << t(b[:text].to_sym,:scope=>b[:scope].to_sym)
|
||||
html << "\" />"
|
||||
html << t(b[:text].to_sym,:scope=>b[:scope].to_sym)
|
||||
html << "</button> "
|
||||
end
|
||||
html << "</div>"
|
||||
end
|
||||
|
||||
def group_action_text(buttons,text)
|
||||
html = ""
|
||||
html << "<div class=\"group\">"
|
||||
buttons.each do |b|
|
||||
html << "<button class=\"button\" type=\"submit\" name=\"#{b[:text]}\">"
|
||||
html << "<img src=\""
|
||||
html << current_theme_image_path(b[:image])
|
||||
html << "\" alt=\""
|
||||
html << t(b[:text].to_sym,:scope=>b[:scope].to_sym)
|
||||
html << "\" />"
|
||||
html << t(b[:text].to_sym,:scope=>b[:scope].to_sym)
|
||||
html << "</button> "
|
||||
end
|
||||
html << text
|
||||
html << "</div>"
|
||||
end
|
||||
|
||||
def form_buttons(buttons)
|
||||
html = ""
|
||||
html << "<div class=\"group\">"
|
||||
|
||||
buttons.each do |b|
|
||||
html << "<button class=\"button\" type=\"submit\" name=\"#{b[:text]}\">"
|
||||
html << "<img src=\""
|
||||
html << current_theme_image_path(b[:image])
|
||||
html << "\" alt=\""
|
||||
html << t(b[:text].to_sym)
|
||||
html << "\" />"
|
||||
html << t(b[:text].to_sym)
|
||||
html << "</button> "
|
||||
end
|
||||
|
||||
html << "</div>"
|
||||
end
|
||||
|
||||
def form_button_value(text,image,onclick)
|
||||
html = ""
|
||||
html << "<div class=\"group\">"
|
||||
html << "<button class=\"button\" type=\"submit\" onclick=\"window.location='"
|
||||
html << onclick
|
||||
html << "'\">"
|
||||
html << "<img src=\""
|
||||
html << current_theme_image_path(image)
|
||||
html << "\" alt=\""
|
||||
html << text
|
||||
html << "\" />"
|
||||
html << t(text.to_sym)
|
||||
html << "</button></div>"
|
||||
end
|
||||
|
||||
def simple_input_field(name,id,label,value)
|
||||
html = ""
|
||||
html << "<div class=\"param_group\">"
|
||||
html << "<label class=\"label\">#{label}</label>"
|
||||
html << "<input name=\"#{name}[#{id}]\" id=\"#{name}_#{id} class=\"text_field\" type=\"text\" value=\"#{value}\">"
|
||||
html << "</div>"
|
||||
end
|
||||
|
||||
def select_field(name,object,label,blank)
|
||||
html = ""
|
||||
html << "<div class=\"group\">"
|
||||
html << "<label class=\"label\">#{label}</label>"
|
||||
html << select(name, name, object.all.collect {|p| [ p.name, p.id ] }, { :include_blank => (blank == true ? true : false)})
|
||||
html << "</div>"
|
||||
end
|
||||
|
||||
def select_field_table(object,field,table_choices,choice,blank)
|
||||
model_name = eval(object.class.model_name)
|
||||
html = ""
|
||||
html << "<div class=\"param_group\">"
|
||||
html << "<label class=\"label\">#{model_name.human_attribute_name(field)}</label>"
|
||||
html << select(object.class.to_s.downcase, field, options_for_select(table_choices,choice), {:include_blank => blank})
|
||||
html << "</div>"
|
||||
end
|
||||
|
||||
def select_field_table_t(object,field,table_choices,choice,blank)
|
||||
model_name = eval(object.class.model_name)
|
||||
html = ""
|
||||
html << "<div class=\"param_group\">"
|
||||
html << "<label class=\"label\">#{model_name.human_attribute_name(field)}</label>"
|
||||
t = []
|
||||
table_choices.each do |c|
|
||||
t << [t(c.to_sym,:scope=>:prefs),c.to_s]
|
||||
end
|
||||
html << select(object.class.to_s.downcase, field, options_for_select(t,choice), {:include_blank => blank})
|
||||
html << "</div>"
|
||||
end
|
||||
|
||||
#def form_simle_field(name,label,value)
|
||||
# html = ""
|
||||
# html << "<div class=\"group\">"
|
||||
# html << "<label class=\"label\">#{label}</label>"
|
||||
# html << "<input class=\"text_field\" type=\"text\" value=\"#{value}\">"
|
||||
# html << "</div>"
|
||||
#end
|
||||
|
||||
#def nav_to_folders
|
||||
# link_to( t(:folders,:scope=>:folder), :controller=>:folders, :action=>:index )
|
||||
#end
|
||||
#
|
||||
#def nav_to_messages
|
||||
# link_to( t(:messages,:scope=>:message), :controller=>:messages, :action=>:index )
|
||||
#end
|
||||
#
|
||||
#def nav_to_compose
|
||||
# link_to( t(:compose,:scope=>:compose), :controller=>:messages, :action=>:compose )
|
||||
#end
|
||||
#
|
||||
#def nav_to_contacts
|
||||
# link_to( t(:contacts,:scope=>:contact), contacts_path )
|
||||
#end
|
||||
#
|
||||
#def nav_to_prefs
|
||||
# link_to( t(:prefs,:scope=>:prefs), prefs_look_path )
|
||||
#end
|
||||
|
||||
def single_navigation(label,scope)
|
||||
s = ""
|
||||
s += "<ul>"
|
||||
s += "<li class=\"first active\">#{link_to(t(label,:scope=>scope),'#')}</li>"
|
||||
s += "<li class=\"last\"> </li>"
|
||||
s += "</ul>"
|
||||
end
|
||||
|
||||
def main_navigation(active)
|
||||
instance_variable_set("@#{active}", "active")
|
||||
s = ""
|
||||
s += "<ul>"
|
||||
s += "<li class=\"first #{@messages_tab}\">#{link_to( t(:messages,:scope=>:message), messages_path )}</li>"
|
||||
s += "<li class=\"#{@compose_tab}\">#{link_to( t(:compose,:scope=>:compose), compose_path )}</li>"
|
||||
s += "<li class=\"#{@folders_tab}\">#{link_to( t(:folders,:scope=>:folder), folders_path )}</li>"
|
||||
s += "<li class=\"#{@contacts_tab}\">#{link_to( t(:contacts,:scope=>:contact), contacts_path )}</li>"
|
||||
s += "<li class=\"#{@prefs_tab}\">#{link_to( t(:prefs,:scope=>:prefs), prefs_look_path )}</li>"
|
||||
s += "<li class=\"last #{@links_tab}\">#{link_to( t(:links,:scope=>:link), links_path )}</li>"
|
||||
s += "</ul>"
|
||||
end
|
||||
|
||||
def prefs_navigation(active)
|
||||
instance_variable_set("@#{active}", "active")
|
||||
s = ""
|
||||
s += "<ul>"
|
||||
s += "<li class=\"first #{@look_tab}\">#{link_to( t(:look,:scope=>:prefs), prefs_look_path )}</li>"
|
||||
s += "<li class=\"#{@identity_tab}\">#{link_to( t(:identity,:scope=>:prefs), prefs_identity_path )}</li>"
|
||||
s += "<li class=\"last #{@servers_tab}\">#{link_to( t(:servers,:scope=>:prefs), prefs_servers_path )}</li>"
|
||||
s += "</ul>"
|
||||
end
|
||||
|
||||
def multi_select(id, name, objects, selected_objects, label, value,joiner,content = {})
|
||||
options = ""
|
||||
objects.each do |o|
|
||||
selected = selected_objects.include?(o) ? " selected=\"selected\"" : ""
|
||||
option_value = escape_once(o.send(value))
|
||||
text = [option_value]
|
||||
unless content[:text].nil?
|
||||
text = []
|
||||
content[:text].each do |t|
|
||||
text << o.send(t)
|
||||
end
|
||||
text = text.join(joiner)
|
||||
end
|
||||
text.gsub!(/^\./,'')
|
||||
bracket = []
|
||||
unless content[:bracket].nil?
|
||||
content[:bracket].each do |b|
|
||||
bracket << o.send(b)
|
||||
end
|
||||
bracket = bracket.join(joiner)
|
||||
end
|
||||
option_content = bracket.empty? ? "#{text}" : "#{text} (#{bracket})"
|
||||
options << "<option value=\"#{option_value}\"#{selected}> #{option_content} </option>\n"
|
||||
end
|
||||
"<div class=\"param_group\"><label class=\"label\">#{label}</label><select multiple=\"multiple\" size=10 id=\"#{id}\" name=\"#{name}\">\n#{options}</select></div>"
|
||||
end
|
||||
|
||||
def force_charset(text)
|
||||
begin
|
||||
Iconv.iconv("UTF-8",$defaults["msg_unknown_charset"],text)
|
||||
rescue
|
||||
text
|
||||
end
|
||||
end
|
||||
|
||||
def content_for_sidebar
|
||||
s = render :partial => 'sidebar/logo'
|
||||
s += render :partial => 'folders/list'
|
||||
s += render :partial => 'sidebar/calendar_view'
|
||||
s += render :partial => 'internal/version'
|
||||
s
|
||||
end
|
||||
|
||||
def boolean_answer(answer)
|
||||
answer == true ? t(:true_answer,:scope=>:common) : t(:false_answer,:scope=>:common)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
module ContactsHelper
|
||||
|
||||
def contacts_table_header
|
||||
html = ""
|
||||
$defaults["contacts_table_fields"].each do |f|
|
||||
html << "<th>"
|
||||
if params[:sort_field] == f
|
||||
params[:sort_dir].nil? ? dir = 'desc' : dir = nil
|
||||
end
|
||||
|
||||
html << link_to(Contact.human_attribute_name(f), {:controller => 'contacts',:action => 'index',:sort_field => f,:sort_dir => dir}, {:class=>"header"})
|
||||
html << "</th>"
|
||||
end
|
||||
html
|
||||
end
|
||||
|
||||
end
|
|
@ -1,66 +0,0 @@
|
|||
module FolderHelper
|
||||
|
||||
def folder_link(folder)
|
||||
|
||||
folder.parent.empty? ? name = folder.name : name = folder.parent.gsub(/\./,'#') + "#" + folder.name
|
||||
|
||||
if folder.isInbox?
|
||||
name_shown = t(:inbox_name,:scope => :folder)
|
||||
elsif folder.isSent?
|
||||
name_shown = t(:sent_name,:scope => :folder)
|
||||
elsif folder.isDrafts?
|
||||
name_shown = t(:drafts_name,:scope => :folder)
|
||||
elsif folder.isTrash?
|
||||
name_shown = t(:trash_name,:scope => :folder)
|
||||
else
|
||||
name_shown = folder.name.capitalize
|
||||
end
|
||||
s = link_to name_shown, folders_select_path(:id => name)
|
||||
|
||||
if folder.isTrash?
|
||||
if not folder.total.zero?
|
||||
s <<' ('
|
||||
s << link_to(t(:emptybin,:scope=>:folder),folders_emptybin_path)
|
||||
s << ')'
|
||||
end
|
||||
else
|
||||
if !folder.unseen.zero?
|
||||
s += ' (' + folder.unseen.to_s + ')'
|
||||
end
|
||||
end
|
||||
s
|
||||
end
|
||||
|
||||
def pretty_folder_name(folder)
|
||||
if folder.nil?
|
||||
t(:no_selected,:scope=>:folder)
|
||||
else
|
||||
if folder.isInbox?
|
||||
t(:inbox_name,:scope => :folder)
|
||||
elsif folder.isSent?
|
||||
t(:sent_name,:scope => :folder)
|
||||
elsif folder.isDrafts?
|
||||
t(:drafts_name,:scope => :folder)
|
||||
elsif folder.isTrash?
|
||||
t(:trash_name,:scope => :folder)
|
||||
else
|
||||
folder.name.capitalize
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def select_for_folders(name,id,collection,label,choice,blank)
|
||||
html = ""
|
||||
html << "<div class=\"param_group\">"
|
||||
html << "<label class=\"label\">#{label}</label>"
|
||||
html << simple_select_for_folders(name,id,collection,choice,blank)
|
||||
html << "</div>"
|
||||
end
|
||||
|
||||
def simple_select_for_folders(name,id,collection,choice,blank)
|
||||
html = ""
|
||||
html << select(name , id, options_from_collection_for_select(collection, 'id', 'full_name', choice),{ :include_blank => (blank == true ? true : false)})
|
||||
html
|
||||
end
|
||||
|
||||
end
|
|
@ -1,2 +0,0 @@
|
|||
module InternalHelper
|
||||
end
|
|
@ -1,17 +0,0 @@
|
|||
module LinksHelper
|
||||
|
||||
def links_table_header
|
||||
html = ""
|
||||
$defaults["links_table_fields"].each do |f|
|
||||
html << "<th>"
|
||||
if params[:sort_field] == f
|
||||
params[:sort_dir].nil? ? dir = 'desc' : dir = nil
|
||||
end
|
||||
|
||||
html << link_to(Link.human_attribute_name(f), {:controller => 'links',:action => 'index',:sort_field => f,:sort_dir => dir}, {:class=>"header"})
|
||||
html << "</th>"
|
||||
end
|
||||
html
|
||||
end
|
||||
|
||||
end
|
|
@ -1,113 +0,0 @@
|
|||
module MessagesHelper
|
||||
|
||||
def size_formatter(size)
|
||||
if size <= 2**10
|
||||
"#{size} #{t(:bytes,:scope=>:common)}"
|
||||
elsif size <= 2**20
|
||||
sprintf("%.1f #{t(:kbytes,:scope=>:common)}",size.to_f/2**10)
|
||||
else
|
||||
sprintf("%.1f #{t(:mbytes,:scope=>:common)}",size.to_f/2**20)
|
||||
end
|
||||
end
|
||||
|
||||
def date_formatter(date)
|
||||
date.nil? ? t(:no_date,:scope=>:message) : date.strftime("%Y-%m-%d %H:%M")
|
||||
end
|
||||
|
||||
def address_formatter(addr,op)
|
||||
s = ""
|
||||
return s if addr.nil?
|
||||
length = $defaults["msg_address_length"].to_i
|
||||
|
||||
case op
|
||||
when :index
|
||||
fs = addr.gsub(/\"/,"").split(/</)
|
||||
fs[0].size.zero? ? s = fs[1] : s = fs[0]
|
||||
s.length >= length ? s = s[0,length]+"..." : s
|
||||
return h(s)
|
||||
when :show
|
||||
#addr = addr[0].charseted.gsub(/\"/,"")
|
||||
return h(addr.gsub(/\"/,""))
|
||||
when :raw
|
||||
#fs = addr.gsub(/\"/,"").split(/</)
|
||||
#fs[0].size.zero? ? s = fs[1] : s << fs[0] + " <" + fs[1] + ">"
|
||||
s = h(addr)
|
||||
return s
|
||||
when :reply
|
||||
return h(addr)
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def subject_formatter(message,op)
|
||||
case op
|
||||
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
|
||||
when :reply
|
||||
if message.nil? or message.size.zero?
|
||||
t(:reply_string,:scope=>:show)
|
||||
else
|
||||
t(:reply_string,:scope=>:show) + " " + message
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def attachment_formatter(message)
|
||||
message.content_type =~ /^text\/plain/ ? "" : image_tag(current_theme_image_path('star.png'))
|
||||
end
|
||||
|
||||
def headers_links
|
||||
#if @current_folder.hasFullName?(@folder_sent_name) || @current_folder.hasFullName?(@folder_drafts_name)
|
||||
if @current_folder == @sent_folder || @current_folder == @drafts_folder
|
||||
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
|
||||
|
||||
def content_text_plain_for_render(text)
|
||||
html = "<pre class=\"clearfix\">"
|
||||
#html << text.gsub!(/\r\n/,"\n")
|
||||
html << h(text)
|
||||
html << "</pre>"
|
||||
html
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
module MessagesOpsHelper
|
||||
end
|
|
@ -1,16 +0,0 @@
|
|||
module PrefsHelper
|
||||
def servers_table_header
|
||||
html = ""
|
||||
$defaults["servers_table_fields"].each do |f|
|
||||
html << "<th>"
|
||||
if params[:sort_field] == f
|
||||
params[:sort_dir].nil? ? dir = 'desc' : dir = nil
|
||||
end
|
||||
|
||||
html << link_to(Server.human_attribute_name(f), {:controller => 'prefs',:action => 'servers',:sort_field => f,:sort_dir => dir}, {:class=>"header"})
|
||||
html << "</th>"
|
||||
end
|
||||
html
|
||||
end
|
||||
|
||||
end
|
|
@ -1,2 +0,0 @@
|
|||
module UserHelper
|
||||
end
|
0
app/views/contents_moved_to_olive_theme_directory → app/mailers/.gitkeep
Executable file → Normal file
0
app/views/contents_moved_to_olive_theme_directory → app/mailers/.gitkeep
Executable file → Normal file
0
app/models/.gitkeep
Normal file
0
app/models/.gitkeep
Normal file
|
@ -1,54 +0,0 @@
|
|||
class Contact < ActiveRecord::Base
|
||||
|
||||
validates_length_of :nick, :within => 5..15
|
||||
validates_length_of :first_name,:last_name, :within => 3..20
|
||||
validates_length_of :email, :within => 5..50
|
||||
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
|
||||
validates_length_of :info, :maximum => 100
|
||||
validate :check_unique_nick, :on => :create
|
||||
default_scope :order => 'nick ASC'
|
||||
|
||||
belongs_to :user
|
||||
|
||||
def self.getPageForUser(user,page,sort_field,sort_dir)
|
||||
|
||||
if sort_field
|
||||
if Contact.attribute_method?(sort_field) == true
|
||||
order = sort_field
|
||||
sort_dir == 'desc' ? order += ' desc' : sort_dir
|
||||
end
|
||||
end
|
||||
|
||||
Contact.paginate :page => page , :per_page => $defaults["contacts_per_page"], :conditions=> ['user_id = ?', user.id],:order => order
|
||||
end
|
||||
|
||||
def full_name
|
||||
first_name + ' ' + last_name
|
||||
end
|
||||
|
||||
def check_unique_nick
|
||||
if !Contact.where('upper(nick) = ? and user_id = ?',nick.upcase,user_id).size.zero?
|
||||
errors.add(:nick, :not_unique)
|
||||
end
|
||||
end
|
||||
|
||||
def export
|
||||
fields = []
|
||||
fields << nick.presence || ""
|
||||
fields << first_name || ""
|
||||
fields << last_name || ""
|
||||
fields << email || ""
|
||||
fields << info || ""
|
||||
fields.join(';')
|
||||
end
|
||||
|
||||
def self.import(user,line)
|
||||
fields = line.split(/;/)
|
||||
contact = user.contacts.build( :nick => fields[0].strip,
|
||||
:first_name => fields[1].strip,
|
||||
:last_name => fields[2].strip,
|
||||
:email => fields[3].strip,
|
||||
:info => fields[4].strip)
|
||||
contact.save!
|
||||
end
|
||||
end
|
|
@ -1,146 +0,0 @@
|
|||
class Folder < ActiveRecord::Base
|
||||
|
||||
belongs_to :user
|
||||
validates_presence_of :name, :on => :create
|
||||
before_save :check_fill_params, :on => :create
|
||||
has_many :messages, :dependent => :destroy
|
||||
|
||||
SYS_NONE = 0
|
||||
SYS_TRASH = 1
|
||||
SYS_INBOX = 2
|
||||
SYS_SENT = 3
|
||||
SYS_DRAFTS = 4
|
||||
|
||||
default_scope :order => 'name asc'
|
||||
scope :shown, where(['shown = ?',true])
|
||||
scope :inbox, where(['sys = ?',SYS_INBOX])
|
||||
scope :sent, where(['sys = ?',SYS_SENT])
|
||||
scope :drafts, where(['sys = ?',SYS_DRAFTS])
|
||||
scope :trash, where(['sys = ?',SYS_TRASH])
|
||||
scope :sys, where(['sys > ?',SYS_NONE])
|
||||
|
||||
def full_name
|
||||
if parent.empty?
|
||||
name
|
||||
else
|
||||
parent + delim + name
|
||||
end
|
||||
end
|
||||
|
||||
def depth
|
||||
parent.split('.').size
|
||||
end
|
||||
|
||||
def selected?(session_folder)
|
||||
fields = session_folder.split("#")
|
||||
fields[1].nil? ? fields.insert(0,"") : fields
|
||||
(fields[1].downcase == name.downcase) && (fields[0].downcase == parent.downcase)
|
||||
end
|
||||
|
||||
def update_stats
|
||||
logger.info "MESS_BEFORE: "+messages.inspect
|
||||
unseen = messages.where(:unseen => true).count
|
||||
total = messages.count
|
||||
logger.info "MESS: "+messages.inspect
|
||||
logger.info "MESS: #{unseen} #{total}"
|
||||
update_attributes(:unseen => unseen, :total => total)
|
||||
end
|
||||
|
||||
def hasFullName?(folder_name)
|
||||
full_name.downcase == folder_name.downcase
|
||||
end
|
||||
|
||||
def isSystem?
|
||||
sys > SYS_NONE
|
||||
end
|
||||
|
||||
def isTrash?
|
||||
sys == SYS_TRASH
|
||||
end
|
||||
|
||||
def isSent?
|
||||
sys == SYS_SENT
|
||||
end
|
||||
|
||||
def isInbox?
|
||||
sys == SYS_INBOX
|
||||
end
|
||||
|
||||
def isDrafts?
|
||||
sys == SYS_DRAFTS
|
||||
end
|
||||
|
||||
def setNone
|
||||
update_attributes(:sys => SYS_NONE)
|
||||
end
|
||||
|
||||
def setTrash
|
||||
update_attributes(:sys => SYS_TRASH)
|
||||
end
|
||||
|
||||
def setSent
|
||||
update_attributes(:sys => SYS_SENT)
|
||||
end
|
||||
|
||||
def setInbox
|
||||
update_attributes(:sys => SYS_INBOX)
|
||||
end
|
||||
|
||||
def setDrafts
|
||||
update_attributes(:sys => SYS_DRAFTS)
|
||||
end
|
||||
|
||||
|
||||
|
||||
############################################## private section #####################################
|
||||
|
||||
private
|
||||
|
||||
def check_fill_params
|
||||
self.total.nil? ? self.total = 0 : self.total
|
||||
self.unseen.nil? ? self.unseen = 0 : self.unseen
|
||||
self.parent.nil? ? self.parent = "" : self.parent
|
||||
self.haschildren.nil? ? self.haschildren = false : self.haschildren
|
||||
self.delim.nil? ? self.delim = "." : self.delim
|
||||
self.sys.nil? ? self.sys = SYS_NONE : self.sys
|
||||
end
|
||||
|
||||
def self.createBulk(user,imapFolders)
|
||||
imapFolders.each do |name,data|
|
||||
data.attribs.find_index(:Haschildren).nil? ? has_children = 0 : has_children = 1
|
||||
name_fields = name.split(data.delim)
|
||||
|
||||
if name_fields.count > 1
|
||||
name = name_fields.delete_at(name_fields.size - 1)
|
||||
parent = name_fields.join(data.delim)
|
||||
else
|
||||
name = name_fields[0]
|
||||
parent = ""
|
||||
end
|
||||
|
||||
user.folders.create(
|
||||
:name => name,
|
||||
:parent => parent,
|
||||
:haschildren => has_children,
|
||||
:delim => data.delim,
|
||||
:total => data.messages,
|
||||
:unseen => data.unseen,
|
||||
:sys => SYS_NONE)
|
||||
end
|
||||
end
|
||||
|
||||
def self.find_by_full_name(data)
|
||||
folder = data.gsub(/\./,'#')
|
||||
fields = folder.split("#")
|
||||
nam = fields.delete_at(fields.size - 1)
|
||||
fields.size.zero? == true ? par = "" : par = fields.join(".")
|
||||
where(['name = ? and parent = ?',nam,par]).first
|
||||
end
|
||||
|
||||
def self.refresh(mailbox,user)
|
||||
user.folders.destroy_all
|
||||
folders=mailbox.folders
|
||||
Folder.createBulk(user,folders)
|
||||
end
|
||||
|
||||
end
|
|
@ -1,19 +0,0 @@
|
|||
class Link < ActiveRecord::Base
|
||||
validates_length_of :name, :within => 5..30
|
||||
validates_length_of :url, :within => 5..150
|
||||
validates_length_of :info, :maximum => 50
|
||||
belongs_to :user
|
||||
default_scope :order => 'name asc'
|
||||
|
||||
def self.getPageForUser(user,page,sort_field,sort_dir)
|
||||
|
||||
if sort_field
|
||||
if Link.attribute_method?(sort_field) == true
|
||||
order = sort_field
|
||||
sort_dir == 'desc' ? order += ' desc' : sort_dir
|
||||
end
|
||||
end
|
||||
|
||||
Link.paginate :page => page , :per_page => $defaults["links_per_page"], :conditions=> ['user_id = ?', user.id],:order => order
|
||||
end
|
||||
end
|
|
@ -1,72 +0,0 @@
|
|||
require 'iconv'
|
||||
require 'mail'
|
||||
|
||||
class Message < ActiveRecord::Base
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :folder
|
||||
|
||||
set_primary_key :uid
|
||||
attr_accessible :unseen, :to_addr, :size, :content_type, :folder_id, :subject, :date, :uid, :from_addr, :user_id, :msg_id, :body,:cc_addr,:bcc_addr
|
||||
attr_accessor :body
|
||||
|
||||
def self.addr_to_db(addr)
|
||||
ret = ""
|
||||
name = addr.name
|
||||
name.nil? ? ret : ret << ApplicationController.decode_quoted(name)
|
||||
ret << "<" + addr.mailbox + "@" + addr.host
|
||||
ret
|
||||
end
|
||||
|
||||
def self.getPageForUser(user,folder,page,sort_field,sort_dir)
|
||||
|
||||
order = 'date desc'
|
||||
if sort_field
|
||||
if Message.attribute_method?(sort_field) == true
|
||||
order = sort_field
|
||||
sort_dir == 'desc' ? order += ' desc' : sort_dir
|
||||
end
|
||||
end
|
||||
|
||||
Message.paginate :page => page , :per_page => user.prefs.msgs_per_page.to_i, :conditions=> ['user_id = ? and folder_id = ?', user.id,folder.id],:order => order
|
||||
end
|
||||
|
||||
def self.createForUser(user,folder,message)
|
||||
|
||||
# envelope = imap_message.attr['ENVELOPE']
|
||||
#
|
||||
# envelope.from.nil? ? from = "" : from = addr_to_db(envelope.from[0])
|
||||
# envelope.to.nil? ? to = "" : to = addr_to_db(envelope.to[0])
|
||||
# envelope.subject.nil? ? subject = "" : subject = ApplicationController.decode_quoted(envelope.subject)
|
||||
|
||||
mail = Mail.new(message.attr['RFC822.HEADER'])
|
||||
|
||||
mail.date.nil? ? date = nil : date = mail.date.to_s
|
||||
mail.From.nil? ? from = nil : from = mail.From.charseted
|
||||
mail.To.nil? ? to = nil : to = mail.To.charseted
|
||||
mail.Subject.nil? ? subject = nil : subject = mail.Subject.charseted
|
||||
|
||||
#logger.custom('subject',mail.Subject.encoded)
|
||||
#logger.custom('subject',subject)
|
||||
#logger.custom('mail',mail.inspect)
|
||||
|
||||
create(
|
||||
:user_id => user.id,
|
||||
:folder_id => folder.id,
|
||||
:msg_id => mail.message_id,
|
||||
:uid => message.attr['UID'].to_i,
|
||||
:from_addr => from,
|
||||
:to_addr => to,
|
||||
:subject => subject,
|
||||
:content_type => mail.content_type,
|
||||
:date => date,
|
||||
:unseen => !(message.attr['FLAGS'].member? :Seen),
|
||||
:size => message.attr['RFC822.SIZE']
|
||||
)
|
||||
end
|
||||
|
||||
def change_folder(folder)
|
||||
update_attributes(:folder_id => folder.id)
|
||||
end
|
||||
|
||||
end
|
|
@ -1,19 +0,0 @@
|
|||
class Prefs < ActiveRecord::Base
|
||||
|
||||
validates_presence_of :theme,:locale
|
||||
|
||||
has_one :user
|
||||
|
||||
protected
|
||||
|
||||
def self.create_default(user)
|
||||
Prefs.create(:user_id => user.id,
|
||||
:theme => $defaults['theme'],
|
||||
:locale => $defaults['locale'],
|
||||
:msgs_per_page => $defaults['msgs_per_page'],
|
||||
:msg_send_type => $defaults['msg_send_type']
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
# TODO move refresh to prefs and make refresh page with messages
|
|
@ -1,41 +0,0 @@
|
|||
class Server < ActiveRecord::Base
|
||||
|
||||
validates_presence_of :name
|
||||
belongs_to :user
|
||||
#before_save :fill_params
|
||||
|
||||
def self.primary_for_imap
|
||||
where(:for_imap=>true).first
|
||||
end
|
||||
|
||||
def self.primary_for_smtp
|
||||
where(:for_smtp=>true).first
|
||||
end
|
||||
|
||||
def self.create_defaults(user)
|
||||
create( :user_id=>user.id,
|
||||
:name=>"localhost",
|
||||
:port=>$defaults['imap_port'],
|
||||
:use_ssl=>false,
|
||||
:use_tls=>false,
|
||||
:for_smtp=>false,
|
||||
:for_imap=>true
|
||||
)
|
||||
create( :user_id=>user.id,
|
||||
:name=>"localhost",
|
||||
:port=>$defaults['smtp_port'],
|
||||
:use_ssl=>false,
|
||||
:use_tls=>false,
|
||||
:for_smtp=>true,
|
||||
:for_imap=>false
|
||||
)
|
||||
end
|
||||
|
||||
# private
|
||||
|
||||
# def fill_params
|
||||
# port.nil? ? port = $defaults['imap_port'] : port
|
||||
# $defaults['imap_use_ssl'] == true ? self.use_ssl = 1 : self.use_ssl = 0
|
||||
# end
|
||||
|
||||
end
|
|
@ -1,64 +0,0 @@
|
|||
require 'ezcrypto'
|
||||
|
||||
class User < ActiveRecord::Base
|
||||
|
||||
#acts_as_notes_owner
|
||||
|
||||
validates_presence_of :first_name,:last_name
|
||||
validates_uniqueness_of :login
|
||||
has_many :servers, :dependent => :destroy
|
||||
has_one :prefs, :dependent => :destroy
|
||||
has_many :folders, :dependent => :destroy
|
||||
has_many :messages, :dependent => :destroy
|
||||
has_many :contacts, :dependent => :destroy
|
||||
has_many :links, :dependent => :destroy
|
||||
|
||||
def set_cached_password(session,password)
|
||||
if $defaults['session_encryption']
|
||||
session[:session_salt] = generate_salt
|
||||
session[:user_password] = EzCrypto::Key.encrypt_with_password($defaults['session_password'], session[:session_salt], password)
|
||||
else
|
||||
session[:user_password] = password
|
||||
end
|
||||
end
|
||||
|
||||
def get_cached_password(session)
|
||||
if $defaults['session_encryption']
|
||||
EzCrypto::Key.decrypt_with_password($defaults['session_password'], session[:session_salt], session[:user_password])
|
||||
else
|
||||
session[:user_password]
|
||||
end
|
||||
end
|
||||
|
||||
def generate_salt
|
||||
(0...8).map{65.+(rand(25)).chr}.join
|
||||
end
|
||||
|
||||
def name
|
||||
first_name + " " + last_name
|
||||
end
|
||||
|
||||
def full_id
|
||||
(name + " <" + email + ">") if email
|
||||
end
|
||||
|
||||
def email
|
||||
if login =~ /\@/
|
||||
login
|
||||
else
|
||||
(login + "@" + domain) if domain.presence
|
||||
end
|
||||
end
|
||||
|
||||
def username
|
||||
login.gsub(/\@/,"_").gsub(/\./,"_")
|
||||
end
|
||||
|
||||
def has_domain?
|
||||
return domain if domain.presence
|
||||
if login =~ /\@/
|
||||
login.split(/\@/)[1]
|
||||
end
|
||||
end
|
||||
|
||||
end
|
14
app/views/layouts/application.html.erb
Normal file
14
app/views/layouts/application.html.erb
Normal file
|
@ -0,0 +1,14 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Mailr</title>
|
||||
<%= stylesheet_link_tag "application", :media => "all" %>
|
||||
<%= javascript_include_tag "application" %>
|
||||
<%= csrf_meta_tags %>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<%= yield %>
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue