diff --git a/app/controllers/folders_controller.rb b/app/controllers/folders_controller.rb new file mode 100644 index 0000000..d07d6ec --- /dev/null +++ b/app/controllers/folders_controller.rb @@ -0,0 +1,23 @@ +class FoldersController < ApplicationController + include ImapUtils + + before_filter :login_required + before_filter :load_imap_session + after_filter :close_imap_session + + layout 'public' + + def index + @folders = @mailbox.folders + end + + def create + @mailbox.create_folder(CDF::CONFIG[:mail_inbox] + '.' + params[:folder]) + redirect_to folders_path + end + + def destroy + @mailbox.delete_folder params[:id] + redirect_to folders_path + end +end diff --git a/app/controllers/webmail_controller.rb b/app/controllers/webmail_controller.rb index c5543da..0454543 100644 --- a/app/controllers/webmail_controller.rb +++ b/app/controllers/webmail_controller.rb @@ -5,7 +5,7 @@ require 'mail2screen' require 'ezcrypto' class WebmailController < ApplicationController -# uses_component_template_root + include ImapUtils # Administrative functions before_filter :login_required @@ -35,17 +35,6 @@ class WebmailController < ApplicationController redirect_to(:action=>'messages') end - def manage_folders - if operation_param == _('Add folder') - @mailbox.create_folder(CDF::CONFIG[:mail_inbox]+"."+params["folder_name"]) - elsif operation_param == _('(Delete)') - @mailbox.delete_folder(params["folder_name"]) - elsif operation_param == _('(Subscribe)') - elsif operation_param == _('(Select)') - end - @folders = @mailbox.folders - end - def messages session["return_to"] = nil @search_field = params['search_field'] @@ -334,62 +323,12 @@ class WebmailController < ApplicationController private - def get_upass - if CDF::CONFIG[:crypt_session_pass] - EzCrypto::Key.decrypt_with_password(CDF::CONFIG[:encryption_password], CDF::CONFIG[:encryption_salt], session["wmp"]) - else - # retrun it plain - session["wmp"] - end - end - 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 load_imap_session - return if ['error_connection'].include?(action_name) - get_imap_session - end - - def get_imap_session - begin - @mailbox = IMAPMailbox.new - uname = (get_mail_prefs.check_external_mail == 1 ? user.email : user.local_email) - upass = get_upass - @mailbox.connect(uname, upass) - load_folders - rescue Exception => ex - logger.error("Exception on loggin webmail session - #{ex} - #{ex.backtrace.join("\t\n")}") - render :action => "error_connection" - end - end - - def close_imap_session - return if @mailbox.nil? or not(@mailbox.connected) - @mailbox.disconnect - @mailbox = nil - end - - def have_to_load_folders? - return true if ['messages', 'delete', 'reply', 'forward', 'empty', 'message', 'download', - 'filter', 'filter_add', 'view_source', 'compose', 'prefs', 'filters'].include?(action_name) - return false - end - - def load_folders - if have_to_load_folders?() - if params["folder_name"] - @folder_name = params["folder_name"] - else - @folder_name = session["folder_name"] ? session["folder_name"] : CDF::CONFIG[:mail_inbox] - end - session["folder_name"] = @folder_name - @folders = @mailbox.folders if @folders.nil? - end - end def create_mail m = CDF::Mail.new(user.mail_temporary_path) @@ -416,19 +355,6 @@ class WebmailController < ApplicationController m end - def user - @user = Customer.find(logged_customer) if @user.nil? - @user - end - - def get_mail_prefs - if not(@mailprefs) - if not(@mailprefs = MailPref.find_by_customer_id(logged_customer)) - @mailprefs = MailPref.create("customer_id"=>logged_customer) - end - end - @mailprefs - end def send_part(part) if part.content_type == "text/html" diff --git a/app/helpers/folders_helper.rb b/app/helpers/folders_helper.rb new file mode 100644 index 0000000..d27e7b4 --- /dev/null +++ b/app/helpers/folders_helper.rb @@ -0,0 +1,2 @@ +module FoldersHelper +end diff --git a/app/helpers/navigation_helper.rb b/app/helpers/navigation_helper.rb index 757bec8..0fc88cd 100644 --- a/app/helpers/navigation_helper.rb +++ b/app/helpers/navigation_helper.rb @@ -19,11 +19,12 @@ module NavigationHelper if folder.name == CDF::CONFIG[:mail_trash] or folder.name == CDF::CONFIG[:mail_inbox] or folder.name == CDF::CONFIG[:mail_sent] short_fn(folder) else - return short_fn(folder) + - (" " + link_to(_('(Delete)'), :controller=>"webmail", :action=>"manage_folders", :params=>{"op"=>_('(Delete)'), "folder_name"=>folder.name})) + short_fn(folder) + ' ' + link_to(_('Delete'), folder_path(folder.name), :method => :delete) end end + private + def short_fn(folder) if folder.name.include? folder.delim " " + folder.name.split(folder.delim).last diff --git a/app/helpers/webmail_helper.rb b/app/helpers/webmail_helper.rb index a0725a5..0442854 100644 --- a/app/helpers/webmail_helper.rb +++ b/app/helpers/webmail_helper.rb @@ -35,10 +35,6 @@ module WebmailHelper link_to(_('View source'), {:controller=>"webmail", :action=>"view_source", :params=>{"msg_id"=>msg_id}}, {'target'=>"_blank"}) end - def link_manage_folders - link_to(_('add/edit'), :controller=>"webmail", :action=>"manage_folders") - end - def link_filter_add link_to(_('Add filter'), :controller=>'webmail', :action=>'filter_add') end diff --git a/app/views/webmail/manage_folders.rhtml b/app/views/folders/index.html.erb similarity index 76% rename from app/views/webmail/manage_folders.rhtml rename to app/views/folders/index.html.erb index 038cca7..748883a 100644 --- a/app/views/webmail/manage_folders.rhtml +++ b/app/views/folders/index.html.erb @@ -19,13 +19,13 @@