some fixes

This commit is contained in:
Wojciech Todryk 2011-09-10 20:31:55 +02:00
parent a1352b9402
commit 639d223629
12 changed files with 80 additions and 94 deletions

View file

@ -5,15 +5,8 @@ class ApplicationController < ActionController::Base
protect_from_forgery protect_from_forgery
before_filter :load_defaults,:current_user,:set_locale before_filter :load_defaults,:current_user,:set_locale
before_filter :plugins_configuration before_filter :plugins_configuration
# rescue_from ActiveRecord::RecordNotFound do
# logger.custom('record_not_found','exc')
# reset_session
# redirect_to :controller=>'user', :action => 'login'
# end
def load_defaults def load_defaults
$defaults ||= YAML::load(File.open(Rails.root.join('config','defaults.yml'))) $defaults ||= YAML::load(File.open(Rails.root.join('config','defaults.yml')))
end end
@ -68,44 +61,6 @@ class ApplicationController < ActionController::Base
end end
end end
def self.decode_quoted(text,unknown_charset = $defaults["msg_unknown_charset"])
begin
if text.match(/\=\?.+\?\w\?.+\?\=/).nil?
after = Iconv.conv('UTF-8',unknown_charset,text)
#after = text
else
# FIXME support multiple showing of =?xxx?=
after = text
match = text.match(/\=\?.+\?\w\?.+\?\=/).to_s
f = match.split(/\?/)
case f[2].downcase
when 'q':
replace = f[3].gsub(/_/," ").unpack("M").first
when 'b':
replace = f[3].gsub(/_/," ").unpack("m").first
else
replace = match
end
match.gsub!(/\?/,'\?')
match.gsub!(/\)/,'\)')
after = text.gsub(/#{match}/,replace)
if f[1].downcase != 'utf-8'
after = Iconv.conv('UTF-8',f[1],after)
end
end
#logger.custom('after',after)
return after
rescue Exception => e
logger.error("Class Message: #{e.to_s}: T: #{text} M: #{match} R: #{replace} A: #{after}")
return text
end
end
def prepare_compose_buttons def prepare_compose_buttons
@buttons = [] @buttons = []
@buttons << {:text => 'send',:scope=>:compose,:image => 'email.png'} @buttons << {:text => 'send',:scope=>:compose,:image => 'email.png'}
@ -122,7 +77,6 @@ class ApplicationController < ActionController::Base
files.each do |f| files.each do |f|
@attachments << {:name => File.basename(f).gsub!(/#{@current_user.username}_/,"") , :size => File.stat(f).size } @attachments << {:name => File.basename(f).gsub!(/#{@current_user.username}_/,"") , :size => File.stat(f).size }
end end
logger.custom('a',@attachments.inspect)
end end
def get_system_folders def get_system_folders

View file

@ -65,7 +65,9 @@ class MessagesController < ApplicationController
end end
def compose def compose
#before_filter #before filter
@operation = :new
logger.custom('m',@message.inspect)
end end
def show def show
@ -82,7 +84,7 @@ class MessagesController < ApplicationController
@plain_header = mail.header.to_s @plain_header = mail.header.to_s
# FIXME missing fields # FIXME missing fields and support arrays
#@from = mail.From.addrs.presence #@from = mail.From.addrs.presence
#@to = mail.To.addrs.presence #@to = mail.To.addrs.presence
@from = @message.from_addr @from = @message.from_addr

View file

@ -53,7 +53,7 @@ class MessagesOpsController < ApplicationController
move move
end end
rescue Exception => e rescue Exception => e
flash[:error] = "#{t(:imap_error)} (#{e.to_s})" flash[:error] = "#{t(:imap_error,:scope=>:internal)} (#{e.to_s})"
end end
redirect_to :controller => 'messages', :action => 'index' redirect_to :controller => 'messages', :action => 'index'
end end
@ -124,11 +124,17 @@ class MessagesOpsController < ApplicationController
end end
def upload def upload
#FIXME check if uploads directory exists
@operation = :upload
create_message_with_params
if not params[:upload]
flash[:error] = t(:no_attach,:scope=>:compose)
else
name = params[:upload][:datafile].original_filename name = params[:upload][:datafile].original_filename
upload_dir = $defaults["msg_upload_dir"] upload_dir = $defaults["msg_upload_dir"]
path = File.join(upload_dir, @current_user.username + "_" + name) path = File.join(upload_dir, @current_user.username + "_" + name)
File.open(path, "wb") { |f| f.write(params[:upload][:datafile].read) } File.open(path, "wb") { |f| f.write(params[:upload][:datafile].read) }
create_message_with_params end
render 'messages/compose' render 'messages/compose'
end end
@ -166,12 +172,15 @@ class MessagesOpsController < ApplicationController
def sendout_or_save def sendout_or_save
#FIXME check if domain is set
if params[:delete_marked] and params[:files] if params[:delete_marked] and params[:files]
params[:files].each do |filename| params[:files].each do |filename|
path = File.join(Rails.root,$defaults["msg_upload_dir"],@current_user.username + "_" +filename) path = File.join(Rails.root,$defaults["msg_upload_dir"],@current_user.username + "_" +filename)
File.delete(path) if File.exist?(path) File.delete(path) if File.exist?(path)
end end
create_message_with_params create_message_with_params
@operation = :new
render 'messages/compose' render 'messages/compose'
return return
end end
@ -193,6 +202,7 @@ class MessagesOpsController < ApplicationController
if smtp_server.nil? if smtp_server.nil?
flash[:error] = t(:not_configured_smtp,:scope => :compose) flash[:error] = t(:not_configured_smtp,:scope => :compose)
@operation = :new
render 'messages/compose' render 'messages/compose'
return return
end end
@ -245,13 +255,11 @@ class MessagesOpsController < ApplicationController
protected protected
def edit def edit
old_message = @current_user.messages.find(params[:id].first) old_message = @current_user.messages.find(params[:id].first)
@message = Message.new @message = Message.new
@message.to_addr = address_formatter(old_message.to_addr,:raw) @message.to_addr = old_message.to_addr
@message.subject = old_message.subject @message.subject = old_message.subject
imap_message = @mailbox.fetch_body(old_message.uid) imap_message = @mailbox.fetch_body(old_message.uid)
@edit = true
mail = Mail.new(imap_message) mail = Mail.new(imap_message)
if mail.multipart? if mail.multipart?
@message.body = mail.text_part.decoded_and_charseted @message.body = mail.text_part.decoded_and_charseted
@ -259,14 +267,15 @@ class MessagesOpsController < ApplicationController
@message.body = mail.decoded_and_charseted @message.body = mail.decoded_and_charseted
end end
@attachments = [] @attachments = []
@operation = :edit
render 'messages/compose' render 'messages/compose'
end end
def reply def reply
old_message = @current_user.messages.find(params[:uids].first) old_message = @current_user.messages.find(params[:uids].first)
@message = Message.new @message = Message.new
@message.to_addr = address_formatter(old_message.from_addr,:raw) @message.to_addr = old_message.from_addr
@message.subject = t(:reply_string,:scope=>:show) + old_message.subject @message.subject = old_message.subject
imap_message = @mailbox.fetch_body(old_message.uid) imap_message = @mailbox.fetch_body(old_message.uid)
mail = Mail.new(imap_message) mail = Mail.new(imap_message)
@ -276,6 +285,7 @@ class MessagesOpsController < ApplicationController
@message.body = mail.decoded_and_charseted.gsub(/<\/?[^>]*>/, "") @message.body = mail.decoded_and_charseted.gsub(/<\/?[^>]*>/, "")
end end
@attachments = [] @attachments = []
@operation = :reply
render 'messages/compose' render 'messages/compose'
end end

View file

@ -26,11 +26,11 @@ def form_field(object,field,flabel,example,val)
html << "\"" html << "\""
html << " name=\"#{object.class.name.downcase}[#{field}]\"" html << " name=\"#{object.class.name.downcase}[#{field}]\""
html << " type=\"text\" class=\"text_field\" value=\"" html << " type=\"text\" class=\"text_field\" value=\""
value = object.instance_eval(field) || val || "" value = val || object.instance_eval(field) || ""
html << value html << value
html << "\"/>" html << "\"/>"
html << "<span class=\"description\">" html << "<span class=\"description\">"
html << t(:example) html << t(:example,:scope=>:common)
html << ": " html << ": "
html << example html << example
html << "</span>" html << "</span>"
@ -70,10 +70,10 @@ def area_field(object,field,flabel,example,val,cols,rows)
name = object.class.name.downcase + '[' + field + ']' name = object.class.name.downcase + '[' + field + ']'
id = object.class.name.downcase+"_"+field id = object.class.name.downcase+"_"+field
value = object.instance_eval(field) || val || "" value = val || object.instance_eval(field) || ""
html << "<textarea id=\"#{id}\" name=\"#{name}\" class=\"text_area\" cols=\"#{cols}\" rows=\"#{rows}\">#{value}</textarea>" html << "<textarea id=\"#{id}\" name=\"#{name}\" class=\"text_area\" cols=\"#{cols}\" rows=\"#{rows}\">#{value}</textarea>"
desc = t(:example) + ": " + example desc = t(:example,:scope=>:common) + ": " + example
html << "<span class=\"description\">#{desc}</span>" html << "<span class=\"description\">#{desc}</span>"
html << "</div>" html << "</div>"

View file

@ -14,12 +14,12 @@ module MessagesHelper
date.nil? ? t(:no_date,:scope=>:message) : date.strftime("%Y-%m-%d %H:%M") date.nil? ? t(:no_date,:scope=>:message) : date.strftime("%Y-%m-%d %H:%M")
end end
def address_formatter(addr,mode) def address_formatter(addr,op)
s = "" s = ""
return s if addr.nil? return s if addr.nil?
length = $defaults["msg_address_length"].to_i length = $defaults["msg_address_length"].to_i
case mode case op
when :index when :index
fs = addr.gsub(/\"/,"").split(/</) fs = addr.gsub(/\"/,"").split(/</)
fs[0].size.zero? ? s = fs[1] : s = fs[0] fs[0].size.zero? ? s = fs[1] : s = fs[0]
@ -27,30 +27,32 @@ module MessagesHelper
return h(s) return h(s)
when :show when :show
#addr = addr[0].charseted.gsub(/\"/,"") #addr = addr[0].charseted.gsub(/\"/,"")
return h(addr) return h(addr.gsub(/\"/,""))
when :raw when :raw
#fs = addr.gsub(/\"/,"").split(/</) #fs = addr.gsub(/\"/,"").split(/</)
#fs[0].size.zero? ? s = fs[1] : s << fs[0] + " <" + fs[1] + ">" #fs[0].size.zero? ? s = fs[1] : s << fs[0] + " <" + fs[1] + ">"
s = h(addr) s = h(addr)
return s return s
when :reply
return h(addr)
end end
end end
# def show_addr_formatter(addrs) def body_formatter(body,op)
# return h(force_charset(addrs[0].decoded)) case op
# end 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 show_subject_formatter(subject) def subject_formatter(message,op)
# if subject.to_s.nil? case op
# t(:no_subject,:scope=>:message)
# else
# return h(force_charset(subject.decoded))
# end
# end
def subject_formatter(message,mode)
case mode
when :index when :index
if message.subject.nil? or message.subject.size.zero? if message.subject.nil? or message.subject.size.zero?
s = t(:no_subject,:scope=>:message) s = t(:no_subject,:scope=>:message)
@ -65,6 +67,12 @@ module MessagesHelper
else else
message.subject message.subject
end 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
end end

View file

@ -36,10 +36,11 @@ class User < ActiveRecord::Base
end end
def full_address def full_address
d = domain.presence || ""
if email =~ /\@/ if email =~ /\@/
email email
else else
email + "@" + domain email + "@" + d
end end
end end

View file

@ -43,4 +43,4 @@ session_password: asDD3s2@sAdc983#
mailbox_max_parent_folder_depth: 3 mailbox_max_parent_folder_depth: 3
# array of logins which only can login to application, comment it to allow everyone to login # array of logins which only can login to application, comment it to allow everyone to login
only_can_logins: [wtodryk] only_can_logins: [soldier]

View file

@ -132,13 +132,13 @@ pl:
write_your_message_here: Tu wpisz swoją wiadomość write_your_message_here: Tu wpisz swoją wiadomość
was_sent: Wiadomość została wysłana was_sent: Wiadomość została wysłana
was_saved: Wiadomość została zapisana w katalogu roboczym was_saved: Wiadomość została zapisana w katalogu roboczym
not_configured_smtp: Brak konfiguracji SMTP not_configured_smtp: Brak konfiguracji SMTP
select_file: Wybierz plik select_file: Wybierz plik
delete_marked: Usuń zaznaczone delete_marked: Usuń zaznaczone
send_file: Wyślij plik send_file: Wyślij plik
send: Wyślij send: Wyślij
save_as_draft: Zapisz w katalogu roboczym save_as_draft: Zapisz w katalogu roboczym
no_attach: Nie wybrano żadnego pliku
show: show:
reply: Odpowiedz reply: Odpowiedz

BIN
themes/olive/images/key.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

@ -1,9 +1,6 @@
<div class="msg_header"> <div class="msg_header">
<%= raw show_param_view(@message,"from_addr",address_formatter(@from,:show)) %> <%= raw show_param_view(@message,"from_addr",address_formatter(@from,:show)) %>
<%= raw show_param_view(@message,"to_addr",address_formatter(@to,:show)) %> <%= raw show_param_view(@message,"to_addr",address_formatter(@to,:show)) %>
<% if @to.size > 1 %>
<%= raw show_param_view(@message,"to_addr","To dodatkowe jest") %>
<% end %>
<% if not @cc.nil? %> <% if not @cc.nil? %>
<%= raw show_param_view(@message,"cc_addr","CC jest") %> <%= raw show_param_view(@message,"cc_addr","CC jest") %>
<% end %> <% end %>

View file

@ -1,11 +1,25 @@
<%= form_tag(sendout_or_save_path)%> <%= form_tag(sendout_or_save_path)%>
<div class="params"> <div class="params">
<%= raw form_field(@message,"to_addr",nil,"joe@domain.com"+', '+t(:not_contain_at,:scope=>:compose),@message.to_addr) %> <%= raw form_field( @message,
<% if not @reply.nil? %> "to_addr",
<% @message.subject = t(:reply_string,:scope=>:compose) + @message.subject %> nil,
<% end %> "joe@domain.com"+', '+ t(:not_contain_at,:scope=>:compose),
<%= raw form_field(@message,"subject",nil,t(:subject_of_the_message,:scope=>:compose),@message.subject) %> address_formatter(@message.to_addr,@operation)
<%= raw area_field(@message,"body",nil,t(:write_your_message_here,:scope=>:compose),@message.body,80,20) %> ) %>
<%= raw form_field( @message,
"subject",
nil,
t(:subject_of_the_message,:scope=>:compose),
subject_formatter(@message.subject,@operation)
) %>
<%= raw area_field( @message,
"body",
nil,
t(:write_your_message_here,:scope=>:compose),
body_formatter(@message.body,@operation),
80,
20
) %>
</div> </div>
<%= raw group_action(@buttons) %> <%= raw group_action(@buttons) %>
<%= render :partial=> 'messages/file_attachs' %> <%= render :partial=> 'messages/file_attachs' %>

View file

@ -35,7 +35,7 @@
<div class="group navform wat-cf"> <div class="group navform wat-cf">
<div class="right"> <div class="right">
<button class="button" type="submit"> <button class="button" type="submit">
<img src="<%= current_theme_image_path('key.png')%>" alt="login" /> <%= t :log_in %> <img src="<%= current_theme_image_path('key.png')%>" alt="login" /> <%= t(:log_in,:scope=>:common) %>
</button> </button>
</div> </div>
</div> </div>