From 37f548ce46dc4e97b30e0237968dc3371070676d Mon Sep 17 00:00:00 2001 From: Wojciech Todryk Date: Wed, 27 Jul 2011 20:34:30 +0200 Subject: [PATCH] devel --- .gitignore | 0 Gemfile.lock | 0 Rakefile | 0 app/controllers/application_controller.rb | 4 + app/controllers/internal_controller.rb | 11 ++- app/controllers/messages_controller.rb | 27 +++++- app/controllers/user_controller.rb | 9 +- app/helpers/application_helper.rb | 4 +- app/helpers/internal_helper.rb | 0 app/helpers/messages_helper.rb | 16 ++++ app/helpers/user_helper.rb | 0 app/models/folder.rb | 41 ++++++++++ app/models/message.rb | 2 + app/models/prefs.rb | 0 app/models/server.rb | 14 ++++ app/models/user.rb | 3 +- app/views/messages/index.html.erb | 2 - config.ru | 0 config/application.rb | 0 config/boot.rb | 0 config/defaults.yml | 7 ++ config/environment.rb | 0 config/environments/development.rb | 0 config/environments/production.rb | 0 config/environments/test.rb | 0 config/initializers/backtrace_silencers.rb | 0 config/initializers/inflections.rb | 0 config/initializers/mime_types.rb | 0 config/initializers/secret_token.rb | 0 config/initializers/session_store.rb | 0 config/locales/en.yml | 1 + config/routes.rb | 6 +- db/migrate/20110723115402_create_users.rb | 0 db/migrate/20110723153214_create_servers.rb | 0 db/migrate/20110724125806_create_prefs.rb | 0 .../20110724134917_add_params_to_prefs.rb | 0 .../20110725210440_add_use_ssl_to_servers.rb | 9 ++ db/migrate/20110727070907_create_folders.rb | 17 ++++ ...0110727074214_rename_attribs_in_folders.rb | 11 +++ .../20110727081504_change_new_in_folder.rb | 9 ++ .../20110727105240_add_column_to_folder.rb | 9 ++ ...0110727132531_add_column_msgs_to_folder.rb | 9 ++ db/migrate/20110727134352_create_messages.rb | 23 ++++++ db/schema.rb | 32 +++++++- db/seeds.rb | 0 doc/README_FOR_APP | 0 lib/imap_folder.rb | 23 ++++++ lib/imap_mailbox.rb | 77 ++++++++++++++++++ lib/imap_message.rb | 5 ++ lib/imap_session.rb | 21 +++++ lib/imap_utils.rb | 48 ----------- lib/tasks/.gitkeep | 0 public/404.html | 0 public/422.html | 0 public/500.html | 0 public/favicon.ico | 0 public/images/rails.png | Bin public/javascripts/application.js | 0 public/javascripts/controls.js | 0 public/javascripts/dragdrop.js | 0 public/javascripts/effects.js | 0 public/javascripts/prototype.js | 0 public/javascripts/rails.js | 0 public/robots.txt | 0 public/stylesheets/.gitkeep | 0 test/fixtures/folders.yml | 15 ++++ test/fixtures/messages.yml | 27 ++++++ test/fixtures/prefs.yml | 0 test/fixtures/servers.yml | 0 test/fixtures/users.yml | 0 test/functional/core_controller_test.rb | 0 test/functional/internal_controller_test.rb | 0 test/functional/messages_controller_test.rb | 0 test/performance/browsing_test.rb | 0 test/test_helper.rb | 0 test/unit/folder_test.rb | 8 ++ test/unit/helpers/core_helper_test.rb | 0 test/unit/helpers/internal_helper_test.rb | 0 test/unit/helpers/messages_helper_test.rb | 0 test/unit/message_test.rb | 8 ++ test/unit/prefs_test.rb | 0 test/unit/server_test.rb | 0 test/unit/user_test.rb | 0 themes/olive/images/tick.png | Bin themes/olive/views/internal/error.html.erb | 2 +- themes/olive/views/messages/index.html.erb | 26 ++++++ themes/olive/views/user/setup.html.erb | 8 +- themes/olive/views/user/unknown.html.erb | 2 +- vendor/plugins/.gitkeep | 0 89 files changed, 466 insertions(+), 70 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 Gemfile.lock mode change 100644 => 100755 Rakefile mode change 100644 => 100755 app/controllers/application_controller.rb mode change 100644 => 100755 app/controllers/internal_controller.rb mode change 100644 => 100755 app/controllers/messages_controller.rb mode change 100644 => 100755 app/controllers/user_controller.rb mode change 100644 => 100755 app/helpers/application_helper.rb mode change 100644 => 100755 app/helpers/internal_helper.rb mode change 100644 => 100755 app/helpers/messages_helper.rb mode change 100644 => 100755 app/helpers/user_helper.rb create mode 100755 app/models/folder.rb create mode 100755 app/models/message.rb mode change 100644 => 100755 app/models/prefs.rb mode change 100644 => 100755 app/models/server.rb mode change 100644 => 100755 app/models/user.rb delete mode 100644 app/views/messages/index.html.erb mode change 100644 => 100755 config.ru mode change 100644 => 100755 config/application.rb mode change 100644 => 100755 config/boot.rb mode change 100644 => 100755 config/defaults.yml mode change 100644 => 100755 config/environment.rb mode change 100644 => 100755 config/environments/development.rb mode change 100644 => 100755 config/environments/production.rb mode change 100644 => 100755 config/environments/test.rb mode change 100644 => 100755 config/initializers/backtrace_silencers.rb mode change 100644 => 100755 config/initializers/inflections.rb mode change 100644 => 100755 config/initializers/mime_types.rb mode change 100644 => 100755 config/initializers/secret_token.rb mode change 100644 => 100755 config/initializers/session_store.rb mode change 100644 => 100755 config/routes.rb mode change 100644 => 100755 db/migrate/20110723115402_create_users.rb mode change 100644 => 100755 db/migrate/20110723153214_create_servers.rb mode change 100644 => 100755 db/migrate/20110724125806_create_prefs.rb mode change 100644 => 100755 db/migrate/20110724134917_add_params_to_prefs.rb create mode 100755 db/migrate/20110725210440_add_use_ssl_to_servers.rb create mode 100755 db/migrate/20110727070907_create_folders.rb create mode 100755 db/migrate/20110727074214_rename_attribs_in_folders.rb create mode 100755 db/migrate/20110727081504_change_new_in_folder.rb create mode 100755 db/migrate/20110727105240_add_column_to_folder.rb create mode 100755 db/migrate/20110727132531_add_column_msgs_to_folder.rb create mode 100755 db/migrate/20110727134352_create_messages.rb mode change 100644 => 100755 db/schema.rb mode change 100644 => 100755 db/seeds.rb mode change 100644 => 100755 doc/README_FOR_APP create mode 100755 lib/imap_folder.rb create mode 100755 lib/imap_mailbox.rb create mode 100755 lib/imap_message.rb create mode 100755 lib/imap_session.rb delete mode 100644 lib/imap_utils.rb mode change 100644 => 100755 lib/tasks/.gitkeep mode change 100644 => 100755 public/404.html mode change 100644 => 100755 public/422.html mode change 100644 => 100755 public/500.html mode change 100644 => 100755 public/favicon.ico mode change 100644 => 100755 public/images/rails.png mode change 100644 => 100755 public/javascripts/application.js mode change 100644 => 100755 public/javascripts/controls.js mode change 100644 => 100755 public/javascripts/dragdrop.js mode change 100644 => 100755 public/javascripts/effects.js mode change 100644 => 100755 public/javascripts/prototype.js mode change 100644 => 100755 public/javascripts/rails.js mode change 100644 => 100755 public/robots.txt mode change 100644 => 100755 public/stylesheets/.gitkeep create mode 100755 test/fixtures/folders.yml create mode 100755 test/fixtures/messages.yml mode change 100644 => 100755 test/fixtures/prefs.yml mode change 100644 => 100755 test/fixtures/servers.yml mode change 100644 => 100755 test/fixtures/users.yml mode change 100644 => 100755 test/functional/core_controller_test.rb mode change 100644 => 100755 test/functional/internal_controller_test.rb mode change 100644 => 100755 test/functional/messages_controller_test.rb mode change 100644 => 100755 test/performance/browsing_test.rb mode change 100644 => 100755 test/test_helper.rb create mode 100755 test/unit/folder_test.rb mode change 100644 => 100755 test/unit/helpers/core_helper_test.rb mode change 100644 => 100755 test/unit/helpers/internal_helper_test.rb mode change 100644 => 100755 test/unit/helpers/messages_helper_test.rb create mode 100755 test/unit/message_test.rb mode change 100644 => 100755 test/unit/prefs_test.rb mode change 100644 => 100755 test/unit/server_test.rb mode change 100644 => 100755 test/unit/user_test.rb mode change 100644 => 100755 themes/olive/images/tick.png mode change 100644 => 100755 themes/olive/views/internal/error.html.erb create mode 100755 themes/olive/views/messages/index.html.erb mode change 100644 => 100755 vendor/plugins/.gitkeep diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/Gemfile.lock b/Gemfile.lock old mode 100644 new mode 100755 diff --git a/Rakefile b/Rakefile old mode 100644 new mode 100755 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb old mode 100644 new mode 100755 index dcaf4fd..b8bcf93 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -39,4 +39,8 @@ class ApplicationController < ActionController::Base end end + def selected_folder + session[:selected_folder] ? @selected_folder = session[:selected_folder] : @selected_folder = $defaults['imap_inbox_folder'] + end + end diff --git a/app/controllers/internal_controller.rb b/app/controllers/internal_controller.rb old mode 100644 new mode 100755 index c3a8752..1d38b2d --- a/app/controllers/internal_controller.rb +++ b/app/controllers/internal_controller.rb @@ -4,9 +4,16 @@ class InternalController < ApplicationController layout "simple" def error - @title = t(:general_error) + @title = params[:title] || t(:general_error) @error = params[:error] || t(:unspecified_error) - logger.error @error + logger.error "!!! InternalControllerError: " + @error + end + + def imaperror + @title = t(:imap_error) + @error = params[:error] || t(:unspecified_error) + logger.error "!!! InternalControllerImapError: " + @error + render 'error' end end diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb old mode 100644 new mode 100755 index 20232ba..52b277a --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -1,14 +1,33 @@ -require 'imap_utils' +require 'imap_session' +require 'imap_mailbox' class MessagesController < ApplicationController - include ImapUtils + include ImapMailboxModule + include ImapSessionModule + + before_filter :check_current_user ,:selected_folder + + before_filter :open_imap_session, :only => :refresh + after_filter :close_imap_session, :only => :refresh - before_filter :check_current_user, :info theme :theme_resolver def index - logger.info "YYYYYYYYYYYYY #{@m.inspect}" + @folders = @current_user.folders.order("name asc") + @current_folder = @current_user.folders.current(@selected_folder) + end + + def refresh + @current_user.folders.destroy_all + folders=@mailbox.folders + Folder.createBulk(@current_user,folders) + redirect_to :action => 'index' + end + + def folder + session[:selected_folder] = params[:id] + redirect_to :action => 'index' end end diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb old mode 100644 new mode 100755 index e23e55a..83f7c98 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -15,7 +15,7 @@ class UserController < ApplicationController def authenticate user = User.find_by_email(params[:user][:email]) if user.nil? - redirect_to :action => 'unknown' + redirect_to :action => 'unknown' ,:email=> params[:user][:email] else auten = true if auten == true @@ -26,7 +26,7 @@ class UserController < ApplicationController redirect_to(session["return_to"]) session["return_to"] = nil else - redirect_to :controller=> "messages", :action=>"index" + redirect_to :controller=> 'messages', :action=> 'refresh' end @@ -49,12 +49,15 @@ class UserController < ApplicationController end def create + @user = User.new - @server = Server.new @user.email = params["user_email"] @user.first_name = params["user_first_name"] @user.last_name = params["user_last_name"] + + @server = Server.new @server.name = params["server_name"] + if @user.valid? and @server.valid? @user.save @server.user_id = @user.id diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb old mode 100644 new mode 100755 index 8db6bf8..95146e9 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,6 +1,6 @@ module ApplicationHelper -def form_field(object,field,flabel,example) +def form_field(object,field,flabel,example,val) html = "" html << "
" @@ -24,7 +24,7 @@ def form_field(object,field,flabel,example) html << "" html << "" diff --git a/app/helpers/internal_helper.rb b/app/helpers/internal_helper.rb old mode 100644 new mode 100755 diff --git a/app/helpers/messages_helper.rb b/app/helpers/messages_helper.rb old mode 100644 new mode 100755 index f1bca9f..cca40f3 --- a/app/helpers/messages_helper.rb +++ b/app/helpers/messages_helper.rb @@ -1,2 +1,18 @@ module MessagesHelper + + def folder_link(folder) + folder.parent.empty? ? name = folder.name : name = folder.parent.gsub(/\./,'#') + "#" + folder.name + s = link_to folder.name.capitalize, :controller => 'messages', :action => 'folder', :id => name + if !folder.unseen.zero? + s += ' (' + folder.unseen.to_s + ')' + end + s + end + + def pretty_folder_name(folder) + #folder = folder.gsub(/#/,".") + folder.name.capitalize + end + end + diff --git a/app/helpers/user_helper.rb b/app/helpers/user_helper.rb old mode 100644 new mode 100755 diff --git a/app/models/folder.rb b/app/models/folder.rb new file mode 100755 index 0000000..513eaca --- /dev/null +++ b/app/models/folder.rb @@ -0,0 +1,41 @@ +class Folder < ActiveRecord::Base + + belongs_to :user + validates_presence_of :name, :on => :create + before_save :check_fill_params, :on => :create + + private + + def check_fill_params + self.messages.nil? ? self.messages = 0 : self.messages + self.unseen.nil? ? self.unseen = 0 : self.unseen + self.msgs_updated_at.nil? ? self.msgs_updated_at = (DateTime.now-1) : self.msgs_updated_at + end + + def self.createBulk(user,imapFolders) + imapFolders.each do |name,data| + data.attribs.find_index(:Haschildren).nil? ? has_children = 0 : has_children = 1 + name_fields = name.split(data.delim) + + if name_fields.count > 1 + name = name_fields.delete_at(name_fields.size - 1) + parent = name_fields.join(data.delim) + else + name = name_fields[0] + parent = "" + end + + user.folders.create(:name=>name,:parent=>parent,:haschildren=>has_children,:delim=>data.delim,:messages => data.messages,:unseen => data.unseen) + end + end + + def self.current(data) + folder = data.split("#") + if folder.size > 1 + where(['name = ? and parent = ?',folder[1],folder[0]]).first + else + where(['name = ?',folder[0]]).first + end + end + +end diff --git a/app/models/message.rb b/app/models/message.rb new file mode 100755 index 0000000..590e3e3 --- /dev/null +++ b/app/models/message.rb @@ -0,0 +1,2 @@ +class Message < ActiveRecord::Base +end diff --git a/app/models/prefs.rb b/app/models/prefs.rb old mode 100644 new mode 100755 diff --git a/app/models/server.rb b/app/models/server.rb old mode 100644 new mode 100755 index 3897d85..ef08784 --- a/app/models/server.rb +++ b/app/models/server.rb @@ -1,4 +1,18 @@ class Server < ActiveRecord::Base + validates_presence_of :name belongs_to :user + before_save :fill_params + + def self.primary + first + end + + private + + def fill_params + self.port = $defaults['imap_port'] + $defaults['imap_use_ssl'] == true ? self.use_ssl = 1 : self.use_ssl = 0 + end + end diff --git a/app/models/user.rb b/app/models/user.rb old mode 100644 new mode 100755 index 409abc3..220cddb --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,11 +1,12 @@ require 'ezcrypto' class User < ActiveRecord::Base - validates_presence_of :email, :on => :create + validates_presence_of :first_name,:last_name validates_uniqueness_of :email has_many :servers, :dependent => :destroy has_one :prefs, :dependent => :destroy + has_many :folders, :dependent => :destroy def set_cached_password(session,password) if $defaults['session_encryption'] diff --git a/app/views/messages/index.html.erb b/app/views/messages/index.html.erb deleted file mode 100644 index 903e282..0000000 --- a/app/views/messages/index.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

