class Mail::PartsList

Attributes

parts[R]

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/mail/parts_list.rb, line 8
def initialize(*args)
  @parts = Array.new(*args)
  super @parts
end

Public Instance Methods

attachments() click to toggle source
# File lib/mail/parts_list.rb, line 24
def attachments
  Mail::AttachmentsList.new(@parts)
end
collect() { |o| ... } click to toggle source
# File lib/mail/parts_list.rb, line 28
def collect
  if block_given?
    ary = PartsList.new
    each { |o| ary << yield(o) }
    ary
  else
    to_a
  end
end
Also aliased as: map
collect!() click to toggle source
# File lib/mail/parts_list.rb, line 43
def collect!
  raise NoMethodError, "#collect! is not defined, please call #collect and create a new PartsList"
end
inspect_structure(parent_id = '') click to toggle source
# File lib/mail/parts_list.rb, line 47
def inspect_structure(parent_id = '')
  enum_for(:map).with_index { |part, i|
    i = i + 1 # Use 1-based indexes since this is for humans to read
    id = parent_id.empty? ? "#{i}" : "#{parent_id}.#{i}"
    if part.content_type == "message/rfc822"
      sub_list = Mail.new(part.body).parts
    else
      sub_list = part.parts
    end
    id + '. ' + part.inspect +
      if sub_list.any?
        "\n" + sub_list.inspect_structure(id)
      end.to_s
  }.join("\n")
end
map()
Alias for: collect
map!() click to toggle source
# File lib/mail/parts_list.rb, line 39
def map!
  raise NoMethodError, "#map! is not defined, please call #collect and create a new PartsList"
end
recursive_delete_if() { |part).tap {| ... } click to toggle source
# File lib/mail/parts_list.rb, line 83
def recursive_delete_if
  delete_if { |part|
    if part.content_type == "message/rfc822"
      sub_list = Mail.new(part.body).parts
    else
      sub_list = part.parts
    end
    (yield part).tap {
      if sub_list.any?
        sub_list.recursive_delete_if {|part| yield part }
      end
recursive_each() { |part| ... } click to toggle source
# File lib/mail/parts_list.rb, line 63
def recursive_each(&block)
  each do |part|
    if part.content_type == "message/rfc822"
      sub_list = Mail.new(part.body).parts
    else
      sub_list = part.parts
    end

    yield part

    sub_list.recursive_each(&block)
  end
end
recursive_size() click to toggle source
# File lib/mail/parts_list.rb, line 77
def recursive_size
  i = 0
  recursive_each {|p| i += 1 }
  i
end