Class: OnlyofficeIredmailHelper::IredMailHelper

Inherits:
Object
  • Object
show all
Includes:
DeleteMethods, LoginMethods, MailGetters, MailboxesMethods, MessageMethods, MoveMessageMethods, ReadDefaultsMethods, SendMessageMethods
Defined in:
lib/onlyoffice_iredmail_helper.rb

Overview

Class for working with mail

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SendMessageMethods

#create_msg, #send_mail

Methods included from MessageMethods

#mark_message_as_seen

Methods included from MailGetters

#email_by_date_and_title, #get_html_body_email_by_subject, #get_text_body_email_by_subject

Methods included from MailboxesMethods

#create_mailbox, #delete_mailbox, #mailboxes

Methods included from LoginMethods

#login

Methods included from DeleteMethods

#delete_all_messages, #delete_email_by_subject

Constructor Details

#initialize(options = {}) ⇒ IredMailHelper

Returns a new instance of IredMailHelper.



34
35
36
37
38
39
40
41
42
# File 'lib/onlyoffice_iredmail_helper.rb', line 34

def initialize(options = {})
  read_defaults
  @domainname = options[:domainname] || @default_domain
  @username = options[:username] || @default_user
  @password = options[:password] || @default_password
  @subject = options[:subject] || @default_subject
  @body = options[:body]
  @mailbox_for_archive = 'checked'
end

Instance Attribute Details

#usernameObject (readonly)

Returns the value of attribute username.



32
33
34
# File 'lib/onlyoffice_iredmail_helper.rb', line 32

def username
  @username
end

Instance Method Details

#check_email_by_subject(options = {}, times = 300, move_out = false) ⇒ True, False

Check if message exists by params

Parameters:

  • options (Hash) (defaults to: {})

    options of get

  • times (Integer) (defaults to: 300)

    count to check

Returns:

  • (True, False)

    result of check



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/onlyoffice_iredmail_helper.rb', line 77

def check_email_by_subject(options = {}, times = 300, move_out = false)
  
  @imap.select('INBOX')
  start_time = Time.now
  while Time.now - start_time < times
    get_emails_search_or_new(options).each do |message_id|
      string_found = get_mail_data(message_id, options[:search])[:subject].to_s.upcase.gsub(/\s+/, ' ')
      string_to_be_found = options[:subject].to_s.upcase.gsub(/\s+/, ' ')
      next unless string_found.include? string_to_be_found

      move_out_or_mark_seen(message_id, move_out)
      return true
    end
  end
  false
end

#get_email_by_subject(options = {}, times = 300, move_out = false) ⇒ Hash

Get email by subject

Parameters:

  • options (Hash) (defaults to: {})

    options of get

  • times (Integer) (defaults to: 300)

    count to check

  • move_out (True, False) (defaults to: false)

    should message to move out

Returns:

  • (Hash)

    mail



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/onlyoffice_iredmail_helper.rb', line 99

def get_email_by_subject(options = {}, times = 300, move_out = false)
  
  @imap.select('INBOX')
  start_time = Time.now
  while Time.now - start_time < times
    get_emails_search_or_new(options).each do |message_id|
      mail = get_mail_data(message_id)
      string_found = mail[:subject].to_s.upcase.gsub(/\s+/, ' ')
      string_to_be_found = options[:subject].to_s.upcase.gsub(/\s+/, ' ')
      next unless string_found.include? string_to_be_found

      move_out_or_mark_seen(message_id, move_out)
      return mail
    end
  end
  nil
end

#inspectString

Returns inspect info.

Returns:

  • (String)

    inspect info



45
46
47
48
49
# File 'lib/onlyoffice_iredmail_helper.rb', line 45

def inspect
  "IredMailHelper domain: #{@domainname}, " \
    "user: #{@username}, " \
    "subject: #{@subject}"
end

#mail_by_subject(options = {}, times = 300) ⇒ Hash

Get email

Parameters:

  • options (Hash) (defaults to: {})

    options of get

  • times (Integer) (defaults to: 300)

    count to check

Returns:

  • (Hash)

    mail



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/onlyoffice_iredmail_helper.rb', line 55

def mail_by_subject(options = {}, times = 300)
  
  @imap.select('INBOX')
  start_time = Time.now
  while Time.now - start_time < times
    get_emails_search_or_new(options).each do |message_id|
      mail = get_mail_data(message_id)
      mail_subject_found = mail[:subject].to_s.upcase
      mail_subject_to_be_found = options[:subject].to_s.upcase
      next unless mail_subject_found.include? mail_subject_to_be_found

      move_out_or_mark_seen(message_id, options[:move_out])
      return mail
    end
  end
  nil
end