Class: Zm::Client::Message

Inherits:
Base::Object show all
Includes:
BelongsToFolder, BelongsToTag
Defined in:
lib/zm/client/message/message.rb,
lib/zm/client/message/message_flags.rb,
lib/zm/client/message/message_recipients.rb,
lib/zm/client/message/attachments_collection.rb

Overview

class message for account

Defined Under Namespace

Classes: Attachment, AttachmentsCollection, Body, FlagsCollection, Recipient, Recipients

Instance Attribute Summary collapse

Attributes inherited from Base::Object

#name, #parent, #token

Instance Method Summary collapse

Methods included from BelongsToTag

#tags

Methods included from BelongsToFolder

#folder, #folder!, #folder=, #folder_id, #move!, #trash!

Methods inherited from Base::Object

#clone, #inspect, #instance_variables_map, #logger, #recorded?, #save!, #to_h, #to_s, #update_attribute

Constructor Details

#initialize(parent) {|_self| ... } ⇒ Message

Returns a new instance of Message.

Yields:

  • (_self)

Yield Parameters:



14
15
16
17
18
19
# File 'lib/zm/client/message/message.rb', line 14

def initialize(parent)
  @parent = parent
  @subject = ''

  yield(self) if block_given?
end

Instance Attribute Details

#autoSendTimeObject

Returns the value of attribute autoSendTime.



10
11
12
# File 'lib/zm/client/message/message.rb', line 10

def autoSendTime
  @autoSendTime
end

#dObject

Returns the value of attribute d.



10
11
12
# File 'lib/zm/client/message/message.rb', line 10

def d
  @d
end

#fObject

Returns the value of attribute f.



10
11
12
# File 'lib/zm/client/message/message.rb', line 10

def f
  @f
end

#frObject

Returns the value of attribute fr.



10
11
12
# File 'lib/zm/client/message/message.rb', line 10

def fr
  @fr
end

#idObject

Returns the value of attribute id.



10
11
12
# File 'lib/zm/client/message/message.rb', line 10

def id
  @id
end

#idntObject

Returns the value of attribute idnt.



10
11
12
# File 'lib/zm/client/message/message.rb', line 10

def idnt
  @idnt
end

#lObject

Returns the value of attribute l.



10
11
12
# File 'lib/zm/client/message/message.rb', line 10

def l
  @l
end

#midObject

Returns the value of attribute mid.



10
11
12
# File 'lib/zm/client/message/message.rb', line 10

def mid
  @mid
end

#sObject Also known as: size

Returns the value of attribute s.



10
11
12
# File 'lib/zm/client/message/message.rb', line 10

def s
  @s
end

#suObject

Returns the value of attribute su.



10
11
12
# File 'lib/zm/client/message/message.rb', line 10

def su
  @su
end

#subjectObject

Returns the value of attribute subject.



10
11
12
# File 'lib/zm/client/message/message.rb', line 10

def subject
  @subject
end

#tnObject

Returns the value of attribute tn.



10
11
12
# File 'lib/zm/client/message/message.rb', line 10

def tn
  @tn
end

Instance Method Details

#attachmentsObject



27
28
29
30
31
# File 'lib/zm/client/message/message.rb', line 27

def attachments
  return @attachments if defined? @attachments

  @attachments = AttachmentsCollection.new
end

#bodyObject



33
34
35
36
37
# File 'lib/zm/client/message/message.rb', line 33

def body
  return @body if defined? @body

  @body = Body.new
end

#create!(*args) ⇒ Object

Raises:

  • (NotImplementedError)


57
58
59
# File 'lib/zm/client/message/message.rb', line 57

def create!(*args)
  raise NotImplementedError
end

#dateObject



49
50
51
# File 'lib/zm/client/message/message.rb', line 49

def date
  @date ||= Time.at(d.to_i / 1000)
end

#delete!Object



88
89
90
91
92
93
# File 'lib/zm/client/message/message.rb', line 88

def delete!
  return false if @id.nil?

  @parent.sacc.invoke(jsns_builder.to_delete)
  @id = nil
end

#download(dest_file_path, fmt = 'eml') ⇒ Object



39
40
41
42
# File 'lib/zm/client/message/message.rb', line 39

def download(dest_file_path, fmt = 'eml')
  uploader = Upload.new(@parent, RestAccountConnector.new)
  uploader.download_file( Zm::Client::FolderDefault::ROOT[:path], fmt, [Zm::Client::FolderView::MESSAGE], [@id], dest_file_path)
end

#flagsObject



53
54
55
# File 'lib/zm/client/message/message.rb', line 53

def flags
  @flags ||= FlagsCollection.new(self)
end

#jsns_builderObject



117
118
119
# File 'lib/zm/client/message/message.rb', line 117

def jsns_builder
  @jsns_builder ||= MessageJsnsBuilder.new(self)
end

#modify!(*args) ⇒ Object

Raises:

  • (NotImplementedError)


61
62
63
# File 'lib/zm/client/message/message.rb', line 61

def modify!(*args)
  raise NotImplementedError
end

#read(fmt = 'eml') ⇒ Object



44
45
46
47
# File 'lib/zm/client/message/message.rb', line 44

def read(fmt = 'eml')
  uploader = Upload.new(@parent, RestAccountConnector.new)
  uploader.read_file( Zm::Client::FolderDefault::ROOT[:path], fmt, [Zm::Client::FolderView::MESSAGE], [@id])
end

#recipientsObject



21
22
23
24
25
# File 'lib/zm/client/message/message.rb', line 21

def recipients
  return @recipients if defined? @recipients

  @recipients = Recipients.new
end

#rename!(*args) ⇒ Object

Raises:

  • (NotImplementedError)


84
85
86
# File 'lib/zm/client/message/message.rb', line 84

def rename!(*args)
  raise NotImplementedError
end

#saccObject



113
114
115
# File 'lib/zm/client/message/message.rb', line 113

def sacc
  @parent.sacc
end

#send!Object



103
104
105
106
# File 'lib/zm/client/message/message.rb', line 103

def send!
  soap_request = SoapElement.mail(SoapMailConstants::SEND_MSG_REQUEST).add_attributes(jsns_builder.to_jsns)
  @parent.sacc.invoke(soap_request)
end

#spam!Object



99
100
101
# File 'lib/zm/client/message/message.rb', line 99

def spam!
  @parent.sacc.invoke(jsns_builder.to_spam)
end

#unspam!Object



95
96
97
# File 'lib/zm/client/message/message.rb', line 95

def unspam!
  @parent.sacc.invoke(jsns_builder.to_unspam)
end

#update!(l: nil, rgb: nil, color: nil, f: nil, tn: nil) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/zm/client/message/message.rb', line 65

def update!(l: nil, rgb: nil, color: nil, f: nil, tn: nil)
  attrs = {
    op: :update,
    id: @id,
    l: l,
    rgb: rgb,
    color: color,
    f: f,
    tn: tn
  }

  attrs.delete_if { |_, v| v.nil? }

  soap_request = SoapElement.mail(SoapMailConstants::MSG_ACTION_REQUEST)
  node_action = SoapElement.create(SoapConstants::ACTION).add_attributes(attrs)
  soap_request.add_node(node_action)
  @parent.sacc.invoke(soap_request)
end