«
Previous
|
Next
»
Revision 7153c29d
Added by Marc Dequènes over 6 years ago
- ID 7153c29d3d8bb7f59ab58bf968072247973050a4
- Parent bdcaf541
lib/cyborghood/mail_order.rb | ||
---|---|---|
logger.debug "Parsing Mail"
|
||
|
||
# analyse mail parts
|
||
order_txt = nil
|
||
if message.multipart?
|
||
if message.parts[0].mime_type == "text/plain"
|
||
order_txt = message.parts[0].decoded
|
||
i = -1
|
||
message.parts.each do |part|
|
||
i += 1
|
||
next if i == 0
|
||
|
||
@shared_parameters[i] = CommandParameter.new(part.decoded, part.mime_type)
|
||
|
||
filename = part.header['content-disposition'].filename || part.content_type_parameters['name']
|
||
@shared_parameters[filename] = CommandParameterRef.new(i) if filename
|
||
end
|
||
end
|
||
else
|
||
order_txt = message.decoded if message.mime_type == "text/plain"
|
||
end
|
||
return Order.new(:error => _("Mail does not contain a proper text part for commands."), :user => @user) if order_txt.nil?
|
||
@order_txt = nil
|
||
search_text_part(message)
|
||
return Order.new(:error => _("Mail does not contain a proper text part for commands."), :user => @user) if @order_txt.nil?
|
||
|
||
# find command lines
|
||
command_lines = order_txt.split("\n")
|
||
command_lines = @order_txt.split("\n")
|
||
|
||
# remove message signature
|
||
signature_pos = command_lines.index("-- ")
|
||
... | ... | |
end
|
||
end
|
||
end
|
||
|
||
private
|
||
|
||
def search_text_part(message)
|
||
@i ||= 0
|
||
if message.multipart?
|
||
message.parts.each {|part| search_text_part(part) }
|
||
else
|
||
if message.mime_type == "text/plain" and @order_txt.nil?
|
||
@order_txt = message.decoded
|
||
else
|
||
@i += 1
|
||
|
||
@shared_parameters[@i] = CommandParameter.new(message.decoded, message.mime_type)
|
||
|
||
filename = message.header['content-disposition'].filename || message.content_type_parameters['name']
|
||
@shared_parameters[filename] = CommandParameterRef.new(@i) if filename
|
||
end
|
||
end
|
||
end
|
||
end
|
||
end
|
Also available in: Unified diff
search for the mail part containing orders
Previously only the first part was checked. Now multiparts are searched
recursively. The first 'text/plain' part found is taken as orders,
subsequent ones are treated as attachments like other parts with a
different MIME type.
This fixes problems with memoryhole protected-headers implemented in
recent Thunderbird/Enigmail and possibly other MUA's specific
constructs.