class Hermes::Multipart
Constants
- BOUNDARY_CHARS
- BOUNDARY_CHARS_STD
- MIME
Attributes
boundary[R]
epilog[R]
list[R]
prolog[R]
Public Class Methods
new(boundary, prolog, list, epilog)
click to toggle source
# File lib/hermes/message.rb, line 153 def initialize boundary, prolog, list, epilog @boundary = boundary.notempty? @prolog, @list, @epilog = prolog, list, epilog end
Public Instance Methods
[](num)
click to toggle source
# File lib/hermes/message.rb, line 193 def [] num @list[ num] end
boundary!()
click to toggle source
# File lib/hermes/message.rb, line 158 def boundary! b = BOUNDARY_CHARS_STD.length r = Time.now.strftime "%Y%m%d%H%M%S." 16.times { r << BOUNDARY_CHARS_STD[ (rand b)].chr } @boundary = r end
each(&block)
click to toggle source
# File lib/hermes/message.rb, line 197 def each &block @list.each &block end
inspect()
click to toggle source
# File lib/hermes/message.rb, line 165 def inspect r = "" r << "#<#{cls}:" r << "0x%x" % (object_id<<1) r << " n=#{@list.length}" r << ">" end
length()
click to toggle source
# File lib/hermes/message.rb, line 201 def length ; @list.length ; end
parse(input, parameters)
click to toggle source
# File lib/hermes/message.rb, line 133 def parse input, parameters b = parameters[ :boundary] b or raise ParseError, "Missing boundary parameter." PartFile.open input, b do |partfile| list = [] while partfile.next_part do m = Message.parse partfile list.push m end new b, partfile.prolog, list, partfile.epilog end end
to_s()
click to toggle source
# File lib/hermes/message.rb, line 173 def to_s @boundary or raise IllegalBoundary r = "" splitter = "--#@boundary" re = /#{Regexp.quote @boundary}/ @prolog =~ re and raise IllegalBoundary r << @prolog @list.each { |p| s = p.to_s s =~ re rescue nil $& and raise IllegalBoundary r << splitter << $/ << s << $/ } @epilog =~ re and raise IllegalBoundary r << splitter << "--" << @epilog rescue IllegalBoundary boundary! retry end