app/models/mail_notify.rb in parlement-0.5 vs app/models/mail_notify.rb in parlement-0.6
- old
+ new
@@ -7,44 +7,28 @@
class MailNotify < ActionMailer::Base
def publish(elt)
logger.info "Create a mail for publication"
subject elt.subject
- recipients (mailing_list(elt.parent).subject.blank? ? '' : mailing_list(elt.parent).subject ) \
- + ' <' \
- + mailing_list(elt.parent).id + '@' + ActionMailer::Base.server_settings[:domain] \
- + '>'
+ ml = mailing_list(elt.parent)
+ recipients (ml.subject.blank? ? '' : ml.subject ) \
+ + " <#{ml.id}@#{ActionMailer::Base.server_settings[:domain]}>"
+
from ((elt.person and elt.person.name) ? elt.person.name : ANONYMOUS_POSTER) \
- + ' <' \
+ + " <" \
+ ((elt.person and elt.person.email) \
- ? elt.person.email : ANONYMOUS_POSTER + '@' + ActionMailer::Base.server_settings[:domain]) \
- + '> '
+ ? elt.person.email : "#{ANONYMOUS_POSTER}@#{ActionMailer::Base.server_settings[:domain]}") \
+ + ">"
# Try to render the element as html
- body(:elt => elt)
+ body :elt => elt
- #content_type 'multipart/alternative'
- #part "text/html" do |a|
- # a.body = render(:template => "/home/manu/develop/parlement/trunk/app/views/mail_notify/publish.text.html.rhtml",
- # :locals => { :elt => elt })
- #end
- #part "text/plain" do |a|
- # a.body = render(:template => "mail_notify/publish.text.plain",
- # :locals => { :elt => elt })
- #end
- # :body => email_builder.render(:file => "mail_notify/publish.text.html.rhtml")
- #attachment :content_type => "text/html",
- # :body => email_builder.render(:file => "mail_notify/publish.text.html.rhtml")
- #attachment :content_type => "text/plain",
- # :body => email_builder.render(:file => "mail_notify/publish.text.plain.rhtml")
-
-
# This is the essential of a mailing list, you reply to the mailing list,
# where every body sends their mail.
# This very mail can be a mailing list all by itself...
- @headers['Reply-to'] = mailing_list(elt).id + '@' + ActionMailer::Base.server_settings[:domain]
+ @headers['Reply-to'] = "#{ml.id}@#{ActionMailer::Base.server_settings[:domain]}"
@headers['In-Reply-To'] = elt.parent.mail.message \
if elt.parent and elt.parent.mail and elt.parent.mail.message
@sent_on = elt.created_on
@@ -54,11 +38,11 @@
@headers['references'] = ''
@headers['references'] << parentMsg.mail_parents if parentMsg.mail_parents
@headers['references'] << parentMsg.message if parentMsg.message
end
- @headers['X-Mailer'] = ActionMailer::Base.server_settings[:domain] + " v" + PARLEMENT_VERSION
+ @headers['X-Mailer'] = "#{ActionMailer::Base.server_settings[:domain]} v#{PARLEMENT_VERSION}"
logger.info "Mail created"
end
private
@@ -68,10 +52,10 @@
#
# The algo used is simple: find a parent id smaller than the usually auto
# generated ids
#
def mailing_list(elt)
- if (elt.id.size > 21 and elt.parent_id != 'ROOT') then
+ if (elt.id.size > 21 and elt.parent_id != 'ROOT' and !elt.subject.match 'Re: ') then
mailing_list elt.parent
else
elt
end
end