mailosaur 3.0.1 → 5.0.1.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +14 -13
  3. data/README.md +42 -8
  4. data/lib/Mailosaur/analysis.rb +184 -0
  5. data/lib/Mailosaur/files.rb +291 -0
  6. data/lib/Mailosaur/mailosaur_base_client.rb +120 -0
  7. data/lib/Mailosaur/mailosaur_error.rb +23 -0
  8. data/lib/Mailosaur/messages.rb +673 -0
  9. data/lib/Mailosaur/models/attachment.rb +99 -0
  10. data/lib/Mailosaur/models/forwarding_rule.rb +78 -0
  11. data/lib/Mailosaur/models/image.rb +55 -0
  12. data/lib/Mailosaur/models/link.rb +55 -0
  13. data/lib/Mailosaur/models/message.rb +219 -0
  14. data/lib/Mailosaur/models/message_address.rb +66 -0
  15. data/lib/Mailosaur/models/message_content.rb +84 -0
  16. data/lib/Mailosaur/models/message_header.rb +55 -0
  17. data/lib/Mailosaur/models/message_list_result.rb +54 -0
  18. data/lib/Mailosaur/models/message_summary.rb +199 -0
  19. data/lib/Mailosaur/models/metadata.rb +52 -0
  20. data/lib/Mailosaur/models/search_criteria.rb +69 -0
  21. data/lib/Mailosaur/models/server.rb +118 -0
  22. data/lib/Mailosaur/models/server_create_options.rb +44 -0
  23. data/lib/Mailosaur/models/server_list_result.rb +54 -0
  24. data/lib/Mailosaur/models/spam_analysis_result.rb +56 -0
  25. data/lib/Mailosaur/models/spam_assassin_rule.rb +66 -0
  26. data/lib/Mailosaur/models/spam_filter_results.rb +53 -0
  27. data/lib/Mailosaur/module_definition.rb +6 -0
  28. data/lib/Mailosaur/servers.rb +542 -0
  29. data/lib/Mailosaur/version.rb +8 -0
  30. data/lib/mailosaur.rb +52 -108
  31. metadata +78 -46
  32. data/lib/helper.rb +0 -6
  33. data/lib/mailosaur/attachment.rb +0 -10
  34. data/lib/mailosaur/email.rb +0 -23
  35. data/lib/mailosaur/email_address.rb +0 -9
  36. data/lib/mailosaur/email_data.rb +0 -13
  37. data/lib/mailosaur/image.rb +0 -8
  38. data/lib/mailosaur/link.rb +0 -8
  39. data/lib/mailosaur/message_generator.rb +0 -31
data/lib/mailosaur.rb CHANGED
@@ -1,113 +1,57 @@
1
- require_relative 'helper.rb'
2
-
3
-
4
- class Mailosaur
5
- attr_reader :message
6
-
7
- def initialize(mailbox = nil, apiKey = nil, base_url = nil, smtp_host = nil)
8
- @mailbox = ENV['MAILOSAUR_MAILBOX'] || mailbox
9
- @api_key = ENV['MAILOSAUR_APIKEY'] || apiKey
10
- @base_url = base_url || ENV['MAILOSAUR_BASE_URL'] || 'https://mailosaur.com/api'
11
- @smtp_host = smtp_host || ENV['MAILOSAUR_SMTP_HOST'] || 'mailosaur.io'
12
- @message = MessageGenerator.new
13
- end
14
-
15
- # Retrieves all emails which have the searchPattern text in their body or subject.
16
- def get_emails(search_criteria = {})
17
- if search_criteria.is_a? String
18
- search_criteria = {'search' => search_criteria}
19
- end
20
- search_criteria['key'] = @api_key
21
- response = send_get_emails_request(search_criteria)
22
- if !response.nil? && response.length > 2
23
- data = JSON.parse(response.body)
24
- data.map { |em| Email.new(em) }
25
- else
26
- message.no_emails_found(search_criteria)
1
+ require 'date'
2
+ require 'json'
3
+ require 'base64'
4
+ require 'erb'
5
+ require 'securerandom'
6
+ require 'time'
7
+ require 'timeliness'
8
+ require 'faraday'
9
+ require 'faraday-cookie_jar'
10
+ require 'concurrent'
11
+ require 'ms_rest'
12
+ require 'Mailosaur/module_definition'
13
+
14
+ module Mailosaur
15
+ autoload :Analysis, 'Mailosaur/analysis.rb'
16
+ autoload :Files, 'Mailosaur/files.rb'
17
+ autoload :Messages, 'Mailosaur/messages.rb'
18
+ autoload :Servers, 'Mailosaur/servers.rb'
19
+ autoload :MailosaurBaseClient, 'Mailosaur/mailosaur_base_client.rb'
20
+ autoload :MailosaurError, 'Mailosaur/mailosaur_error.rb'
21
+
22
+ module Models
23
+ autoload :MessageHeader, 'Mailosaur/models/message_header.rb'
24
+ autoload :SpamAssassinRule, 'Mailosaur/models/spam_assassin_rule.rb'
25
+ autoload :Metadata, 'Mailosaur/models/metadata.rb'
26
+ autoload :SpamAnalysisResult, 'Mailosaur/models/spam_analysis_result.rb'
27
+ autoload :Message, 'Mailosaur/models/message.rb'
28
+ autoload :MessageAddress, 'Mailosaur/models/message_address.rb'
29
+ autoload :MessageSummary, 'Mailosaur/models/message_summary.rb'
30
+ autoload :Image, 'Mailosaur/models/image.rb'
31
+ autoload :MessageListResult, 'Mailosaur/models/message_list_result.rb'
32
+ autoload :Attachment, 'Mailosaur/models/attachment.rb'
33
+ autoload :SearchCriteria, 'Mailosaur/models/search_criteria.rb'
34
+ autoload :ForwardingRule, 'Mailosaur/models/forwarding_rule.rb'
35
+ autoload :MessageContent, 'Mailosaur/models/message_content.rb'
36
+ autoload :Server, 'Mailosaur/models/server.rb'
37
+ autoload :Link, 'Mailosaur/models/link.rb'
38
+ autoload :ServerListResult, 'Mailosaur/models/server_list_result.rb'
39
+ autoload :SpamFilterResults, 'Mailosaur/models/spam_filter_results.rb'
40
+ autoload :ServerCreateOptions, 'Mailosaur/models/server_create_options.rb'
41
+ end
42
+
43
+ class MailosaurClient < MailosaurBaseClient
44
+ def initialize(api_key, base_url = 'https://mailosaur.com/')
45
+ credentials = MsRest::BasicAuthenticationCredentials.new(api_key, '')
46
+ super(credentials, base_url, nil)
27
47
  end
