Sha256: 1190bef8a2e34d8cc4a225d4a244ca28f18e83f9fe1b8f3a2b257a0b6341d47f

Contents?: true

Size: 1.79 KB

Versions: 1

Compression:

Stored size: 1.79 KB

Contents

#
# Send a publication email whenever an elt is saved
#
# Important:
# the bcc, which is actually used for sending, is setup in the Mail class
#
class MailNotify < ActionMailer::Base
	def publish(elt)
		logger.info "Create a mail for publication"
		subject elt.subject

		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]}") \
			+ ">"

		# Try to render the element as html
		body :elt => elt

		# 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'] = "#{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

		parentMsg = elt.parent.mail
		if parentMsg
			@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}"

		logger.info "Mail created"
	end

	private

	#
	# Try to fine, define, the mailing list id this elt is part of
	#
	# 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' and !elt.subject.match 'Re: ') then
			mailing_list elt.parent
		else
			elt
		end
	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
parlement-0.6 app/models/mail_notify.rb