onlyoffice_gmail_helper 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/onlyoffice_gmail_helper/version.rb +1 -1
- data/lib/onlyoffice_gmail_helper.rb +10 -324
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 964bbe677c33d0c017f204fe2d37682091e5008bbc1b88fb3613eff57d91b2bb
|
4
|
+
data.tar.gz: bcde1191c95f16ce78dba04240466e599a267548b5996dde7257b8b54c1c2b07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a67a317be75b4d0197f1ac5826f2af03298f44e11fa79fb0ed6817f0a5974934556ab712b67a90544512cec5a376b64a7cd2eefaa2834018acfd9cac1b0aaf67
|
7
|
+
data.tar.gz: 33da4377cb1b682a76007aedf65abab9385b1635274756e6895258f947d495b75f8936a12681b61ef5676c3a096bdab8170b381e7fc34e79c2e84cb982d689f3
|
@@ -6,33 +6,6 @@ require 'onlyoffice_gmail_helper/email_account'
|
|
6
6
|
require 'onlyoffice_gmail_helper/mail_message'
|
7
7
|
require 'onlyoffice_gmail_helper/version'
|
8
8
|
|
9
|
-
# Override object class
|
10
|
-
class Object
|
11
|
-
# @return [Date] format date for imap
|
12
|
-
def to_imap_date
|
13
|
-
Date.parse(to_s).strftime('%d-%b-%Y')
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
# Monkey patch IMAP to fix https://bugs.ruby-lang.org/issues/14750
|
18
|
-
# TODO: Remove after release of fix as stable version
|
19
|
-
module Net
|
20
|
-
# Imap main class
|
21
|
-
class IMAP
|
22
|
-
# override bugged method
|
23
|
-
alias send_literal_bug_14750 send_literal
|
24
|
-
|
25
|
-
# Override for but 14750
|
26
|
-
def send_literal(str, tag = nil)
|
27
|
-
if RUBY_VERSION.start_with?('2.5', '2.6')
|
28
|
-
send_literal_bug_14750(str, tag)
|
29
|
-
else
|
30
|
-
send_literal_bug_14750(str)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
9
|
# Helper module for GMail
|
37
10
|
module OnlyofficeGmailHelper
|
38
11
|
# Main class of gem
|
@@ -80,74 +53,6 @@ module OnlyofficeGmailHelper
|
|
80
53
|
Exception
|
81
54
|
end
|
82
55
|
|
83
|
-
# Refresh connection data
|
84
|
-
# @return [nil]
|
85
|
-
def refresh
|
86
|
-
logout
|
87
|
-
@gmail = Gmail.new(@user, @password)
|
88
|
-
end
|
89
|
-
|
90
|
-
# Wait until unread message exists
|
91
|
-
# @param [String] title message to wait
|
92
|
-
# @param [Integer] timeout to wait
|
93
|
-
# @param [Integer] period sleep between tries
|
94
|
-
# @return [MailMessage] found message
|
95
|
-
def wait_until_unread_message(title,
|
96
|
-
timeout = @timeout_for_mail, period = 60)
|
97
|
-
counter = 0
|
98
|
-
message_found = false
|
99
|
-
while counter < timeout && !message_found
|
100
|
-
@gmail.inbox.emails.each do |current_mail|
|
101
|
-
next unless current_mail.subject.include?(title)
|
102
|
-
|
103
|
-
message = MailMessage.new(current_mail.subject,
|
104
|
-
current_mail.html_part.body)
|
105
|
-
return message
|
106
|
-
end
|
107
|
-
sleep period
|
108
|
-
refresh
|
109
|
-
end
|
110
|
-
raise "Message with title: #{title} not found for #{timeout * 60} seconds"
|
111
|
-
end
|
112
|
-
|
113
|
-
# Get body message by title
|
114
|
-
# @param [String] current_portal_full portal name to search
|
115
|
-
# @param [String] title1 title to filter
|
116
|
-
# @param [String] title2 title to filter
|
117
|
-
# @param [Boolean] delete this message
|
118
|
-
# @param [Boolean] _to_mail unused
|
119
|
-
# @return [MailMessage] found message
|
120
|
-
def get_body_message_by_title_from_mail(current_portal_full, title1 = 'Welcome to ONLYOFFICE™ Portal!', title2 = 'Добро пожаловать на портал TeamLab!', delete = true, _to_mail = nil)
|
121
|
-
mail_not_found = true
|
122
|
-
attempt = 0
|
123
|
-
while mail_not_found
|
124
|
-
messages_array = mailbox.emails(:unread, search: current_portal_full.to_s)
|
125
|
-
messages_array.each do |current_mail|
|
126
|
-
current_subject = current_mail.message.subject
|
127
|
-
a = current_subject.include? title1
|
128
|
-
b = current_subject.include? title2
|
129
|
-
if a || b
|
130
|
-
current_subject = begin
|
131
|
-
current_mail.html_part.body.decoded.force_encoding('utf-8').encode('UTF-8')
|
132
|
-
rescue StandardError
|
133
|
-
Exception
|
134
|
-
end
|
135
|
-
current_mail.delete! if current_subject == 'Welcome to Your TeamLab Portal!'
|
136
|
-
if current_subject.include? current_portal_full
|
137
|
-
current_mail.delete! if delete
|
138
|
-
return current_subject
|
139
|
-
end
|
140
|
-
else
|
141
|
-
raise "Message with title: #{title1} not found after #{attempt} attempt" if attempt == 10
|
142
|
-
|
143
|
-
sleep 10
|
144
|
-
attempt += 1
|
145
|
-
current_mail.delete! if delete
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
56
|
# Get mail body by title
|
152
57
|
# @param [String] portal_address to filter
|
153
58
|
# @param [String] subject to find
|
@@ -163,7 +68,7 @@ module OnlyofficeGmailHelper
|
|
163
68
|
next unless message_found?(current_mail.message.subject, subject)
|
164
69
|
|
165
70
|
body = begin
|
166
|
-
current_mail
|
71
|
+
message_body(current_mail)
|
167
72
|
rescue StandardError
|
168
73
|
Exception
|
169
74
|
end
|
@@ -174,56 +79,6 @@ module OnlyofficeGmailHelper
|
|
174
79
|
nil
|
175
80
|
end
|
176
81
|
|
177
|
-
# @return [Array<Message>] list of underad messages
|
178
|
-
def get_unread_messages
|
179
|
-
refresh
|
180
|
-
array_of_mail = []
|
181
|
-
mailbox.emails(:unread).reverse_each do |current_mail|
|
182
|
-
current_title = current_mail.message.subject
|
183
|
-
current_subject = begin
|
184
|
-
current_mail.html_part.body.decoded
|
185
|
-
.force_encoding('utf-8').encode('UTF-8')
|
186
|
-
rescue StandardError
|
187
|
-
Exception
|
188
|
-
end
|
189
|
-
current_mail.mark(:unread)
|
190
|
-
reply_to = current_mail.reply_to[0] unless current_mail.reply_to == []
|
191
|
-
array_of_mail << MailMessage.new(current_title,
|
192
|
-
current_subject,
|
193
|
-
reply_to)
|
194
|
-
end
|
195
|
-
array_of_mail
|
196
|
-
end
|
197
|
-
|
198
|
-
# received mail in format "Thu, 23 Jan 2014 15:34:57 +0400". Day of week may\may not be present
|
199
|
-
# @param [String] date_str original string
|
200
|
-
# @return [Hash] date
|
201
|
-
def get_current_date(date_str)
|
202
|
-
data_arr = date_str.split.reverse
|
203
|
-
{ day: data_arr[4].to_i, hour: data_arr[1].split(':')[0].to_i, minute: data_arr[1].split(':')[1].to_i }
|
204
|
-
end
|
205
|
-
|
206
|
-
# Check unread messages for message
|
207
|
-
# @param [String] mail_message to find
|
208
|
-
# @return [Boolean] result
|
209
|
-
def check_unread_messages_for_message(mail_message)
|
210
|
-
messages = get_unread_messages
|
211
|
-
timer = 0
|
212
|
-
message_found = false
|
213
|
-
while timer < @timeout_for_mail && message_found == false
|
214
|
-
messages.each do |current_unread_mail|
|
215
|
-
# p current_unread_mail
|
216
|
-
if current_unread_mail == mail_message
|
217
|
-
delete_messages(current_unread_mail)
|
218
|
-
return true
|
219
|
-
end
|
220
|
-
end
|
221
|
-
messages = get_unread_messages
|
222
|
-
timer += 1
|
223
|
-
end
|
224
|
-
false
|
225
|
-
end
|
226
|
-
|
227
82
|
# Check message for message with portal
|
228
83
|
# @param [String] message title
|
229
84
|
# @param [String] current_portal_full_name name
|
@@ -244,28 +99,6 @@ module OnlyofficeGmailHelper
|
|
244
99
|
false
|
245
100
|
end
|
246
101
|
|
247
|
-
# Delete message with portal address
|
248
|
-
# @param [String] message title to delete
|
249
|
-
# @param [String] current_portal_full_name to delete
|
250
|
-
# @return [nil]
|
251
|
-
def delete_message_with_portal_address(message, current_portal_full_name)
|
252
|
-
300.times do
|
253
|
-
messages_array = mailbox.emails(:unread, search: current_portal_full_name.to_s)
|
254
|
-
messages_array.each do |current_mail|
|
255
|
-
if message.title == current_mail.message.subject
|
256
|
-
current_mail.delete!
|
257
|
-
return true
|
258
|
-
else
|
259
|
-
begin
|
260
|
-
current_mail.mark(:unread)
|
261
|
-
rescue StandardError
|
262
|
-
Exception
|
263
|
-
end
|
264
|
-
end
|
265
|
-
end
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
102
|
# Delete specific message
|
270
103
|
# @param [String] message title to delete
|
271
104
|
# @return [nil]
|
@@ -295,49 +128,6 @@ module OnlyofficeGmailHelper
|
|
295
128
|
OnlyofficeLoggerHelper.log("Finished deleting all messaged on mail: #{@user}")
|
296
129
|
end
|
297
130
|
|
298
|
-
# Archive all inbox
|
299
|
-
# @return [nil]
|
300
|
-
def archive_inbox
|
301
|
-
OnlyofficeLoggerHelper.log("Start achieving all messaged in inbox on mail: #{@user}")
|
302
|
-
@gmail.inbox.emails.each(&:archive!) if mail_inbox_count.nonzero?
|
303
|
-
OnlyofficeLoggerHelper.log("Finished achieving all messaged in inbox on mail: #{@user}")
|
304
|
-
end
|
305
|
-
|
306
|
-
# @param [String] contain_string message to delete
|
307
|
-
# @return [nil]
|
308
|
-
def delete_all_message_contains(contain_string)
|
309
|
-
OnlyofficeLoggerHelper.log("Messages containing #{contain_string} will be deleted")
|
310
|
-
messages_array = mailbox.emails(:unread, search: contain_string)
|
311
|
-
messages_array.each(&:delete!)
|
312
|
-
end
|
313
|
-
|
314
|
-
# Reply to mail
|
315
|
-
# @param [String] mail_to_reply
|
316
|
-
# @param [String] reply_body to do
|
317
|
-
# @return [nil]
|
318
|
-
def reply_mail(mail_to_reply, reply_body)
|
319
|
-
messages = get_unread_messages
|
320
|
-
timer = 0
|
321
|
-
message_found = false
|
322
|
-
while timer < @timeout_for_mail && message_found == false
|
323
|
-
messages.each do |current_unread_mail|
|
324
|
-
next unless current_unread_mail == mail_to_reply
|
325
|
-
|
326
|
-
email = @gmail.compose do
|
327
|
-
to("#{current_unread_mail.reply_to.mailbox}@#{current_unread_mail.reply_to.host}".to_s)
|
328
|
-
subject "Re: #{current_unread_mail.title}"
|
329
|
-
body reply_body
|
330
|
-
end
|
331
|
-
email.deliver!
|
332
|
-
delete_messages(current_unread_mail)
|
333
|
-
return true
|
334
|
-
end
|
335
|
-
messages = get_unread_messages
|
336
|
-
timer += 1
|
337
|
-
end
|
338
|
-
false
|
339
|
-
end
|
340
|
-
|
341
131
|
# Send mail
|
342
132
|
# @param [String] email to send
|
343
133
|
# @param [String] title to send
|
@@ -355,25 +145,6 @@ module OnlyofficeGmailHelper
|
|
355
145
|
OnlyofficeLoggerHelper.log("send_mail(#{email}, #{title}, #{body}, #{attachment})")
|
356
146
|
end
|
357
147
|
|
358
|
-
# Send notification
|
359
|
-
# @param [String] email to send
|
360
|
-
# @param [String] test_name - name of test
|
361
|
-
# @param [String] error - error to send
|
362
|
-
# @param [String] mail_title to send
|
363
|
-
# @return [nil]
|
364
|
-
def send_notification(email, test_name, error, mail_title = 'Teamlab Daily Check')
|
365
|
-
body = "Fail in #{test_name}\n" \
|
366
|
-
"Error text: \n\t #{error}"
|
367
|
-
send_mail(email, mail_title, body)
|
368
|
-
end
|
369
|
-
|
370
|
-
# @return [Integer] count message in inbox
|
371
|
-
def mail_inbox_count
|
372
|
-
count = @gmail.inbox.emails.count
|
373
|
-
OnlyofficeLoggerHelper.log("#{count} mails in inbox of #{@user}")
|
374
|
-
count
|
375
|
-
end
|
376
|
-
|
377
148
|
# List all mail in label with date
|
378
149
|
# @param [String] string label
|
379
150
|
# @param [Date] date_start to find
|
@@ -398,105 +169,20 @@ module OnlyofficeGmailHelper
|
|
398
169
|
array_of_mail
|
399
170
|
end
|
400
171
|
|
401
|
-
|
402
|
-
# @param [String] string messanger
|
403
|
-
# @return [nil]
|
404
|
-
def delete_from_sender(string)
|
405
|
-
mailbox.emails(from: string).each(&:delete!)
|
406
|
-
end
|
407
|
-
|
408
|
-
# Mark all messages as unread
|
409
|
-
# @return [nil]
|
410
|
-
def mark_all_unread
|
411
|
-
mailbox.emails.each do |current_mail|
|
412
|
-
current_mail.mark(:unread)
|
413
|
-
end
|
414
|
-
end
|
415
|
-
|
416
|
-
# Send mail test result
|
417
|
-
# @param [String] mail to send
|
418
|
-
# @param [String] title to send
|
419
|
-
# @param [Array<String>] array_results test data
|
420
|
-
# @return [nil]
|
421
|
-
def send_mail_test_result(mail, title, array_results)
|
422
|
-
body = ''
|
423
|
-
array_results.each do |current_result|
|
424
|
-
current_result[1] = 'OK' if current_result[1].nil?
|
425
|
-
body = "#{body}#{current_result[0]}\t#{current_result[1]}\n"
|
426
|
-
end
|
427
|
-
|
428
|
-
if mail.is_a?(Array)
|
429
|
-
mail.each do |current_mail_user|
|
430
|
-
email = @gmail.compose do
|
431
|
-
to current_mail_user
|
432
|
-
subject title
|
433
|
-
body body
|
434
|
-
end
|
435
|
-
email.deliver!
|
436
|
-
end
|
437
|
-
else
|
438
|
-
email = @gmail.compose do
|
439
|
-
to mail
|
440
|
-
subject title
|
441
|
-
body body
|
442
|
-
end
|
443
|
-
email.deliver!
|
444
|
-
end
|
445
|
-
end
|
446
|
-
|
447
|
-
# If not returning nested levels please change content of file
|
448
|
-
# +/home/#{user}/.rvm/gems/#{gemset}/gems/gmail-0.4.0/lib/gmail/labels.rb+
|
449
|
-
# to content of that file: https://github.com/jgrevich/gmail/blob/6ed88950bd631696aeb1bc4b9133b03d1ae4055f/lib/gmail/labels.rb
|
450
|
-
# @return [Array<String>] list of all labels
|
451
|
-
def get_labels
|
452
|
-
@gmail.labels.all
|
453
|
-
end
|
172
|
+
private
|
454
173
|
|
455
|
-
|
456
|
-
|
457
|
-
def get_unread_mails_with_tags
|
458
|
-
refresh
|
459
|
-
array_of_mail = []
|
460
|
-
mailbox.emails(:unread).each do |current_mail|
|
461
|
-
current_title = current_mail.message.subject
|
462
|
-
current_subject = begin
|
463
|
-
current_mail.html_part.body.decoded.force_encoding('utf-8').encode('UTF-8')
|
464
|
-
rescue StandardError
|
465
|
-
Exception
|
466
|
-
end
|
467
|
-
current_mail.mark(:unread)
|
468
|
-
reply_to = current_mail.reply_to[0] unless current_mail.reply_to.nil?
|
469
|
-
current_tag = current_mail
|
470
|
-
array_of_mail << MailMessage.new(current_title, current_subject, reply_to, current_tag)
|
471
|
-
end
|
472
|
-
array_of_mail
|
174
|
+
def message_found?(given, needed)
|
175
|
+
given.to_s.upcase.include? needed.to_s.upcase
|
473
176
|
end
|
474
177
|
|
475
|
-
# Get body
|
476
|
-
#
|
477
|
-
# @param [
|
178
|
+
# Get message body
|
179
|
+
# Html part if exists, or text part if not
|
180
|
+
# @param [Gmail::Message] message to get
|
478
181
|
# @return [String] body
|
479
|
-
def
|
480
|
-
|
481
|
-
300.times do |current|
|
482
|
-
p "current time: #{current}"
|
483
|
-
messages_array = mailbox.emails(:unread, search: portal_name.to_s)
|
484
|
-
messages_array.each do |current_mail|
|
485
|
-
current_subject = current_mail.message.subject
|
486
|
-
p "current_subject: #{current_subject}"
|
487
|
-
if message_found?(current_subject, subject)
|
488
|
-
body_text = current_mail.message.text_part.body.decoded.force_encoding('utf-8').encode('UTF-8').gsub(/\s+/, ' ').strip
|
489
|
-
return body_text
|
490
|
-
end
|
491
|
-
end
|
492
|
-
end
|
493
|
-
nil
|
494
|
-
end
|
182
|
+
def message_body(message)
|
183
|
+
return message.body.to_s unless message.html_part
|
495
184
|
|
496
|
-
|
497
|
-
|
498
|
-
def message_found?(given, needed)
|
499
|
-
given.to_s.upcase.include? needed.to_s.upcase
|
185
|
+
message.html_part.body.decoded.force_encoding('utf-8').encode('UTF-8')
|
500
186
|
end
|
501
187
|
end
|
502
188
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onlyoffice_gmail_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ONLYOFFICE
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-11-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: gmail
|
@@ -193,6 +193,7 @@ metadata:
|
|
193
193
|
documentation_uri: https://www.rubydoc.info/gems/onlyoffice_gmail_helper
|
194
194
|
homepage_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_gmail_helper
|
195
195
|
source_code_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_gmail_helper
|
196
|
+
rubygems_mfa_required: 'true'
|
196
197
|
post_install_message:
|
197
198
|
rdoc_options: []
|
198
199
|
require_paths:
|
@@ -208,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
208
209
|
- !ruby/object:Gem::Version
|
209
210
|
version: '0'
|
210
211
|
requirements: []
|
211
|
-
rubygems_version: 3.
|
212
|
+
rubygems_version: 3.2.29
|
212
213
|
signing_key:
|
213
214
|
specification_version: 4
|
214
215
|
summary: ONLYOFFICE Helper Gem for GMail
|