module RIMS::Protocol::FetchParser::Utils
Public Class Methods
encode_bodystructure(array)
click to toggle source
# File lib/rims/protocol/parser.rb, line 811 def encode_bodystructure(array) if ((array.length > 0) && (array.first.is_a? Array)) then s = '('.b array = array.dup begin s << encode_bodystructure(array.shift) end while ((array.length > 0) && (array.first.is_a? Array)) s << ' '.b << array.map{|i| encode_value(i) }.join(' '.b) s << ')'.b elsif ((array.length > 0) && (array.first.upcase == 'MESSAGE')) then msg_body_list = array[0..7].map{|v| encode_value(v) } msg_body_list << encode_bodystructure(array[8]) msg_body_list << array[9..-1].map{|v| encode_value(v) } '('.b << msg_body_list.join(' '.b) << ')'.b else encode_list(array) end end
encode_header(name_value_pair_list)
click to toggle source
# File lib/rims/protocol/parser.rb, line 831 def encode_header(name_value_pair_list) name_value_pair_list.map{|n, v| ''.b << n << ': ' << v << "\r\n" }.join('') << "\r\n" end
encode_list(array)
click to toggle source
# File lib/rims/protocol/parser.rb, line 803 def encode_list(array) unless (array.is_a? Array) then raise TypeError, 'not a array type.' end encode_value(array) end
encode_value(object)
click to toggle source
# File lib/rims/protocol/parser.rb, line 785 def encode_value(object) case (object) when Symbol object.to_s when String Protocol.quote(object) when Integer object.to_s when NilClass 'NIL'.b when Array '('.b << object.map{|v| encode_value(v) }.join(' '.b) << ')'.b else raise "unknown value: #{object}" end end
get_body_content(mail, name, nest_mail: false)
click to toggle source
# File lib/rims/protocol/parser.rb, line 863 def get_body_content(mail, name, nest_mail: false) if (nest_mail) then if (mail.message?) then mail.message.__send__(name) else nil end else mail.__send__(name) end end
get_body_section(mail, index_list)
click to toggle source
# File lib/rims/protocol/parser.rb, line 836 def get_body_section(mail, index_list) if (index_list.empty?) then mail else i, *next_index_list = index_list unless (i > 0) then raise SyntaxError, "not a none-zero body section number: #{i}" end if (mail.multipart?) then get_body_section(mail.parts[i - 1], next_index_list) elsif (mail.message?) then get_body_section(mail.message, index_list) else if (i == 1) then if (next_index_list.empty?) then mail else nil end else nil end end end end
Private Instance Methods
encode_bodystructure(array)
click to toggle source
# File lib/rims/protocol/parser.rb, line 811 def encode_bodystructure(array) if ((array.length > 0) && (array.first.is_a? Array)) then s = '('.b array = array.dup begin s << encode_bodystructure(array.shift) end while ((array.length > 0) && (array.first.is_a? Array)) s << ' '.b << array.map{|i| encode_value(i) }.join(' '.b) s << ')'.b elsif ((array.length > 0) && (array.first.upcase == 'MESSAGE')) then msg_body_list = array[0..7].map{|v| encode_value(v) } msg_body_list << encode_bodystructure(array[8]) msg_body_list << array[9..-1].map{|v| encode_value(v) } '('.b << msg_body_list.join(' '.b) << ')'.b else encode_list(array) end end
encode_header(name_value_pair_list)
click to toggle source
# File lib/rims/protocol/parser.rb, line 831 def encode_header(name_value_pair_list) name_value_pair_list.map{|n, v| ''.b << n << ': ' << v << "\r\n" }.join('') << "\r\n" end
encode_list(array)
click to toggle source
# File lib/rims/protocol/parser.rb, line 803 def encode_list(array) unless (array.is_a? Array) then raise TypeError, 'not a array type.' end encode_value(array) end
encode_value(object)
click to toggle source
# File lib/rims/protocol/parser.rb, line 785 def encode_value(object) case (object) when Symbol object.to_s when String Protocol.quote(object) when Integer object.to_s when NilClass 'NIL'.b when Array '('.b << object.map{|v| encode_value(v) }.join(' '.b) << ')'.b else raise "unknown value: #{object}" end end
get_body_content(mail, name, nest_mail: false)
click to toggle source
# File lib/rims/protocol/parser.rb, line 863 def get_body_content(mail, name, nest_mail: false) if (nest_mail) then if (mail.message?) then mail.message.__send__(name) else nil end else mail.__send__(name) end end
get_body_section(mail, index_list)
click to toggle source
# File lib/rims/protocol/parser.rb, line 836 def get_body_section(mail, index_list) if (index_list.empty?) then mail else i, *next_index_list = index_list unless (i > 0) then raise SyntaxError, "not a none-zero body section number: #{i}" end if (mail.multipart?) then get_body_section(mail.parts[i - 1], next_index_list) elsif (mail.message?) then get_body_section(mail.message, index_list) else if (i == 1) then if (next_index_list.empty?) then mail else nil end else nil end end end end