Messages#index

-

Find me in app/views/messages/index.html.erb

diff --git a/config.ru b/config.ru old mode 100644 new mode 100755 diff --git a/config/application.rb b/config/application.rb old mode 100644 new mode 100755 diff --git a/config/boot.rb b/config/boot.rb old mode 100644 new mode 100755 diff --git a/config/defaults.yml b/config/defaults.yml old mode 100644 new mode 100755 index 6b13797..a0941f2 --- a/config/defaults.yml +++ b/config/defaults.yml @@ -1,8 +1,15 @@ theme: olive locale: en msgs_per_page: 20 +msgs_refresh_time: 300 msg_send_type: html imap_debug: true +imap_use_ssl: 'false' +imap_port: 143 +imap_ssl_port: 993 +imap_bye_timeout_retry_seconds: 2 +imap_inbox_folder: inbox session_encryption: true session_password: asDD3s2@sAdc983# + diff --git a/config/environment.rb b/config/environment.rb old mode 100644 new mode 100755 diff --git a/config/environments/development.rb b/config/environments/development.rb old mode 100644 new mode 100755 diff --git a/config/environments/production.rb b/config/environments/production.rb old mode 100644 new mode 100755 diff --git a/config/environments/test.rb b/config/environments/test.rb old mode 100644 new mode 100755 diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb old mode 100644 new mode 100755 diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb old mode 100644 new mode 100755 diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb old mode 100644 new mode 100755 diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb old mode 100644 new mode 100755 diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb old mode 100644 new mode 100755 diff --git a/config/locales/en.yml b/config/locales/en.yml index d39f717..4d37c1c 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -78,3 +78,4 @@ en: login_failure: Login failure. Bad email or password general_error: General error unspecified_error: Unspecified error occured + imap_error: Imap Error diff --git a/config/routes.rb b/config/routes.rb old mode 100644 new mode 100755 index bdfcd45..05fcc84 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,15 +1,19 @@ Mailr::Application.routes.draw do get "internal/error" - post "internal/error" + get "internal/imaperror" root :to => "messages#index" get "messages/index" + get "messages/refresh" + match 'messages/folder/:id' => 'messages#folder' + get "user/logout" post "user/authenticate" post "user/create" get "user/login" get "user/setup" + match 'user/setup/:id' => 'user#setup' get "user/unknown" themes_for_rails diff --git a/db/migrate/20110723115402_create_users.rb b/db/migrate/20110723115402_create_users.rb old mode 100644 new mode 100755 diff --git a/db/migrate/20110723153214_create_servers.rb b/db/migrate/20110723153214_create_servers.rb old mode 100644 new mode 100755 diff --git a/db/migrate/20110724125806_create_prefs.rb b/db/migrate/20110724125806_create_prefs.rb old mode 100644 new mode 100755 diff --git a/db/migrate/20110724134917_add_params_to_prefs.rb b/db/migrate/20110724134917_add_params_to_prefs.rb old mode 100644 new mode 100755 diff --git a/db/migrate/20110725210440_add_use_ssl_to_servers.rb b/db/migrate/20110725210440_add_use_ssl_to_servers.rb new file mode 100755 index 0000000..d6e51bb --- /dev/null +++ b/db/migrate/20110725210440_add_use_ssl_to_servers.rb @@ -0,0 +1,9 @@ +class AddUseSslToServers < ActiveRecord::Migration + def self.up + add_column :servers, :use_ssl, :boolean + end + + def self.down + remove_column :servers, :use_ssl, :boolean + end +end diff --git a/db/migrate/20110727070907_create_folders.rb b/db/migrate/20110727070907_create_folders.rb new file mode 100755 index 0000000..fba11a5 --- /dev/null +++ b/db/migrate/20110727070907_create_folders.rb @@ -0,0 +1,17 @@ +class CreateFolders < ActiveRecord::Migration + def self.up + create_table :folders do |t| + t.string :name + t.string :delim + t.string :attribs + t.integer :messages + t.integer :new + t.references :user + t.timestamps + end + end + + def self.down + drop_table :folders + end +end diff --git a/db/migrate/20110727074214_rename_attribs_in_folders.rb b/db/migrate/20110727074214_rename_attribs_in_folders.rb new file mode 100755 index 0000000..8d3f701 --- /dev/null +++ b/db/migrate/20110727074214_rename_attribs_in_folders.rb @@ -0,0 +1,11 @@ +class RenameAttribsInFolders < ActiveRecord::Migration + def self.up + rename_column :folders,:attribs,:haschildren + change_column :folders,:haschildren,:boolean + end + + def self.down + change_column :folders,:haschildren,:string + rename_column :folders,:haschildren,:attribs + end +end diff --git a/db/migrate/20110727081504_change_new_in_folder.rb b/db/migrate/20110727081504_change_new_in_folder.rb new file mode 100755 index 0000000..32bea01 --- /dev/null +++ b/db/migrate/20110727081504_change_new_in_folder.rb @@ -0,0 +1,9 @@ +class ChangeNewInFolder < ActiveRecord::Migration + def self.up + rename_column :folders,:new,:unseen + end + + def self.down + rename_column :folders,:unseen,:new + end +end diff --git a/db/migrate/20110727105240_add_column_to_folder.rb b/db/migrate/20110727105240_add_column_to_folder.rb new file mode 100755 index 0000000..43bf3e9 --- /dev/null +++ b/db/migrate/20110727105240_add_column_to_folder.rb @@ -0,0 +1,9 @@ +class AddColumnToFolder < ActiveRecord::Migration + def self.up + add_column :folders, :parent, :string + end + + def self.down + remove_column :folders, :parent + end +end diff --git a/db/migrate/20110727132531_add_column_msgs_to_folder.rb b/db/migrate/20110727132531_add_column_msgs_to_folder.rb new file mode 100755 index 0000000..b82b390 --- /dev/null +++ b/db/migrate/20110727132531_add_column_msgs_to_folder.rb @@ -0,0 +1,9 @@ +class AddColumnMsgsToFolder < ActiveRecord::Migration + def self.up + add_column :folders, :msgs_updated_at, :datetime + end + + def self.down + remove_column :folders, :msgs_updated_at + end +end diff --git a/db/migrate/20110727134352_create_messages.rb b/db/migrate/20110727134352_create_messages.rb new file mode 100755 index 0000000..4a9f3ba --- /dev/null +++ b/db/migrate/20110727134352_create_messages.rb @@ -0,0 +1,23 @@ +class CreateMessages < ActiveRecord::Migration + def self.up + create_table :messages do |t| + t.integer :folder_id + t.integer :user_id + t.string :msg_id + t.string :from + t.string :to + t.string :subject + t.string :content_type + t.integer :uid + t.integer :size + t.boolean :unread + t.datetime :date + + t.timestamps + end + end + + def self.down + drop_table :messages + end +end diff --git a/db/schema.rb b/db/schema.rb old mode 100644 new mode 100755 index fe23a1f..e43ef63 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,36 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20110724134917) do +ActiveRecord::Schema.define(:version => 20110727134352) do + + create_table "folders", :force => true do |t| + t.string "name" + t.string "delim" + t.boolean "haschildren" + t.integer "messages" + t.integer "unseen" + t.integer "user_id" + t.datetime "created_at" + t.datetime "updated_at" + t.string "parent" + t.datetime "msgs_updated_at" + end + + create_table "messages", :force => true do |t| + t.integer "folder_id" + t.integer "user_id" + t.string "msg_id" + t.string "from" + t.string "to" + t.string "subject" + t.string "content_type" + t.integer "uid" + t.integer "size" + t.boolean "unread" + t.datetime "date" + t.datetime "created_at" + t.datetime "updated_at" + end create_table "prefs", :force => true do |t| t.string "theme" @@ -28,6 +57,7 @@ ActiveRecord::Schema.define(:version => 20110724134917) do t.integer "user_id" t.datetime "created_at" t.datetime "updated_at" + t.boolean "use_ssl" end create_table "users", :force => true do |t| diff --git a/db/seeds.rb b/db/seeds.rb old mode 100644 new mode 100755 diff --git a/doc/README_FOR_APP b/doc/README_FOR_APP old mode 100644 new mode 100755 diff --git a/lib/imap_folder.rb b/lib/imap_folder.rb new file mode 100755 index 0000000..a8788e1 --- /dev/null +++ b/lib/imap_folder.rb @@ -0,0 +1,23 @@ +require 'net/imap' + +module ImapFolderModule + +class IMAPFolder + + attr_reader :utf7_name + attr_reader :delim + attr_reader :attribs + attr_reader :name + attr_accessor :messages + attr_accessor :unseen + + def initialize(utf7_name,delim,attribs) + @utf7_name = utf7_name + @name = Net::IMAP.decode_utf7 utf7_name + @delim = delim + @attribs = attribs + end + +end + +end diff --git a/lib/imap_mailbox.rb b/lib/imap_mailbox.rb new file mode 100755 index 0000000..c9a8606 --- /dev/null +++ b/lib/imap_mailbox.rb @@ -0,0 +1,77 @@ +require 'net/imap' +require 'imap_folder' + +module ImapMailboxModule + +class IMAPError < RuntimeError +end + +class IMAPMailbox + + attr_reader :connected + attr_accessor :selected_folder + attr_accessor :logger + + def initialize(logger) + @selected_folder = '' + @folders = {} + @connected = false + @logger = logger + end + + def connect(server,username,password) + + server_name = server.name + server_port = server.port + server_use_ssl = server.use_ssl + + unless @connected + begin + @imap = Net::IMAP.new(server_name, server_port, server_use_ssl) + rescue Net::IMAP::ByeResponseError => bye + begin + System.sleep($defaults['imap_bye_timeout_retry_seconds']) + @imap = Net::IMAP.new(server_name, server_port, server_use_ssl) + rescue Exception => ex + raise IMAPError, ex.inspect + end + rescue Exception => ex + raise IMAPError, ex.inspect + end + @username = username + begin + @imap.login(username, password) + @connected = true + rescue Exception => ex + raise IMAPError, ex.inspect + end + end + end + + def disconnect + if @connected + @imap.logout + @imap.disconnect + @imap = nil + @connected = false + end + end + + def folders + @folders = {} + folders = @imap.list('', '*') + if folders + folders.each do |f| + folder = ImapFolderModule::IMAPFolder.new(f.name,f.delim,f.attr) + status = @imap.status(folder.name, ["MESSAGES", "UNSEEN"]) + folder.messages = status["MESSAGES"] + folder.unseen = status["UNSEEN"] + @folders[folder.name] = folder + end + end + @folders + end + +end + +end diff --git a/lib/imap_message.rb b/lib/imap_message.rb new file mode 100755 index 0000000..69cb45b --- /dev/null +++ b/lib/imap_message.rb @@ -0,0 +1,5 @@ +require 'net/imap' + +module ImapMessageModule +end + diff --git a/lib/imap_session.rb b/lib/imap_session.rb new file mode 100755 index 0000000..3e1af87 --- /dev/null +++ b/lib/imap_session.rb @@ -0,0 +1,21 @@ +require 'net/imap' +require 'imap_mailbox' + +module ImapSessionModule + +def open_imap_session + begin + @mailbox = ImapMailboxModule::IMAPMailbox.new(logger) + @mailbox.connect(@current_user.servers.primary,@current_user.email, @current_user.get_cached_password(session)) + rescue Exception => ex + redirect_to :controller => 'internal', :action => 'imaperror' , :error => ex.inspect + end +end + +def close_imap_session + return if @mailbox.nil? or not(@mailbox.connected) + @mailbox.disconnect + @mailbox = nil +end + +end diff --git a/lib/imap_utils.rb b/lib/imap_utils.rb deleted file mode 100644 index 8ca719e..0000000 --- a/lib/imap_utils.rb +++ /dev/null @@ -1,48 +0,0 @@ -require 'net/imap' - -module ImapUtils - -class IMAPMailbox -# -# attr_reader :connected -# attr_accessor :selected_mailbox -# cattr_accessor :logger -# - def initialize(logger) -# @selected_mailbox = '' -# @folders = {} -# @connected = false - @logger = logger - @logger.info "XXXXXXXXXX i am in" - end -# -end - -def info - @m = IMAPMailbox.new(logger) - logger.info "XXXXXXXXXXXXX" - logger.info @m.inspect -end -# -#def load_imap_session -# begin -# @mailbox = IMAPMailbox.new(self.logger) -## uname = (get_mail_prefs.check_external_mail == 1 ? user.email : user.local_email) -## upass = get_upass -## @mailbox.connect(uname, upass) -## load_folders -# rescue Exception => ex -# render :controller => "internal", :action => "error" , :error => ex.inspect -# end -#end - -# def close_imap_session -# return if @mailbox.nil? or not(@mailbox.connected) -# @mailbox.disconnect -# @mailbox = nil -# end - - - - -end diff --git a/lib/tasks/.gitkeep b/lib/tasks/.gitkeep old mode 100644 new mode 100755 diff --git a/public/404.html b/public/404.html old mode 100644 new mode 100755 diff --git a/public/422.html b/public/422.html old mode 100644 new mode 100755 diff --git a/public/500.html b/public/500.html old mode 100644 new mode 100755 diff --git a/public/favicon.ico b/public/favicon.ico old mode 100644 new mode 100755 diff --git a/public/images/rails.png b/public/images/rails.png old mode 100644 new mode 100755 diff --git a/public/javascripts/application.js b/public/javascripts/application.js old mode 100644 new mode 100755 diff --git a/public/javascripts/controls.js b/public/javascripts/controls.js old mode 100644 new mode 100755 diff --git a/public/javascripts/dragdrop.js b/public/javascripts/dragdrop.js old mode 100644 new mode 100755 diff --git a/public/javascripts/effects.js b/public/javascripts/effects.js old mode 100644 new mode 100755 diff --git a/public/javascripts/prototype.js b/public/javascripts/prototype.js old mode 100644 new mode 100755 diff --git a/public/javascripts/rails.js b/public/javascripts/rails.js old mode 100644 new mode 100755 diff --git a/public/robots.txt b/public/robots.txt old mode 100644 new mode 100755 diff --git a/public/stylesheets/.gitkeep b/public/stylesheets/.gitkeep old mode 100644 new mode 100755 diff --git a/test/fixtures/folders.yml b/test/fixtures/folders.yml new file mode 100755 index 0000000..fdba86d --- /dev/null +++ b/test/fixtures/folders.yml @@ -0,0 +1,15 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +one: + name: MyString + delim: MyString + attribs: MyString + messages: 1 + new: 1 + +two: + name: MyString + delim: MyString + attribs: MyString + messages: 1 + new: 1 diff --git a/test/fixtures/messages.yml b/test/fixtures/messages.yml new file mode 100755 index 0000000..9e6bcec --- /dev/null +++ b/test/fixtures/messages.yml @@ -0,0 +1,27 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +one: + folder_id: 1 + user_id: 1 + msg_id: MyString + from: MyString + to: MyString + subject: MyString + content_type: MyString + uid: 1 + size: 1 + unread: false + date: 2011-07-27 15:43:52 + +two: + folder_id: 1 + user_id: 1 + msg_id: MyString + from: MyString + to: MyString + subject: MyString + content_type: MyString + uid: 1 + size: 1 + unread: false + date: 2011-07-27 15:43:52 diff --git a/test/fixtures/prefs.yml b/test/fixtures/prefs.yml old mode 100644 new mode 100755 diff --git a/test/fixtures/servers.yml b/test/fixtures/servers.yml old mode 100644 new mode 100755 diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml old mode 100644 new mode 100755 diff --git a/test/functional/core_controller_test.rb b/test/functional/core_controller_test.rb old mode 100644 new mode 100755 diff --git a/test/functional/internal_controller_test.rb b/test/functional/internal_controller_test.rb old mode 100644 new mode 100755 diff --git a/test/functional/messages_controller_test.rb b/test/functional/messages_controller_test.rb old mode 100644 new mode 100755 diff --git a/test/performance/browsing_test.rb b/test/performance/browsing_test.rb old mode 100644 new mode 100755 diff --git a/test/test_helper.rb b/test/test_helper.rb old mode 100644 new mode 100755 diff --git a/test/unit/folder_test.rb b/test/unit/folder_test.rb new file mode 100755 index 0000000..fdd21d6 --- /dev/null +++ b/test/unit/folder_test.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class FolderTest < ActiveSupport::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end +end diff --git a/test/unit/helpers/core_helper_test.rb b/test/unit/helpers/core_helper_test.rb old mode 100644 new mode 100755 diff --git a/test/unit/helpers/internal_helper_test.rb b/test/unit/helpers/internal_helper_test.rb old mode 100644 new mode 100755 diff --git a/test/unit/helpers/messages_helper_test.rb b/test/unit/helpers/messages_helper_test.rb old mode 100644 new mode 100755 diff --git a/test/unit/message_test.rb b/test/unit/message_test.rb new file mode 100755 index 0000000..e4de21d --- /dev/null +++ b/test/unit/message_test.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class MessageTest < ActiveSupport::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end +end diff --git a/test/unit/prefs_test.rb b/test/unit/prefs_test.rb old mode 100644 new mode 100755 diff --git a/test/unit/server_test.rb b/test/unit/server_test.rb old mode 100644 new mode 100755 diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb old mode 100644 new mode 100755 diff --git a/themes/olive/images/tick.png b/themes/olive/images/tick.png old mode 100644 new mode 100755 diff --git a/themes/olive/views/internal/error.html.erb b/themes/olive/views/internal/error.html.erb old mode 100644 new mode 100755 index 3bb4ed4..fb2ff64 --- a/themes/olive/views/internal/error.html.erb +++ b/themes/olive/views/internal/error.html.erb @@ -8,7 +8,7 @@

