Class: MsgExtractor::MessageObject
- Inherits:
-
Object
- Object
- MsgExtractor::MessageObject
show all
- Defined in:
- lib/msg_extractor/message_object.rb
Overview
Shared base for every MSG item type: property access, bodies, recipients, attachments. Works for the root message and for embedded messages.
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(cfbf, storage: nil, named: nil, kind: :root, properties: nil) ⇒ MessageObject
Returns a new instance of MessageObject.
11
12
13
14
15
16
17
|
# File 'lib/msg_extractor/message_object.rb', line 11
def initialize(cfbf, storage: nil, named: nil, kind: :root, properties: nil)
@cfbf = cfbf
@storage = storage || cfbf.root
@kind = kind
@properties = properties || Mapi::PropertyStore.new(cfbf, @storage, kind)
@named = named || Mapi::NamedPropertyMap.read(cfbf, @storage)
end
|
Instance Attribute Details
#named ⇒ Object
:nodoc: internal reuse by MsgExtractor.from_storage
9
10
11
|
# File 'lib/msg_extractor/message_object.rb', line 9
def named
@named
end
|
#properties ⇒ Object
Returns the value of attribute properties.
7
8
9
|
# File 'lib/msg_extractor/message_object.rb', line 7
def properties
@properties
end
|
Instance Method Details
#attachments ⇒ Object
70
71
72
73
|
# File 'lib/msg_extractor/message_object.rb', line 70
def attachments
@attachments ||= child_storages("__ATTACH_VERSION1.0_#")
.map { |e| Attachment.new(@cfbf, e, named: @named) }
end
|
#bcc ⇒ Object
68
|
# File 'lib/msg_extractor/message_object.rb', line 68
def bcc = recipients.select { |r| r.type == Recipient::BCC }
|
#body ⇒ Object
26
27
28
29
|
# File 'lib/msg_extractor/message_object.rb', line 26
def body
return @body if defined?(@body)
@body = properties[Mapi::PR_BODY] || (html_body && Util.html_to_text(html_body))
end
|
#cc ⇒ Object
67
|
# File 'lib/msg_extractor/message_object.rb', line 67
def cc = recipients.select { |r| r.type == Recipient::CC }
|
#message_class ⇒ Object
19
|
# File 'lib/msg_extractor/message_object.rb', line 19
def message_class = properties[Mapi::PR_MESSAGE_CLASS]
|
#named_value(guid, lid_or_name) ⇒ Object
75
76
77
78
|
# File 'lib/msg_extractor/message_object.rb', line 75
def named_value(guid, lid_or_name)
id = @named.resolve(guid, lid_or_name)
id && properties[id]
end
|
#recipients ⇒ Object
61
62
63
64
|
# File 'lib/msg_extractor/message_object.rb', line 61
def recipients
@recipients ||= child_storages("__RECIP_VERSION1.0_#")
.map { |e| Recipient.from_storage(@cfbf, e) }
end
|
#save(dir: ".") ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/msg_extractor/message_object.rb', line 80
def save(dir: ".")
name = Util.sanitize_filename(subject || "message")
base = Util.dedupe_path(::File.join(dir, name))
FileUtils.mkdir_p(base)
::File.write(::File.join(base, "message.txt"), body, encoding: Encoding::UTF_8) if body
::File.binwrite(::File.join(base, "message.html"), html_body.b) if html_body
attachments.each do |attachment|
attachment.save(dir: base) unless attachment.embedded_message?
end
base
end
|
#sender ⇒ Object
53
54
55
56
57
58
59
|
# File 'lib/msg_extractor/message_object.rb', line 53
def sender
return @sender if defined?(@sender)
name = properties[Mapi::PR_SENDER_NAME]
email = properties[Mapi::PR_SENDER_SMTP] || properties[Mapi::PR_SENDER_EMAIL]
email = nil unless email&.include?("@")
@sender = (name || email) && Recipient.new(name: name, email: email, type: nil)
end
|
#subject ⇒ Object
20
|
# File 'lib/msg_extractor/message_object.rb', line 20
def subject = properties[Mapi::PR_SUBJECT]
|
#to ⇒ Object
66
|
# File 'lib/msg_extractor/message_object.rb', line 66
def to = recipients.select { |r| r.type == Recipient::TO }
|