This commit is contained in:
Wojciech Todryk 2011-09-03 13:07:40 +02:00
parent 961e9d6f4b
commit fdd3019f55
56 changed files with 958 additions and 226 deletions

View file

@ -3,7 +3,9 @@ require 'yaml'
class ApplicationController < ActionController::Base 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 rescue_from ActiveRecord::RecordNotFound do
@ -12,14 +14,14 @@ class ApplicationController < ActionController::Base
redirect_to :controller=>'user', :action => 'login' redirect_to :controller=>'user', :action => 'login'
end end
def load_defaults
$defaults ||= YAML::load(File.open(Rails.root.join('config','defaults.yml')))
end
################################# protected section ########################################### ################################# protected section ###########################################
protected protected
def load_defaults
$defaults ||= YAML::load(File.open(Rails.root.join('config','defaults.yml')))
end
def theme_resolver def theme_resolver
if @current_user.nil? if @current_user.nil?
$defaults['theme'] $defaults['theme']
@ -49,24 +51,35 @@ class ApplicationController < ActionController::Base
end end
def selected_folder def selected_folder
session[:selected_folder] ? @selected_folder = session[:selected_folder] : @selected_folder = $defaults['mailbox_inbox'] 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 end
def get_current_folders def get_current_folders
@folders_shown = @current_user.folders.shown.order("name asc") @folders_shown = @current_user.folders.shown.order("name asc")
@current_folder = @current_user.folders.find_by_full_name(@selected_folder) if not @selected_folder.nil?
@current_folder = @current_user.folders.find_by_full_name(@selected_folder)
end
end end
def self.decode_quoted(text,unknown_charset = $defaults["msg_unknown_charset"]) def self.decode_quoted(text,unknown_charset = $defaults["msg_unknown_charset"])
begin begin
if text.=~(/=\?/).nil? if text.match(/\=\?.+\?\w\?.+\?\=/).nil?
after = Iconv.conv('UTF-8',unknown_charset,text) after = Iconv.conv('UTF-8',unknown_charset,text)
#after = text #after = text
else else
# TODO support multiple showing of =?xxx?=
text =~ /(=\?.+\?=)/ # FIXME support multiple showing of =?xxx?=
after = text after = text
match = $1 match = text.match(/\=\?.+\?\w\?.+\?\=/).to_s
f = match.split(/\?/) f = match.split(/\?/)
case f[2].downcase case f[2].downcase
when 'q': when 'q':
@ -85,6 +98,7 @@ class ApplicationController < ActionController::Base
end end
end end
#logger.custom('after',after)
return after return after
rescue Exception => e rescue Exception => e
logger.error("Class Message: #{e.to_s}: T: #{text} M: #{match} R: #{replace} A: #{after}") logger.error("Class Message: #{e.to_s}: T: #{text} M: #{match} R: #{replace} A: #{after}")

View file

@ -1,8 +1,6 @@
class ContactsController < ApplicationController class ContactsController < ApplicationController
before_filter :check_current_user,:selected_folder before_filter :check_current_user,:selected_folder, :get_current_folders
before_filter :get_current_folders
before_filter :get_contacts, :only => [:index] before_filter :get_contacts, :only => [:index]

View file

@ -6,34 +6,36 @@ class FoldersController < ApplicationController
include ImapMailboxModule include ImapMailboxModule
include ImapSessionModule include ImapSessionModule
before_filter :check_current_user ,:selected_folder before_filter :check_current_user,:selected_folder, :get_current_folders
before_filter :open_imap_session, :except => [:index,:show_hide] before_filter :open_imap_session, :except => [:index,:show_hide,:system]
after_filter :close_imap_session, :except => [:index,:show_hide] after_filter :close_imap_session, :except => [:index,:show_hide,:system]
before_filter :get_folders before_filter :get_folders
theme :theme_resolver theme :theme_resolver
def index def index
@buttons = []
@buttons << {:text => 'show_hide',:image => 'tick.png'}
@buttons << {:text => 'refresh',:image => 'tick.png'}
end end
def create def create
if params["folder"].empty? if params[:folder][:target].empty?
flash[:warning] = t(:to_create_empty,:scope=>:folder) flash[:warning] = t(:to_create_empty,:scope=>:folder)
render "index" render "index"
else else
begin begin
#TODO recreate local copy of folders #TODO recreate local copy of folders
if params["parent_folder"].empty? if params[:folder][:parent].empty?
@mailbox.create_folder(params[:folder]) @mailbox.create_folder(params[:folder][:target])
else else
parent_folder = @current_user.folders.find(params["parent_folder"]) parent_folder = @current_user.folders.find(params[:folder][:parent])
if parent_folder.depth >= $defaults["mailbox_max_parent_folder_depth"].to_i if parent_folder.depth >= $defaults["mailbox_max_parent_folder_depth"].to_i
raise Exception, t(:max_depth,:scope=>:folder) raise Exception, t(:max_depth,:scope=>:folder)
end end
@mailbox.create_folder(parent_folder.full_name + parent_folder.delim + params[:folder]) @mailbox.create_folder(parent_folder.full_name + parent_folder.delim + params[:folder][:target])
end end
rescue Exception => e rescue Exception => e
flash[:error] = t(:can_not_create,:scope=>:folder) + ' (' + e.to_s + ')' flash[:error] = t(:can_not_create,:scope=>:folder) + ' (' + e.to_s + ')'
@ -46,25 +48,18 @@ class FoldersController < ApplicationController
end end
def delete def delete
if params["folder"].empty? if params[:folder][:delete].empty?
flash[:warning] = t(:to_delete_empty,:scope=>:folder) flash[:warning] = t(:to_delete_empty,:scope=>:folder)
render "index" render "index"
else else
begin begin
folder = @current_user.folders.find(params["folder"]) folder = @current_user.folders.find(params[:folder][:delete])
system_folders = Array.new if @folders_system.include?(folder)
system_folders << $defaults["mailbox_inbox"] raise Exception, t(:system,:scope=>:folder)
system_folders << $defaults["mailbox_trash"]
system_folders << $defaults["mailbox_sent"]
system_folders << $defaults["mailbox_drafts"]
if system_folders.include?(folder.full_name.downcase)
raise Exception, t(:system_folder)
end end
@mailbox.delete_folder(folder.full_name) @mailbox.delete_folder(folder.full_name)
logger.custom('c',@current_folder.inspect)
logger.custom('f',folder.inspect)
if @current_folder.eql? folder if @current_folder.eql? folder
session[:selected_folder] = $defaults['mailbox_inbox'] session[:selected_folder] = nil
end end
folder.destroy folder.destroy
rescue Exception => e rescue Exception => e
@ -77,25 +72,48 @@ class FoldersController < ApplicationController
end end
end end
def show_hide def system
if !params["folders_to_show"].nil? logger.custom('sss',params[:folder].inspect)
@folders.each do |f| @folders.each do |f|
if params["folders_to_show"].include?(f.id.to_s) logger.custom('s',f.inspect)
f.shown = true if f.isSystem?
f.save f.setNone
else
f.shown = false
f.save
end
end end
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' redirect_to :action => 'index'
end end
def refresh def refresh
Folder.refresh(@mailbox,@current_user) # TODO save system folders
flash.keep if params[:refresh]
redirect_to :action => 'index' 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 end
def select def select
@ -114,7 +132,10 @@ class FoldersController < ApplicationController
def emptybin def emptybin
begin begin
trash_folder = @current_user.folders.find_by_full_name($defaults["mailbox_trash"]) 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) @mailbox.set_folder(trash_folder.full_name)
trash_folder.messages.each do |m| trash_folder.messages.each do |m|
@mailbox.delete_message(m.uid) @mailbox.delete_message(m.uid)
@ -134,16 +155,13 @@ class FoldersController < ApplicationController
protected protected
def get_folders def get_folders
@folders = @current_user.folders.order("name asc") @folders = @current_user.folders
@folders_shown = [] @folders_shown = @current_user.folders.shown
@folders.each do |f| #@folders_system = @current_user.folders.sys
if f.shown == true @current_user.folders.inbox.first.nil? ? @folder_inbox = "" : @folder_inbox = @current_user.folders.inbox.first.id
@folders_shown << f @current_user.folders.drafts.first.nil? ? @folder_drafts = "" : @folder_drafts = @current_user.folders.drafts.first.id
end @current_user.folders.sent.first.nil? ? @folder_sent = "" : @folder_sent = @current_user.folders.sent.first.id
if f.selected?(@selected_folder) @current_user.folders.trash.first.nil? ? @folder_trash = "" : @folder_trash = @current_user.folders.trash.first.id
@current_folder = f
end
end
end end
end end

