parlement 0.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +14 -4
- data/README +25 -5
- data/Rakefile +21 -21
- data/app/controllers/account_controller.rb +5 -1
- data/app/controllers/elt_controller.rb +7 -10
- data/app/controllers/person_controller.rb +9 -0
- data/app/controllers/subscriber_controller.rb +21 -0
- data/app/helpers/elt_helper.rb +25 -13
- data/app/helpers/mailman.rb +9 -92
- data/app/helpers/subscriber_helper.rb +2 -0
- data/app/models/attachment.rb +2 -0
- data/app/models/elt.rb +64 -2
- data/app/models/mail.rb +198 -0
- data/app/models/mail_notify.rb +63 -0
- data/app/models/person.rb +8 -1
- data/app/views/account/_login.rhtml +31 -28
- data/app/views/account/_show.rhtml +4 -4
- data/app/views/elt/_elt.rhtml +23 -28
- data/app/views/elt/_list.rhtml +6 -2
- data/app/views/elt/new.rhtml +1 -1
- data/app/views/elt/show.rhtml +32 -10
- data/app/views/layouts/top.rhtml +16 -10
- data/app/views/mail_notify/publish.text.html.rhtml +46 -0
- data/app/views/mail_notify/publish.text.plain.rhtml +2 -0
- data/app/views/person/_listElts.rhtml +33 -0
- data/app/views/person/show.rhtml +21 -19
- data/config/boot.rb +2 -0
- data/config/environment.rb +19 -13
- data/config/environments/development.rb +3 -1
- data/config/environments/production.rb +2 -0
- data/config/environments/test.rb +2 -0
- data/config/routes.rb +5 -2
- data/db/ROOT/mail.txt +2 -0
- data/db/ROOT/parlement/news/release0.2.txt +8 -0
- data/db/ROOT/parlement/news/release0.3.txt +11 -0
- data/db/ROOT/parlement/test.txt +6 -1
- data/db/ROOT/parlement.txt +23 -30
- data/db/ROOT/perso.txt +17 -18
- data/db/development_structure.sql +133 -217
- data/db/schema.rb +83 -0
- data/db/schema.sql +11 -15
- data/lib/data_import.rb +3 -1
- data/public/attachment/file/architecture.png +0 -0
- data/public/attachment/file/architecture.svg +8972 -0
- data/public/attachment/file/security.svg +8960 -0
- data/public/images/Sleep-Deprivation-5.JPG +0 -0
- data/public/images/eltBackground.png +0 -0
- data/public/images/eltBackground.svg +89 -0
- data/public/images/orange_by_darren_Hester_350o.jpg +0 -0
- data/public/images/rails.png +0 -0
- data/public/images/smile.png +0 -0
- data/public/images/smile.svg +257 -0
- data/public/images/world.png +0 -0
- data/public/images/world.svg +170 -0
- data/public/javascripts/controls.js +30 -1
- data/public/javascripts/dragdrop.js +210 -145
- data/public/javascripts/effects.js +261 -399
- data/public/javascripts/ie7.js +6 -0
- data/public/javascripts/prototype.js +131 -72
- data/public/oldindex.html +270 -71
- data/public/stylesheets/default.css +189 -215
- data/script/about +1 -1
- data/script/breakpointer +1 -1
- data/script/console +1 -1
- data/script/destroy +1 -1
- data/script/generate +1 -1
- data/script/performance/benchmarker +1 -1
- data/script/performance/profiler +1 -1
- data/script/plugin +1 -1
- data/script/process/reaper +1 -1
- data/script/process/spawner +1 -1
- data/script/process/spinner +1 -1
- data/script/runner +1 -1
- data/script/server +1 -1
- data/test/fixtures/elts.yml +2 -0
- data/test/fixtures/mail/mail_ruby +27 -0
- data/test/fixtures/mail/mail_rubyChild +28 -0
- data/test/fixtures/mail/mail_rubyWithAttachment +7932 -0
- data/test/fixtures/mail/mail_rubyWithSubject +27 -0
- data/test/fixtures/mails.yml +7 -1
- data/test/fixtures/people.yml +5 -0
- data/test/fixtures/subscribers.yml +11 -0
- data/test/functional/account_controller_test.rb +38 -37
- data/test/functional/subscriber_controller_test.rb +128 -0
- data/test/test_helper.rb +44 -0
- data/test/unit/attachment_test.rb +1 -1
- data/test/unit/elt_test.rb +3 -2
- data/test/unit/mail_notify_test.rb +37 -0
- data/test/unit/mail_test.rb +124 -1
- data/test/unit/notifier_test.rb +0 -14
- data/test/unit/person_test.rb +2 -1
- data/test/unit/subscriber_test.rb +35 -0
- data/test/unit/user_test.rb +3 -3
- data/vendor/plugins/file_column/CHANGELOG +64 -0
- data/vendor/plugins/file_column/README +54 -0
- data/vendor/plugins/file_column/Rakefile +36 -0
- data/vendor/plugins/file_column/TODO +6 -0
- data/vendor/plugins/file_column/init.rb +12 -0
- data/vendor/plugins/file_column/lib/file_column.rb +719 -0
- data/vendor/plugins/file_column/lib/file_column_helper.rb +145 -0
- data/vendor/plugins/file_column/lib/file_compat.rb +28 -0
- data/vendor/plugins/file_column/lib/magick_file_column.rb +188 -0
- data/vendor/plugins/file_column/lib/validations.rb +112 -0
- data/vendor/plugins/file_column/test/abstract_unit.rb +90 -0
- data/vendor/plugins/file_column/test/connection.rb +17 -0
- data/vendor/plugins/file_column/test/file_column_helper_test.rb +97 -0
- data/vendor/plugins/file_column/test/file_column_test.rb +630 -0
- data/vendor/plugins/file_column/test/fixtures/entry.rb +32 -0
- data/vendor/plugins/file_column/test/fixtures/invalid-image.jpg +1 -0
- data/vendor/plugins/file_column/test/fixtures/kerb.jpg +0 -0
- data/vendor/plugins/file_column/test/fixtures/mysql.sql +25 -0
- data/vendor/plugins/file_column/test/fixtures/schema.rb +10 -0
- data/vendor/plugins/file_column/test/fixtures/skanthak.png +0 -0
- data/vendor/plugins/file_column/test/magick_test.rb +251 -0
- data/vendor/plugins/file_column/test/magick_view_only_test.rb +21 -0
- data/vendor/plugins/guid/README.TXT +19 -0
- data/vendor/plugins/guid/init.rb +23 -0
- data/vendor/plugins/guid/lib/usesguid.rb +37 -0
- data/vendor/plugins/guid/lib/uuid22.rb +43 -0
- data/vendor/plugins/guid/lib/uuidtools.rb +565 -0
- metadata +83 -15
- data/db/ROOT/CV.txt +0 -166
- data/lib/file_column.rb +0 -263
- data/lib/file_column_helper.rb +0 -45
- /data/{lib → vendor/plugins/file_column/lib}/rails_file_column.rb +0 -0
data/CHANGES
CHANGED
@@ -1,13 +1,23 @@
|
|
1
1
|
- parlement changelog
|
2
2
|
|
3
|
+
== Version 0.3
|
4
|
+
|
5
|
+
Major version, adding the possibility to use not only the web forums, but mails
|
6
|
+
|
7
|
+
* mailing list functionality!!!
|
8
|
+
* new look
|
9
|
+
* tests all pass
|
10
|
+
* rails 1.0
|
11
|
+
* plugin guid
|
12
|
+
* W3C xhtml 1.0 compliant
|
13
|
+
|
14
|
+
|
3
15
|
== Version 0.2
|
4
16
|
|
5
17
|
Evolutions
|
6
18
|
|
7
|
-
* Anonymous users doing a quick post (where the subject is not modified) will
|
8
|
-
|
9
|
-
* Each person has a public page listing its posts (this page can also be used
|
10
|
-
to post...)
|
19
|
+
* Anonymous users doing a quick post (where the subject is not modified) will be marked as "anon"
|
20
|
+
* Each person has a public page listing its posts (this page can also be used to post...)
|
11
21
|
* Display the creation time for the most important posts
|
12
22
|
|
13
23
|
|
data/README
CHANGED
@@ -1,9 +1,31 @@
|
|
1
1
|
I am using debian, so here are a few commands I use:
|
2
|
-
# apt-get install ruby
|
3
2
|
# apt-get install postgresql
|
4
|
-
#
|
5
|
-
#
|
3
|
+
# sudo su - postgres
|
4
|
+
# createuser /your_login/
|
5
|
+
# apt-get install ruby
|
6
|
+
# apt-get install libpgsql-ruby
|
6
7
|
# apt-get install irb
|
8
|
+
# apt-get install libredcloth-ruby
|
9
|
+
# apt-get install rdoc
|
10
|
+
|
11
|
+
-> why???
|
12
|
+
# ln -s /sbin/ifconfig /bin/
|
13
|
+
|
14
|
+
# gem install -r rails
|
15
|
+
Only if you expect to develop and release:
|
16
|
+
# gem install -r meta_project
|
17
|
+
|
18
|
+
|
19
|
+
The database is setup for user "manu", you may need to change the file
|
20
|
+
config/database.yml for your own settings.
|
21
|
+
|
22
|
+
Change config/environment.rb to set the domain, default is something like
|
23
|
+
'leparlement.org', define it as your web site or email domain.
|
24
|
+
|
25
|
+
In procmail, define a rule to redirect the relevant mail to parlement, I use:
|
26
|
+
:0 c
|
27
|
+
* ^TO parlement|leparlement.org
|
28
|
+
| /home/manu/parlement/trunk/script/runner 'Mailman.receive STDIN.read'
|
7
29
|
|
8
30
|
|
9
31
|
Once you have everything set up (ruby, postgresql, redcloth, irb), you can
|
@@ -13,8 +35,6 @@ launch parlement thus:
|
|
13
35
|
~ ruby lib/data_import.rb
|
14
36
|
~ ruby ./script/server
|
15
37
|
|
16
|
-
The database is setup for user "manu", you may need to change the file
|
17
|
-
config/database.yml for your own settings.
|
18
38
|
|
19
39
|
Now you can go to localhost:3000
|
20
40
|
|
data/Rakefile
CHANGED
@@ -35,7 +35,7 @@ PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
|
35
35
|
PKG_FILES = FileList[
|
36
36
|
'[A-Z]*', 'app/**/*', 'components/**/*', 'config/**/*', 'db/**/*',
|
37
37
|
'lib/**/*', 'public/**/*', 'script/**/*', 'test/**/*', 'vendor/**/*'
|
38
|
-
].exclude(/\
|
38
|
+
].exclude(/\bsvn\b|~$/)
|
39
39
|
|
40
40
|
spec = Gem::Specification.new do |s|
|
41
41
|
## Basic information.
|
@@ -54,7 +54,7 @@ spec = Gem::Specification.new do |s|
|
|
54
54
|
EOF
|
55
55
|
s.files = PKG_FILES
|
56
56
|
s.require_path = 'lib'
|
57
|
-
s.autorequire = 'rails
|
57
|
+
s.autorequire = 'rails'
|
58
58
|
s.has_rdoc = false
|
59
59
|
s.requirements << 'none'
|
60
60
|
s.test_files = Dir.glob('test/unit/*')
|
@@ -73,11 +73,10 @@ EOF
|
|
73
73
|
s.add_dependency('rails')
|
74
74
|
end
|
75
75
|
|
76
|
+
desc "Build Gem"
|
76
77
|
Rake::GemPackageTask.new(spec) do |pkg|
|
77
|
-
#pkg.gem_spec = spec
|
78
78
|
pkg.need_zip = true
|
79
79
|
pkg.need_tar = true
|
80
|
-
#pkg.package_files.include("*")
|
81
80
|
end
|
82
81
|
|
83
82
|
|
@@ -90,8 +89,8 @@ task :todo do
|
|
90
89
|
end
|
91
90
|
end
|
92
91
|
|
93
|
-
#task :release => [:verify_env_vars, :release_files, :publish_doc, :publish_news
|
94
|
-
task :release => [:
|
92
|
+
#task :release => [:verify_env_vars, :release_files, :publish_doc, :publish_news]
|
93
|
+
task :release => [:release_files, :publish_news]
|
95
94
|
|
96
95
|
task :verify_env_vars do
|
97
96
|
if not ENV["RUBYFORGE_USER"]
|
@@ -122,7 +121,6 @@ task :verify_env_vars do
|
|
122
121
|
print "freshmeat's password: "
|
123
122
|
ENV["FRESHMEAT_PASSWORD"] = STDIN.gets.chomp
|
124
123
|
end
|
125
|
-
|
126
124
|
end
|
127
125
|
|
128
126
|
task :publish_doc do
|
@@ -131,7 +129,7 @@ task :publish_doc do
|
|
131
129
|
end
|
132
130
|
|
133
131
|
desc "Release files on RubyForge"
|
134
|
-
task :release_files => [:
|
132
|
+
task :release_files => [:verify_env_vars, :package] do
|
135
133
|
release_files = FileList[ "pkg/#{PKG_FILE_NAME}.gem",
|
136
134
|
"pkg/#{PKG_FILE_NAME}.tgz",
|
137
135
|
"pkg/#{PKG_FILE_NAME}.zip" ]
|
@@ -140,6 +138,8 @@ task :release_files => [:gem] do
|
|
140
138
|
# Never hardcode user name and password in the Rakefile!
|
141
139
|
release.user_name = ENV['RUBYFORGE_USER']
|
142
140
|
release.password = ENV['RUBYFORGE_PASSWORD']
|
141
|
+
#puts "login: ", ENV['RUBYFORGE_USER']
|
142
|
+
#puts "password: ", ENV['RUBYFORGE_PASSWORD']
|
143
143
|
release.files = release_files.to_a
|
144
144
|
release.release_name = "#{PKG_NAME} #{PKG_VERSION}"
|
145
145
|
# The rest of the options are defaults (among others, release_notes and release_changes, parsed from CHANGES)
|
@@ -148,24 +148,31 @@ end
|
|
148
148
|
|
149
149
|
|
150
150
|
desc "Publish news"
|
151
|
-
task :publish_news => [:
|
152
|
-
|
151
|
+
task :publish_news => [:verify_env_vars] do
|
152
|
+
#release_files = FileList[ "pkg/#{PKG_FILE_NAME}.gem",
|
153
|
+
# "pkg/#{PKG_FILE_NAME}.tgz",
|
154
|
+
# "pkg/#{PKG_FILE_NAME}.zip" ]
|
155
|
+
|
156
|
+
Rake::XForge::NewsPublisher.new(MetaProject::Project::XForge::RubyForge.new(PKG_NAME)) do |news|
|
153
157
|
# Never hardcode user name and password in the Rakefile!
|
154
158
|
news.user_name = ENV['RUBYFORGE_USER']
|
155
159
|
news.password = ENV['RUBYFORGE_PASSWORD']
|
156
160
|
end
|
157
161
|
|
162
|
+
"""
|
158
163
|
fm = DevTools::Freshmeat::FreshmeatService.new(ENV['FRESHMEAT_USER'], ENV['FRESHMEAT_PASSWORD'])
|
159
164
|
fm.get_project_list.each do |p|
|
160
|
-
puts p
|
161
165
|
branches = fm.get_branch_list( p.shortName )
|
162
|
-
puts branches.inspect
|
163
166
|
release = fm.get_release( p.shortName, branches[0], p.version )
|
164
|
-
|
167
|
+
if PKG_NAME == p.shortName
|
168
|
+
puts p
|
169
|
+
release.version = PKG_VERSION
|
170
|
+
release.changes = PKG_VERSION
|
171
|
+
end
|
165
172
|
end
|
166
173
|
puts fm.logout
|
167
174
|
|
168
|
-
|
175
|
+
|
169
176
|
Rake::XForge::NewsPublisher.new(MetaProject::Project::XForge::Fresh.new(PKG_NAME)) do |news|
|
170
177
|
# Never hardcode user name and password in the Rakefile!
|
171
178
|
news.user_name = ENV['RUBYFORGE_USER']
|
@@ -174,10 +181,3 @@ task :publish_news => [:gem] do
|
|
174
181
|
"""
|
175
182
|
end
|
176
183
|
|
177
|
-
desc "Tag all the CVS files with the latest release number (REL=x.y.z)"
|
178
|
-
task :tag do
|
179
|
-
reltag = "REL_#{PKG_VERSION.gsub(/\./, '_')}"
|
180
|
-
puts "Tagging CVS with [#{reltag}]"
|
181
|
-
sh %{cvs tag #{reltag}}
|
182
|
-
end
|
183
|
-
|
@@ -1,3 +1,6 @@
|
|
1
|
+
#
|
2
|
+
# This class manages users inscription, login and logout
|
3
|
+
#
|
1
4
|
class AccountController < UserController
|
2
5
|
model :person
|
3
6
|
model :user
|
@@ -116,6 +119,7 @@ class AccountController < UserController
|
|
116
119
|
|
117
120
|
def logout
|
118
121
|
@session[:person] = @person = nil
|
122
|
+
@session[:user] = @user = nil
|
119
123
|
render :partial => 'login', :locals => { :divId => params[:divId] }
|
120
124
|
end
|
121
125
|
|
@@ -143,8 +147,8 @@ class AccountController < UserController
|
|
143
147
|
end
|
144
148
|
|
145
149
|
|
146
|
-
protected
|
147
150
|
# Mostly copied from the login engine
|
151
|
+
protected
|
148
152
|
def signup
|
149
153
|
if @person and not @user
|
150
154
|
@user = User.new
|
@@ -1,7 +1,8 @@
|
|
1
|
-
|
2
|
-
This is the central component to parlement
|
3
|
-
|
4
|
-
|
1
|
+
#
|
2
|
+
# This is the central component to parlement
|
3
|
+
#
|
4
|
+
# An element is just the name for a poll/message/issue
|
5
|
+
#
|
5
6
|
class EltController < ApplicationController
|
6
7
|
def index
|
7
8
|
params[:id] = params[:id].gsub(/.html/, '')
|
@@ -31,10 +32,12 @@ class EltController < ApplicationController
|
|
31
32
|
end
|
32
33
|
|
33
34
|
def rss
|
35
|
+
params[:id] = params[:id].gsub(/.rss/, '')
|
34
36
|
@headers["Content-Type"] = "text/xml; charset=utf-8"
|
35
37
|
@elt = Elt.find(params[:id]) if @elt == nil
|
36
38
|
end
|
37
39
|
|
40
|
+
# Used to initialise the elt, its subject mainly
|
38
41
|
def new
|
39
42
|
@elt = Elt.new
|
40
43
|
@elt.parent = Elt.find(params[:id])
|
@@ -61,12 +64,6 @@ class EltController < ApplicationController
|
|
61
64
|
@elt.person = @session[:person]
|
62
65
|
|
63
66
|
if params[:submit] == 'preview' or @elt.save
|
64
|
-
#cookies[:person] = { :value => @elt.person.name,
|
65
|
-
# :expires => Time.now + 360000 }
|
66
|
-
#flash[:notice] = 'Elt was successfully created.'
|
67
|
-
#redirect_to :action => 'top', :id => @elt.parent_id
|
68
|
-
#render_component(:action => 'show', :id => @elt.id )
|
69
|
-
|
70
67
|
render :partial => '/elt/elt', :locals => { :elt => @elt, :eltTop => false }
|
71
68
|
else
|
72
69
|
flash[:notice] = 'Error'
|
@@ -1,4 +1,7 @@
|
|
1
1
|
class PersonController < ApplicationController
|
2
|
+
# To make sure we can also display properly this person's elements
|
3
|
+
helper :elt
|
4
|
+
|
2
5
|
layout 'top'
|
3
6
|
model :person
|
4
7
|
|
@@ -10,4 +13,10 @@ class PersonController < ApplicationController
|
|
10
13
|
flash[:error] = "Person '#{params[:id]}' does not exist"
|
11
14
|
redirect_to '/'
|
12
15
|
end
|
16
|
+
|
17
|
+
def list
|
18
|
+
@person = Person.find(params[:id]) if @person == nil
|
19
|
+
render :partial => '/person/listElts', :locals => { :person => @person }
|
20
|
+
end
|
13
21
|
end
|
22
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class SubscriberController < ApplicationController
|
2
|
+
|
3
|
+
def subscribe
|
4
|
+
@elt = Elt.find(params[:id])
|
5
|
+
|
6
|
+
if @session[:person]
|
7
|
+
if @elt.subscribers.include?(@session[:person])
|
8
|
+
@elt.subscribers.delete(@session[:person])
|
9
|
+
logger.info "Unsubscribed #{@session[:person].name} from #{@elt.subject}..."
|
10
|
+
render :inline => "Unsubscribed..."
|
11
|
+
else
|
12
|
+
@elt.subscribers << @session[:person]
|
13
|
+
logger.info "Subscribed #{@session[:person].name} to #{@elt.subject}..."
|
14
|
+
render :inline => "Subscribed..."
|
15
|
+
end
|
16
|
+
else
|
17
|
+
puts "Not logged in!"
|
18
|
+
render :inline => "First you need to login... it's easy, juste type a pseudo, any pseudo ;-) "
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/app/helpers/elt_helper.rb
CHANGED
@@ -16,22 +16,34 @@ module EltHelper
|
|
16
16
|
.gsub(/^\d+[\.-]\s+/, '# ') \
|
17
17
|
if data != nil
|
18
18
|
|
19
|
+
# Remove any leading and finishing <p> </p>
|
19
20
|
textiled = text.blank? ? "" : RedCloth.new(text).to_html
|
20
21
|
if textiled[0..2] == "<p>" then textiled = textiled[3..-1] end
|
21
22
|
if textiled[-4..-1] == "</p>" then textiled = textiled[0..-5] end
|
22
|
-
return textiled
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
.gsub(
|
29
|
-
.gsub(
|
30
|
-
.gsub(/[^\n]\n^>/, '') \
|
31
|
-
.gsub(/^\d+[ \.-]+/, '# ') \
|
32
|
-
# ).gsub(/(.{65,182})<br\s\/>/, \
|
33
|
-
# ).gsub(/([\r\n\<\>=\w\d\s.\:;,$*?!\-����������\"\&#;()\/]{65,182})<br\s\/>([^>])/,
|
34
|
-
) if data != nil
|
35
|
-
|
24
|
+
textiled
|
25
|
+
|
26
|
+
# hard_breaks = false
|
27
|
+
# auto_link textilize_without_paragraph(data \
|
28
|
+
# .gsub(/\&\#8211\;/, '* ') \
|
29
|
+
# .gsub(/^-\s/, '* ') \
|
30
|
+
# .gsub(/[^\n]\n^>/, '') \
|
31
|
+
# .gsub(/^\d+[ \.-]+/, '# ') \
|
32
|
+
# # ).gsub(/(.{65,182})<br\s\/>/, \
|
33
|
+
# # ).gsub(/([\r\n\<\>=\w\d\s.\:;,$*?!\-����������\"\&#;()\/]{65,182})<br\s\/>([^>])/,
|
34
|
+
# ) if data != nil
|
35
|
+
end
|
36
|
+
|
37
|
+
#
|
38
|
+
# Should we display an element's title
|
39
|
+
#
|
40
|
+
# The algo used is simple, display a title if it is not a simple reply to its
|
41
|
+
# parent
|
42
|
+
#
|
43
|
+
def displayTitle? elt
|
44
|
+
#elt.id and elt.subject.reverse.index(elt.parent.subject.reverse) != 0
|
45
|
+
elt.id and elt.parent and elt.subject != elt.parent.subject \
|
46
|
+
and not elt.subject =~ /^((\[[\w]*\] )*(r�f|re|sv|aw)*(.)*:[ \t]*)+#{elt.parent.subject}/
|
36
47
|
end
|
37
48
|
end
|
49
|
+
|
data/app/helpers/mailman.rb
CHANGED
@@ -1,96 +1,13 @@
|
|
1
|
-
|
2
|
-
Receive an email from which an elt is created.
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
#
|
2
|
+
# Receive an email from which an elt is created.
|
3
|
+
#
|
4
|
+
# An associated mail is kept to make sure we don't lose any data. Attachments
|
5
|
+
# are also created in an associated table
|
6
|
+
#
|
6
7
|
class Mailman < ActionMailer::Base
|
7
|
-
""" This is to make sure we only have utf-8, no iso-8859 """
|
8
|
-
def unquote(text)
|
9
|
-
text.gsub(/\=\?.*?\?\=/) do |m|
|
10
|
-
TMail::Unquoter.unquote_and_convert_to(m, 'utf-8')
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
8
|
def receive(email)
|
15
|
-
|
16
|
-
|
17
|
-
@elt.subject = unquote(email.subject)
|
18
|
-
|
19
|
-
@elt.body = ''
|
20
|
-
|
21
|
-
@elt.person = Person.find_by_name(unquote(email.friendly_from))
|
22
|
-
@elt.person = Person.new if @elt.person == nil
|
23
|
-
@elt.person.name = unquote(email.friendly_from)
|
24
|
-
@elt.person.email = email.from.first
|
25
|
-
|
26
|
-
if email.references != nil
|
27
|
-
# Try to fin its email parent in the db
|
28
|
-
for parent in email.references
|
29
|
-
m = Mail.find_by_message(parent.to_s)
|
30
|
-
@elt.parent = m.elt if m != nil
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
if @elt.parent == nil
|
35
|
-
parentId = @elt.subject.match(/\[\w*\]/)
|
36
|
-
logger.info parentId
|
37
|
-
if parentId != nil
|
38
|
-
parentId = parentId[0].gsub(/[\[\]]/, '')
|
39
|
-
parentElt = Elt.find(parentId)
|
40
|
-
logger.info parentElt
|
41
|
-
if parentElt != nil
|
42
|
-
@elt.subject = @elt.subject
|
43
|
-
@elt.parent_id = parentId
|
44
|
-
end
|
45
|
-
logger.info @elt.subject
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
@elt.parent_id = 'mails' if @elt.parent == nil
|
50
|
-
|
51
|
-
|
52
|
-
mngAttachment(email) if email != nil
|
53
|
-
|
54
|
-
|
55
|
-
logger.info email.from.first
|
56
|
-
@mail = Mail.new
|
57
|
-
logger.info email.friendly_from
|
58
|
-
@mail.message = email.message_id
|
59
|
-
logger.info email.references
|
60
|
-
@mail.mail_parents = email.references
|
61
|
-
|
62
|
-
@mail.file = email.encoded
|
63
|
-
|
64
|
-
@elt.save
|
65
|
-
@mail.elt = @elt
|
66
|
-
@mail.save
|
67
|
-
end
|
68
|
-
|
69
|
-
def mngAttachment(attachment)
|
70
|
-
if attachment.content_type == 'text/plain'
|
71
|
-
@elt.body += attachment.body
|
72
|
-
elsif attachment.multipart?
|
73
|
-
attachment.parts.each do |part|
|
74
|
-
mngAttachment(part)
|
75
|
-
end
|
76
|
-
elsif attachment.content_type != 'text/html'
|
77
|
-
@attach = @elt.attachments.build
|
78
|
-
body = attachment.body
|
79
|
-
|
80
|
-
@attach.content_type = attachment.content_type
|
81
|
-
|
82
|
-
def body.original_filename=(orig)
|
83
|
-
@original_filename = orig
|
84
|
-
end
|
85
|
-
body.original_filename = attachment.type_param('name')
|
86
|
-
def body.original_filename
|
87
|
-
@original_filename
|
88
|
-
end
|
89
|
-
def body.read
|
90
|
-
self.to_s
|
91
|
-
end
|
92
|
-
|
93
|
-
@attach.file = body
|
94
|
-
end
|
9
|
+
elt = Elt.new
|
10
|
+
elt.receive(email)
|
95
11
|
end
|
96
12
|
end
|
13
|
+
|
data/app/models/attachment.rb
CHANGED
data/app/models/elt.rb
CHANGED
@@ -1,17 +1,79 @@
|
|
1
|
+
#
|
2
|
+
# This is, in fact, the main parlement class!
|
3
|
+
#
|
1
4
|
class Elt < ActiveRecord::Base
|
5
|
+
usesguid
|
6
|
+
|
2
7
|
acts_as_tree :order => "position is not null, position, created_on"
|
3
|
-
|
8
|
+
|
4
9
|
has_one :mail, :dependent => true
|
5
10
|
has_many :attachments, :dependent => true
|
6
11
|
|
12
|
+
belongs_to :person
|
13
|
+
|
14
|
+
has_and_belongs_to_many :subscribers,
|
15
|
+
:class_name => "Person",
|
16
|
+
:join_table => "subscribers"
|
17
|
+
|
7
18
|
# for live_tree
|
8
19
|
def name
|
9
20
|
subject
|
10
21
|
end
|
11
22
|
|
23
|
+
# Just a quick method to get all subscribers as a simple list
|
24
|
+
def all_recipients
|
25
|
+
result = Array.new
|
26
|
+
eltRecipient = self
|
27
|
+
while eltRecipient
|
28
|
+
result.concat eltRecipient.subscribers
|
29
|
+
eltRecipient = eltRecipient.parent
|
30
|
+
end
|
31
|
+
logger.debug "all_recipients result: #{result.to_s}"
|
32
|
+
return result
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# Receive this new elt as an email, sent through app/helpers/mailman.rb
|
37
|
+
#
|
38
|
+
def receive(mail)
|
39
|
+
logger.info "Receive \"#{mail.subject}\""
|
40
|
+
|
41
|
+
# TODO
|
42
|
+
# Loop detection, will need more work
|
43
|
+
mail1 = Mail.find_by_message(mail.message_id)
|
44
|
+
# The to_s seems necessary
|
45
|
+
mail2 = Mail.find_by_message(mail['X-Message-Id'].to_s) if mail['X-Message-Id']
|
46
|
+
|
47
|
+
if not mail1 and not mail2
|
48
|
+
self.mail = Mail.new if not self.mail
|
49
|
+
self.mail.elt = self
|
50
|
+
self.mail.receive(mail)
|
51
|
+
save
|
52
|
+
else
|
53
|
+
logger.info "Already received (id: #{mail.message_id})...\n"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
#
|
58
|
+
# Save and publish this elt
|
59
|
+
#
|
12
60
|
def save
|
13
61
|
super
|
14
|
-
|
62
|
+
publish
|
63
|
+
logger.info "\n"
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
#
|
69
|
+
# Mail the elt to all subscribers
|
70
|
+
#
|
71
|
+
def publish
|
72
|
+
logger.info "Publish #{subject}"
|
73
|
+
self.mail = Mail.new if not self.mail
|
74
|
+
self.mail.elt = self
|
75
|
+
self.mail.publish
|
76
|
+
self.mail.save
|
15
77
|
end
|
16
78
|
end
|
17
79
|
|