devel
This commit is contained in:
parent
910a6f3bc0
commit
8868a84123
|
@ -8,11 +8,11 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
before_filter :plugins_configuration
|
||||
|
||||
rescue_from ActiveRecord::RecordNotFound do
|
||||
logger.custom('record_not_found','exc')
|
||||
reset_session
|
||||
redirect_to :controller=>'user', :action => 'login'
|
||||
end
|
||||
# rescue_from ActiveRecord::RecordNotFound do
|
||||
# logger.custom('record_not_found','exc')
|
||||
# reset_session
|
||||
# redirect_to :controller=>'user', :action => 'login'
|
||||
# end
|
||||
|
||||
def load_defaults
|
||||
$defaults ||= YAML::load(File.open(Rails.root.join('config','defaults.yml')))
|
||||
|
@ -106,6 +106,23 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
end
|
||||
|
||||
def prepare_compose_buttons
|
||||
@buttons = []
|
||||
@buttons << {:text => 'send',:image => 'tick.png'}
|
||||
@buttons << {:text => 'save_as_draft',:image => 'tick.png'}
|
||||
end
|
||||
|
||||
##################################### protected section ########################################
|
||||
|
||||
protected
|
||||
|
||||
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
|
||||
|
|
|
@ -3,24 +3,32 @@ class InternalController < ApplicationController
|
|||
theme :theme_resolver
|
||||
layout "simple"
|
||||
|
||||
def error
|
||||
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)
|
||||
@error = params[:error] || t(:unspecified_error)
|
||||
@title = t(:imap_error,:scope => :internal)
|
||||
@error = params[:error] || t(:unspecified_error, :scope => :internal)
|
||||
logger.error "!!! InternalControllerImapError: " + @error
|
||||
render 'error'
|
||||
end
|
||||
|
||||
def page_not_found
|
||||
@title = t(:page_not_found)
|
||||
@error = t(:page_not_found)
|
||||
logger.error "!!! InternalControllerError: " + @error
|
||||
render 'error'
|
||||
end
|
||||
|
||||
def loginfailure
|
||||
reset_session
|
||||
flash[:error] = t(:login_failure,:scope=>:user)
|
||||
|
|
|
@ -15,11 +15,11 @@ class MessagesController < ApplicationController
|
|||
|
||||
before_filter :open_imap_session, :select_imap_folder
|
||||
|
||||
before_filter :prepare_buttons, :only => [:compose,:reply,:edit,:sendout_or_save]
|
||||
before_filter :prepare_compose_buttons, :only => [:compose]
|
||||
|
||||
#before_filter :mail_defaults, :only => [:sendout_or_save]
|
||||
|
||||
before_filter :get_system_folders, :only => [:index,:ops,:sendout_or_save]
|
||||
before_filter :get_system_folders, :only => [:index]
|
||||
|
||||
after_filter :close_imap_session
|
||||
|
||||
|
@ -73,195 +73,6 @@ class MessagesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def reply
|
||||
|
||||
attachments = []
|
||||
body = ''
|
||||
|
||||
old_message = @current_user.messages.find(params[:id])
|
||||
@message = Message.new
|
||||
@message.to_addr = address_formatter(old_message.from_addr,:raw)
|
||||
@message.subject = old_message.subject
|
||||
@reply = true
|
||||
imap_message = @mailbox.fetch_body(old_message.uid)
|
||||
mail = Mail.new(imap_message)
|
||||
if mail.multipart?
|
||||
Attachment.fromMultiParts(attachments,old_message.id,mail.parts)
|
||||
else
|
||||
Attachment.fromSinglePart(attachments,old_message.id,mail)
|
||||
end
|
||||
|
||||
for idx in 0..attachments.size-1
|
||||
if attachments[idx].isText?
|
||||
body << attachments[idx].decode_and_charset
|
||||
break
|
||||
end
|
||||
end
|
||||
@message.body = body
|
||||
render 'compose'
|
||||
end
|
||||
|
||||
def edit
|
||||
|
||||
attachments = []
|
||||
body = ''
|
||||
|
||||
old_message = @current_user.messages.find(params[:id])
|
||||
@message = Message.new
|
||||
@message.to_addr = address_formatter(old_message.to_addr,:raw)
|
||||
@message.subject = old_message.subject
|
||||
imap_message = @mailbox.fetch_body(old_message.uid)
|
||||
mail = Mail.new(imap_message)
|
||||
if mail.multipart?
|
||||
Attachment.fromMultiParts(attachments,old_message.id,mail.parts)
|
||||
else
|
||||
Attachment.fromSinglePart(attachments,old_message.id,mail)
|
||||
end
|
||||
|
||||
for idx in 0..attachments.size-1
|
||||
if attachments[idx].isText?
|
||||
body << attachments[idx].decode_and_charset
|
||||
break
|
||||
end
|
||||
end
|
||||
@message.body = body
|
||||
render 'compose'
|
||||
end
|
||||
|
||||
def sendout_or_save
|
||||
|
||||
mail = Mail.new
|
||||
mail.subject = params[:message][:subject]
|
||||
mail.from = @current_user.full_address
|
||||
mail.to = params[:message][:to_addr]
|
||||
mail.body = params[:message][:body]
|
||||
#mail.add_file :filename => 'somefile.png', :content => File.read('/tmp/script_monitor_20110810143216.log')
|
||||
|
||||
if params[:send]
|
||||
smtp_server = @current_user.servers.primary_for_smtp
|
||||
|
||||
if smtp_server.nil?
|
||||
flash[:error] = t(:not_configured_smtp,:scope => :compose)
|
||||
@message = Message.new
|
||||
if params[:message]
|
||||
@message = update_attributes(params[:message])
|
||||
end
|
||||
render 'compose'
|
||||
return
|
||||
end
|
||||
|
||||
begin
|
||||
|
||||
set_mail_defaults(@current_user,smtp_server,session)
|
||||
#logger.custom('mail',Mail.delivery_method.inspect)
|
||||
|
||||
@response = mail.deliver!
|
||||
#logger.custom('response',@response.inspect)
|
||||
|
||||
if @sent_folder.nil?
|
||||
raise t(:not_configured_sent,:scope=>:compose)
|
||||
end
|
||||
@mailbox.append(@sent_folder.full_name,mail.to_s,[:Seen])
|
||||
|
||||
rescue Exception => e
|
||||
flash[:error] = "#{t(:imap_error)} (#{e.to_s})"
|
||||
redirect_to :action => 'index'
|
||||
return
|
||||
end
|
||||
flash[:notice] = t(:was_sent,:scope => :compose)
|
||||
redirect_to :action => 'index'
|
||||
elsif params[:save_as_draft]
|
||||
begin
|
||||
if @drafts_folder.nil?
|
||||
raise t(:not_configured_drafts,:scope=>:compose)
|
||||
end
|
||||
# TODO delete old one if was edit
|
||||
@mailbox.append(@drafts_folder.full_name,mail.to_s,[:Seen])
|
||||
rescue Exception => e
|
||||
flash[:error] = "#{t(:imap_error)} (#{e.to_s})"
|
||||
redirect_to :action => 'index'
|
||||
return
|
||||
end
|
||||
flash[:notice] = t(:was_saved,:scope => :compose)
|
||||
redirect_to :action => 'index'
|
||||
end
|
||||
end
|
||||
|
||||
def msgops
|
||||
begin
|
||||
if !params["uids"]
|
||||
flash[:warning] = t(:no_selected,:scope=>:message)
|
||||
elsif params["reply"]
|
||||
redirect_to :action => 'reply', :id => params[:id]
|
||||
return
|
||||
end
|
||||
rescue Exception => e
|
||||
flash[:error] = "#{t(:imap_error)} (#{e.to_s})"
|
||||
end
|
||||
redirect_to :action => 'show', :id => params[:id]
|
||||
end
|
||||
|
||||
def ops
|
||||
begin
|
||||
if !params["uids"]
|
||||
flash[:warning] = t(:no_selected,:scope=>:message)
|
||||
elsif params["set_unread"]
|
||||
params["uids"].each do |uid|
|
||||
@mailbox.set_unread(uid)
|
||||
@current_user.messages.find_by_uid(uid).update_attributes(:unseen => 1)
|
||||
end
|
||||
elsif params["set_read"]
|
||||
params["uids"].each do |uid|
|
||||
@mailbox.set_read(uid)
|
||||
@current_user.messages.find_by_uid(uid).update_attributes(:unseen => 0)
|
||||
end
|
||||
elsif params["trash"]
|
||||
if not @trash_folder.nil?
|
||||
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
|
||||
elsif params["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
|
||||
elsif params["move"]
|
||||
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.move_message(uid,dest_folder.full_name)
|
||||
message = @current_folder.messages.find_by_uid(uid)
|
||||
message.change_folder(dest_folder)
|
||||
end
|
||||
@mailbox.expunge
|
||||
dest_folder.update_stats
|
||||
@current_folder.update_stats
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
flash[:error] = "#{t(:imap_error)} (#{e.to_s})"
|
||||
end
|
||||
redirect_to :action => 'index'
|
||||
end
|
||||
|
||||
def show
|
||||
@images = []
|
||||
@attachments = []
|
||||
|
@ -315,25 +126,6 @@ class MessagesController < ApplicationController
|
|||
@attachments << part
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
#@attachments = []
|
||||
#logger.custom('after_parse',Time.now)
|
||||
#if mail.multipart?
|
||||
# Attachment.fromMultiParts(@attachments,@message.id,@mail.parts)
|
||||
#else
|
||||
# Attachment.fromSinglePart(@attachments,@message.id,@mail)
|
||||
# end
|
||||
#logger.custom('attach',Time.now)
|
||||
|
||||
# for idx in 0..@attachments.size-1
|
||||
# @attachments[idx].idx = idx
|
||||
# @attachments[idx].isText? ? @render_as_text << @attachments[idx].decode_and_charset : @render_as_text
|
||||
# @attachments[idx].isHtml? ? @render_as_html_idx ||= idx : @render_as_html_idx
|
||||
# @attachments[idx].isImageAndNotCid? ? @images << @attachments[idx] : @images
|
||||
# end
|
||||
#logger.custom('done',Time.now)
|
||||
#@attachments = @mail.attachments
|
||||
end
|
||||
|
||||
def html_body
|
||||
|
@ -350,85 +142,23 @@ class MessagesController < ApplicationController
|
|||
render 'html_body',:layout => 'html_body'
|
||||
end
|
||||
|
||||
def body
|
||||
attachments = []
|
||||
cids = []
|
||||
message = @current_user.messages.find(params[:id])
|
||||
mail = Mail.new(@mailbox.fetch_body(message.uid))
|
||||
|
||||
if mail.multipart?
|
||||
Attachment.fromMultiParts(attachments,message.id,mail.parts)
|
||||
else
|
||||
Attachment.fromSinglePart(attachments,message.id,mail)
|
||||
end
|
||||
html = attachments[params[:idx].to_i]
|
||||
|
||||
@body = html.decode_and_charset
|
||||
|
||||
for idx in 0..attachments.size-1
|
||||
if not attachments[idx].cid.size.zero?
|
||||
@body.gsub!(/cid:#{attachments[idx].cid}/,messages_attachment_download_path(message.uid,idx))
|
||||
end
|
||||
end
|
||||
|
||||
render 'html_view',:layout => 'html_view'
|
||||
end
|
||||
|
||||
def attachment
|
||||
attachments = []
|
||||
message = @current_user.messages.find(params[:id])
|
||||
mail = Mail.new(@mailbox.fetch_body(message.uid))
|
||||
if mail.multipart?
|
||||
Attachment.fromMultiParts(attachments,message.id,mail.parts)
|
||||
if mail.multipart? == true
|
||||
attachments = mail.attachments
|
||||
else
|
||||
Attachment.fromSinglePart(attachments,message.id,mail)
|
||||
attachments << Mail::Part.new(mail)
|
||||
end
|
||||
a = attachments[params[:idx].to_i]
|
||||
headers['Content-type'] = a.type
|
||||
headers['Content-Disposition'] = %(attachment; filename="#{a.name}")
|
||||
render :text => a.decode
|
||||
headers['Content-type'] = a.main_type + "/" + a.sub_type
|
||||
headers['Content-Disposition'] = %(attachment; filename="#{a.filename}")
|
||||
render :text => a.decoded
|
||||
end
|
||||
|
||||
############################################# protected section ##########################################
|
||||
|
||||
def prepare_buttons
|
||||
@buttons = []
|
||||
@buttons << {:text => 'send',:image => 'tick.png'}
|
||||
@buttons << {:text => 'save_as_draft',:image => 'tick.png'}
|
||||
end
|
||||
|
||||
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.full_address
|
||||
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
|
||||
|
||||
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
|
||||
protected
|
||||
|
||||
end
|
||||
|
|
245
app/controllers/messages_ops_controller.rb
Executable file
245
app/controllers/messages_ops_controller.rb
Executable file
|
@ -0,0 +1,245 @@
|
|||
require 'imap_session'
|
||||
require 'imap_mailbox'
|
||||
require 'imap_message'
|
||||
require 'mail'
|
||||
|
||||
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 => [:sendout_or_save,:single,:multi]
|
||||
after_filter :close_imap_session
|
||||
theme :theme_resolver
|
||||
|
||||
|
||||
############################################### single #####################################
|
||||
|
||||
def single
|
||||
if params[:reply]
|
||||
reply
|
||||
return
|
||||
elsif params[:trash]
|
||||
trash
|
||||
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)} (#{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.find_by_uid(uid).update_attributes(:unseen => 1)
|
||||
end
|
||||
end
|
||||
|
||||
def set_read
|
||||
params["uids"].each do |uid|
|
||||
@mailbox.set_read(uid)
|
||||
@current_user.messages.find_by_uid(uid).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])
|
||||
params["uids"].each do |uid|
|
||||
@mailbox.move_message(uid,dest_folder.full_name)
|
||||
message = @current_folder.messages.find_by_uid(uid)
|
||||
message.change_folder(dest_folder)
|
||||
end
|
||||
@mailbox.expunge
|
||||
dest_folder.update_stats
|
||||
@current_folder.update_stats
|
||||
end
|
||||
end
|
||||
|
||||
############################################### sendout_or_save ############################
|
||||
|
||||
def sendout_or_save
|
||||
|
||||
mail = Mail.new
|
||||
mail.subject = params[:message][:subject]
|
||||
mail.from = @current_user.full_address
|
||||
mail.to = params[:message][:to_addr]
|
||||
mail.body = params[:message][:body]
|
||||
#mail.add_file :filename => 'somefile.png', :content => File.read('/tmp/script_monitor_20110810143216.log')
|
||||
|
||||
if params[:send]
|
||||
smtp_server = @current_user.servers.primary_for_smtp
|
||||
|
||||
if smtp_server.nil?
|
||||
flash[:error] = t(:not_configured_smtp,:scope => :compose)
|
||||
@message = Message.new
|
||||
if params[:message]
|
||||
@message = update_attributes(params[:message])
|
||||
end
|
||||
render 'messages/compose'
|
||||
return
|
||||
end
|
||||
|
||||
begin
|
||||
|
||||
set_mail_defaults(@current_user,smtp_server,session)
|
||||
logger.custom('mail',Mail.delivery_method.inspect)
|
||||
|
||||
@response = mail.deliver!
|
||||
logger.custom('response',@response.inspect)
|
||||
|
||||
if @sent_folder.nil?
|
||||
raise t(:not_configured_sent,:scope=>:compose)
|
||||
end
|
||||
@mailbox.append(@sent_folder.full_name,mail.to_s,[:Seen])
|
||||
|
||||
rescue Exception => e
|
||||
flash[:error] = "#{t(:imap_error)} (#{e.to_s})"
|
||||
redirect_to :controller => 'messages', :action => 'index'
|
||||
return
|
||||
end
|
||||
flash[:notice] = t(:was_sent,:scope => :compose)
|
||||
redirect_to :controller => 'messages', :action => 'index'
|
||||
elsif params[:save_as_draft]
|
||||
begin
|
||||
if @drafts_folder.nil?
|
||||
raise t(:not_configured_drafts,:scope=>:compose)
|
||||
end
|
||||
# TODO delete old one if was edit
|
||||
@mailbox.append(@drafts_folder.full_name,mail.to_s,[:Seen])
|
||||
rescue Exception => e
|
||||
flash[:error] = "#{t(:imap_error)} (#{e.to_s})"
|
||||
redirect_to :controller => 'messages', :action => 'index'
|
||||
return
|
||||
end
|
||||
flash[:notice] = t(:was_saved,:scope => :compose)
|
||||
redirect_to :controller => 'messages', :action => 'index'
|
||||
end
|
||||
end
|
||||
|
||||
###################################### protected section #######################################
|
||||
|
||||
protected
|
||||
|
||||
def edit
|
||||
|
||||
old_message = @current_user.messages.find(params[:id].first)
|
||||
@message = Message.new
|
||||
@message.to_addr = address_formatter(old_message.to_addr,:raw)
|
||||
@message.subject = old_message.subject
|
||||
imap_message = @mailbox.fetch_body(old_message.uid)
|
||||
@edit = true
|
||||
mail = Mail.new(imap_message)
|
||||
if mail.multipart?
|
||||
@message.body = mail.text_part.decoded_and_charseted
|
||||
else
|
||||
@message.body = mail.decoded_and_charseted
|
||||
end
|
||||
render 'messages/compose'
|
||||
end
|
||||
|
||||
def reply
|
||||
old_message = @current_user.messages.find(params[:uids].first)
|
||||
@message = Message.new
|
||||
@message.to_addr = address_formatter(old_message.from_addr,:raw)
|
||||
@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.decoded_and_charseted
|
||||
else
|
||||
@message.body = mail.decoded_and_charseted
|
||||
end
|
||||
render 'messages/compose'
|
||||
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.full_address
|
||||
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
|
2
app/helpers/messages_ops_helper.rb
Executable file
2
app/helpers/messages_ops_helper.rb
Executable file
|
@ -0,0 +1,2 @@
|
|||
module MessagesOpsHelper
|
||||
end
|
|
@ -1,192 +0,0 @@
|
|||
|
||||
class Attachment
|
||||
include ActiveModel::Validations
|
||||
include ActiveModel::Conversion
|
||||
extend ActiveModel::Naming
|
||||
|
||||
attr_accessor :type, :charset, :encoding, :name, :description, :content, :message_id, :idx, :boundary, :format, :multipart,:size,:cid
|
||||
attr_reader :link
|
||||
|
||||
def initialize(attributes = {})
|
||||
|
||||
attributes.each do |name, value|
|
||||
send("#{name}=", value)
|
||||
end
|
||||
|
||||
if not @type.nil?
|
||||
params = @type.split(/;\s*/)
|
||||
@type = params[0]
|
||||
params.each do |p|
|
||||
if p =~ /=/
|
||||
fields = p.split(/=/)
|
||||
key = fields[0]
|
||||
fields.delete_at(0)
|
||||
value = fields.join("=")
|
||||
# FIXME maybe do decoding only for name and filename key
|
||||
if Attachment.attribute_method?(key) == true
|
||||
send("#{key}=", ApplicationController.decode_quoted(value))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def multipart?
|
||||
multipart
|
||||
end
|
||||
|
||||
def self.fromMultiParts(attachments,id,parts)
|
||||
parts.each do |part|
|
||||
a = build(id,part)
|
||||
if a.multipart?
|
||||
fromMultiParts(attachments,id,part.parts)
|
||||
else
|
||||
attachments << a
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.fromSinglePart(attachments,id,part)
|
||||
a = build(id,part)
|
||||
attachments << a
|
||||
end
|
||||
|
||||
def self.build(id,part)
|
||||
cid = ''
|
||||
if not part.content_id.nil?
|
||||
part.content_id =~ /\<(\S+)\>/
|
||||
cid = $1
|
||||
else
|
||||
cid = ''
|
||||
end
|
||||
a = Attachment.new( :message_id => id,
|
||||
:description => part.content_description,
|
||||
:type => part.content_type,
|
||||
:content => part.body.raw_source,
|
||||
:encoding => part.body.encoding,
|
||||
:size => part.body.raw_source.size,
|
||||
:charset => part.body.charset,
|
||||
:multipart => part.multipart?,
|
||||
:cid => cid
|
||||
)
|
||||
return a
|
||||
end
|
||||
|
||||
|
||||
def persisted?
|
||||
false
|
||||
end
|
||||
|
||||
def name
|
||||
if @name.nil?
|
||||
case type
|
||||
when /^text\/html/
|
||||
"index#{idx}.html"
|
||||
when /^multipart/
|
||||
"multipart#{idx}.part"
|
||||
when /^text\/plain/
|
||||
"file#{idx}.txt"
|
||||
else
|
||||
"filaname.dat"
|
||||
end
|
||||
else
|
||||
@name
|
||||
end
|
||||
end
|
||||
|
||||
def to_s
|
||||
s = "Attachment:\n"
|
||||
instance_variables.sort.each do |name|
|
||||
if name == "@content"
|
||||
s += "\t#{name}: size #{instance_variable_get(name).size}\n"
|
||||
else
|
||||
s += "\t#{name}: #{instance_variable_get(name)}\n"
|
||||
end
|
||||
end
|
||||
s
|
||||
end
|
||||
|
||||
def isText?
|
||||
@type.nil? or @type =~ /^text\/plain/
|
||||
end
|
||||
|
||||
def isHtml?
|
||||
@type =~ /^text\/html/
|
||||
end
|
||||
|
||||
def isImageAndNotCid?
|
||||
@type =~ /^image/ and @cid.size.zero?
|
||||
end
|
||||
|
||||
def title
|
||||
@description.nil? ? name : @description
|
||||
end
|
||||
|
||||
def type
|
||||
@type.nil? ? '' : @type
|
||||
end
|
||||
|
||||
def charset
|
||||
@charset.nil? ? '' : @charset
|
||||
end
|
||||
|
||||
def encoding
|
||||
@encoding.nil? ? '' : @encoding
|
||||
end
|
||||
|
||||
def format
|
||||
@format.nil? ? '' : @format
|
||||
end
|
||||
|
||||
def boundary
|
||||
@boundary.nil? ? '' : @boundary
|
||||
end
|
||||
|
||||
def decode
|
||||
begin
|
||||
case @encoding
|
||||
when /quoted-printable/
|
||||
#decoded = @content.gsub(/_/," ").unpack("M").first
|
||||
decoded = @content.unpack("M").first
|
||||
when /base64/
|
||||
decoded = @content.unpack("m").first
|
||||
when /uuencode/
|
||||
array = @content.split(/\n/)
|
||||
if array[0] =~ /^begin/
|
||||
size = array.size
|
||||
array.delete_at(size-1)
|
||||
array.delete_at(size-2)
|
||||
array.delete_at(0)
|
||||
end
|
||||
string = array.join
|
||||
decoded = string.unpack("u").first
|
||||
else
|
||||
decoded = @content
|
||||
end
|
||||
rescue
|
||||
@content
|
||||
end
|
||||
end
|
||||
|
||||
def decode_and_charset
|
||||
begin
|
||||
decoded = decode
|
||||
|
||||
if not @charset == 'UTF-8'
|
||||
@charset.nil? ? charset = $defaults["msg_unknown_charset"] : charset = @charset
|
||||
charseted = Iconv.iconv("UTF-8",charset,decoded).first
|
||||
else
|
||||
charseted = decoded
|
||||
end
|
||||
|
||||
charseted
|
||||
rescue
|
||||
decoded
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
0
arts/favicon.png
Normal file → Executable file
0
arts/favicon.png
Normal file → Executable file
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
0
arts/favicon.xcf
Normal file → Executable file
0
arts/favicon.xcf
Normal file → Executable file
|
@ -38,4 +38,4 @@ session_password: asDD3s2@sAdc983#
|
|||
mailbox_max_parent_folder_depth: 3
|
||||
|
||||
# array of logins which only can login to application, comment it to allow everyone to login
|
||||
only_can_logins: [soldier]
|
||||
only_can_logins: [wtodryk]
|
||||
|
|
16
config/initializers/show_exceptions.rb
Executable file
16
config/initializers/show_exceptions.rb
Executable file
|
@ -0,0 +1,16 @@
|
|||
require 'action_dispatch/middleware/show_exceptions'
|
||||
|
||||
module ActionDispatch
|
||||
class ShowExceptions
|
||||
private
|
||||
def render_exception_with_template(env, exception)
|
||||
body = InternalController.action(rescue_responses[exception.class.name]).call(env)
|
||||
log_error(exception)
|
||||
body
|
||||
rescue
|
||||
render_exception_without_template(env, exception)
|
||||
end
|
||||
|
||||
alias_method_chain :render_exception, :template
|
||||
end
|
||||
end
|
|
@ -84,6 +84,10 @@ pl:
|
|||
sent_name: Wysłane
|
||||
trash_name: Kosz
|
||||
drafts_name: Roboczy
|
||||
not_configured_drafts: Folder Roboczy nie został przypisany
|
||||
not_configured_sent: Folder Wysłany nie został przypisany
|
||||
not_configured_trash: Folder Kosz nie został przypisany
|
||||
not_configured_inbox: Folder Odebrane nie został przypisany
|
||||
|
||||
message:
|
||||
messages: Wiadomości
|
||||
|
@ -112,10 +116,6 @@ pl:
|
|||
was_saved: Wiadomość została zapisana w katalogu roboczym
|
||||
reply_string: "Odp: "
|
||||
not_configured_smtp: Brak konfiguracji SMTP
|
||||
not_configured_drafts: Folder Roboczy nie został przypisany
|
||||
not_configured_sent: Folder Wysłany nie został przypisany
|
||||
not_configured_trash: Folder Kosz nie został przypisany
|
||||
not_configured_inbox: Folder Odebrane nie został przypisany
|
||||
|
||||
show:
|
||||
replay_to: Odpowiedz
|
||||
|
@ -133,6 +133,13 @@ pl:
|
|||
login: Logowanie
|
||||
only_can_logins: Podany identyfikator użytkownika nie uprawnia do korzystania z aplikacji
|
||||
|
||||
internal:
|
||||
imap_error: Błąd protokołu IMAP
|
||||
unspecified_error: Nieoczekiwany błąd
|
||||
not_found: Nie znaleziono żądanej strony
|
||||
internal_server_error: Błąd aplikacji
|
||||
unprocessable_entity: Błąd procesowania
|
||||
|
||||
must_be_unique: musi być unikalny
|
||||
some_add_info: jakieś dodatkowe informacje
|
||||
example: przykład
|
||||
|
@ -140,11 +147,9 @@ pl:
|
|||
create: Utwórz
|
||||
delete: Usuń
|
||||
show_hide: Pokaż/Ukryj
|
||||
mailr: Mailr
|
||||
mailr: MailR
|
||||
save: Zapisz
|
||||
imap_error: Błąd protokołu IMAP
|
||||
unspecified_error: Nieoczekiwany błąd
|
||||
page_not_found: Nie znaleziono żądanej strony
|
||||
|
||||
copy: Skopiuj
|
||||
move: Przenieś
|
||||
to: do
|
||||
|
|
|
@ -31,20 +31,24 @@ Mailr::Application.routes.draw do
|
|||
get "internal/loginfailure"
|
||||
get "internal/onlycanlogins"
|
||||
|
||||
match "messages_ops/single" => 'messages_ops#single'
|
||||
match "messages_ops/multi" => 'messages_ops#multi'
|
||||
match "messages_ops/sendout_or_save" => 'messages_ops#sendout_or_save' ,:as =>:sendout_or_save
|
||||
|
||||
root :to => "messages#index"
|
||||
#get "messages/refresh_status"
|
||||
#get "messages/emptybin"
|
||||
#match "messages/select/:id" => 'messages#select', :as => :messages_select
|
||||
get "messages/index"
|
||||
#match 'messages/folder/:id' => 'messages#folder', :as => :messages_folder
|
||||
post "messages/ops"
|
||||
post "messages/msgops"
|
||||
#post "messages/ops"
|
||||
#post "messages/msgops"
|
||||
match "messages/compose" => 'messages#compose'
|
||||
match "messages/edit/:id" => 'messages#edit' ,:as => :messages_edit
|
||||
match "messages/reply/:id" => 'messages#reply'
|
||||
match "messages/sendout_or_save" => 'messages#sendout_or_save' ,:as =>:sendout_or_save
|
||||
#match "messages/edit/:id" => 'messages#edit' ,:as => :messages_edit
|
||||
#match "messages/reply/:id" => 'messages#reply'
|
||||
|
||||
match "messages/show/:id" => 'messages#show'
|
||||
match "messages/body/:id/:idx" => 'messages#body' , :as => :messages_part_body
|
||||
#match "messages/body/:id/:idx" => 'messages#body' , :as => :messages_part_body
|
||||
match "messages/html_body/:id" => 'messages#html_body' , :as => :messages_html_body
|
||||
match "messages/attachment/:id/:idx" => 'messages#attachment', :as => :messages_attachment_download
|
||||
|
||||
|
@ -58,7 +62,7 @@ Mailr::Application.routes.draw do
|
|||
|
||||
themes_for_rails
|
||||
|
||||
match '*a', :to => 'internal#page_not_found'
|
||||
match '*a', :to => 'internal#not_found'
|
||||
|
||||
# The priority is based upon order of creation:
|
||||
# first created -> highest priority.
|
||||
|
|
0
public/favicon.ico
Normal file → Executable file
0
public/favicon.ico
Normal file → Executable file
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
8
test/functional/messages_ops_controller_test.rb
Executable file
8
test/functional/messages_ops_controller_test.rb
Executable file
|
@ -0,0 +1,8 @@
|
|||
require 'test_helper'
|
||||
|
||||
class MessagesOpsControllerTest < ActionController::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
end
|
4
test/unit/helpers/messages_ops_helper_test.rb
Executable file
4
test/unit/helpers/messages_ops_helper_test.rb
Executable file
|
@ -0,0 +1,4 @@
|
|||
require 'test_helper'
|
||||
|
||||
class MessagesOpsHelperTest < ActionView::TestCase
|
||||
end
|
|
@ -16,6 +16,4 @@
|
|||
<td>
|
||||
<%= link_to t(:download), messages_attachment_download_path(attachment.parent_id,attachment.idx) %>
|
||||
</td>
|
||||
<td>
|
||||
<%= link_to t(:view), messages_part_body_path(attachment.parent_id,attachment.idx) %>
|
||||
</td>
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<h2><%= t(:new_message,:scope=>:compose) %></h2>
|
||||
<%= form_tag(sendout_or_save_path)%>
|
||||
<div class="inner">
|
||||
<%= render :partial => 'new' %>
|
||||
<%= render :partial => 'messages/new' %>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<%= raw main_navigation(:messages) %>
|
||||
</div>
|
||||
<div class="content">
|
||||
<%= form_tag({:controller=>'messages', :action=>'ops'},{:name=>'messages'})%>
|
||||
<%= form_tag({:controller=>'messages_ops', :action=>'multi'},{:name=>'messages'})%>
|
||||
|
||||
<% if @current_folder.nil? %>
|
||||
<h2><%= t(:no_selected,:scope=>:folder) %></h2>
|
||||
|
@ -22,7 +22,7 @@
|
|||
<div class="header_info"><%= t(:no_in,:scope=>:message) %></div>
|
||||
</div>
|
||||
<% else %>
|
||||
<%= render :partial => 'ops' %>
|
||||
<%= render :partial => 'multi_ops' %>
|
||||
<%= render :partial => 'list' %>
|
||||
<% end %>
|
||||
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
<%= raw main_navigation(:show) %>
|
||||
</div>
|
||||
<div class="content">
|
||||
<%= form_tag(messages_msgops_path)%>
|
||||
<%= form_tag(messages_ops_single_path)%>
|
||||
<%= render :partial => 'header' %>
|
||||
<%= render :partial => 'msg_ops' %>
|
||||
<%= render :partial => 'single_ops' %>
|
||||
|
||||
<% if not @attachments.size.zero? %>
|
||||
<%= render :partial => 'attachments' %>
|
||||
|
|
Loading…
Reference in a new issue