Class: Mapi::Msg

Inherits:
Message show all
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, Recipient

Constant Summary

Constants inherited from Message

Mapi::Message::CONVERSION_MAP

Instance Attribute Summary collapse

Attributes inherited from Item

#properties

Class Method Summary collapse

Instance Method Summary collapse

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

Parameters:

  • root (Ole::Storage::Dirent)
  • helper (Helper)


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_parentBoolean

Returns:

  • (Boolean)


375
376
377
# File 'lib/mapi/msg.rb', line 375

def close_parent
  @close_parent
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).

Parameters:

  • arg (Object)
  • mode (Object) (defaults to: nil)
  • helper (Helper) (defaults to: nil)

Returns:

  • (Ole::Storage::Dirent)


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

Instance Method Details

#attachmentsArray<Attachment>

Returns:



422
423
424
425
426
427
# File 'lib/mapi/msg.rb', line 422

def attachments
	@attachments ||= @root.children.
		select { |child| child.dir? and child.name =~ ATTACH_RX }.
		map { |child| Attachment.new child, helper }.
		select { |attach| attach.valid? }
end

#closeObject



417
418
419
# File 'lib/mapi/msg.rb', line 417

def close
	@root.ole.close if @close_parent
end

#recipientsArray<Recipient>

Returns:



430
431
432
433
434
# File 'lib/mapi/msg.rb', line 430

def recipients
	@recipients ||= @root.children.
		select { |child| child.dir? and child.name =~ RECIP_RX }.
		map { |child| Recipient.new child, helper }
end