Class: Rockdove::ExchangeMail

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/rockdove/exchange_mail.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mail_item, connection) ⇒ ExchangeMail

Returns a new instance of ExchangeMail.



15
16
17
18
# File 'lib/rockdove/exchange_mail.rb', line 15

def initialize(mail_item, connection)
  @mail_item = mail_item
  @connection = connection
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



13
14
15
# File 'lib/rockdove/exchange_mail.rb', line 13

def connection
  @connection
end

Instance Method Details

#attachmentsObject

Retrieve collection of attachments by accessing Rockdove::ExchangeMail @class_instance.attachments



59
60
61
# File 'lib/rockdove/exchange_mail.rb', line 59

def attachments
  @mail_item.attachments
end

#bodyObject

Retrieve parsed body content of the mail by accessing Rockdove::ExchangeMail @class_instance.body



41
42
43
44
45
46
# File 'lib/rockdove/exchange_mail.rb', line 41

def body
  content = ""
  mail = get_items(@mail_item)
  content = parse_it(mail.first.body, mail.first.body_type) unless mail.first.body.empty?
  content.force_encoding('UTF-8')  
end

#cc_recipientsObject

Get a list of cc recipients by accessing Rockdove::ExchangeMail @class_instance.cc_recipients



26
27
28
# File 'lib/rockdove/exchange_mail.rb', line 26

def cc_recipients
  @mail_item.cc_recipients.collect &:email_address if @mail_item.cc_recipients
end

#date_time_createdObject

Retrieve date_time_created of the mail by accessing Rockdove::ExchangeMail @class_instance.date_time_created



73
74
75
# File 'lib/rockdove/exchange_mail.rb', line 73

def date_time_created
  @mail_item.date_time_created
end

#date_time_sentObject

Retrieve date_time_sent of the mail by accessing Rockdove::ExchangeMail @class_instance.date_time_sent



78
79
80
# File 'lib/rockdove/exchange_mail.rb', line 78

def date_time_sent
  @mail_item.date_time_sent
end

#fromObject

Retrieve from email address by accessing Rockdove::ExchangeMail @class_instance.from



31
32
33
# File 'lib/rockdove/exchange_mail.rb', line 31

def from
  @mail_item.from.email_address if @mail_item.from
end

#get_items(mail) ⇒ Object

Retrieves the mail item with text type body content



49
50
51
# File 'lib/rockdove/exchange_mail.rb', line 49

def get_items(mail)
  @connection.get_items([mail.id], nil, {:item_shape => retrieve_text_type})
end

#has_attachments?Boolean

Has attachments boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/rockdove/exchange_mail.rb', line 54

def has_attachments?
  @mail_item.has_attachments?
end

#parse_it(mail_body, type) ⇒ Object

This method parses the mail content provided @params of body and body_type



83
84
85
# File 'lib/rockdove/exchange_mail.rb', line 83

def parse_it(mail_body, type)
  Rockdove::EmailParser.parse_mail(mail_body, type)
end

#retrieve_text_typeObject

Retrieves text type body content of the mail



88
89
90
# File 'lib/rockdove/exchange_mail.rb', line 88

def retrieve_text_type
  {:base_shape=>"AllProperties", :body_type=>"Text"}
end

#save_to_file(attachment, base_dir, file_name) ⇒ Object

Saves the attachment to a file by accessing Rockdove::ExchangeMail @class_instance.save_to_file with args attachment_object_from_rockdove::exchange_mail.attachments, base_dir, file_name



64
65
66
67
68
69
70
# File 'lib/rockdove/exchange_mail.rb', line 64

def save_to_file(attachment, base_dir, file_name)
  base_dir << '/' unless(base_dir.nil? or base_dir.end_with?('/'))
  File.open("#{base_dir}#{file_name}", 'w+b') do |f|
    f.write(Base64.decode64(attachment.content))
  end
  true      
end

#subjectObject

Retrieve subject of the mail by accessing Rockdove::ExchangeMail @class_instance.subject



36
37
38
# File 'lib/rockdove/exchange_mail.rb', line 36

def subject
  @mail_item.subject
end

#to_recipientsObject

Get a list of to recipients by accessing Rockdove::ExchangeMail @class_instance.to_recipients



21
22
23
# File 'lib/rockdove/exchange_mail.rb', line 21

def to_recipients
  @mail_item.to_recipients.collect &:email_address if @mail_item.to_recipients
end