<%= @title %>

-

<%= @description %>

+

<%= @error %>

diff --git a/themes/olive/views/messages/index.html.erb b/themes/olive/views/messages/index.html.erb new file mode 100755 index 0000000..74660c5 --- /dev/null +++ b/themes/olive/views/messages/index.html.erb @@ -0,0 +1,26 @@ + +<%= link_to t(:refresh), :controller => 'messages', :action => 'refresh' %> + +

Current: <%= pretty_folder_name(@current_folder) %>

+ +<%= @current_folder.inspect %> +<%= Time.now - @current_folder.msgs_updated_at %> + +

Folders

+<% if @folders.size.zero? %> +No folders. +<% else %> + +<% end %> + +<%= link_to t(:logout), :controller => 'user', :action => 'logout' %> + + diff --git a/themes/olive/views/user/setup.html.erb b/themes/olive/views/user/setup.html.erb index a1e858b..6c17f5f 100755 --- a/themes/olive/views/user/setup.html.erb +++ b/themes/olive/views/user/setup.html.erb @@ -9,10 +9,10 @@

<%= t(:setup_title) %>

- <%= raw form_field(@user,"email",nil,"joe.doe@domain.domain") %> - <%= raw form_field(@user,"first_name",nil,"Joe") %> - <%= raw form_field(@user,"last_name",nil,"Doe") %> - <%= raw form_field(@server,"name","server_name","domain.domain") %> + <%= raw form_field(@user,"email",nil,"joe.doe@domain.domain",params['email']) %> + <%= raw form_field(@user,"first_name",nil,"Joe","") %> + <%= raw form_field(@user,"last_name",nil,"Doe","") %> + <%= raw form_field(@server,"name","server_name","domain.domain","") %> <%= raw form_button("send") %>
diff --git a/themes/olive/views/user/unknown.html.erb b/themes/olive/views/user/unknown.html.erb index b105815..8ae7211 100755 --- a/themes/olive/views/user/unknown.html.erb +++ b/themes/olive/views/user/unknown.html.erb @@ -10,7 +10,7 @@

<%= t(:unknown_user_flash) %>

<%= t(:unknown_user_login) %> -> <%= link_to "Login",:controller => "user",:action =>"login" %>

-

<%= t(:unknown_user_setup) %> -> <%= link_to "Setup",:controller => "user",:action => "setup" %>

+

<%= t(:unknown_user_setup) %> -> <%= link_to "Setup",:controller => "user",:action => "setup",:email => params['email'] %>

diff --git a/vendor/plugins/.gitkeep b/vendor/plugins/.gitkeep old mode 100644 new mode 100755