# Copyright (c) 2006 Luben Manolov # # The MIT License # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # Site-specific parameters # These are Mailr constants. If you want to overwrite # some of them - change config/environment.rb # containing new constants in LOCALCONFIG module variable - they # will overwrite default values. Example site.rb: # # module CDF # LOCALCONFIG = { # :mysql_version => '4.1', # :default_encoding => 'utf-8', # :imap_server => 'your.imap.server', # :imap_auth => 'LOGIN' # } # end module CDF CONFIG = { :mysql_version => '4.0', :default_language => 'en', :default_encoding => 'ISO-8859-1', :mail_charset => 'ISO-8859-1', :mail_inbox => 'INBOX', :mail_trash => 'INBOX.Trash', :mail_sent => 'INBOX.Sent', :mail_bulk_sent => "INBOX.SentBulk", :mail_spam => "INBOX.Spam", :mail_temp_path => 'mail_temp', :mail_filters_path => '/home/vmail/mailfilters', :mail_send_types => {"Plain text" => "text/plain", "HTML"=>"text/html", "HTML and PlainText" => "multipart"}, :mail_message_rows => [5, 10, 15, 20, 25, 30, 50], :mail_filters_fields => {'From' => '^From', 'To' => '^To', 'CC' => '^CC', 'Subject' => '^Subject', 'Body' => '^Body'}, :mail_filters_expressions => ['contains', 'starts with'], :mail_search_fields => ['FROM', 'TO', 'CC', 'SUBJECT', 'BODY'], :temp_file_location => ".", :contacts_per_page => 15, :contact_letters => ['A','B','C','D','E','F','G','H','I','J','K','L','M','N',' O','P','Q','R','S','T','U','V','W','X','Y','Z'], :upload_file_temp_path => "/tmp", :imap_server => 'localhost', :imap_use_ssl => false, :imap_port => 143, :imap_auth => 'PLAIN', # 'LOGIN', 'NOAUTH' :encryption_salt => 'EnCr1p10n$@lt', :encryption_password => '$0MeEncr1pt10nP@a$sw0rd', :debug_imap => false, :crypt_session_pass => true, # Set it to false (in site.rb) if you get any error messages like # "Unsupported cipher algorithm (aes-128-cbc)." - meaning that OpenSSL modules for crypt algo is not loaded. Setting it to false will store password in session in plain format! :send_from_domain => nil, # Set this variable to your domain name in environment.rb if you make login to imap only with username (without '@domain') :imap_bye_timeout_retry_seconds => 2 } end module MailrEngine private def login_filter if logged_user.nil? @session["return_to"] = @request.request_uri redirect_to :controller=>"/login", :action => "index" return false end end def logged_user # returns user id @session['mailr_id'] end def localize # We will use instance vars for the locale so we can make use of them in # the templates. @charset = 'utf-8' @headers['Content-Type'] = "text/html; charset=#{@charset}" # Here is a very simplified approach to extract the prefered language # from the request. If all fails, just use 'en_EN' as the default. temp = if @request.env['HTTP_ACCEPT_LANGUAGE'].nil? [] else @request.env['HTTP_ACCEPT_LANGUAGE'].split(',').first.split('-') rescue [] end language = temp.slice(0) dialect = temp.slice(1) @language = language.nil? ? 'en' : language.downcase # default is en # If there is no dialect use the language code ('en' becomes 'en_EN'). @dialect = dialect.nil? ? @language.upcase : dialect # The complete locale string consists of # language_DIALECT (en_EN, en_GB, de_DE, ...) @locale = "#{@language}_#{@dialect.upcase}" @htmllang = @language == @dialect ? @language : "#{@language}-#{@dialect}" # Finally, bind the textdomain to the locale. From now on every used # _('String') will get translated into the right language. (Provided # that we have a corresponding mo file in the right place). bindtextdomain('messages', "#{RAILS_ROOT}/locale", @locale, @charset) end end