Class: Ronin::DB::EmailAddress

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Model, Model::Importable
Defined in:
lib/ronin/db/email_address.rb

Overview

Represents email addresses and their associated user names and host names.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model::Importable

included

Methods included from Model

included

Instance Attribute Details

#addressString

The raw string of the email address.

Returns:

  • (String)


48
# File 'lib/ronin/db/email_address.rb', line 48

attribute :address, :string

#created_atTime

Tracks when the email address was created at.

Returns:

  • (Time)


87
# File 'lib/ronin/db/email_address.rb', line 87

attribute :created_at, :datetime

#credentialsArray<Credential>

Any web credentials that are associated with the email address.

Returns:



81
# File 'lib/ronin/db/email_address.rb', line 81

has_many :credentials, dependent: :destroy

#host_nameHostName

The host-name component of the email address.

Returns:



68
# File 'lib/ronin/db/email_address.rb', line 68

belongs_to :host_name, required: true

#idInteger

The primary key of the email address.

Returns:

  • (Integer)


42
# File 'lib/ronin/db/email_address.rb', line 42

attribute :id, :integer

#ip_addressesArray<IPAddress>

Any IP addresses associated with the host name.

Returns:



74
75
# File 'lib/ronin/db/email_address.rb', line 74

has_many :ip_addresses, through:    :host_name,
class_name: 'IPAddress'

#user_nameUserName

The user-name component of the email address.

Returns:



61
# File 'lib/ronin/db/email_address.rb', line 61

belongs_to :user_name, required: true

Class Method Details

.import(email) ⇒ EmailAddress

Imports an email address.

Parameters:

  • email (String)

    The email address to parse.

Returns:

  • (EmailAddress)

    A new or previously saved email address resource.

Raises:

  • (ArgumentError)

    The email address did not have a user name or a host name.



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/ronin/db/email_address.rb', line 161

def self.import(email)
  if email =~ /\s/
    raise(ArgumentError,"email address #{email.inspect} must not contain spaces")
  end

  normalized_email = email.downcase
  user, host       = normalized_email.split('@',2)

  if user.empty?
    raise(ArgumentError,"email address #{email.inspect} must have a user name")
  end

  if host.empty?
    raise(ArgumentError,"email address #{email.inspect} must have a host name")
  end

  return create(
    address:   normalized_email,
    user_name: UserName.find_or_import(user),
    host_name: HostName.find_or_import(host)
  )
end

.lookup(email) ⇒ EmailAddress?

Looks up the email address.

Parameters:

  • email (String)

    The raw email address string.

Returns:



143
144
145
# File 'lib/ronin/db/email_address.rb', line 143

def self.lookup(email)
  find_by(address: email)
end

.with_host_name(name) ⇒ Array<EmailAddress>

Searches for email addresses associated with the given host name(s).

Parameters:

  • name (Array<String>, String)

    The host name(s) to search for.

Returns:



100
101
102
# File 'lib/ronin/db/email_address.rb', line 100

def self.with_host_name(name)
  joins(:host_name).where(host_name: {name: name})
end

.with_ip_address(ip) ⇒ Array<EmailAddress>

Searches for email addresses associated with the given IP address(es).

Parameters:

  • ip (Array<String>, String)

    The IP address(es) to search for.

Returns:



115
116
117
# File 'lib/ronin/db/email_address.rb', line 115

def self.with_ip_address(ip)
  joins(:ip_addresses).where(ip_addresses: {address: ip})
end

.with_user_name(name) ⇒ Array<EmailAddress>

Searches for email addresses associated with the given user name(s).

Parameters:

  • name (Array<String>, String)

    The user name(s) to search for.

Returns:



130
131
132
# File 'lib/ronin/db/email_address.rb', line 130

def self.with_user_name(name)
  joins(:user_name).where(user_name: {name: name})
end

Instance Method Details

#hostString

The host of the email address.

Returns:

  • (String)

    The host name.



204
205
206
# File 'lib/ronin/db/email_address.rb', line 204

def host
  self.host_name.name if self.host_name
end

#to_sString

Converts the email address into a String.

Returns:

  • (String)

    The raw email address.



216
217
218
# File 'lib/ronin/db/email_address.rb', line 216

def to_s
  "#{self.user_name}@#{self.host_name}"
end

#userString

The user of the email address.

Returns:

  • (String)

    The user name.



192
193
194
# File 'lib/ronin/db/email_address.rb', line 192

def user
  self.user_name.name if self.user_name
end