folder managing refactor
This commit is contained in:
parent
69b208f27a
commit
0d20ce14b8
23
app/controllers/folders_controller.rb
Normal file
23
app/controllers/folders_controller.rb
Normal file
|
@ -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
|
|
@ -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"
|
||||
|
|
2
app/helpers/folders_helper.rb
Normal file
2
app/helpers/folders_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
module FoldersHelper
|
||||
end
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
<div id="folders">
|
||||
<h4><%=_('Add folder')%></h4>
|
||||
<hr/>
|
||||
<form action="/webmail/webmail/manage_folders" method="post">
|
||||
<% form_tag folders_path, :id => 'new_folder' do %>
|
||||
<ul>
|
||||
<li><label for='folder_name'><%=_('Name')%>:</label></li>
|
||||
<li><input type="text" name="folder_name" value="" size="18" id='folder_name'/></li>
|
||||
<li><input type="submit" name="op" value="<%=_('Add folder')%>"/></li>
|
||||
<li><label for='folder'><%=_('Name')%>:</label></li>
|
||||
<li><%= text_field_tag 'folder', '', :size => 18 %></li>
|
||||
<li><%= submit_tag _('Add folder') %></li>
|
||||
</ul>
|
||||
</form>
|
||||
<% end %>
|
||||
</div>
|
||||
<% } %>
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<div id="folders">
|
||||
<h4><%=_('Folders')%><br/><%=link_manage_folders%></h4>
|
||||
<h4><%=_('Folders')%><br/><%= link_to 'add/edit', folders_path %></h4>
|
||||
<hr/>
|
||||
<ul> <% for folder in @folders %>
|
||||
<li><%=folder_link(folder)%></li> <% end %>
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
ActionController::Routing::Routes.draw do |map|
|
||||
map.resources :folders, :requirements => {:id => /[^\/]+/}
|
||||
|
||||
# Add your own custom routes here.
|
||||
# The priority is based upon order of creation: first created -> highest priority.
|
||||
|
||||
|
|
69
lib/imap_utils.rb
Normal file
69
lib/imap_utils.rb
Normal file
|
@ -0,0 +1,69 @@
|
|||
module ImapUtils
|
||||
private
|
||||
|
||||
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"
|
||||
render :text => ex.inspect, :content_type => 'text/plain'
|
||||
end
|
||||
end
|
||||
|
||||
def close_imap_session
|
||||
return if @mailbox.nil? or not(@mailbox.connected)
|
||||
@mailbox.disconnect
|
||||
@mailbox = nil
|
||||
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 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 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 user
|
||||
@user = Customer.find(logged_customer) if @user.nil?
|
||||
@user
|
||||
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
|
||||
end
|
|
@ -58,3 +58,5 @@ b.br {bottom: -1px; right: -1px; background-position: bottom right;}
|
|||
#wholepage { color: #000 }
|
||||
|
||||
#logout {font-size: 10px; color: #5350b9; float: right;}
|
||||
|
||||
#new_folder ul {list-style: none;}
|
||||
|
|
Loading…
Reference in a new issue