zm-ruby-client 0.18.5 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/Gemfile +2 -2
- data/README.md +7 -0
- data/lib/zm/client/account/account.rb +31 -308
- data/lib/zm/client/account/account_aliases_collection.rb +52 -0
- data/lib/zm/client/account/account_dls_membership_collection.rb +4 -1
- data/lib/zm/client/account/account_dls_owner_collection.rb +8 -1
- data/lib/zm/client/account/account_jsns_builder.rb +77 -0
- data/lib/zm/client/account/account_jsns_initializer.rb +9 -24
- data/lib/zm/client/account/accounts_builder.rb +0 -1
- data/lib/zm/client/account/accounts_collection.rb +32 -8
- data/lib/zm/client/account.rb +1 -0
- data/lib/zm/client/ace/ace.rb +6 -22
- data/lib/zm/client/ace/ace_jsns_builder.rb +15 -16
- data/lib/zm/client/ace/ace_jsns_initializer.rb +0 -1
- data/lib/zm/client/ace/aces_builder.rb +0 -1
- data/lib/zm/client/ace/aces_collection.rb +2 -18
- data/lib/zm/client/appointment/appointment.rb +38 -30
- data/lib/zm/client/appointment/appointment_jsns_builder.rb +22 -34
- data/lib/zm/client/appointment/appointment_jsns_initializer.rb +6 -3
- data/lib/zm/client/appointment/appointments_builder.rb +6 -18
- data/lib/zm/client/appointment/appointments_collection.rb +25 -4
- data/lib/zm/client/backup/backup.rb +4 -32
- data/lib/zm/client/backup/backup_jsns_initializer.rb +26 -0
- data/lib/zm/client/backup/backups_builder.rb +8 -13
- data/lib/zm/client/backup/backups_collection.rb +2 -1
- data/lib/zm/client/backup.rb +1 -0
- data/lib/zm/client/base/account_search_objects_collection.rb +34 -13
- data/lib/zm/client/base/admin_objects_collection.rb +82 -17
- data/lib/zm/client/base/base_account_jsns_builder.rb +98 -0
- data/lib/zm/client/base/base_jsns_builder.rb +47 -0
- data/lib/zm/client/base/base_jsns_initializer.rb +43 -12
- data/lib/zm/client/base/ldap_filter.rb +20 -5
- data/lib/zm/client/base/mailbox_infos_collection.rb +68 -0
- data/lib/zm/client/base/mailbox_object.rb +299 -0
- data/lib/zm/client/base/mailbox_prefs_collection.rb +75 -0
- data/lib/zm/client/base/object.rb +28 -62
- data/lib/zm/client/base/objects_builder.rb +4 -10
- data/lib/zm/client/base/objects_collection.rb +13 -10
- data/lib/zm/client/base/zimbra_attribute.rb +10 -8
- data/lib/zm/client/base/zimbra_attributes_collection.rb +154 -10
- data/lib/zm/client/base.rb +5 -5
- data/lib/zm/client/cluster/cluster.rb +43 -39
- data/lib/zm/client/cluster/cluster_config.rb +5 -5
- data/lib/zm/client/common/recipients.rb +3 -3
- data/lib/zm/client/common/token_metadata.rb +4 -1
- data/lib/zm/client/common/utils.rb +57 -0
- data/lib/zm/client/common.rb +2 -1
- data/lib/zm/client/connector/rest_account.rb +15 -28
- data/lib/zm/client/connector/soap_account.rb +38 -441
- data/lib/zm/client/connector/soap_admin.rb +16 -552
- data/lib/zm/client/connector/soap_base.rb +30 -21
- data/lib/zm/client/connector/soap_error.rb +1 -3
- data/lib/zm/client/constant.rb +21 -11
- data/lib/zm/client/contact/contact.rb +42 -83
- data/lib/zm/client/contact/contact_jsns_builder.rb +60 -0
- data/lib/zm/client/contact/contact_jsns_initializer.rb +78 -0
- data/lib/zm/client/contact/contact_member.rb +29 -28
- data/lib/zm/client/contact/contact_members_collection.rb +44 -0
- data/lib/zm/client/contact/contacts_builder.rb +8 -1
- data/lib/zm/client/contact/contacts_collection.rb +17 -1
- data/lib/zm/client/contact/group_contact_jsns_builder.rb +51 -0
- data/lib/zm/client/contact/mod_group_contact.rb +4 -67
- data/lib/zm/client/contact.rb +5 -1
- data/lib/zm/client/cos/cos.rb +35 -40
- data/lib/zm/client/cos/cos_accounts_collection.rb +19 -0
- data/lib/zm/client/cos/cos_domains_collection.rb +20 -0
- data/lib/zm/client/cos/cos_jsns_builder.rb +72 -0
- data/lib/zm/client/cos/cos_jsns_initializer.rb +29 -0
- data/lib/zm/client/cos/cos_servers_collection.rb +60 -0
- data/lib/zm/client/cos/coses_builder.rb +8 -1
- data/lib/zm/client/cos/coses_collection.rb +8 -5
- data/lib/zm/client/cos.rb +5 -0
- data/lib/zm/client/datasource/datasource.rb +69 -0
- data/lib/zm/client/datasource/datasource_jsns_builder.rb +32 -0
- data/lib/zm/client/datasource/datasource_jsns_initializer.rb +27 -0
- data/lib/zm/client/datasource/datasources_builder.rb +29 -0
- data/lib/zm/client/datasource/datasources_collection.rb +21 -0
- data/lib/zm/client/datasource.rb +7 -0
- data/lib/zm/client/distributionlist/distributionlist.rb +52 -118
- data/lib/zm/client/distributionlist/distributionlist_aces_collection.rb +31 -0
- data/lib/zm/client/distributionlist/distributionlist_aliases_collection.rb +53 -0
- data/lib/zm/client/distributionlist/distributionlist_jsns_builder.rb +82 -0
- data/lib/zm/client/distributionlist/distributionlist_jsns_initializer.rb +32 -0
- data/lib/zm/client/distributionlist/distributionlist_members_collection.rb +47 -0
- data/lib/zm/client/distributionlist/distributionlist_owners_collection.rb +52 -0
- data/lib/zm/client/distributionlist/distributionlists_builder.rb +8 -1
- data/lib/zm/client/distributionlist/distributionlists_collection.rb +8 -9
- data/lib/zm/client/distributionlist/dls_membership_collection.rb +4 -1
- data/lib/zm/client/distributionlist.rb +2 -0
- data/lib/zm/client/document/document.rb +27 -24
- data/lib/zm/client/document/document_jsns_builder.rb +18 -0
- data/lib/zm/client/document/document_jsns_initializer.rb +44 -0
- data/lib/zm/client/document/documents_builder.rb +6 -16
- data/lib/zm/client/document/documents_collection.rb +17 -67
- data/lib/zm/client/document.rb +2 -0
- data/lib/zm/client/domain/domain.rb +39 -55
- data/lib/zm/client/domain/domain_accounts_collection.rb +1 -1
- data/lib/zm/client/domain/domain_distributionlists_collection.rb +13 -0
- data/lib/zm/client/domain/domain_jsns_builder.rb +69 -0
- data/lib/zm/client/domain/domain_jsns_initializer.rb +25 -0
- data/lib/zm/client/domain/domain_resources_collection.rb +13 -0
- data/lib/zm/client/domain/domains_builder.rb +8 -1
- data/lib/zm/client/domain/domains_collection.rb +7 -7
- data/lib/zm/client/domain.rb +4 -0
- data/lib/zm/client/filter_rule.rb +7 -0
- data/lib/zm/client/filter_rules/filter_rule.rb +10 -0
- data/lib/zm/client/filter_rules/filter_rule_jsns_initializer.rb +24 -0
- data/lib/zm/client/filter_rules/filter_rules_builder.rb +21 -0
- data/lib/zm/client/filter_rules/filter_rules_collection.rb +21 -0
- data/lib/zm/client/filter_rules/outgoing_filter_rules_collection.rb +15 -0
- data/lib/zm/client/folder/folder.rb +77 -61
- data/lib/zm/client/folder/folder_grant.rb +34 -14
- data/lib/zm/client/folder/folder_grant_jsns_builder.rb +15 -4
- data/lib/zm/client/folder/folder_grants_collection.rb +36 -2
- data/lib/zm/client/folder/folder_jsns_builder.rb +22 -48
- data/lib/zm/client/folder/folder_jsns_initializer.rb +34 -17
- data/lib/zm/client/folder/folder_retention_policies_collection.rb +2 -3
- data/lib/zm/client/folder/folder_retention_policy.rb +0 -1
- data/lib/zm/client/folder/folders_builder.rb +7 -10
- data/lib/zm/client/folder/folders_collection.rb +5 -2
- data/lib/zm/client/folder/folders_jsns_builder.rb +3 -1
- data/lib/zm/client/folder/mod_document_folder.rb +10 -6
- data/lib/zm/client/folder.rb +1 -1
- data/lib/zm/client/identity/identities_builder.rb +8 -1
- data/lib/zm/client/identity/identities_collection.rb +2 -1
- data/lib/zm/client/identity/identity.rb +34 -42
- data/lib/zm/client/identity/identity_jsns_builder.rb +57 -0
- data/lib/zm/client/identity/identity_jsns_initializer.rb +29 -0
- data/lib/zm/client/identity.rb +3 -1
- data/lib/zm/client/license/license.rb +9 -22
- data/lib/zm/client/license/license_jsns_initializer.rb +20 -0
- data/lib/zm/client/license/licenses_collection.rb +3 -13
- data/lib/zm/client/license.rb +2 -1
- data/lib/zm/client/message/attachments_collection.rb +55 -0
- data/lib/zm/client/message/message.rb +36 -264
- data/lib/zm/client/message/message_flags.rb +107 -0
- data/lib/zm/client/message/message_jsns_builder.rb +85 -0
- data/lib/zm/client/message/message_jsns_initializer.rb +71 -0
- data/lib/zm/client/message/message_recipients.rb +59 -0
- data/lib/zm/client/message/messages_builder.rb +7 -18
- data/lib/zm/client/message/messages_collection.rb +17 -2
- data/lib/zm/client/message.rb +5 -0
- data/lib/zm/client/mountpoint/mountpoint.rb +43 -20
- data/lib/zm/client/mountpoint/mountpoint_jsns_builder.rb +8 -53
- data/lib/zm/client/mountpoint/mountpoint_jsns_initializer.rb +22 -13
- data/lib/zm/client/mountpoint/mountpoints_builder.rb +4 -5
- data/lib/zm/client/mountpoint/mountpoints_collection.rb +1 -2
- data/lib/zm/client/mta_queue/mta_queue.rb +13 -28
- data/lib/zm/client/mta_queue/mta_queue_jsns_builder.rb +41 -0
- data/lib/zm/client/mta_queue/mta_queue_jsns_initializer.rb +23 -0
- data/lib/zm/client/mta_queue/mta_queues_builder.rb +4 -8
- data/lib/zm/client/mta_queue/mta_queues_collection.rb +8 -27
- data/lib/zm/client/mta_queue.rb +2 -0
- data/lib/zm/client/mta_queue_item/mta_queue_item.rb +4 -31
- data/lib/zm/client/mta_queue_item/mta_queue_item_jsns_initializer.rb +33 -0
- data/lib/zm/client/mta_queue_item/mta_queue_items_builder.rb +4 -9
- data/lib/zm/client/mta_queue_item/mta_queue_items_collection.rb +7 -42
- data/lib/zm/client/mta_queue_item.rb +2 -1
- data/lib/zm/client/resource/resource.rb +24 -91
- data/lib/zm/client/resource/resource_jsns_builder.rb +79 -0
- data/lib/zm/client/resource/resource_jsns_initializer.rb +29 -0
- data/lib/zm/client/resource/resources_builder.rb +8 -1
- data/lib/zm/client/resource/resources_collection.rb +9 -7
- data/lib/zm/client/resource.rb +2 -0
- data/lib/zm/client/search_folder/search_folder.rb +38 -16
- data/lib/zm/client/search_folder/search_folder_jsns_builder.rb +38 -19
- data/lib/zm/client/search_folder/search_folder_jsns_initializer.rb +17 -13
- data/lib/zm/client/search_folder/search_folders_builder.rb +0 -1
- data/lib/zm/client/search_folder/search_folders_collection.rb +2 -1
- data/lib/zm/client/server/server.rb +16 -488
- data/lib/zm/client/server/server_jsns_initializer.rb +16 -0
- data/lib/zm/client/server/servers_builder.rb +8 -1
- data/lib/zm/client/server/servers_collection.rb +13 -5
- data/lib/zm/client/server.rb +1 -0
- data/lib/zm/client/share/share.rb +5 -43
- data/lib/zm/client/share/share_jsns_initializer.rb +32 -0
- data/lib/zm/client/share/share_mountpoints_collection.rb +38 -0
- data/lib/zm/client/share/shares_builder.rb +8 -1
- data/lib/zm/client/share/shares_collection.rb +11 -16
- data/lib/zm/client/share.rb +2 -0
- data/lib/zm/client/signature/signature.rb +25 -29
- data/lib/zm/client/signature/signature_jsns_builder.rb +31 -13
- data/lib/zm/client/signature/signature_jsns_initializer.rb +16 -12
- data/lib/zm/client/signature/signatures_builder.rb +1 -2
- data/lib/zm/client/signature/signatures_collection.rb +2 -1
- data/lib/zm/client/signature.rb +1 -1
- data/lib/zm/client/soap_request/account_soap_constants.rb +76 -0
- data/lib/zm/client/soap_request/admin_soap_constants.rb +214 -0
- data/lib/zm/client/soap_request/mail_soap_constants.rb +162 -0
- data/lib/zm/client/soap_request/soap_constants.rb +55 -0
- data/lib/zm/client/soap_request/soap_context.rb +38 -0
- data/lib/zm/client/soap_request/soap_element.rb +90 -0
- data/lib/zm/client/soap_request.rb +8 -0
- data/lib/zm/client/tag/account_object_tags_collection.rb +65 -0
- data/lib/zm/client/tag/tag.rb +34 -22
- data/lib/zm/client/tag/tag_jsns_builder.rb +14 -35
- data/lib/zm/client/tag/tag_jsns_initializer.rb +4 -6
- data/lib/zm/client/tag/tags_builder.rb +0 -1
- data/lib/zm/client/tag/tags_collection.rb +2 -1
- data/lib/zm/client/tag.rb +1 -0
- data/lib/zm/client/task/task.rb +18 -49
- data/lib/zm/client/task/task_jsns_initializer.rb +45 -0
- data/lib/zm/client/task/tasks_builder.rb +6 -16
- data/lib/zm/client/task/tasks_collection.rb +29 -0
- data/lib/zm/client/task.rb +1 -0
- data/lib/zm/client/upload/upload.rb +26 -30
- data/lib/zm/client/version.rb +3 -3
- data/lib/zm/client.rb +4 -1
- data/lib/zm/modules/base.rb +10 -0
- data/lib/zm/modules/belongs_to_folder.rb +37 -0
- data/lib/zm/modules/belongs_to_tag.rb +11 -0
- data/lib/zm/modules/common/zimbra-attrs.json +1 -1
- data/lib/zm/modules/has_soap_admin_connector.rb +12 -0
- data/lib/zm/modules/inspector.rb +24 -0
- data/lib/zm/modules/missing_method_static_collection.rb +13 -0
- data/lib/zm/modules/zm_logger.rb +3 -1
- data/lib/zm/modules/zm_model.rb +4 -2
- data/lib/zm/utils/thread_pool.rb +4 -2
- data/lib/zm-ruby-client.rb +2 -0
- data/zm-ruby-client.gemspec +12 -9
- metadata +93 -34
- data/lib/zm/client/base/account_object.rb +0 -51
- data/lib/zm/client/base/admin_object.rb +0 -51
- data/lib/zm/client/base/folder_object.rb +0 -41
- data/lib/zm/client/config.rb +0 -12
- data/lib/zm/client/data_source.rb +0 -5
- data/lib/zm/modules/common/account_common.rb +0 -71
- data/lib/zm/modules/common/cos_common.rb +0 -463
- data/lib/zm/modules/common/dl_common.rb +0 -38
- data/lib/zm/modules/common/identity_common.rb +0 -19
- data/lib/zm/modules/common/resource_common.rb +0 -59
- data/lib/zm/modules/common/signature_common.rb +0 -16
- data/lib/zm/modules/common/zimbra-attrs.json.bak +0 -1
- data/test/accounts.rb +0 -89
- data/test/ace.rb +0 -50
- data/test/cluster.rb +0 -41
- data/test/cluster_config.rb +0 -30
- data/test/cluster_zimbra_attributes.rb +0 -38
- data/test/coses.rb +0 -26
- data/test/domains.rb +0 -70
- data/test/folder.rb +0 -125
- data/test/folder_grant.rb +0 -51
- data/test/mountpoint.rb +0 -49
- data/test/retention_policies.rb +0 -40
- data/test/search_folder.rb +0 -67
- data/test/signature.rb +0 -53
- data/test/tag.rb +0 -65
- data/test/zimbra_attributes.rb +0 -35
@@ -3,312 +3,84 @@
|
|
3
3
|
module Zm
|
4
4
|
module Client
|
5
5
|
# class message for account
|
6
|
-
class Message < Base::
|
7
|
-
|
8
|
-
|
6
|
+
class Message < Base::Object
|
7
|
+
include BelongsToFolder
|
8
|
+
include BelongsToTag
|
9
9
|
|
10
|
-
attr_accessor :subject
|
11
|
-
attr_reader :recipients, :attachments, :body
|
10
|
+
attr_accessor :id, :d, :l, :f, :su, :fr, :autoSendTime, :mid, :idnt, :tn, :subject
|
11
|
+
attr_reader :recipients, :attachments, :body
|
12
12
|
|
13
|
-
def initialize(parent
|
13
|
+
def initialize(parent)
|
14
14
|
@parent = parent
|
15
|
-
@recipients = Recipients.new
|
16
15
|
@subject = ''
|
17
|
-
@body = Body.new
|
18
|
-
@attachments = Attachments.new
|
19
16
|
|
20
|
-
|
17
|
+
@recipients = Recipients.new
|
18
|
+
@body = Body.new
|
19
|
+
@attachments = AttachmentsCollection.new
|
21
20
|
|
22
21
|
yield(self) if block_given?
|
23
22
|
end
|
24
23
|
|
25
|
-
def
|
26
|
-
|
24
|
+
def download(dest_file_path, fmt = 'eml')
|
25
|
+
uploader = Upload.new(@parent, RestAccountConnector.new)
|
26
|
+
uploader.download_file( Zm::Client::FolderDefault::ROOT[:path], fmt, [Zm::Client::FolderView::MESSAGE], [@id], dest_file_path)
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
30
|
-
|
29
|
+
def date
|
30
|
+
@date ||= Time.at(d.to_i / 1000)
|
31
31
|
end
|
32
32
|
|
33
|
-
def
|
34
|
-
@
|
33
|
+
def flags
|
34
|
+
@flags ||= FlagsCollection.new(self)
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
38
|
-
|
39
|
-
@l = folder.id
|
37
|
+
def create!(*args)
|
38
|
+
raise NotImplementedError
|
40
39
|
end
|
41
40
|
|
42
|
-
def
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
def move!(folder_id = l)
|
47
|
-
msg_action('move', l: folder_id)
|
48
|
-
l = folder_id if l != folder_id
|
41
|
+
def modify!(*args)
|
42
|
+
raise NotImplementedError
|
49
43
|
end
|
50
44
|
|
51
|
-
def
|
52
|
-
|
45
|
+
def update!(*args)
|
46
|
+
raise NotImplementedError
|
53
47
|
end
|
54
48
|
|
55
|
-
def
|
56
|
-
|
49
|
+
def rename!(*args)
|
50
|
+
raise NotImplementedError
|
57
51
|
end
|
58
52
|
|
59
|
-
def
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
def flag!
|
64
|
-
msg_action('flag')
|
65
|
-
end
|
66
|
-
|
67
|
-
def untag!(tag_name)
|
68
|
-
msg_action('!tag', tn: tag_name)
|
69
|
-
end
|
53
|
+
def delete!
|
54
|
+
return false if @id.nil?
|
70
55
|
|
71
|
-
|
72
|
-
|
56
|
+
@parent.sacc.invoke(jsns_builder.to_delete)
|
57
|
+
@id = nil
|
73
58
|
end
|
74
59
|
|
75
60
|
def unspam!
|
76
|
-
|
61
|
+
@parent.sacc.invoke(jsns_builder.to_unspam)
|
77
62
|
end
|
78
63
|
|
79
64
|
def spam!
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
def trash!
|
84
|
-
msg_action('trash')
|
65
|
+
@parent.sacc.invoke(jsns_builder.to_spam)
|
85
66
|
end
|
86
67
|
|
87
68
|
def send!
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
def to_jsns
|
92
|
-
h = {
|
93
|
-
id: @id,
|
94
|
-
attach: @attachments.to_jsns,
|
95
|
-
e: @recipients.to_jsns,
|
96
|
-
su: { _content: @su },
|
97
|
-
mp: @body.to_jsns
|
98
|
-
}.delete_if { |_, v| v.nil? }
|
99
|
-
|
100
|
-
h[:did] = @id if l.to_i == FolderDefault::DRAFTS[:id]
|
101
|
-
|
102
|
-
h
|
103
|
-
end
|
104
|
-
|
105
|
-
def init_from_json(json)
|
106
|
-
# puts json
|
107
|
-
@id = json[:id]
|
108
|
-
@date = Time.at(json[:d]/1000)
|
109
|
-
@l = json[:l]
|
110
|
-
@su = json[:su]
|
111
|
-
@fr = json[:fr]
|
112
|
-
@autoSendTime = json[:autoSendTime]
|
113
|
-
@mid = json[:mid]
|
114
|
-
@idnt = json[:idnt]
|
115
|
-
@has_attachment = json[:f].to_s.include?('a')
|
116
|
-
|
117
|
-
json[:e].each do |e|
|
118
|
-
recipient = Recipient.new(e[:t], e[:a], e[:p])
|
119
|
-
@recipients.add(recipient)
|
120
|
-
end
|
121
|
-
|
122
|
-
init_part_from_json(json[:mp])
|
123
|
-
end
|
124
|
-
|
125
|
-
def init_part_from_json(json)
|
126
|
-
return if json.nil?
|
127
|
-
# puts json
|
128
|
-
json = [json] unless json.is_a?(Array)
|
129
|
-
|
130
|
-
json.each do |json_part|
|
131
|
-
if ['text/plain', 'text/html'].include?(json_part[:ct])
|
132
|
-
init_body_from_json(json_part)
|
133
|
-
elsif json_part[:cd] == 'attachment'
|
134
|
-
init_attachment_from_json(json_part)
|
135
|
-
else
|
136
|
-
init_part_from_json(json_part[:mp])
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
def init_body_from_json(json)
|
142
|
-
# puts "\ninit_body_from_json #{json}\n"
|
143
|
-
body.text = json[:content] if json[:ct] == 'text/plain'
|
144
|
-
body.html = json[:content] if json[:ct] == 'text/html'
|
145
|
-
end
|
146
|
-
|
147
|
-
def init_attachment_from_json(json)
|
148
|
-
# puts "\ninit_attachment_from_json #{json}\n"
|
149
|
-
pj = Zm::Client::Message::Attachment.new(self)
|
150
|
-
# pj.part = json[:part],
|
151
|
-
pj.mid = json[:mid]
|
152
|
-
pj.aid = json[:aid]
|
153
|
-
pj.ct = json[:ct]
|
154
|
-
pj.s = json[:s]
|
155
|
-
pj.filename = json[:filename]
|
156
|
-
pj.ci = json[:ci]
|
157
|
-
pj.cd = json[:cd]
|
158
|
-
pj.part = json[:part]
|
159
|
-
attachments.add(pj)
|
160
|
-
end
|
161
|
-
|
162
|
-
def msg_action(action_name, options = {})
|
163
|
-
@parent.sacc.msg_action(@parent.token, action_name, id, options)
|
164
|
-
true
|
69
|
+
soap_request = SoapElement.mail(SoapMailConstants::SEND_MSG_REQUEST).add_attributes(jsns_builder.to_jsns)
|
70
|
+
@parent.sacc.invoke(soap_request)
|
165
71
|
end
|
166
72
|
|
167
73
|
# content fo an email
|
168
74
|
class Body
|
169
75
|
attr_accessor :text, :html
|
170
|
-
|
171
|
-
def text_jsns
|
172
|
-
@text.nil? ? nil : { ct: 'text/plain', content: { _content: @text } }
|
173
|
-
end
|
174
|
-
|
175
|
-
def html_jsns
|
176
|
-
@html.nil? ? nil : { ct: 'text/html', content: { _content: @html } }
|
177
|
-
end
|
178
|
-
|
179
|
-
def to_jsns
|
180
|
-
[
|
181
|
-
{
|
182
|
-
ct: 'multipart/alternative',
|
183
|
-
mp: [text_jsns, html_jsns].compact
|
184
|
-
}
|
185
|
-
]
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
# collection attachments
|
190
|
-
class Attachments
|
191
|
-
attr_reader :all
|
192
|
-
def initialize
|
193
|
-
@all = []
|
194
|
-
end
|
195
|
-
|
196
|
-
def add(attachment)
|
197
|
-
return unless attachment.is_a?(Attachment)
|
198
|
-
|
199
|
-
@all.push(attachment)
|
200
|
-
end
|
201
|
-
|
202
|
-
def to_jsns
|
203
|
-
@all.map(&:to_jsns)
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
# class attachment for email
|
208
|
-
class Attachment
|
209
|
-
attr_accessor :aid, :part, :mid, :ct, :s, :filename, :ci, :cd
|
210
|
-
|
211
|
-
def initialize(parent)
|
212
|
-
@parent = parent
|
213
|
-
yield(self) if block_given?
|
214
|
-
end
|
215
|
-
|
216
|
-
def download(dest_file_path)
|
217
|
-
h = {
|
218
|
-
id: @parent.id,
|
219
|
-
part: part,
|
220
|
-
auth: 'qp',
|
221
|
-
zauthtoken: account.token,
|
222
|
-
disp: 'a'
|
223
|
-
}
|
224
|
-
|
225
|
-
url = account.home_url
|
226
|
-
|
227
|
-
uri = Addressable::URI.new
|
228
|
-
uri.query_values = h
|
229
|
-
url << '?' << uri.query
|
230
|
-
|
231
|
-
uploader = Upload.new(@parent, RestAccountConnector.new)
|
232
|
-
uploader.download_file_with_url(url, dest_file_path)
|
233
|
-
end
|
234
|
-
|
235
|
-
def to_jsns
|
236
|
-
{
|
237
|
-
part: part,
|
238
|
-
mid: mid,
|
239
|
-
aid: aid,
|
240
|
-
ct: ct,
|
241
|
-
s: s,
|
242
|
-
filename: filename,
|
243
|
-
ci: ci,
|
244
|
-
cd: cd
|
245
|
-
}.reject { |_, v| v.nil? }
|
246
|
-
end
|
247
|
-
|
248
|
-
def account
|
249
|
-
@parent.parent
|
250
|
-
end
|
251
76
|
end
|
252
77
|
|
253
|
-
|
254
|
-
|
255
|
-
def initialize
|
256
|
-
@recipients = []
|
257
|
-
end
|
258
|
-
|
259
|
-
def to_jsns
|
260
|
-
@recipients.map(&:to_jsns)
|
261
|
-
end
|
262
|
-
|
263
|
-
def add(recipient)
|
264
|
-
return unless recipient.is_a?(Recipient)
|
265
|
-
|
266
|
-
@recipients.push(recipient)
|
267
|
-
end
|
268
|
-
|
269
|
-
def to
|
270
|
-
@recipients.select { |r| r.field == Recipient::TO }
|
271
|
-
end
|
272
|
-
|
273
|
-
def cc
|
274
|
-
@recipients.select { |r| r.field == Recipient::CC }
|
275
|
-
end
|
276
|
-
|
277
|
-
def bcc
|
278
|
-
@recipients.select { |r| r.field == Recipient::BCC }
|
279
|
-
end
|
280
|
-
|
281
|
-
def from
|
282
|
-
@recipients.select { |r| r.field == Recipient::FROM }
|
283
|
-
end
|
78
|
+
def sacc
|
79
|
+
@parent.sacc
|
284
80
|
end
|
285
81
|
|
286
|
-
|
287
|
-
|
288
|
-
FROM = :f
|
289
|
-
TO = :t
|
290
|
-
CC = :c
|
291
|
-
BCC = :b
|
292
|
-
|
293
|
-
attr_accessor :field, :email, :display_name
|
294
|
-
|
295
|
-
def initialize(field, email, display_name = nil)
|
296
|
-
@email = email
|
297
|
-
@field = field.to_sym
|
298
|
-
@display_name = display_name
|
299
|
-
end
|
300
|
-
|
301
|
-
def to_s
|
302
|
-
"#{@email} (#{@display_name})"
|
303
|
-
end
|
304
|
-
|
305
|
-
def to_jsns
|
306
|
-
{
|
307
|
-
t: @field,
|
308
|
-
a: @email,
|
309
|
-
p: @display_name
|
310
|
-
}.reject { |_, v| v.nil? }
|
311
|
-
end
|
82
|
+
def jsns_builder
|
83
|
+
@jsns_builder ||= MessageJsnsBuilder.new(self)
|
312
84
|
end
|
313
85
|
end
|
314
86
|
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zm
|
4
|
+
module Client
|
5
|
+
# class message for account
|
6
|
+
class Message
|
7
|
+
class FlagsCollection
|
8
|
+
def initialize(parent)
|
9
|
+
@parent = parent
|
10
|
+
end
|
11
|
+
|
12
|
+
def all
|
13
|
+
@all || all!
|
14
|
+
end
|
15
|
+
|
16
|
+
def all!
|
17
|
+
@parent.f.to_s.chars
|
18
|
+
end
|
19
|
+
|
20
|
+
# properties
|
21
|
+
|
22
|
+
def unread?
|
23
|
+
all.include?('u')
|
24
|
+
end
|
25
|
+
|
26
|
+
def flagged?
|
27
|
+
all.include?('f')
|
28
|
+
end
|
29
|
+
|
30
|
+
def attachment?
|
31
|
+
all.include?('a')
|
32
|
+
end
|
33
|
+
|
34
|
+
def replied
|
35
|
+
all.include?('r')
|
36
|
+
end
|
37
|
+
|
38
|
+
def sent_by_me?
|
39
|
+
all.include?('s')
|
40
|
+
end
|
41
|
+
|
42
|
+
def forwarded?
|
43
|
+
all.include?('w')
|
44
|
+
end
|
45
|
+
|
46
|
+
def calendar_invite?
|
47
|
+
all.include?('v')
|
48
|
+
end
|
49
|
+
|
50
|
+
def draft?
|
51
|
+
all.include?('d')
|
52
|
+
end
|
53
|
+
|
54
|
+
def imap_deleted?
|
55
|
+
all.include?('x')
|
56
|
+
end
|
57
|
+
|
58
|
+
def notification?
|
59
|
+
all.include?('n')
|
60
|
+
end
|
61
|
+
|
62
|
+
def urgent?
|
63
|
+
all.include?('!')
|
64
|
+
end
|
65
|
+
|
66
|
+
def low_priority?
|
67
|
+
all.include?('?')
|
68
|
+
end
|
69
|
+
|
70
|
+
def priority?
|
71
|
+
all.include?('+')
|
72
|
+
end
|
73
|
+
|
74
|
+
# actions
|
75
|
+
|
76
|
+
def unread!
|
77
|
+
attrs = { op: '!read', id: @parent.id }
|
78
|
+
@parent.sacc.invoke(build(attrs))
|
79
|
+
end
|
80
|
+
|
81
|
+
def read!
|
82
|
+
attrs = { op: 'read', id: @parent.id }
|
83
|
+
@parent.sacc.invoke(build(attrs))
|
84
|
+
end
|
85
|
+
|
86
|
+
def unflag!
|
87
|
+
attrs = { op: '!flag', id: @parent.id }
|
88
|
+
@parent.sacc.invoke(build(attrs))
|
89
|
+
end
|
90
|
+
|
91
|
+
def flag!
|
92
|
+
attrs = { op: 'flag', id: @parent.id }
|
93
|
+
@parent.sacc.invoke(build(attrs))
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def build(attrs)
|
99
|
+
soap_request = SoapElement.mail(SoapMailConstants::ITEM_ACTION_REQUEST)
|
100
|
+
node_action = SoapElement.create(SoapConstants::ACTION).add_attributes(attrs)
|
101
|
+
soap_request.add_node(node_action)
|
102
|
+
soap_request
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zm
|
4
|
+
module Client
|
5
|
+
# class for account message jsns builder
|
6
|
+
class MessageJsnsBuilder < BaseAccountJsnsBuilder
|
7
|
+
def initialize(item)
|
8
|
+
@item = item
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_jsns
|
12
|
+
jsns = {
|
13
|
+
id: @item.id,
|
14
|
+
attach: attachments_jsns,
|
15
|
+
e: recipients_jsns,
|
16
|
+
su: { _content: @item.su },
|
17
|
+
mp: body_jsns
|
18
|
+
}.delete_if { |_, v| v.nil? }
|
19
|
+
|
20
|
+
jsns[:did] = @item.id if @item.l.to_i == FolderDefault::DRAFTS[:id]
|
21
|
+
|
22
|
+
jsns
|
23
|
+
end
|
24
|
+
|
25
|
+
def attachments_jsns
|
26
|
+
@item.attachments.all.map do |attachment|
|
27
|
+
{
|
28
|
+
part: attachment.part,
|
29
|
+
mid: attachment.mid,
|
30
|
+
aid: attachment.aid,
|
31
|
+
ct: attachment.ct,
|
32
|
+
s: attachment.s,
|
33
|
+
filename: attachment.filename,
|
34
|
+
ci: attachment.ci,
|
35
|
+
cd: attachment.cd
|
36
|
+
}.reject { |_, v| v.nil? }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def recipients_jsns
|
41
|
+
return nil if @item.recipients.all.empty?
|
42
|
+
|
43
|
+
@item.recipients.all.map do |recipient|
|
44
|
+
{
|
45
|
+
t: recipient.field,
|
46
|
+
a: recipient.email,
|
47
|
+
p: recipient.display_name
|
48
|
+
}.reject { |_, v| v.nil? }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def body_jsns
|
53
|
+
return nil if @item.body.text.nil? && @item.body.html.nil?
|
54
|
+
|
55
|
+
text_jsns = @item.body.text.nil? ? nil : { ct: ContentType::TEXT, content: { _content: @item.body.text } }
|
56
|
+
html_jsns = @item.body.html.nil? ? nil : { ct: ContentType::HTML, content: { _content: @item.body.html } }
|
57
|
+
|
58
|
+
[
|
59
|
+
{
|
60
|
+
ct: ContentPart::ALTERNATIVE,
|
61
|
+
mp: [text_jsns, html_jsns].compact
|
62
|
+
}
|
63
|
+
]
|
64
|
+
end
|
65
|
+
|
66
|
+
def to_spam
|
67
|
+
attrs = {
|
68
|
+
op: :spam,
|
69
|
+
id: @item.id
|
70
|
+
}
|
71
|
+
|
72
|
+
build(attrs)
|
73
|
+
end
|
74
|
+
|
75
|
+
def to_unspam
|
76
|
+
attrs = {
|
77
|
+
op: '!spam',
|
78
|
+
id: @item.id
|
79
|
+
}
|
80
|
+
|
81
|
+
build(attrs)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zm
|
4
|
+
module Client
|
5
|
+
# class for initialize account message
|
6
|
+
class MessageJsnsInitializer
|
7
|
+
class << self
|
8
|
+
def create(parent, json)
|
9
|
+
item = Message.new(parent)
|
10
|
+
update(item, json)
|
11
|
+
end
|
12
|
+
|
13
|
+
def update(item, json)
|
14
|
+
item.id = json[:id]
|
15
|
+
item.d = json[:d]
|
16
|
+
item.l = json[:l]
|
17
|
+
item.su = json[:su]
|
18
|
+
item.fr = json[:fr]
|
19
|
+
item.autoSendTime = json[:autoSendTime]
|
20
|
+
item.mid = json[:mid]
|
21
|
+
item.idnt = json[:idnt]
|
22
|
+
item.f = json[:f]
|
23
|
+
item.tn = json[:tn].to_s.split(',')
|
24
|
+
|
25
|
+
json[:e].each do |e|
|
26
|
+
recipient = Recipient.new(e[:t], e[:a], e[:p])
|
27
|
+
item.recipients.add(recipient)
|
28
|
+
end
|
29
|
+
|
30
|
+
update_mps(item, json[:mp])
|
31
|
+
|
32
|
+
item
|
33
|
+
end
|
34
|
+
|
35
|
+
def update_mps(item, mps)
|
36
|
+
return if mps.nil?
|
37
|
+
|
38
|
+
mps = [mps] unless mps.is_a?(Array)
|
39
|
+
|
40
|
+
mps.each do |mp|
|
41
|
+
if ContentType::ALL.include?(mp[:ct])
|
42
|
+
update_body(item, mp)
|
43
|
+
elsif mp[:cd] == 'attachment'
|
44
|
+
update_attachment(item, mp)
|
45
|
+
else
|
46
|
+
update_mps(item, mp[:mp])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def update_body(item, json)
|
52
|
+
item.body.text = json[:content] if json[:ct] == ContentType::TEXT
|
53
|
+
item.body.html = json[:content] if json[:ct] == ContentType::HTML
|
54
|
+
end
|
55
|
+
|
56
|
+
def update_attachment(item, json)
|
57
|
+
pj = Zm::Client::Message::Attachment.new(self)
|
58
|
+
pj.mid = json[:mid]
|
59
|
+
pj.aid = json[:aid]
|
60
|
+
pj.ct = json[:ct]
|
61
|
+
pj.s = json[:s]
|
62
|
+
pj.filename = json[:filename]
|
63
|
+
pj.ci = json[:ci]
|
64
|
+
pj.cd = json[:cd]
|
65
|
+
pj.part = json[:part]
|
66
|
+
item.attachments.add(pj)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Zm
|
4
|
+
module Client
|
5
|
+
class Message
|
6
|
+
# Collection recipients
|
7
|
+
class Recipients
|
8
|
+
attr_reader :all
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@all = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def add(recipient)
|
15
|
+
return unless recipient.is_a?(Zm::Client::Recipient)
|
16
|
+
|
17
|
+
@all.push(recipient)
|
18
|
+
end
|
19
|
+
|
20
|
+
def to
|
21
|
+
@all.select { |r| r.field == Zm::Client::Recipient::TO }
|
22
|
+
end
|
23
|
+
|
24
|
+
def cc
|
25
|
+
@all.select { |r| r.field == Zm::Client::Recipient::CC }
|
26
|
+
end
|
27
|
+
|
28
|
+
def bcc
|
29
|
+
@all.select { |r| r.field == Zm::Client::Recipient::BCC }
|
30
|
+
end
|
31
|
+
|
32
|
+
def from
|
33
|
+
@all.select { |r| r.field == Zm::Client::Recipient::FROM }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Class one recipient for email
|
38
|
+
class Recipient
|
39
|
+
FROM = :f
|
40
|
+
TO = :t
|
41
|
+
CC = :c
|
42
|
+
BCC = :b
|
43
|
+
|
44
|
+
attr_accessor :field, :email
|
45
|
+
attr_writer :display_name
|
46
|
+
|
47
|
+
def initialize(field, email, display_name = nil)
|
48
|
+
@email = email
|
49
|
+
@field = field.to_sym
|
50
|
+
@display_name = display_name
|
51
|
+
end
|
52
|
+
|
53
|
+
def display_name
|
54
|
+
@display_name || "#{@email} (#{@display_name})"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -4,28 +4,17 @@ module Zm
|
|
4
4
|
module Client
|
5
5
|
# class factory [messages]
|
6
6
|
class MessagesBuilder < Base::ObjectsBuilder
|
7
|
-
def initialize(
|
8
|
-
|
9
|
-
@
|
7
|
+
def initialize(parent, json)
|
8
|
+
super(parent, json)
|
9
|
+
@json_item_key = :m
|
10
10
|
end
|
11
11
|
|
12
12
|
def make
|
13
|
-
|
14
|
-
Message.new(@account, s)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def ids
|
19
|
-
hits = @json.dig(:Body, :SearchResponse, :hit) || []
|
20
|
-
hits.map { |s| s[:id] }
|
21
|
-
end
|
22
|
-
|
23
|
-
def root
|
24
|
-
root = @json[:Body][:SearchResponse][:m]
|
25
|
-
return [] if root.nil?
|
13
|
+
return [] if json_items.nil?
|
26
14
|
|
27
|
-
|
28
|
-
|
15
|
+
json_items.map do |entry|
|
16
|
+
MessageJsnsInitializer.create(@parent, entry)
|
17
|
+
end
|
29
18
|
end
|
30
19
|
end
|
31
20
|
end
|