Project

General

Profile

Download (1.65 KB) Statistics
| Branch: | Tag: | Revision:
require 'cyborghood/order'

module CyborgHood
class MailOrder < Order
def self.parse(user, message)
logger.debug "Parsing Mail"
order_txt = nil
shared_parameters = nil
if message.multipart?
if message.parts[0].content_type == "text/plain"
order_txt = message.parts[0].body
shared_parameters = {}
i = 1
message.parts.each do |p|
shared_parameters[i] = SharedParameter.new(p.body, p.content_type)
filename = p.header['content-type'].params('filename')
shared_parameters[filename] = ParameterReference.new(i) if filename
i += 1
end
end
else
order_txt = message.body if message.content_type == "text/plain"
shared_parameters = {}
end
return new(:error => N_("Mail does not contain a proper text part for commands."), :user => user) if order_txt.nil?

command_lines = order_txt.split("\n")

# remove message signature
signature_pos = command_lines.index("-- ")
command_lines.slice!(signature_pos..-1) if signature_pos

super(user, command_lines, shared_parameters) do |word, errors, used_refs|
if word =~ /^@([a-zA-Z0-9._-]+)$/
ref = $1
d_ref, d_param = dereference_param(shared_parameters, param)
if d_ref.nil?
# TODO: a message class is needed to handle passing translatable strings with parameters (doing late sprintf for example)
errors << N_("Attachment '#{ref}' not found.")
else
used_refs << d_ref
end
d_param
else
word
end
end
end
end
end
(7-7/9)