onlyoffice_gmail_helper 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/onlyoffice_gmail_helper.rb +502 -0
- data/lib/onlyoffice_gmail_helper/email_account.rb +30 -0
- data/lib/onlyoffice_gmail_helper/email_account/mail_account.rb +17 -0
- data/lib/onlyoffice_gmail_helper/mail_message.rb +67 -0
- data/lib/onlyoffice_gmail_helper/name.rb +7 -0
- data/lib/onlyoffice_gmail_helper/version.rb +6 -0
- metadata +215 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a72371e5187dc5f9ea6b6cd938c77d0f3288f9c44b6399dd71fd392aa6eb1441
|
4
|
+
data.tar.gz: 13668d6d4485109a04a6449275f81acb6eb57fcaa2b1c581bbc5baf1f426fcde
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a4da08cf22fda03b870d5d18d4bdca3a86c763b00415eec83adae9e75e9f633f6c6abe2dda795bd26561f49041bd3b6b07bbc61e8f089a6e84502d7b48fb44d2
|
7
|
+
data.tar.gz: baf3cf12a74db4fbdbfcc55c814b469c78c631264187398aba19fad5eba5728fe38373b8c86c30eab29217a6159e3fbf3686c32b6f2178f89aea83baf9bb9dd6
|
@@ -0,0 +1,502 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'gmail'
|
4
|
+
require 'onlyoffice_logger_helper'
|
5
|
+
require 'onlyoffice_gmail_helper/email_account'
|
6
|
+
require 'onlyoffice_gmail_helper/mail_message'
|
7
|
+
require 'onlyoffice_gmail_helper/version'
|
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
|
+
# Helper module for GMail
|
37
|
+
module OnlyofficeGmailHelper
|
38
|
+
# Main class of gem
|
39
|
+
class Gmail_helper
|
40
|
+
# @return [Gmail] gmail object
|
41
|
+
attr_accessor :gmail
|
42
|
+
# @return [String] user name
|
43
|
+
attr_accessor :user
|
44
|
+
# @return [String] user password
|
45
|
+
attr_accessor :password
|
46
|
+
# @return [Integer] default timeout for operation
|
47
|
+
attr_accessor :timeout_for_mail
|
48
|
+
# @return [String] default label
|
49
|
+
attr_accessor :label
|
50
|
+
|
51
|
+
def initialize(user = EmailAccount::GMAIL_DEFAULT.login, password = EmailAccount::GMAIL_DEFAULT.password, timeout_for_mail = 10, label = nil)
|
52
|
+
@user = user
|
53
|
+
@password = password
|
54
|
+
@gmail = Gmail.new(user, password)
|
55
|
+
@imap = @gmail.instance_variable_get(:@imap)
|
56
|
+
@timeout_for_mail = timeout_for_mail
|
57
|
+
@label = label
|
58
|
+
end
|
59
|
+
|
60
|
+
# Select mailbox
|
61
|
+
# @return [nil]
|
62
|
+
def mailbox
|
63
|
+
if @label
|
64
|
+
if @label == :inbox
|
65
|
+
@gmail.inbox
|
66
|
+
else
|
67
|
+
@gmail.mailbox(@label)
|
68
|
+
end
|
69
|
+
else
|
70
|
+
@gmail.mailbox('[Gmail]/All Mail')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Perform logout
|
75
|
+
# @return [nil]
|
76
|
+
def logout
|
77
|
+
@gmail.logout
|
78
|
+
@imap.disconnect until @imap.disconnected?
|
79
|
+
rescue StandardError
|
80
|
+
Exception
|
81
|
+
end
|
82
|
+
|
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
|
+
# Get mail body by title
|
152
|
+
# @param [String] portal_address to filter
|
153
|
+
# @param [String] subject to find
|
154
|
+
# @param [Integer] time to wait
|
155
|
+
# @param [Boolean] delete if needed
|
156
|
+
# @return [MailMessage] found message
|
157
|
+
def get_body_message_by_title(portal_address, subject, time = 300, delete = true)
|
158
|
+
start_time = Time.now
|
159
|
+
flags = block_given? ? yield : { search: portal_address.to_s }
|
160
|
+
while Time.now - start_time < time
|
161
|
+
messages_array = mailbox.emails(:unread, flags)
|
162
|
+
messages_array.each do |current_mail|
|
163
|
+
next unless message_found?(current_mail.message.subject, subject)
|
164
|
+
|
165
|
+
body = begin
|
166
|
+
current_mail.html_part.body.decoded.force_encoding('utf-8').encode('UTF-8')
|
167
|
+
rescue StandardError
|
168
|
+
Exception
|
169
|
+
end
|
170
|
+
current_mail.delete! if delete
|
171
|
+
return body
|
172
|
+
end
|
173
|
+
end
|
174
|
+
nil
|
175
|
+
end
|
176
|
+
|
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
|
+
# Check message for message with portal
|
228
|
+
# @param [String] message title
|
229
|
+
# @param [String] current_portal_full_name name
|
230
|
+
# @param [Integer] times to wait
|
231
|
+
# @return [Boolean] is messag found
|
232
|
+
def check_messages_for_message_with_portal_address(message, current_portal_full_name, times: 300)
|
233
|
+
times.times do
|
234
|
+
messages_array = mailbox.emails(:unread, search: current_portal_full_name.to_s)
|
235
|
+
messages_array.each do |current_mail|
|
236
|
+
next unless message_found?(current_mail.message.subject, message.title)
|
237
|
+
|
238
|
+
OnlyofficeLoggerHelper.log('Email successfully found and removed')
|
239
|
+
current_mail.delete!
|
240
|
+
return true
|
241
|
+
end
|
242
|
+
sleep 1
|
243
|
+
end
|
244
|
+
false
|
245
|
+
end
|
246
|
+
|
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
|
+
# Delete specific message
|
270
|
+
# @param [String] message title to delete
|
271
|
+
# @return [nil]
|
272
|
+
def delete_messages(message)
|
273
|
+
message = [message] unless message.is_a?(Array)
|
274
|
+
message.each do |message_to_delete|
|
275
|
+
mailbox.emails(:unread).each do |current_mail|
|
276
|
+
if message_to_delete.title == current_mail.message.subject
|
277
|
+
current_mail.delete!
|
278
|
+
else
|
279
|
+
begin
|
280
|
+
current_mail.mark(:unread)
|
281
|
+
rescue StandardError
|
282
|
+
Exception
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
# Delete all messsages
|
290
|
+
# @return [nil]
|
291
|
+
def delete_all_messages
|
292
|
+
OnlyofficeLoggerHelper.log("Start deleting all messaged on mail: #{@user}")
|
293
|
+
mailbox.emails.each(&:delete!)
|
294
|
+
@gmail.logout
|
295
|
+
OnlyofficeLoggerHelper.log("Finished deleting all messaged on mail: #{@user}")
|
296
|
+
end
|
297
|
+
|
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
|
+
# Send mail
|
342
|
+
# @param [String] email to send
|
343
|
+
# @param [String] title to send
|
344
|
+
# @param [String] body to send
|
345
|
+
# @param [String] attachment to send
|
346
|
+
# @return [nil]
|
347
|
+
def send_mail(email, title, body, attachment = nil)
|
348
|
+
email = @gmail.compose do
|
349
|
+
to email
|
350
|
+
subject title
|
351
|
+
body body
|
352
|
+
add_file attachment unless attachment.nil?
|
353
|
+
end
|
354
|
+
email.deliver!
|
355
|
+
OnlyofficeLoggerHelper.log("send_mail(#{email}, #{title}, #{body}, #{attachment})")
|
356
|
+
end
|
357
|
+
|
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
|
+
# List all mail in label with date
|
378
|
+
# @param [String] string label
|
379
|
+
# @param [Date] date_start to find
|
380
|
+
# @param [Date] date_end to find
|
381
|
+
# @param [String] to whom message send
|
382
|
+
# @return [Array<MailMessage>] list of results
|
383
|
+
def mail_in_label_with_date(string, date_start, date_end, to = nil)
|
384
|
+
array_of_mail = []
|
385
|
+
@gmail.mailbox(string).emails(after: date_start, before: date_end, to: to).each do |current_mail|
|
386
|
+
current_title = current_mail.message.subject
|
387
|
+
current_subject = begin
|
388
|
+
current_mail.html_part.body.decoded
|
389
|
+
.force_encoding('utf-8').encode('UTF-8')
|
390
|
+
rescue StandardError
|
391
|
+
Exception
|
392
|
+
end
|
393
|
+
reply_to = current_mail.reply_to[0] unless current_mail.reply_to.nil?
|
394
|
+
array_of_mail << MailMessage.new(current_title,
|
395
|
+
current_subject,
|
396
|
+
reply_to, Time.parse(current_mail.date))
|
397
|
+
end
|
398
|
+
array_of_mail
|
399
|
+
end
|
400
|
+
|
401
|
+
# Delete all mail from sender
|
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
|
454
|
+
|
455
|
+
# Get list of unread mails with tags
|
456
|
+
# @return [Array<MailMessage>] result
|
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
|
473
|
+
end
|
474
|
+
|
475
|
+
# Get body by email subject
|
476
|
+
# @param [String] subject to get
|
477
|
+
# @param [String] portal_name to filter
|
478
|
+
# @return [String] body
|
479
|
+
def get_body_by_subject_email(subject, portal_name)
|
480
|
+
p 'get_body_by_subject_email'
|
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
|
495
|
+
|
496
|
+
private
|
497
|
+
|
498
|
+
def message_found?(given, needed)
|
499
|
+
given.to_s.upcase.include? needed.to_s.upcase
|
500
|
+
end
|
501
|
+
end
|
502
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'email_account/mail_account'
|
4
|
+
|
5
|
+
module OnlyofficeGmailHelper
|
6
|
+
# Class for storing default mail accounts
|
7
|
+
class EmailAccount
|
8
|
+
# Read default values for account
|
9
|
+
# @return [Hash] result
|
10
|
+
def self.read_defaults
|
11
|
+
return read_env_defaults if read_env_defaults
|
12
|
+
|
13
|
+
yaml = YAML.load_file("#{Dir.home}/.gem-onlyoffice_gmail_helper/config.yml")
|
14
|
+
{ user: yaml['user'], password: yaml['password'] }
|
15
|
+
rescue Errno::ENOENT
|
16
|
+
raise Errno::ENOENT, 'No config found. Please create ~/.gem-onlyoffice_gmail_helper/config.yml'
|
17
|
+
end
|
18
|
+
|
19
|
+
# Read keys from env variables
|
20
|
+
# @return [Hash]
|
21
|
+
def self.read_env_defaults
|
22
|
+
return false unless ENV['GMAIL_USER'] && ENV['GMAIL_PASSWORD']
|
23
|
+
|
24
|
+
{ user: ENV['GMAIL_USER'], password: ENV['GMAIL_PASSWORD'] }
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [MailAccount] default account
|
28
|
+
GMAIL_DEFAULT = MailAccount.new(read_defaults[:user], read_defaults[:password])
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OnlyofficeGmailHelper
|
4
|
+
# Class for storing mail account data
|
5
|
+
class MailAccount
|
6
|
+
# @return [String] user name
|
7
|
+
attr_accessor :username
|
8
|
+
alias login username
|
9
|
+
# @return [String] user password
|
10
|
+
attr_accessor :password
|
11
|
+
|
12
|
+
def initialize(user, pass)
|
13
|
+
@username = user
|
14
|
+
@password = pass
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OnlyofficeGmailHelper
|
4
|
+
# Class for working with single message
|
5
|
+
class MailMessage
|
6
|
+
# @return [String] mail title
|
7
|
+
attr_accessor :title
|
8
|
+
# @return [String] mail content
|
9
|
+
attr_accessor :content
|
10
|
+
# @return [String] reply to field
|
11
|
+
attr_accessor :reply_to
|
12
|
+
# @return [String] date field
|
13
|
+
attr_accessor :date
|
14
|
+
# @return [String] tags field
|
15
|
+
attr_accessor :tags
|
16
|
+
|
17
|
+
def initialize(title, content = nil, reply_to = nil, date = nil, tags = nil)
|
18
|
+
@title = title
|
19
|
+
@content = content
|
20
|
+
@reply_to = reply_to
|
21
|
+
unless @content.nil? && !content.is_a?(Regexp)
|
22
|
+
begin
|
23
|
+
@content.delete!("\n")
|
24
|
+
rescue StandardError
|
25
|
+
Exception
|
26
|
+
end
|
27
|
+
begin
|
28
|
+
@content.gsub!("\r\n", '')
|
29
|
+
rescue StandardError
|
30
|
+
Exception
|
31
|
+
end
|
32
|
+
begin
|
33
|
+
@content.gsub!("\n\n", '')
|
34
|
+
rescue StandardError
|
35
|
+
Exception
|
36
|
+
end
|
37
|
+
begin
|
38
|
+
@content.gsub!('“', '"')
|
39
|
+
rescue StandardError
|
40
|
+
Exception
|
41
|
+
end
|
42
|
+
begin
|
43
|
+
@content.gsub!('”', '"')
|
44
|
+
rescue StandardError
|
45
|
+
Exception
|
46
|
+
end
|
47
|
+
begin
|
48
|
+
@content.tr!("\r", ' ')
|
49
|
+
rescue StandardError
|
50
|
+
Exception
|
51
|
+
end
|
52
|
+
end
|
53
|
+
@date = date
|
54
|
+
@tags = tags
|
55
|
+
end
|
56
|
+
|
57
|
+
# Compare message with other
|
58
|
+
# @param [MailMessage] other to compare
|
59
|
+
# @return [Boolean] result
|
60
|
+
def ==(other)
|
61
|
+
compare_title = (title.delete("\n") == other.title.delete("\n"))
|
62
|
+
compare_body = true
|
63
|
+
compare_body = false if (StaticDataTeamLab.check_email_body if defined?(StaticDataTeamLab.check_email_body)) && compare_title && (other.content =~ content).nonzero?
|
64
|
+
compare_title && compare_body
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
metadata
ADDED
@@ -0,0 +1,215 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: onlyoffice_gmail_helper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ONLYOFFICE
|
8
|
+
- Pavel Lobashov
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2021-01-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: gmail
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0.6'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0.6'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: onlyoffice_logger_helper
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: overcommit
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '13'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '13'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '3'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '3'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rubocop
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '1'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '1'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: rubocop-performance
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '1'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '1'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: rubocop-rake
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - "~>"
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - "~>"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rubocop-rspec
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - "~>"
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '2'
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '2'
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: simplecov
|
142
|
+
requirement: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - "~>"
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
type: :development
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - "~>"
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
- !ruby/object:Gem::Dependency
|
155
|
+
name: yard
|
156
|
+
requirement: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - "~>"
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: 0.9.20
|
164
|
+
type: :development
|
165
|
+
prerelease: false
|
166
|
+
version_requirements: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - "~>"
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 0.9.20
|
174
|
+
description: ONLYOFFICE Helper Gem for GMail. Used in QA
|
175
|
+
email:
|
176
|
+
- shockwavenn@gmail.com
|
177
|
+
executables: []
|
178
|
+
extensions: []
|
179
|
+
extra_rdoc_files: []
|
180
|
+
files:
|
181
|
+
- lib/onlyoffice_gmail_helper.rb
|
182
|
+
- lib/onlyoffice_gmail_helper/email_account.rb
|
183
|
+
- lib/onlyoffice_gmail_helper/email_account/mail_account.rb
|
184
|
+
- lib/onlyoffice_gmail_helper/mail_message.rb
|
185
|
+
- lib/onlyoffice_gmail_helper/name.rb
|
186
|
+
- lib/onlyoffice_gmail_helper/version.rb
|
187
|
+
homepage: https://github.com/ONLYOFFICE-QA/onlyoffice_gmail_helper
|
188
|
+
licenses:
|
189
|
+
- AGPL-3.0
|
190
|
+
metadata:
|
191
|
+
bug_tracker_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_gmail_helper/issues
|
192
|
+
changelog_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_gmail_helper/blob/master/CHANGELOG.md
|
193
|
+
documentation_uri: https://www.rubydoc.info/gems/onlyoffice_gmail_helper
|
194
|
+
homepage_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_gmail_helper
|
195
|
+
source_code_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_gmail_helper
|
196
|
+
post_install_message:
|
197
|
+
rdoc_options: []
|
198
|
+
require_paths:
|
199
|
+
- lib
|
200
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
201
|
+
requirements:
|
202
|
+
- - ">="
|
203
|
+
- !ruby/object:Gem::Version
|
204
|
+
version: '2.5'
|
205
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
206
|
+
requirements:
|
207
|
+
- - ">="
|
208
|
+
- !ruby/object:Gem::Version
|
209
|
+
version: '0'
|
210
|
+
requirements: []
|
211
|
+
rubygems_version: 3.1.4
|
212
|
+
signing_key:
|
213
|
+
specification_version: 4
|
214
|
+
summary: ONLYOFFICE Helper Gem for GMail
|
215
|
+
test_files: []
|