28
48
  end
29
49
 
30
- # Retrieves all emails sent to the given recipient.
31
- def get_emails_by_recipient(recipient_email)
32
- search_criteria = {'recipient' => recipient_email}
33
- get_emails(search_criteria)
34
- end
35
-
36
- # Retrieves the email with the given id.
37
- def get_email(email_id)
38
- params = {'key' => @api_key}
39
- response = RestClient.get("#{@base_url}/emails/#{email_id}", {:params => params})
40
- data = JSON.parse(response.body)
41
- Email.new(data)
42
- end
43
-
44
- # Deletes all emails in a @mailbox.
45
- def delete_all_emails
46
- query_params = {'key' => @api_key }
47
- RestClient.post("#{@base_url}/mailboxes/#{@mailbox}/empty", nil, {:params => query_params})
48
- end
49
-
50
- # Deletes the email with the given id.
51
- def delete_email(email_id)
52
- params = {'key' => @api_key}
53
- RestClient.post("#{@base_url}/emails/#{email_id}/delete", nil, {:params => params})
54
- end
55
-
56
- # Retrieves the attachment with specified id.
57
- def get_attachment(attachment_id)
58
- params = {'key' => @api_key}
59
- RestClient.get("#{@base_url}/attachments/#{attachment_id}", {:params => params}).body
60
- end
61
-
62
- # Retrieves the complete raw EML file for the rawId given. RawId is a property on the email object.
63
- def get_raw_email(raw_id)
64
- params = {'key' => @api_key}
65
- RestClient.get("#{@base_url}/raw/#{raw_id}", {:params => params}).body
66
- end
67
-
68
- # Generates a random email address which can be used to send emails into the @mailbox.
69
- def generate_email_address
70
- uuid = SecureRandom.hex(3)
71
- "%s.%s@%s" % [uuid, @mailbox, @smtp_host]
72
- end
73
-
74
- # old methods
75
- def getEmails(search_criteria = {})
76
- message.new_syntax('getEmails')
77
- get_emails(search_criteria)
78
- end
79
- def getEmailsByRecipient(recipient_email)
80
- message.new_syntax('getEmailsByRecipient')
81
- get_emails_by_recipient(recipient_email)
82
- end
83
- def getEmail(email_id)
84
- message.new_syntax('getEmail')
85
- get_email(email_id)
86
- end
87
- def deleteAllEmail
88
- message.new_syntax('deleteAllEmail')
89
- delete_all_emails
90
- end
91
- def deleteEmail(email_id)
92
- message.new_syntax('deleteEmail')
93
- delete_email(email_id)
94
- end
95
- def getAttachment(attachment_id)
96
- message.new_syntax('getAttachment')
97
- get_attachment(attachment_id)
98
- end
99
- def getRawEmail(raw_id)
100
- message.new_syntax('getRawEmail')
101
- get_raw_email(raw_id)
102
- end
103
- def generateEmailAddress
104
- message.new_syntax('generateEmailAddress')
105
- generate_email_address
106
- end
107
-
108
- private
109
-
110
- def send_get_emails_request(search_criteria)
111
- RestClient.get("#{@base_url}/mailboxes/#{@mailbox}/emails", {:params => search_criteria})
50
+ # Monkey patch generate_email_address method
51
+ class Servers
52
+ def generate_email_address(server)
53
+ host = ENV['MAILOSAUR_SMTP_HOST'] || 'mailosaur.io'
54
+ '%s.%s@%s' % [SecureRandom.hex(3), server, host]
55
+ end
112
56
  end