View file

@ -2,6 +2,7 @@ require 'imap_session'
require 'imap_mailbox' require 'imap_mailbox'
require 'imap_message' require 'imap_message'
require 'mail' require 'mail'
require 'mail_plugin_extension'
class MessagesController < ApplicationController class MessagesController < ApplicationController
@ -13,13 +14,25 @@ class MessagesController < ApplicationController
before_filter :check_current_user ,:selected_folder,:get_current_folders before_filter :check_current_user ,:selected_folder,:get_current_folders
before_filter :open_imap_session, :select_imap_folder before_filter :open_imap_session, :select_imap_folder
before_filter :prepare_buttons, :only => [:compose,:reply,:edit,:sendout_or_save]
#before_filter :mail_defaults, :only => [:sendout_or_save]
before_filter :get_system_folders, :only => [:index,:ops,:sendout_or_save]
after_filter :close_imap_session after_filter :close_imap_session
theme :theme_resolver theme :theme_resolver
def index 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? if @current_folder.nil?
flash[:warning] = t(:no_selected,:scope => :folder)
redirect_to :controller => 'folders', :action => 'index' redirect_to :controller => 'folders', :action => 'index'
return return
end end
@ -32,6 +45,12 @@ class MessagesController < ApplicationController
folder_status['MESSAGES'].zero? ? uids_remote = [] : uids_remote = @mailbox.fetch_uids folder_status['MESSAGES'].zero? ? uids_remote = [] : uids_remote = @mailbox.fetch_uids
uids_local = @current_user.messages.where(:folder_id => @current_folder).collect(&:uid) 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| (uids_local-uids_remote).each do |uid|
@current_folder.messages.find_by_uid(uid).destroy @current_folder.messages.find_by_uid(uid).destroy
end end
@ -49,16 +68,123 @@ class MessagesController < ApplicationController
def compose def compose
@message = Message.new @message = Message.new
if params[:message]
@message = update_attributes(params[:message])
end
end end
def reply def reply
attachments = []
body = ''
old_message = @current_user.messages.find(params[:id])
@message = Message.new @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' render 'compose'
end end
def sendout def edit
flash[:notice] = t(:was_sent,:scope => :sendout)
redirect_to :action => 'index' 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 end
def msgops def msgops
@ -90,20 +216,21 @@ class MessagesController < ApplicationController
@current_user.messages.find_by_uid(uid).update_attributes(:unseen => 0) @current_user.messages.find_by_uid(uid).update_attributes(:unseen => 0)
end end
elsif params["trash"] elsif params["trash"]
dest_folder = @current_user.folders.find_by_full_name($defaults["mailbox_trash"]) if not @trash_folder.nil?
params["uids"].each do |uid| params["uids"].each do |uid|
@mailbox.move_message(uid,dest_folder.full_name) @mailbox.move_message(uid,@trash_folder.full_name)
message = @current_folder.messages.find_by_uid(uid) message = @current_folder.messages.find_by_uid(uid)
message.change_folder(dest_folder) message.change_folder(@trash_folder)
end
@mailbox.expunge
@trash_folder.update_stats
@current_folder.update_stats
end end
@mailbox.expunge
dest_folder.update_stats
@current_folder.update_stats
elsif params["copy"] elsif params["copy"]
if params["dest_folder"].empty? if params[:folder][:target].empty?
flash[:warning] = t(:no_selected,:scope=>:folder) flash[:warning] = t(:no_selected,:scope=>:folder)
else else
dest_folder = @current_user.folders.find(params["dest_folder"]) dest_folder = @current_user.folders.find(params[:folder][:target])
params["uids"].each do |uid| params["uids"].each do |uid|
@mailbox.copy_message(uid,dest_folder.full_name) @mailbox.copy_message(uid,dest_folder.full_name)
message = @current_folder.messages.find_by_uid(uid) message = @current_folder.messages.find_by_uid(uid)
@ -115,10 +242,10 @@ class MessagesController < ApplicationController
@current_folder.update_stats @current_folder.update_stats
end end
elsif params["move"] elsif params["move"]
if params["dest_folder"].empty? if params[:folder][:target].empty?
flash[:warning] = t(:no_selected,:scope=>:folder) flash[:warning] = t(:no_selected,:scope=>:folder)
else else
dest_folder = @current_user.folders.find(params["dest_folder"]) dest_folder = @current_user.folders.find(params[:folder][:target])
params["uids"].each do |uid| params["uids"].each do |uid|
@mailbox.move_message(uid,dest_folder.full_name) @mailbox.move_message(uid,dest_folder.full_name)
message = @current_folder.messages.find_by_uid(uid) message = @current_folder.messages.find_by_uid(uid)
@ -136,33 +263,91 @@ class MessagesController < ApplicationController
end end
def show def show
logger.custom('start',Time.now) @images = []
@attachments = [] @attachments = []
@render_as_text = [] @text_part = nil
@render_as_html_idx = nil @html_part = nil
@message = @current_user.messages.find_by_uid(params[:id]) @message = @current_user.messages.find_by_uid(params[:id])
@message.update_attributes(:unseen => false) @message.update_attributes(:unseen => false)
logger.custom('start_fetch',Time.now)
imap_message = @mailbox.fetch_body(@message.uid) imap_message = @mailbox.fetch_body(@message.uid)
logger.custom('stop_fetch',Time.now)
parts = imap_message.split(/\r\n\r\n/)
@message_header = parts[0]
logger.custom('before_parse',Time.now)
@mail = Mail.new(imap_message)
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 mail = Mail.new(imap_message)
@attachments[idx].isText? ? @render_as_text << @attachments[idx].decode_and_charset : @render_as_text @plain_header = mail.header.to_s
@attachments[idx].isHtml? ? @render_as_html_idx ||= idx : @render_as_html_idx @from = mail.From.addrs
end @to = mail.To.addrs
logger.custom('done',Time.now) @cc = mail.Cc
@bcc = mail.Bcc
@subject = mail.Subject
@date = mail.date
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?
@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?
@images << part
elsif part.isHtml?
@html_part = part.decoded_and_charseted
else
@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
message = @current_user.messages.find(params[:id])
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)
end
render 'html_body',:layout => 'html_body'
end end
def body def body
@ -204,4 +389,46 @@ class MessagesController < ApplicationController
render :text => a.decode render :text => a.decode
end 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
end end

