Class: MsgExtractor::Recipient

Inherits:
Object
  • Object
show all
Defined in:
lib/msg_extractor/recipient.rb

Constant Summary collapse

TO =
1
CC =
2
BCC =
3

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, email:, type:) ⇒ Recipient

Returns a new instance of Recipient.



9
10
11
12
13
# File 'lib/msg_extractor/recipient.rb', line 9

def initialize(name:, email:, type:)
  @name = name
  @email = email
  @type = type
end

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



7
8
9
# File 'lib/msg_extractor/recipient.rb', line 7

def email
  @email
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/msg_extractor/recipient.rb', line 7

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/msg_extractor/recipient.rb', line 7

def type
  @type
end

Class Method Details

.from_storage(cfbf, storage) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/msg_extractor/recipient.rb', line 15

def self.from_storage(cfbf, storage)
  props = Mapi::PropertyStore.new(cfbf, storage, :recipient)
  email = props[Mapi::PR_SMTP_ADDRESS]
  if email.nil?
    address = props[Mapi::PR_EMAIL_ADDRESS]
    email = address if address&.include?("@")
  end
  new(name: props[Mapi::PR_DISPLAY_NAME], email: email,
      type: props[Mapi::PR_RECIPIENT_TYPE] || TO)
end

Instance Method Details

#to_sObject



26
27
28
29
30
31
32
# File 'lib/msg_extractor/recipient.rb', line 26

def to_s
  if name && email && name != email
    "#{name} <#{email}>"
  else
    (email || name).to_s
  end
end