113
57
  end
metadata CHANGED
@@ -1,130 +1,162 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailosaur
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 5.0.1.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mailosaur Ltd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-24 00:00:00.000000000 Z
11
+ date: 2018-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.7.6
19
+ version: 2.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.7.6
26
+ version: 2.1.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: mime-types
28
+ name: ms_rest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: '1.16'
33
+ version: 0.7.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: '1.16'
40
+ version: 0.7.2
41
41
  - !ruby/object:Gem::Dependency
42
- name: rest-client
42
+ name: faraday
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.7'
47
+ version: 0.14.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.7'
54
+ version: 0.14.0
55
55
  - !ruby/object:Gem::Dependency
56
- name: mail
56
+ name: faraday-cookie_jar
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '='
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 2.6.1
62
- type: :development
61
+ version: 0.0.6
62
+ type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '='
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 2.6.1
68
+ version: 0.0.6
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 10.4.2
75
+ version: 10.5.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 10.4.2
82
+ version: 10.5.0
83
83
  - !ruby/object:Gem::Dependency
84
- name: pry
84
+ name: mail
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '='
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.10.4
89
+ version: 2.6.1
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '='
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.10.4
96
+ version: 2.6.1
97
97
  - !ruby/object:Gem::Dependency
98
- name: minitest
98
+ name: shoulda-context
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '='
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 5.8.4
103
+ version: 1.2.2
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '='
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.2.2
111
+ - !ruby/object:Gem::Dependency
112
+ name: test-unit
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
109
116
  - !ruby/object:Gem::Version
110
- version: 5.8.4
117
+ version: 3.2.7
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 3.2.7
111
125
  description: Gem containing ruby client library for Mailosaur.
112
- email: support@mailosaur.com
126
+ email: code@mailosaur.com
113
127
  executables: []
114
128
  extensions: []
115
129
  extra_rdoc_files: []
116
130
  files:
117
131
  - LICENSE
118
132
  - README.md
119
- - lib/helper.rb
133
+ - lib/Mailosaur/analysis.rb
134
+ - lib/Mailosaur/files.rb
135
+ - lib/Mailosaur/mailosaur_base_client.rb
136
+ - lib/Mailosaur/mailosaur_error.rb
137
+ - lib/Mailosaur/messages.rb
138
+ - lib/Mailosaur/models/attachment.rb
139
+ - lib/Mailosaur/models/forwarding_rule.rb
140
+ - lib/Mailosaur/models/image.rb
141
+ - lib/Mailosaur/models/link.rb
142
+ - lib/Mailosaur/models/message.rb
143
+ - lib/Mailosaur/models/message_address.rb
144
+ - lib/Mailosaur/models/message_content.rb
145
+ - lib/Mailosaur/models/message_header.rb
146
+ - lib/Mailosaur/models/message_list_result.rb
147
+ - lib/Mailosaur/models/message_summary.rb
148
+ - lib/Mailosaur/models/metadata.rb
149
+ - lib/Mailosaur/models/search_criteria.rb
150
+ - lib/Mailosaur/models/server.rb
151
+ - lib/Mailosaur/models/server_create_options.rb
152
+ - lib/Mailosaur/models/server_list_result.rb
153
+ - lib/Mailosaur/models/spam_analysis_result.rb
154
+ - lib/Mailosaur/models/spam_assassin_rule.rb
155
+ - lib/Mailosaur/models/spam_filter_results.rb
156
+ - lib/Mailosaur/module_definition.rb
157
+ - lib/Mailosaur/servers.rb
158
+ - lib/Mailosaur/version.rb
120
159
  - lib/mailosaur.rb
121
- - lib/mailosaur/attachment.rb
122
- - lib/mailosaur/email.rb
123
- - lib/mailosaur/email_address.rb
124
- - lib/mailosaur/email_data.rb
125
- - lib/mailosaur/image.rb
126
- - lib/mailosaur/link.rb
127
- - lib/mailosaur/message_generator.rb
128
160
  homepage: https://mailosaur.com