View file

@ -4,21 +4,42 @@ class PrefsController < ApplicationController
before_filter :get_current_folders before_filter :get_current_folders
before_filter :get_prefs before_filter :get_prefs, :only => [:look,:update_look]
theme :theme_resolver theme :theme_resolver
def index def update_look
end
def update
if params[:prefs] if params[:prefs]
@prefs.update_attributes(params[:prefs]) @prefs.update_attributes(params[:prefs])
end end
redirect_to :action => 'index' redirect_to :action => 'look'
end end
############################################ private section ######################################### def update_servers
redirect_to :action => 'servers'
end
def update_identity
if params[:user]
@current_user.update_attributes(params[:user])
end
redirect_to :action => 'identity'
end
def look
end
def identity
@identity = @curent_user
end
def servers
@servers = @current_user.servers
end
############################# protected section ##################################
def get_prefs def get_prefs
@prefs = @current_user.prefs @prefs = @current_user.prefs

View file

@ -61,9 +61,10 @@ class UserController < ApplicationController
if @user.valid? and @server.valid? if @user.valid? and @server.valid?
@user.save @user.save
@server.user_id = @user.id #@server.user_id = @user.id
@server.save #@server.save
Prefs.create_default(@user.id) Prefs.create_default(@user)
Server.create_defaults(@user)
flash[:notice] = t(:setup_done,:scope=>:user) flash[:notice] = t(:setup_done,:scope=>:user)
redirect_to :action => 'login' redirect_to :action => 'login'
else else

View file

