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 Msg::PropertyStore class.

Defined Under Namespace

Classes: Attachment, PropertyStore, Recipient

Constant Summary collapse

ATTACH_RX =

these 2 will actually be of the form 1.0_#(8), where $1 is the 0 based index number in hex should i parse that and use it as an index, or just return in file order? probably should use it later…

/^__attach_version1\.0_.*/
RECIP_RX =
/^__recip_version1\.0_.*/
VALID_RX =
/#{PropertyStore::VALID_RX}|#{ATTACH_RX}|#{RECIP_RX}/

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) ⇒ Msg

Create an Msg from root, an Ole::Storage::Dirent object



352
353
354
355
356
357
# File 'lib/mapi/msg.rb', line 352

def initialize root
	@root = root
	@close_parent = false
	super PropertySet.new(PropertyStore.load(@root))
	Msg.warn_unknown @root
end

Instance Attribute Details

#close_parentObject

Returns the value of attribute close_parent.



335
336
337
# File 'lib/mapi/msg.rb', line 335

def close_parent
  @close_parent
end

#rootObject (readonly)

Returns the value of attribute root.



334
335
336
# File 'lib/mapi/msg.rb', line 334

def root
  @root
end

Class Method Details

.open(arg, mode = nil) ⇒ Object

Alternate constructor, to create an Msg directly from arg and mode, passed directly to Ole::Storage (ie either filename or seekable IO object).



339
340
341
342
343
344
345
346
347
348
349
# File 'lib/mapi/msg.rb', line 339

def self.open arg, mode=nil
	msg = new Ole::Storage.open(arg, mode).root
	# 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



359
360
361
362
363
364
# File 'lib/mapi/msg.rb', line 359

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

#attachmentsObject



370
371
372
373
374
375
# File 'lib/mapi/msg.rb', line 370

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

#closeObject



366
367
368
# File 'lib/mapi/msg.rb', line 366

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

#populate_headersObject



263
264
265
266
267
268
269
270
271
# File 'lib/mapi/convert/note-mime.rb', line 263

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
	end
end

#recipientsObject



377
378
379
380
381
# File 'lib/mapi/msg.rb', line 377

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