2014-02-03 19:23:00 +00:00
|
|
|
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
2013-06-12 15:59:58 +00:00
|
|
|
|
2012-04-13 16:42:25 +00:00
|
|
|
require 'mail'
|
|
|
|
|
|
|
|
class Channel::EmailBuild
|
|
|
|
|
|
|
|
def build(attr, notification = false)
|
|
|
|
mail = Mail.new
|
|
|
|
|
|
|
|
# set organization
|
|
|
|
organization = Setting.get('organization')
|
|
|
|
if organization then;
|
2012-07-28 16:36:47 +00:00
|
|
|
mail['Organization'] = organization.to_s
|
2012-04-13 16:42:25 +00:00
|
|
|
end
|
2012-08-06 06:29:54 +00:00
|
|
|
|
2012-04-13 16:42:25 +00:00
|
|
|
# notification
|
|
|
|
if notification
|
|
|
|
attr['X-Loop'] = 'yes'
|
|
|
|
attr['Precedence'] = 'bulk'
|
|
|
|
attr['Auto-Submitted'] = 'auto-generated'
|
|
|
|
end
|
2012-08-06 06:29:54 +00:00
|
|
|
|
|
|
|
attr['X-Powered-BY'] = 'OTRS - Open Ticket Request System (http://otrs.org/)'
|
2012-12-24 13:55:43 +00:00
|
|
|
attr['X-Mailer'] = 'OTRS Mail Service (3.x)'
|
2012-08-06 06:29:54 +00:00
|
|
|
|
2012-04-13 16:42:25 +00:00
|
|
|
# set headers
|
|
|
|
attr.each do |key, v|
|
|
|
|
if key.to_s != 'attachments' && key.to_s != 'body'
|
|
|
|
mail[key.to_s] = v.to_s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-06-12 15:59:58 +00:00
|
|
|
# add body
|
2012-04-13 16:42:25 +00:00
|
|
|
mail.text_part = Mail::Part.new do
|
|
|
|
body attr[:body]
|
|
|
|
end
|
|
|
|
|
|
|
|
# add attachments
|
|
|
|
if attr[:attachments]
|
|
|
|
attr[:attachments].each do |attachment|
|
|
|
|
mail.attachments[attachment.filename] = {
|
|
|
|
:content_type => attachment.preferences['Content-Type'],
|
|
|
|
:mime_type => attachment.preferences['Mime-Type'],
|
|
|
|
:content => attachment.store_file.data
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return mail
|
|
|
|
end
|
2013-06-12 15:59:58 +00:00
|
|
|
end
|