@ -1,3 +1,5 @@
require 'iconv'
module ApplicationHelper module ApplicationHelper
def form_field(object,field,flabel,example,val) def form_field(object,field,flabel,example,val)
@ -36,7 +38,7 @@ def form_field(object,field,flabel,example,val)
end end
def mail_param_view(object,field,value) def show_param_view(object,field,value)
model_name = eval(object.class.model_name) model_name = eval(object.class.model_name)
html = "" html = ""
html << "<div class=\"group\">" html << "<div class=\"group\">"
@ -69,7 +71,7 @@ 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 = object.instance_eval(field) || val || ""
html << "<textarea id=\"#{id}\" name=\"#{name}\" class=\"text_area\" cols=\"#{cols}\" rows=\"#{rows}\" value=\"#{value}\"></textarea>" html << "<textarea id=\"#{id}\" name=\"#{name}\" class=\"text_area\" cols=\"#{cols}\" rows=\"#{rows}\">#{value}</textarea>"
desc = t(:example) + ": " + example desc = t(:example) + ": " + example
html << "<span class=\"description\">#{desc}</span>" html << "<span class=\"description\">#{desc}</span>"
@ -90,6 +92,24 @@ def form_button(text,image)
html << "</button></div>" html << "</button></div>"
end end
def form_buttons(buttons)
html = ""
html << "<div class=\"group navform wat-cf\">"
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) def form_button_value(text,image,onclick)
html = "" html = ""
html << "<div class=\"group navform wat-cf\">" html << "<div class=\"group navform wat-cf\">"
@ -105,11 +125,11 @@ def form_button_value(text,image,onclick)
html << "</button></div>" html << "</button></div>"
end end
def simple_input_field(name,label,value) def simple_input_field(name,id,label,value)
html = "" html = ""
html << "<div class=\"param_group\">" html << "<div class=\"param_group\">"
html << "<label class=\"label\">#{label}</label>" html << "<label class=\"label\">#{label}</label>"
html << "<input name=\"#{name}\" class=\"text_field\" type=\"text\" value=\"#{value}\">" html << "<input name=\"#{name}[#{id}]\" id=\"#{name}_#{id} class=\"text_field\" type=\"text\" value=\"#{value}\">"
html << "</div>" html << "</div>"
end end
@ -155,7 +175,7 @@ def nav_to_contacts
end end
def nav_to_prefs def nav_to_prefs
link_to( t(:prefs,:scope=>:prefs), prefs_path ) link_to( t(:prefs,:scope=>:prefs), prefs_look_path )
end end
def main_navigation(active) def main_navigation(active)
@ -171,6 +191,26 @@ def main_navigation(active)
s += "</ul>" s += "</ul>"
end end
def prefs_navigation(active)
look_active = ""
identity_active = ""
servers_active = ""
case active
when :look
look_active = "active"
when :identity
identity_active ="active"
when :servers
servers_active ="active"
end
s = ""
s += "<ul class=\"wat-cf\">"
s += "<li class=\"first #{look_active}\">#{link_to( t(:look,:scope=>:prefs), prefs_look_path )}</li>"
s += "<li class=\"#{identity_active}\">#{link_to( t(:identity,:scope=>:prefs), prefs_identity_path )}</li>"
s += "<li class=\"last #{servers_active}\">#{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 = {}) def multi_select(id, name, objects, selected_objects, label, value,joiner,content = {})
options = "" options = ""
objects.each do |o| objects.each do |o|
@ -195,7 +235,15 @@ def multi_select(id, name, objects, selected_objects, label, value,joiner,conten
option_content = bracket.empty? ? "#{text}" : "#{text} (#{bracket})" option_content = bracket.empty? ? "#{text}" : "#{text} (#{bracket})"
options << "<option value=\"#{option_value}\"#{selected}>&nbsp;&nbsp;#{option_content}&nbsp;&nbsp;</option>\n" options << "<option value=\"#{option_value}\"#{selected}>&nbsp;&nbsp;#{option_content}&nbsp;&nbsp;</option>\n"
end end
"<div class=\"group\"><label class=\"label\">#{label}</label><select multiple=\"multiple\" size=10 id=\"#{id}\" name=\"#{name}\">\n#{options}</select></div>" "<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 end

View file

@ -3,9 +3,21 @@ module FolderHelper
def folder_link(folder) def folder_link(folder)
folder.parent.empty? ? name = folder.name : name = folder.parent.gsub(/\./,'#') + "#" + folder.name folder.parent.empty? ? name = folder.name : name = folder.parent.gsub(/\./,'#') + "#" + folder.name
s = link_to folder.name.capitalize, folders_select_path(:id => name)
if folder.full_name.downcase == $defaults["mailbox_trash"].downcase 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? if not folder.total.zero?
s <<' (' s <<' ('
s << link_to(t(:emptybin,:scope=>:folder),folders_emptybin_path) s << link_to(t(:emptybin,:scope=>:folder),folders_emptybin_path)
@ -20,20 +32,34 @@ module FolderHelper
end end
def pretty_folder_name(folder) def pretty_folder_name(folder)
folder.nil? ? t(:no_selected,:scope=>:folder) : folder.name.capitalize 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 end
def select_for_folders(name,id,object,label,blank) def select_for_folders(name,id,collection,label,choice,blank)
html = "" html = ""
html << "<div class=\"group\">" html << "<div class=\"param_group\">"
html << "<label class=\"label\">#{label}</label>" html << "<label class=\"label\">#{label}</label>"
html << simple_select_for_folders(name,id,object,blank) html << simple_select_for_folders(name,id,collection,choice,blank)
html << "</div>" html << "</div>"
end end
def simple_select_for_folders(name,id,object,blank) def simple_select_for_folders(name,id,collection,choice,blank)
html = "" html = ""
html << select(name, id, object.all.collect {|p| [ p.parent.empty? ? p.name : p.parent+p.delim+p.name, p.id ] }, { :include_blank => (blank == true ? true : false)}) html << select(name , id, options_from_collection_for_select(collection, 'id', 'full_name', choice),{ :include_blank => (blank == true ? true : false)})
html html
end end

View file

@ -14,26 +14,40 @@ module MessagesHelper
date.nil? ? t(:no_data) : date.strftime("%Y-%m-%d %H:%M") date.nil? ? t(:no_data) : date.strftime("%Y-%m-%d %H:%M")
end end
# def address_formatter(addr)
# ImapMessageModule::IMAPAddress.parse(addr).friendly
# end
def address_formatter(addr,mode) def address_formatter(addr,mode)
s = "" s = ""
length = $defaults["msg_address_length"].to_i length = $defaults["msg_address_length"].to_i
fs = addr.split(/</) fs = addr.split(/</)
if mode == :index if not fs.size.zero?
fs[0].size.zero? ? s = fs[1] : s = fs[0] case mode
s.length >= length ? s = s[0,length]+"..." : s when :index
else fs[0].size.zero? ? s = fs[1] : s = fs[0]
fs[0].size.zero? ? s = "<" + fs[1] + ">" : s << fs[0] + " <" + fs[1] + ">" s.length >= length ? s = s[0,length]+"..." : s
return h(s)
when :message
fs[0].size.zero? ? s = "<" + fs[1] + ">" : s << fs[0] + " <" + fs[1] + ">"
return h(s)
when :raw
fs[0].size.zero? ? s = fs[1] : s << fs[0] + " <" + fs[1] + ">"
return s
end
end end
return h(s)
end end
def show_addr_formatter(addrs)
return h(force_charset(addrs[0].decoded))
end
def show_subject_formatter(subject)
if subject.to_s.nil?
t(:no_subject,:scope=>:message)
else
return h(force_charset(subject.decoded))
end
end
def subject_formatter(message) def subject_formatter(message)
if message.subject.size.zero? if message.subject.size.zero?
s = t(:no_subject,:scope=>:message) s = t(:no_subject,:scope=>:message)
@ -49,8 +63,8 @@ module MessagesHelper
end end
def headers_links def headers_links
#if @current_folder.hasFullName?(@folder_sent_name) || @current_folder.hasFullName?(@folder_drafts_name)
if @current_folder.hasFullName?($defaults["mailbox_sent"]) if @current_folder == @sent_folder || @current_folder == @drafts_folder
fields = $defaults["msgs_sent_view_fields"] fields = $defaults["msgs_sent_view_fields"]
else else
fields = $defaults["msgs_inbox_view_fields"] fields = $defaults["msgs_inbox_view_fields"]
@ -71,6 +85,7 @@ module MessagesHelper
def content_text_plain_for_render(text) def content_text_plain_for_render(text)
html = "<pre>" html = "<pre>"
#html << text.gsub!(/\r\n/,"\n")
html << h(text) html << h(text)
html << "</pre>" html << "</pre>"
html html

View file

@ -1,3 +1,4 @@
class Attachment class Attachment
include ActiveModel::Validations include ActiveModel::Validations
include ActiveModel::Conversion include ActiveModel::Conversion
@ -19,7 +20,9 @@ class Attachment
if p =~ /=/ if p =~ /=/
fields = p.split(/=/) fields = p.split(/=/)
key = fields[0] key = fields[0]
value = fields[1] fields.delete_at(0)
value = fields.join("=")
# FIXME maybe do decoding only for name and filename key
if Attachment.attribute_method?(key) == true if Attachment.attribute_method?(key) == true
send("#{key}=", ApplicationController.decode_quoted(value)) send("#{key}=", ApplicationController.decode_quoted(value))
end end
@ -111,6 +114,10 @@ class Attachment
@type =~ /^text\/html/ @type =~ /^text\/html/
end end
def isImageAndNotCid?
@type =~ /^image/ and @cid.size.zero?
end
def title def title
@description.nil? ? name : @description @description.nil? ? name : @description
end end

View file

@ -5,6 +5,20 @@ class Folder < ActiveRecord::Base
before_save :check_fill_params, :on => :create before_save :check_fill_params, :on => :create
has_many :messages, :dependent => :destroy 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 def full_name
if parent.empty? if parent.empty?
name name
@ -33,6 +47,48 @@ class Folder < ActiveRecord::Base
full_name.downcase == folder_name.downcase full_name.downcase == folder_name.downcase
end 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 section #####################################
private private
@ -43,6 +99,7 @@ class Folder < ActiveRecord::Base
self.parent.nil? ? self.parent = "" : self.parent self.parent.nil? ? self.parent = "" : self.parent
self.haschildren.nil? ? self.haschildren = false : self.haschildren self.haschildren.nil? ? self.haschildren = false : self.haschildren
self.delim.nil? ? self.delim = "." : self.delim self.delim.nil? ? self.delim = "." : self.delim
self.sys.nil? ? self.sys = SYS_NONE : self.sys
end end
def self.createBulk(user,imapFolders) def self.createBulk(user,imapFolders)
@ -64,7 +121,8 @@ class Folder < ActiveRecord::Base
:haschildren => has_children, :haschildren => has_children,
:delim => data.delim, :delim => data.delim,
:total => data.messages, :total => data.messages,
:unseen => data.unseen) :unseen => data.unseen,
:sys => SYS_NONE)
end end
end end
@ -76,16 +134,10 @@ class Folder < ActiveRecord::Base
where(['name = ? and parent = ?',nam,par]).first where(['name = ? and parent = ?',nam,par]).first
end end
def self.shown
where(['shown = ?',true])
end
def self.refresh(mailbox,user) def self.refresh(mailbox,user)
user.folders.destroy_all user.folders.destroy_all
folders=mailbox.folders folders=mailbox.folders
Folder.createBulk(user,folders) Folder.createBulk(user,folders)
end end
end end

View file

