Class: Mapi::Msg
- Defined in:
- lib/mapi/msg.rb,
lib/mapi/convert/note-mime.rb,
lib/mapi/convert/note-tmail.rb
Overview
# Introduction
Primary class interface to the vagaries of .msg files.
The core of the work is done by the PropertyStore class.
Defined Under Namespace
Classes: Attachment, PropertyStore, Recipient
Constant Summary collapse
- ATTACH_RX =
/^__attach_version1\.0_.*/
- RECIP_RX =
/^__recip_version1\.0_.*/
- VALID_RX =
/#{PropertyStore::VALID_RX}|#{ATTACH_RX}|#{RECIP_RX}/
Constants inherited from Message
Instance Attribute Summary collapse
- #close_parent ⇒ Boolean
- #helper ⇒ Helper readonly
- #root ⇒ Ole::Storage::Dirent readonly
Attributes inherited from Item
Class Method Summary collapse
-
.open(arg, mode = nil, helper = nil) ⇒ Ole::Storage::Dirent
Alternate constructor, to create an Msg directly from ‘arg` and `mode`, passed directly to Ole::Storage (ie either filename or seekable IO object).
- .warn_unknown(obj) ⇒ Object
Instance Method Summary collapse
- #attachments ⇒ Array<Attachment>
- #close ⇒ Object
-
#initialize(root, helper) ⇒ Msg
constructor
Create an Msg from ‘root`, an Ole::Storage::Dirent object.
- #populate_headers ⇒ Object
- #recipients ⇒ Array<Recipient>
Methods inherited from Message
#body_to_mime, #body_to_tmail, #convert, #headers, #inspect, #mime, #mime_type, #to_mime, #to_post, #to_tmail, #to_vcard, #type
Constructor Details
#initialize(root, helper) ⇒ Msg
Create an Msg from ‘root`, an Ole::Storage::Dirent object
400 401 402 403 404 405 406 |
# File 'lib/mapi/msg.rb', line 400 def initialize root, helper @root = root @helper = helper @close_parent = false super PropertySet.new(PropertyStore.load(@root, helper)) Msg.warn_unknown @root end |
Instance Attribute Details
#close_parent ⇒ Boolean
375 376 377 |
# File 'lib/mapi/msg.rb', line 375 def close_parent @close_parent end |
#root ⇒ Ole::Storage::Dirent (readonly)
370 371 372 |
# File 'lib/mapi/msg.rb', line 370 def root @root end |
Class Method Details
.open(arg, mode = nil, helper = nil) ⇒ Ole::Storage::Dirent
Alternate constructor, to create an Mapi::Msg directly from ‘arg` and `mode`, passed directly to Ole::Storage (ie either filename or seekable IO object).
384 385 386 387 388 389 390 391 392 393 394 |
# File 'lib/mapi/msg.rb', line 384 def self.open arg, mode=nil, helper=nil msg = new Ole::Storage.open(arg, mode).root, helper || Helper.new # we will close the ole when we are #closed msg.close_parent = true if block_given? begin yield msg ensure; msg.close end else msg end end |
.warn_unknown(obj) ⇒ Object
410 411 412 413 414 415 |
# File 'lib/mapi/msg.rb', line 410 def self.warn_unknown obj # bit of validation. not important if there is extra stuff, though would be # interested to know what it is. doesn't check dir/file stuff. unknown = obj.children.reject { |child| child.name =~ VALID_RX } Log.warn "skipped #{unknown.length} unknown msg object(s)" unless unknown.empty? end |
Instance Method Details
#attachments ⇒ Array<Attachment>
422 423 424 425 426 427 |
# File 'lib/mapi/msg.rb', line 422 def @attachments ||= @root.children. select { |child| child.dir? and child.name =~ ATTACH_RX }. map { |child| Attachment.new child, helper }. select { |attach| attach.valid? } end |
#close ⇒ Object
417 418 419 |
# File 'lib/mapi/msg.rb', line 417 def close @root.ole.close if @close_parent end |
#populate_headers ⇒ Object
275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/mapi/convert/note-mime.rb', line 275 def populate_headers super if !headers.has_key?('Date') # can employ other methods for getting a time. heres one in a similar vein to msgconvert.pl, # ie taking the time from an ole object time = @root.ole.dirents.map { |dirent| dirent.modify_time || dirent.create_time }.compact.sort.last headers['Date'] = [Time.iso8601(time.to_s).rfc2822] if time # https://github.com/Scompler/ruby-msg/commit/86e2036f1a1b9b7eeb7a7abdea7a8054ef6ab6cf # headers['Date'] = [time.rfc2822] if time end end |