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(desc, list, type = nil) ⇒ Item

Returns a new instance of Item.



1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
# File 'lib/mapi/pst.rb', line 1537

def initialize desc, list, type=nil
	@desc = desc
	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
		desc.pst.special_folder_ids[ipm_wastebasket_entryid] = :wastebasket
	end

	if finder_entryid
		desc.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 = desc.pst.special_folder_ids[desc.desc_id] || type
		end
	end

	@type = type
end

Instance Attribute Details

#parentObject

Returns the value of attribute parent.



1535
1536
1537
# File 'lib/mapi/pst.rb', line 1535

def parent
  @parent
end

#typeObject

Returns the value of attribute type.



1535
1536
1537
# File 'lib/mapi/pst.rb', line 1535

def type
  @type
end

Instance Method Details

#attachmentsObject

i think i will change these, so they can inherit the lazyness from RawPropertyStoreTable. so if you want the last attachment, you can get it without creating the others perhaps. it just has to handle the no table at all case a bit more gracefully.



1648
1649
1650
# File 'lib/mapi/pst.rb', line 1648

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

#childrenObject



1605
1606
1607
# File 'lib/mapi/pst.rb', line 1605

def children
	to_enum(:each_child).to_a
end

#each_childObject



1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
# File 'lib/mapi/pst.rb', line 1569

def each_child
	id = ipm_subtree_entryid
	if id
		root = @desc.pst.desc_from_id id
		raise "couldn't find root" unless root
		raise 'both kinds of children' unless @desc.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 = @desc.pst.desc_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
		@desc.children
	end.each do |desc|
		item = @desc.pst.pst_parse_item(desc)
		item.parent = self
		yield item
	end
end

#each_recursive(&block) ⇒ Object



1657
1658
1659
1660
1661
1662
1663
1664
# File 'lib/mapi/pst.rb', line 1657

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



1622
1623
1624
# File 'lib/mapi/pst.rb', line 1622

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

#inspectObject



1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
# File 'lib/mapi/pst.rb', line 1666

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 = 'desc_id=0x%x' % @desc.desc_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



1612
1613
1614
# File 'lib/mapi/pst.rb', line 1612

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



1617
1618
1619
# File 'lib/mapi/pst.rb', line 1617

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

#pathObject



1597
1598
1599
1600
1601
1602
1603
# File 'lib/mapi/pst.rb', line 1597

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

#recipientsObject



1652
1653
1654
1655
# File 'lib/mapi/pst.rb', line 1652

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