@ -6,7 +6,8 @@ class Message < ActiveRecord::Base
belongs_to :folder belongs_to :folder
set_primary_key :uid set_primary_key :uid
attr_accessible :unseen, :to_addr, :size, :content_type, :folder_id, :subject, :date, :uid, :from_addr, :user_id, :msg_id 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) def self.addr_to_db(addr)
ret = "" ret = ""
@ -33,9 +34,8 @@ class Message < ActiveRecord::Base
envelope = imap_message.attr['ENVELOPE'] envelope = imap_message.attr['ENVELOPE']
from = addr_to_db(envelope.from[0]) envelope.from.nil? ? from = "" : from = addr_to_db(envelope.from[0])
to = addr_to_db(envelope.to[0]) envelope.to.nil? ? to = "" : to = addr_to_db(envelope.to[0])
envelope.subject.nil? ? subject = "" : subject = ApplicationController.decode_quoted(envelope.subject) envelope.subject.nil? ? subject = "" : subject = ApplicationController.decode_quoted(envelope.subject)
create( create(
@ -57,5 +57,4 @@ class Message < ActiveRecord::Base
update_attributes(:folder_id => folder.id) update_attributes(:folder_id => folder.id)
end end
end end

View file

@ -6,8 +6,8 @@ class Prefs < ActiveRecord::Base
protected protected
def self.create_default(user_id) def self.create_default(user)
Prefs.create(:user_id => user_id, Prefs.create(:user_id => user.id,
:theme => $defaults['theme'], :theme => $defaults['theme'],
:locale => $defaults['locale'], :locale => $defaults['locale'],
:msgs_per_page => $defaults['msgs_per_page'], :msgs_per_page => $defaults['msgs_per_page'],

View file

@ -2,17 +2,40 @@ class Server < ActiveRecord::Base
validates_presence_of :name validates_presence_of :name
belongs_to :user belongs_to :user
before_save :fill_params #before_save :fill_params
def self.primary def self.primary_for_imap
first where(:for_imap=>true).first
end end
private def self.primary_for_smtp
where(:for_smtp=>true).first
end
def fill_params def self.create_defaults(user)
self.port = $defaults['imap_port'] create( :user_id=>user.id,
$defaults['imap_use_ssl'] == true ? self.use_ssl = 1 : self.use_ssl = 0 :name=>"localhost",
end :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 end

View file

@ -31,4 +31,16 @@ class User < ActiveRecord::Base
(0...8).map{65.+(rand(25)).chr}.join (0...8).map{65.+(rand(25)).chr}.join
end end
def full_name
first_name + " " + last_name
end
def full_address
if email =~ /\@/
email
else
email + "@" + domain
end
end
end end

View file

@ -30,14 +30,12 @@ imap_ssl_port: 993
imap_bye_timeout_retry_seconds: 2 imap_bye_timeout_retry_seconds: 2
imap_fetch_slice: 20 imap_fetch_slice: 20
smtp_port: 25
session_encryption: true session_encryption: true
session_password: asDD3s2@sAdc983# session_password: asDD3s2@sAdc983#
mailbox_max_parent_folder_depth: 3 mailbox_max_parent_folder_depth: 3
mailbox_inbox: INBOX
mailbox_trash: INBOX.Trash
mailbox_sent: INBOX.sent
mailbox_drafts: INBOX.drafts
# 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: [some_login] only_can_logins: [soldier]

View file

@ -29,6 +29,8 @@ pl:
size: Rozmiar size: Rozmiar
date: Data date: Data
body: Treść body: Treść
cc_addr: Dw
bcc_addr: UDw
user: user:
email: E-mail email: E-mail
password: Hasło password: Hasło
@ -53,14 +55,18 @@ pl:
prefs: prefs:
prefs: Ustawienia prefs: Ustawienia
look: Wygląd
identity: Tożsamość
servers: Serwery
folder: folder:
folder: Folder
folders: Foldery folders: Foldery
no_shown: Nie prezentowany jest żaden folder. Skonfiguruj widok folderów w zakładce no_shown: Nie prezentowany jest żaden folder. Skonfiguruj widok folderów w zakładce
parent: Folder nadrzędny parent: Folder nadrzędny
to_create: Folder do utworzenia to_create: Folder do utworzenia
to_delete: Folder do usunięcia to_delete: Folder do usunięcia
shown: Foldery pokazane shown: Wyświetlane foldery
emptybin: Opróżnij emptybin: Opróżnij
current: Folder bieżący current: Folder bieżący
no_selected: Nie wybrano żadnego folderu no_selected: Nie wybrano żadnego folderu
@ -72,6 +78,12 @@ pl:
can_not_delete: Nie można usunąć folderu can_not_delete: Nie można usunąć folderu
was_deleted: Folder został usunięty was_deleted: Folder został usunięty
to_folder: do folderu to_folder: do folderu
system: Folder systemowy
not_all_configured: Nie wszystkie systemowe foldery zostały skonfigurowane
inbox_name: Odebrane
sent_name: Wysłane
trash_name: Kosz
drafts_name: Roboczy
message: message:
messages: Wiadomości messages: Wiadomości
@ -87,6 +99,8 @@ pl:
content: Treść wiadomości content: Treść wiadomości
header_source: Nagłówek wiadomości header_source: Nagłówek wiadomości
show_header: Pokaż nagłówek show_header: Pokaż nagłówek
edit: Edycja
images: Obrazy
compose: compose:
compose: Nowa wiadomość compose: Nowa wiadomość
@ -94,9 +108,14 @@ pl:
not_contain_at: ",jeżeli nie zawiera znaku @, adres będzie szukany w kontaktach" not_contain_at: ",jeżeli nie zawiera znaku @, adres będzie szukany w kontaktach"
subject_of_the_message: Temat wiadomości subject_of_the_message: Temat wiadomości
write_your_message_here: Tu wpisz swoją wiadomość write_your_message_here: Tu wpisz swoją wiadomość
sendout:
was_sent: Wiadomość została wysłana was_sent: Wiadomość została wysłana
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: show:
replay_to: Odpowiedz replay_to: Odpowiedz
@ -141,4 +160,6 @@ pl:
download: Pobierz download: Pobierz
view: Pokaż view: Pokaż
version: Wersja version: Wersja
save_as_draft: Zapisz w katalogu roboczym
set: Ustaw

View file

@ -1,7 +1,14 @@
Mailr::Application.routes.draw do Mailr::Application.routes.draw do
match "prefs/index" => "prefs#index", :as => :prefs #match "prefs/index" => "prefs#index", :as => :prefs
post "prefs/update"
post "prefs/update_look"
post "prefs/update_identity"
post "prefs/update_servers"
match "prefs/look" => "prefs#look", :as => :prefs_look
match "prefs/identity" => "prefs#identity", :as => :prefs_identity
match "prefs/servers" => "prefs#servers", :as => :prefs_servers
resources :contacts resources :contacts
post "contacts/ops" post "contacts/ops"
@ -11,8 +18,9 @@ Mailr::Application.routes.draw do
match "folders/index" => 'folders#index', :as => :folders match "folders/index" => 'folders#index', :as => :folders
post "folders/create" post "folders/create"
post "folders/delete" post "folders/delete"
post "folders/system"
post "folders/show_hide" post "folders/show_hide"
get "folders/refresh" post "folders/refresh"
get "folders/refresh_status" get "folders/refresh_status"
post "folders/refresh" post "folders/refresh"
match "folders/select/:id" => 'folders#select', :as => :folders_select match "folders/select/:id" => 'folders#select', :as => :folders_select
@ -32,10 +40,12 @@ Mailr::Application.routes.draw do
post "messages/ops" post "messages/ops"
post "messages/msgops" post "messages/msgops"
match "messages/compose" => 'messages#compose' match "messages/compose" => 'messages#compose'
match "messages/edit/:id" => 'messages#edit' ,:as => :messages_edit
match "messages/reply/:id" => 'messages#reply' match "messages/reply/:id" => 'messages#reply'
post "messages/sendout" match "messages/sendout_or_save" => 'messages#sendout_or_save' ,:as =>:sendout_or_save
match "messages/show/:id" => 'messages#show' 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 match "messages/attachment/:id/:idx" => 'messages#attachment', :as => :messages_attachment_download
get "user/logout" get "user/logout"

View file

@ -0,0 +1,13 @@
class AddOptionsToServers < ActiveRecord::Migration
def self.up
add_column :servers,:use_tls,:boolean
add_column :servers,:for_imap,:boolean
add_column :servers,:for_smtp,:boolean
end
def self.down
remove_column :servers,:use_tls
remove_column :servers,:for_imap
remove_column :servers,:for_smtp
end
end

View file

@ -0,0 +1,9 @@
class AddDomainToUsers < ActiveRecord::Migration
def self.up
add_column :users, :domain, :string
end
def self.down
remove_column :users, :domain
end
end

View file

@ -0,0 +1,9 @@
class AddTypeToFolders < ActiveRecord::Migration
def self.up
add_column :folders, :sys, :integer
end
def self.down
remove_column :folders, :sys
end
end

View file

@ -0,0 +1,9 @@
class AddAuthToServers < ActiveRecord::Migration
def self.up
add_column :servers, :auth, :string
end
def self.down
remove_column :servers, :auth
end
end

View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20110816120258) do ActiveRecord::Schema.define(:version => 20110901120826) do
create_table "contacts", :force => true do |t| create_table "contacts", :force => true do |t|
t.string "nick" t.string "nick"
@ -35,6 +35,7 @@ ActiveRecord::Schema.define(:version => 20110816120258) do
t.string "parent" t.string "parent"
t.boolean "shown" t.boolean "shown"
t.string "alter_name" t.string "alter_name"
t.integer "sys"
end end
create_table "messages", :id => false, :force => true do |t| create_table "messages", :id => false, :force => true do |t|
@ -70,6 +71,10 @@ ActiveRecord::Schema.define(:version => 20110816120258) do
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.boolean "use_ssl" t.boolean "use_ssl"
t.boolean "use_tls"
t.boolean "for_imap"
t.boolean "for_smtp"
t.string "auth"
end end
create_table "users", :force => true do |t| create_table "users", :force => true do |t|
@ -78,6 +83,7 @@ ActiveRecord::Schema.define(:version => 20110816120258) do
t.string "last_name" t.string "last_name"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "domain"
end end
end end

View file

@ -194,6 +194,14 @@ class IMAPMailbox
end end
end end
def append(folder,message,flags)
begin
@imap.append(folder,message,flags)
rescue Exception => e
raise e
end
end
end end
end end

View file

@ -6,7 +6,7 @@ module ImapSessionModule
def open_imap_session def open_imap_session
begin begin
@mailbox ||= ImapMailboxModule::IMAPMailbox.new(logger,$defaults["imap_debug"]) @mailbox ||= ImapMailboxModule::IMAPMailbox.new(logger,$defaults["imap_debug"])
@mailbox.connect(@current_user.servers.primary,@current_user.email, @current_user.get_cached_password(session)) @mailbox.connect(@current_user.servers.primary_for_imap,@current_user.email, @current_user.get_cached_password(session))
rescue Exception => ex rescue Exception => ex
redirect_to :controller => 'internal', :action => 'loginfailure' redirect_to :controller => 'internal', :action => 'loginfailure'
end end

45
lib/mail_plugin_extension.rb Executable file
View file

@ -0,0 +1,45 @@
require 'iconv'
module Mail
class Message
def decoded_and_charseted
begin
if not charset.upcase == 'UTF-8'
charset.nil? ? source_charset = $defaults["msg_unknown_charset"] : source_charset = charset
charseted = Iconv.iconv("UTF-8",source_charset,decoded).first
else
charseted = decoded
end
rescue
decoded
end
end
end
class Part
attr_accessor :idx,:parent_id
def isImage?
not (content_type =~ /^image/).nil?
end
def isText?
not (content_type =~ /^text\/plain/).nil?
end
def isHtml?
not (content_type =~ /^text\/html/).nil?
end
def getSize
body.raw_source.size
end
end
end

View file

@ -241,7 +241,6 @@ p {
/* forms */ /* forms */
.form input.text_field, .form textarea.text_area { .form input.text_field, .form textarea.text_area {
width: 100%;
border:1px solid #CFCFCF; border:1px solid #CFCFCF;
} }
@ -417,10 +416,6 @@ div.param_group label.label {
margin-right: 5px; margin-right: 5px;
} }
div.params {
margin-bottom: 15px;
}
div.params div.group { div.params div.group {
margin-bottom: 10px; margin-bottom: 10px;
} }
@ -453,8 +448,7 @@ div.params div.group div.fieldWithErrors label.label, div.params div.group label
font-size: 14px; font-size: 14px;
} }
div.params input.text_field, div.params textarea.text_area { div.params input, div.params textarea, div.params select {
width: 100%;
border:1px solid #CFCFCF; border:1px solid #CFCFCF;
} }
@ -518,3 +512,29 @@ span.attachment pre {
span.attachment span.title { span.attachment span.title {
font-weight: bold; font-weight: bold;
} }
div.images {
margin: 15px 0 5px;
}
div.images span.title {
font-weight: bold;
display: block;
font-size: 14px;
margin-bottom: 5px;
}
div.images div.image {
margin: 5px;
padding: 2px;
}
div.images div.image div.desc {
font-weight: normal;
font-size: 10px;
padding: 2px;
}
div.params input,div.params select,div.params textarea {
width: 100%
}

View file

@ -0,0 +1,7 @@
<%= form_tag(folders_create_path) %>
<div class="params">
<%= raw select_for_folders("folder","parent",@folders,t(:parent,:scope=>:folder),"",true) %>
<%= raw simple_input_field("folder","target",t(:to_create,:scope=>:folder),"") %>
</div>
<%= raw form_button('create','tick.png') %>
</form>

View file

@ -0,0 +1,6 @@
<%= form_tag(folders_delete_path) %>
<div class="params">
<%= raw select_for_folders("folder","delete",@folders,t(:to_delete,:scope=>:folder),"",true) %>
<%= raw form_button('delete','cross.png') %>
</div>
</form>

View file

@ -19,5 +19,5 @@
</div> </div>
</div> </div>
<p> <p>
<%= t(:version) %>: Build 20110826 <%= t(:version) %>: Build 20110901
</p> </p>

View file

@ -0,0 +1,7 @@
<%= form_tag(folders_refresh_path) %>
<div class="params">
<%= raw multi_select("", 'folders_to_show[]', @folders, @folders_shown,t(:shown,:scope=>:folder),:id,"",{:text => [:parent,:delim,:name]}) %>
</div>
<%= raw form_buttons(@buttons) %>
</form>

View file

@ -0,0 +1,9 @@
<%= form_tag(folders_system_path) %>
<div class="params">
<%= raw select_for_folders("folder","mailbox_inbox",@folders,t(:folder,:scope => :folder) + " " + t(:inbox_name,:scope=>:folder),@folder_inbox,true) %>
<%= raw select_for_folders("folder","mailbox_trash",@folders,t(:folder,:scope => :folder) + " " + t(:trash_name,:scope=>:folder),@folder_trash,true) %>
<%= raw select_for_folders("folder","mailbox_sent",@folders,t(:folder,:scope => :folder) + " " + t(:sent_name,:scope=>:folder),@folder_sent,true) %>
<%= raw select_for_folders("folder","mailbox_drafts",@folders,t(:folder,:scope => :folder) + " " + t(:drafts_name,:scope=>:folder),@folder_drafts,true) %>
<%= raw form_button('set','tick.png') %>
</div>
</form>

View file

@ -14,24 +14,12 @@
<div class="inner"> <div class="inner">
<div class="columns wat-cf"> <div class="columns wat-cf">
<div class="column left"> <div class="column left">
<%= form_tag(folders_create_path,:class=>'form') %> <%= render :partial => 'create' %>
<%= raw select_for_folders("","parent_folder",@folders,t(:parent,:scope=>:folder),true) %> <%= render :partial => 'delete' %>
<%= raw simple_input_field("folder",t(:to_create,:scope=>:folder),"") %> <%= render :partial => 'system' %>
<%= raw form_button('create','tick.png') %>
</form>
<%= form_tag(folders_delete_path,:class=>'form') %>
<%= raw select_for_folders("","folder",@folders,t(:to_delete,:scope=>:folder),true) %>
<%= raw form_button('delete','cross.png') %>
</form>
</div> </div>
<div class="column right"> <div class="column right">
<%= form_tag(folders_refresh_path,:class=>'form') %> <%= render :partial => 'refresh' %>
<%= raw form_button('refresh','tick.png') %>
</form>
<%= form_tag(folders_show_hide_path,:class=>'form') %>
<%= raw multi_select("", 'folders_to_show[]', @folders, @folders_shown,t(:shown,:scope=>:folder),:id,"",{:text => [:parent,:delim,:name]}) %>
<%= raw form_button('show_hide','tick.png') %>
</form>
</div> </div>
</div> </div>
</div> </div>

View file

@ -1,21 +1,21 @@
<td> <td>
<%= link_to attachment.title, messages_attachment_download_path(attachment.message_id,attachment.idx) %> <%= link_to attachment.filename, messages_attachment_download_path(attachment.parent_id,attachment.idx) %>
</td> </td>
<td> <td>
<%= attachment.type %> <%= attachment.main_type %>/<%= attachment.sub_type %>
</td> </td>
<td> <td>
<%= attachment.charset %> <%= attachment.charset %>
</td> </td>
<td> <td>
<%= attachment.encoding %> <%= attachment.content_transfer_encoding %>
</td> </td>
<td> <td>
<%= size_formatter(attachment.size) %> <%= size_formatter(attachment.getSize) %>
</td> </td>
<td> <td>
<%= link_to t(:download), messages_attachment_download_path(attachment.message_id,attachment.idx) %> <%= link_to t(:download), messages_attachment_download_path(attachment.parent_id,attachment.idx) %>
</td> </td>
<td> <td>
<%= link_to t(:view), messages_part_body_path(attachment.message_id,attachment.idx) %> <%= link_to t(:view), messages_part_body_path(attachment.parent_id,attachment.idx) %>
</td> </td>

View file

@ -4,7 +4,6 @@
<% trclass = :even %> <% trclass = :even %>
<% for idx in 0..@attachments.size-1 %> <% for idx in 0..@attachments.size-1 %>
<% @attachments[idx].idx = idx %>
<tr class="<%= trclass.to_s %>"> <tr class="<%= trclass.to_s %>">
<%= render :partial => 'attachment', :object => @attachments[idx] %> <%= render :partial => 'attachment', :object => @attachments[idx] %>
</tr> </tr>

View file

@ -1,9 +1,17 @@
<div class="msg_header"> <div class="msg_header">
<%= raw mail_param_view(@message,"from_addr",address_formatter(@message.from_addr,:message)) %> <%= raw show_param_view(@message,"from_addr",show_addr_formatter(@from)) %>
<%= raw mail_param_view(@message,"to_addr",address_formatter(@message.to_addr,:message)) %> <%= raw show_param_view(@message,"to_addr",show_addr_formatter(@to)) %>
<%= raw mail_param_view(@message,"subject",@message.subject) %> <% if @to.size > 1 %>
<%= raw mail_param_view(@message,"date",date_formatter(@message.date)) %> <%= raw show_param_view(@message,"to_addr","To dodatkowe jest") %>
<% end %>
<% if not @cc.nil? %>
<%= raw show_param_view(@message,"cc_addr","CC jest") %>
<% end %>
<% if not @bcc.nil? %>
<%= raw show_param_view(@message,"bcc_addr","BCC jest ") %>
<% end %>
<%= raw show_param_view(@message,"subject",show_subject_formatter(@subject)) %>
<%= raw show_param_view(@message,"date",date_formatter(@date)) %>
<%= hidden_field_tag 'uids[]', @message.uid %> <%= hidden_field_tag 'uids[]', @message.uid %>
<%= hidden_field_tag 'id', @message.id %>
<%= hidden_field_tag 'source', 'show' %> <%= hidden_field_tag 'source', 'show' %>
</div> </div>

View file

@ -1,3 +1,3 @@
<iframe frameborder="0" src="<%= messages_part_body_path(@message.uid,@render_as_html_idx) %>"> <iframe frameborder="0" src="<%= messages_html_body_path(@message.uid) %>">
</iframe> </iframe>

View file

@ -0,0 +1,8 @@
<div class="image">
<%= image_tag(messages_attachment_download_path(image.parent_id,image.idx), :size => "128x128", :alt=>image.filename, :title=>image.filename) %>
<div class="desc">
<span class="name"><%= link_to (image.filename,messages_attachment_download_path(image.parent_id,image.idx)) %></span>
<span class="size"><%= size_formatter(image.getSize) %></span>
</div>
</div>

View file

@ -0,0 +1,8 @@
<div class="images">
<span class="title"><%= t(:images,:scope=>:message) %></span>
<% for idx in 0..@images.size-1 %>
<%= render :partial => 'image', :object => @images[idx] %>
<% end %>
</div>

View file

@ -2,13 +2,13 @@
<%= submit_tag(t(:copy), :name=> 'copy')%> <%= submit_tag(t(:copy), :name=> 'copy')%>
<%= submit_tag(t(:move), :name=>'move')%> <%= submit_tag(t(:move), :name=>'move')%>
<%= t(:to_folder,:scope=>:folder) %> <%= t(:to_folder,:scope=>:folder) %>
<%= raw simple_select_for_folders("","dest_folder",@folders_shown,true) %><br/> <%= raw simple_select_for_folders("folder","target",@folders_shown,'',true) %><br/>
<%= submit_tag(t(:show_header,:scope=>:message), :id=>'show_header')%> <%= submit_tag(t(:show_header,:scope=>:message), :id=>'show_header')%>
<%= submit_tag(t(:delete), :name=>'trash')%> <%= submit_tag(t(:delete), :name=>'trash')%>
<%= submit_tag(t(:replay_to,:scope => :show), :name=>'reply')%> <%= submit_tag(t(:replay_to,:scope => :show), :name=>'reply')%>
<div id="header_source" title="<%= t(:header_source,:scope=>:message)%>"> <div id="header_source" title="<%= t(:header_source,:scope=>:message)%>">
<pre> <pre>
<%= @message_header %> <%= @plain_header %>
</pre> </pre>
</div> </div>
</div> </div>

View file

@ -1,6 +1,10 @@
<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,"to_addr",nil,"joe@domain.com"+', '+t(:not_contain_at,:scope=>:compose),@message.to_addr) %>
<% if not @reply.nil? %>
<% @message.subject = t(:reply_string,:scope=>:compose) + @message.subject %>
<% end %>
<%= raw form_field(@message,"subject",nil,t(:subject_of_the_message,:scope=>:compose),@message.subject) %> <%= raw form_field(@message,"subject",nil,t(:subject_of_the_message,:scope=>:compose),@message.subject) %>
<%= raw area_field(@message,"body",nil,t(:write_your_message_here,:scope=>:compose),@message.body,80,20) %> <%= raw area_field(@message,"body",nil,t(:write_your_message_here,:scope=>:compose),@message.body,80,20) %>
</div> </div>
<%= raw form_button('send','tick.png') %> <%= raw form_buttons(@buttons) %>

View file

@ -4,7 +4,7 @@
<%= submit_tag(t(:move), :name=>'move')%> <%= submit_tag(t(:move), :name=>'move')%>
<%= t(:checked,:scope=>:message) %> <%= t(:checked,:scope=>:message) %>
<%= t(:to_folder,:scope=>:folder) %> <%= t(:to_folder,:scope=>:folder) %>
<%= raw simple_select_for_folders("","dest_folder",@folders_shown,true) %> <%= raw simple_select_for_folders("folder","target",@folders_shown,'',true) %>
<br/> <br/>
<%= submit_tag(t(:delete), :name=>'trash')%> <%= submit_tag(t(:delete), :name=>'trash')%>
<%= submit_tag(t(:set_read,:scope=>:message), :name=>'set_read')%> <%= submit_tag(t(:set_read,:scope=>:message), :name=>'set_read')%>

View file

@ -1,7 +1,7 @@
<td><%= check_box_tag "uids[]", row.uid %></td> <td><%= check_box_tag "uids[]", row.uid %></td>
<td><%= attachment_formatter(row) %></td> <td><%= attachment_formatter(row) %></td>
<% if @current_folder.hasFullName?($defaults["mailbox_sent"]) %> <% if @current_folder == @sent_folder || @current_folder == @drafts_folder %>
<td nowrap="nowrap"><%= address_formatter(row.to_addr,:index) %></td> <td nowrap="nowrap"><%= address_formatter(row.to_addr,:index) %></td>
<% else %> <% else %>
<td nowrap="nowrap"><%= address_formatter(row.from_addr,:index) %></td> <td nowrap="nowrap"><%= address_formatter(row.from_addr,:index) %></td>
@ -9,4 +9,9 @@
<td nowrap="nowrap"><%= subject_formatter(row) %></td> <td nowrap="nowrap"><%= subject_formatter(row) %></td>
<td nowrap="nowrap"><%= date_formatter(row.date) %></td> <td nowrap="nowrap"><%= date_formatter(row.date) %></td>
</td><td nowrap="nowrap"><%= size_formatter(row.size) %></td><td><%= raw('&nbsp;') %> </td><td nowrap="nowrap"><%= size_formatter(row.size) %></td>
<% if @current_folder == @drafts_folder %>
<td><%= link_to(t(:edit,:scope=>:message),messages_edit_path(row.uid)) %></td>
<% else %>
<td><%= raw('&nbsp;') %></td>
<% end %>

View file

@ -12,7 +12,7 @@
</div> </div>
<div class="content"> <div class="content">
<h2><%= t(:new_message,:scope=>:compose) %></h2> <h2><%= t(:new_message,:scope=>:compose) %></h2>
<%= form_tag(messages_sendout_path)%> <%= form_tag(sendout_or_save_path)%>
<div class="inner"> <div class="inner">
<%= render :partial => 'new' %> <%= render :partial => 'new' %>
</div> </div>

View file

@ -3,7 +3,7 @@
<% end %> <% end %>
<% content_for :title do %> <% content_for :title do %>
- <%= @message.subject %> - <%= show_subject_formatter(@subject) %>
<% end %> <% end %>
<div class="block" id="block-tables"> <div class="block" id="block-tables">
@ -19,23 +19,24 @@
<%= render :partial => 'attachments' %> <%= render :partial => 'attachments' %>
<% end %> <% end %>
<% if not @render_as_html_idx.nil? %> <% if not @images.size.zero? %>
<%= render :partial => 'images' %>
<% end %>
<% if not @html_part.nil? %>
<%= render :partial => 'html_part' %> <%= render :partial => 'html_part' %>
<% else %> <% else %>
<div class="render_text"> <div class="render_text">
<span><%= t(:content,:scope=>:message) %></span> <span><%= t(:content,:scope=>:message) %></span>
<% if @render_as_text.size.zero? %> <% if @text_part.nil? %>
<p> <p>
<%= t(:no_content,:scope => :message) %> <%= t(:no_content,:scope => :message) %>
</p> </p>
<% else %> <% else %>
<% @render_as_text.each do |r| %> <%= raw content_text_plain_for_render(@text_part) %>
<%= raw content_text_plain_for_render(r) %>
<% end %>
<% end %> <% end %>
</div> </div>
<% end %> <% end %>
</form> </form>
</div> </div>
</div> </div>

View file

@ -0,0 +1,10 @@
<div class="params">
<p>
<%= h @current_user.full_name %>
</p>
<p>
<%= h @current_user.full_address %>
</p>
</div>
<%= raw form_button('save','tick.png') %>

View file

@ -0,0 +1 @@

View file

@ -0,0 +1,5 @@
<div class="params">
<%= h @servers.inspect %>
</div>
<%= raw form_button('save','tick.png') %>

View file

@ -0,0 +1 @@

View file

@ -0,0 +1,27 @@
<% content_for :sidebar do %>
<%= render :partial => 'folders/list' %>
<% end %>
<% content_for :title do %>
- <%= t(:prefs,:scope=>:prefs) %>
<% end %>
<div class="block" id="block-tables">
<div class="secondary-navigation">
<%= raw main_navigation(:prefs) %>
</div>
<div class="content"><div class="secondary-navigation">
<%= raw prefs_navigation(:identity) %>
</div>
<div class="inner"> <%= form_tag(prefs_update_identity_path,:name=>'prefs') %>
<div class="columns wat-cf">
<div class="column left">
<%= render :partial => 'prefs/identity_left' %>
</div>
<div class="column right">
<%= render :partial => 'prefs/identity_right' %>
</div>
</div></form>
</div>
</div>
</div>

View file

@ -10,14 +10,16 @@
<div class="secondary-navigation"> <div class="secondary-navigation">
<%= raw main_navigation(:prefs) %> <%= raw main_navigation(:prefs) %>
</div> </div>
<div class="content"> <div class="content"><div class="secondary-navigation">
<div class="inner"> <%= form_tag(prefs_update_path,:name=>'prefs') %> <%= raw prefs_navigation(:look) %>
</div>
<div class="inner"> <%= form_tag(prefs_update_look_path,:name=>'prefs') %>
<div class="columns wat-cf"> <div class="columns wat-cf">
<div class="column left"> <div class="column left">
<%= render :partial => 'prefs/left' %> <%= render :partial => 'prefs/look_left' %>
</div> </div>
<div class="column right"> <div class="column right">
<%= render :partial => 'prefs/right' %> <%= render :partial => 'prefs/look_right' %>
</div> </div>
</div></form> </div></form>
</div> </div>

View file

@ -0,0 +1,27 @@
<% content_for :sidebar do %>
<%= render :partial => 'folders/list' %>
<% end %>
<% content_for :title do %>
- <%= t(:prefs,:scope=>:prefs) %>
<% end %>
<div class="block" id="block-tables">
<div class="secondary-navigation">
<%= raw main_navigation(:prefs) %>
</div>
<div class="content"><div class="secondary-navigation">
<%= raw prefs_navigation(:servers) %>
</div>
<div class="inner"> <%= form_tag(prefs_update_servers_path,:name=>'prefs') %>
<div class="columns wat-cf">
<div class="column left">
<%= render :partial => 'prefs/servers_left' %>
</div>
<div class="column right">
<%= render :partial => 'prefs/servers_right' %>
</div>
</div></form>
</div>
</div>
</div>