Class: MsgExtractor::Mapi::NamedPropertyMap
- Inherits:
-
Object
- Object
- MsgExtractor::Mapi::NamedPropertyMap
- Defined in:
- lib/msg_extractor/mapi/named_property_map.rb
Overview
Parses the __nameid_version1.0 storage: maps (property-set GUID, numeric LID or string name) pairs to the 0x8000+ property ids used in this file.
Constant Summary collapse
- PS_MAPI =
"00020328-0000-0000-c000-000000000046"- PS_PUBLIC_STRINGS =
"00020329-0000-0000-c000-000000000046"
Class Method Summary collapse
- .format_guid(bytes) ⇒ Object
- .parse(guid_stream, entry_stream, string_stream) ⇒ Object
- .read(cfbf, storage) ⇒ Object
Instance Method Summary collapse
-
#initialize(map) ⇒ NamedPropertyMap
constructor
A new instance of NamedPropertyMap.
- #resolve(guid, name_or_lid) ⇒ Object
Constructor Details
#initialize(map) ⇒ NamedPropertyMap
Returns a new instance of NamedPropertyMap.
64 65 66 |
# File 'lib/msg_extractor/mapi/named_property_map.rb', line 64 def initialize(map) @map = map end |
Class Method Details
.format_guid(bytes) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/msg_extractor/mapi/named_property_map.rb', line 57 def self.format_guid(bytes) return "00000000-0000-0000-0000-000000000000" if bytes.nil? || bytes.bytesize < 16 d1, d2, d3 = bytes.unpack("Vvv") format("%08x-%04x-%04x-%s-%s", d1, d2, d3, bytes.byteslice(8, 2).unpack1("H4"), bytes.byteslice(10, 6).unpack1("H12")) end |
.parse(guid_stream, entry_stream, string_stream) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/msg_extractor/mapi/named_property_map.rb', line 25 def self.parse(guid_stream, entry_stream, string_stream) map = {} (entry_stream.bytesize / 8).times do |i| name_id, info, prop_index = entry_stream.byteslice(i * 8, 8).unpack("Vvv") guid_index = info >> 1 guid = case guid_index when 1 then PS_MAPI when 2 then PS_PUBLIC_STRINGS else if guid_index >= 3 format_guid(guid_stream.byteslice((guid_index - 3) * 16, 16)) else "00000000-0000-0000-0000-000000000000" end end key = if (info & 1) == 1 length = string_stream.byteslice(name_id, 4)&.unpack1("V") next if length.nil? raw = string_stream.byteslice(name_id + 4, length) || "".b raw.force_encoding(Encoding::UTF_16LE) .encode(Encoding::UTF_8, invalid: :replace, undef: :replace) .downcase else name_id end map[[guid, key]] = 0x8000 + prop_index end new(map) end |
.read(cfbf, storage) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/msg_extractor/mapi/named_property_map.rb', line 9 def self.read(cfbf, storage) nameid = storage.children["__NAMEID_VERSION1.0"] return new({}) unless nameid&.storage? guid_stream = read_child(cfbf, nameid, "__SUBSTG1.0_00020102") entry_stream = read_child(cfbf, nameid, "__SUBSTG1.0_00030102") string_stream = read_child(cfbf, nameid, "__SUBSTG1.0_00040102") parse(guid_stream, entry_stream, string_stream) end |
Instance Method Details
#resolve(guid, name_or_lid) ⇒ Object
68 69 70 71 |
# File 'lib/msg_extractor/mapi/named_property_map.rb', line 68 def resolve(guid, name_or_lid) key = name_or_lid.is_a?(::String) ? name_or_lid.downcase : name_or_lid @map[[guid.downcase, key]] end |