129
161
  licenses:
130
162
  - MIT
@@ -140,12 +172,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
172
  version: '0'
141
173
  required_rubygems_version: !ruby/object:Gem::Requirement
142
174
  requirements:
143
- - - ">="
175
+ - - ">"
144
176
  - !ruby/object:Gem::Version
145
- version: '0'
177
+ version: 1.3.1
146
178
  requirements: []
147
179
  rubyforge_project:
148
- rubygems_version: 2.6.14
180
+ rubygems_version: 2.6.13
149
181
  signing_key:
150
182
  specification_version: 4
151
183
  summary: Client library for Mailosaur
data/lib/helper.rb DELETED
@@ -1,6 +0,0 @@
1
- require 'rubygems'
2
- require 'rest_client'
3
- require 'json'
4
- require 'securerandom'
5
- require "#{File.dirname(__FILE__)}/mailosaur/email"
6
- require "#{File.dirname(__FILE__)}/mailosaur/message_generator"
@@ -1,10 +0,0 @@
1
- class Attachment
2
- attr_accessor :contentType, :fileName, :length, :id
3
-
4
- def initialize(hash)
5
- @contentType = hash['contentType']
6
- @fileName = hash['fileName']
7
- @length = hash['length']
8
- @id = hash['id']
9
- end
10
- end
@@ -1,23 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/email_address"
2
- require "#{File.dirname(__FILE__)}/email_data"
3
- require "#{File.dirname(__FILE__)}/attachment"
4
-
5
- class Email
6
- attr_accessor :id, :creationdate, :senderhost, :from, :to, :mailbox, :rawid, :html, :text, :headers, :subject, :priority, :attachments
7
-
8
- def initialize(hash)
9
- @id = hash['id']
10
- @creationdate = DateTime.iso8601(hash['creationdate'])
11
- @senderhost = hash['senderhost'] || hash['senderHost']
12
- @from= hash['from'].map { |f| EmailAddress.new(f) }
13
- @to= hash['to'].map { |t| EmailAddress.new(t) }
14
- @mailbox = hash['mailbox']
15
- @rawid = hash['rawId'] || hash['rawid']
16
- @html = hash.has_key?('html')?EmailData.new(hash['html']):nil
17
- @text = hash.has_key?('text')?EmailData.new(hash['text']):nil
18
- @headers = hash['headers']
19
- @subject = hash['subject']
20
- @priority = hash['priority']
21
- @attachments = hash.has_key?('attachments')?hash['attachments'].map { |a| Attachment.new(a) } : nil
22
- end
23
- end
@@ -1,9 +0,0 @@
1
- class EmailAddress
2
- attr_accessor :address, :name
3
-
4
- def initialize(hash)
5
- @address = hash['address']
6
- @name = hash['name']
7
- end
8
- end
9
-
@@ -1,13 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/link"
2
- require "#{File.dirname(__FILE__)}/image"
3
-
4
-
5
- class EmailData
6
- attr_accessor :links, :body, :images
7
-
8
- def initialize(hash)
9
- @links =hash.has_key?('links') ? hash['links'].map { |a| Link.new(a) } : nil
10
- @body = hash['body']
11
- @images = hash.has_key?('images') ? hash['images'].map { |a| Image.new(a) } : nil
12
- end
13
- end
@@ -1,8 +0,0 @@
1
- class Image
2
- attr_accessor :src, :alt
3
-
4
- def initialize(hash)
5
- @src = hash['src']
6
- @alt = hash['alt']
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- class Link
2
- attr_accessor :href, :text
3
-
4
- def initialize(hash)
5
- @href = hash['href']
6
- @text = hash['text']
7
- end
8
- end
@@ -1,31 +0,0 @@
1
- class MessageGenerator
2
- attr_accessor :message
3
-
4
- def no_emails_found(data)
5
- "\e[36m No emails were found for #{data} \e[0m\n\e[32m Try checking the params. \e[0m"
6
- end
7
-
8
- def new_syntax(method)
9
- puts ":::::: Please use new syntax for #{method} ::::::\n
10
- \e[36m @mailbox.#{look_ruby(method)}(params) \e[0m"
11
- end
12
-
13
- def sleep
14
- puts "\e[36m Let's give the email some time to get there... \e[0m"
15
- end
16
-
17
- private
18
-
19
- def look_ruby(method)
20
- output = String.new
21
- caps = method.scan(/[A-Z]+/).map(&:downcase!)
22
- other = method.split(/[A-Z]+/)
23
- a3 = other.join('_ ')
24
- a4 = a3.split(' ')
25
- words = ''
26
- other.count.times do |i|
27
- words << "#{a4[i]}#{caps[i]}"
28
- end
29
- words
30
- end
31
- end