Class: Mapi::Pst::Item

Inherits:
Message show all
Includes:
RecursivelyEnumerable
Defined in:
lib/mapi/pst.rb

Defined Under Namespace

Classes: EntryID

Constant Summary

Constants inherited from Message

Message::CONVERSION_MAP

Instance Attribute Summary collapse

Attributes inherited from Item

#properties

Instance Method Summary collapse

Methods inherited from Message

#body_to_mime, #body_to_tmail, #convert, #headers, #mime, #mime_type, #populate_headers, #to_mime, #to_post, #to_tmail, #to_vcard

Constructor Details

#initialize(node, list, type = nil) ⇒ Item

Returns a new instance of Item.

Parameters:

  • node (NodePtr)
  • list (Array)
  • type (Object, nil) (defaults to: nil)


1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
# File 'lib/mapi/pst.rb', line 1686

def initialize node, list, type=nil
	@node = node
	super Pst.make_property_set(list)

	# this is kind of weird, but the ids of the special folders are stored in a hash
	# when the root item is loaded
	if ipm_wastebasket_entryid
		node.pst.special_folder_ids[ipm_wastebasket_entryid] = :wastebasket
	end

	if finder_entryid
		node.pst.special_folder_ids[finder_entryid] = :finder
	end

	# and then here, those are used, along with a crappy heuristic to determine if we are an
	# item
=begin
i think the low bits of the desc_id can give some info on the type.

it seems that 0x4 is for regular messages (and maybe contacts etc)
0x2 is for folders, and 0x8 is for special things like rules etc, that aren't visible.
=end
	unless type
		type = props.valid_folder_mask || ipm_subtree_entryid || props.content_count || props.subfolders ? :folder : :message
		if type == :folder
			type = node.pst.special_folder_ids[node.node_id] || type
		end
	end

	@type = type
end

Instance Attribute Details

#parentItem

Returns:



1681
1682
1683
# File 'lib/mapi/pst.rb', line 1681

def parent
  @parent
end

#typeSymbol

Obtain item type

  • ‘:folder`

  • ‘:message`

  • ‘:wastebasket`

Returns:

  • (Symbol)


1678
1679
1680
# File 'lib/mapi/pst.rb', line 1678

def type
  @type
end

Instance Method Details

#attachmentsArray<Attachment>

Returns:



1811
1812
1813
# File 'lib/mapi/pst.rb', line 1811

def attachments
	@attachments ||= AttachmentTable.new(@node).to_a.map { |list| Attachment.new list }
end

#childrenArray<Item>

Enumerate direct children

Returns:



1761
1762
1763
# File 'lib/mapi/pst.rb', line 1761

def children
	to_enum(:each_child).to_a
end

#each_child {|item| ... } ⇒ void

This method returns an undefined value.

Yields:

  • (item)

Yield Parameters:



1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
# File 'lib/mapi/pst.rb', line 1721

def each_child
	id = ipm_subtree_entryid
	if id
		root = @node.pst.node_from_id id
		raise "couldn't find root" unless root
		raise 'both kinds of children' unless @node.children.empty?
		children = root.children
		# lets look up the other ids we have.
		# typically the wastebasket one "deleted items" is in the children already, but
		# the search folder isn't.
		extras = [ipm_wastebasket_entryid, finder_entryid].compact.map do |id|
			root = @node.pst.node_from_id id
			warn "couldn't find root for id #{id}" unless root
			root
		end.compact
		# i do this instead of union, so as not to mess with the order of the
		# existing children.
		children += (extras - children)
		children
	else
		@node.children
	end.each do |node|
		item = @node.pst.pst_parse_item(node)
		item.parent = self
		yield item
	end
end

#each_recursive {|item| ... } ⇒ void

This method returns an undefined value.

Iterate children (except on this instance) recursively stored in this MessageStore.

Yields:

  • (item)

Yield Parameters:



1826
1827
1828
1829
1830
1831
1832
1833
# File 'lib/mapi/pst.rb', line 1826

def each_recursive(&block)
	#p :self => self
	children.each do |child|
		#p :child => child
		block[child]
		child.each_recursive(&block)
	end
end

#finder_entryidObject

Search Root Record



1784
1785
1786
# File 'lib/mapi/pst.rb', line 1784

def finder_entryid
	@finder_entryid ||= EntryID.new(props.finder_entryid.read).id rescue nil
end

#inspectObject



1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
# File 'lib/mapi/pst.rb', line 1835

def inspect
	attrs = %w[display_name subject sender_name subfolders]
#			attrs = %w[display_name valid_folder_mask ipm_wastebasket_entryid finder_entryid content_count subfolders]
	str = attrs.map { |a| b = props.send a; " #{a}=#{b.inspect}" if b }.compact * ','

	type_s = type == :message ? 'Message' : type == :folder ? 'Folder' : type.to_s.capitalize + 'Folder'
	str2 = 'node_id=0x%x' % @node.node_id

	!str.empty? ? "#<Pst::#{type_s} #{str2}#{str}>" : "#<Pst::#{type_s} #{str2} props=#{props.inspect}>" #\n" + props.transport_message_headers + ">"
end

#ipm_subtree_entryidObject

Top of Personal Folder Record



1770
1771
1772
# File 'lib/mapi/pst.rb', line 1770

def ipm_subtree_entryid
	@ipm_subtree_entryid ||= EntryID.new(props.ipm_subtree_entryid.read).id rescue nil
end

#ipm_wastebasket_entryidObject

Deleted Items Folder Record



1777
1778
1779
# File 'lib/mapi/pst.rb', line 1777

def ipm_wastebasket_entryid
	@ipm_wastebasket_entryid ||= EntryID.new(props.ipm_wastebasket_entryid.read).id rescue nil
end

#pathString

Returns:

  • (String)


1750
1751
1752
1753
1754
1755
1756
# File 'lib/mapi/pst.rb', line 1750

def path
	parents, item = [], self
	parents.unshift item while item = item.parent
	# remove root
	parents.shift
	parents.map { |item| item.props.display_name or raise 'unable to construct path' } * '/'
end

#recipientsArray<Recipient>

Returns:



1816
1817
1818
1819
# File 'lib/mapi/pst.rb', line 1816

def recipients
	#[]
	@recipients ||= RecipientTable.new(@node).to_a.map { |list| Recipient.new list }
end