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)


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

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'

#notesArray<Note>

The associated notes.

Returns:

Since:

  • 0.2.0



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

has_many :notes, dependent: :destroy

#organization_departmentOrganizationDepartment?

The organization department that uses the email address.

Returns:

Since:

  • 0.2.0



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

has_one :organization_department, dependent: :nullify

#organization_email_addressOrganizationEmailAddress?

The association of the organization that use the email address.

Returns:

Since:

  • 0.2.0



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

has_one :organization_email_address, dependent: :destroy

#organization_membersOrganizationMember?

The organization member that uses the email address.

Returns:

Since:

  • 0.2.0



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

has_one :organization_member, dependent: :nullify

#passwordsArray<EmailAddress>

Any passwords used with the email address.

Returns:

Since:

  • 0.2.0



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

has_many :passwords, through: :credentials

#peopleArray<Person>

The people that use the email address.

Returns:

Since:

  • 0.2.0



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

has_many :people, through: :personal_email_addresses

#personal_email_addressesArray<PersonalEmailAddress>

The association between people and the email address.

Returns:

Since:

  • 0.2.0



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

has_many :personal_email_addresses, dependent: :destroy

#service_credentialsArray<ServiceCredential>

The service credentials that use the email address.

Returns:

Since:

  • 0.2.0



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

has_many :service_credentials, through: :credentials

#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

#web_credentialsArray<WebCredential>

Any web credentials that use the email address.

Returns:

Since:

  • 0.2.0



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

has_many :web_credentials, through: :credentials

Class Method Details

.for_organization(name) ⇒ Array<EmailAddress>

Queries all email addresses that are associated with the organization.

Parameters:

  • name (String)

    The organization name to search for.

Returns:

  • (Array<EmailAddress>)

    The email addresses that are associated with the organization.

Since:

  • 0.2.0



259
260
261
262
263
264
265
# File 'lib/ronin/db/email_address.rb', line 259

def self.for_organization(name)
  joins(organization_email_address: :organization).where(
    organization_email_address: {
      ronin_organizations: {name: name}
    }
  )
end

.for_person(full_name) ⇒ Array<EmailAddress>

Queries all email addresses that are associated with the person.

Parameters:

  • full_name (String)

    The person's full name to search for.

Returns:

  • (Array<EmailAddress>)

    The email addresses that are associated with the person.

Since:

  • 0.2.0



242
243
244
# File 'lib/ronin/db/email_address.rb', line 242

def self.for_person(full_name)
  joins(:people).where(people: {full_name: full_name})
end

.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.



294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/ronin/db/email_address.rb', line 294

def self.import(email)
  unless email =~ URI::MailTo::EMAIL_REGEXP
    raise(ArgumentError,"invalid email address: #{email.inspect}")
  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:



276
277
278
# File 'lib/ronin/db/email_address.rb', line 276

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:



172
173
174
# File 'lib/ronin/db/email_address.rb', line 172

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:



187
188
189
# File 'lib/ronin/db/email_address.rb', line 187

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

.with_password(password) ⇒ Array<EmailAddress>

Queries all email addresses that are associated with the password.

Parameters:

  • password (String)

    The plain-text password.

Returns:

  • (Array<EmailAddress>)

    The email addresses that are associated with the password.

Since:

  • 0.2.0



219
220
221
222
223
224
225
226
227
# File 'lib/ronin/db/email_address.rb', line 219

def self.with_password(password)
  joins(credentials: :password).where(
    credentials: {
      ronin_passwords: {
        plain_text: password
      }
    }
  )
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:



202
203
204
# File 'lib/ronin/db/email_address.rb', line 202

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.



337
338
339
# File 'lib/ronin/db/email_address.rb', line 337

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.



349
350
351
# File 'lib/ronin/db/email_address.rb', line 349

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

#userString

The user of the email address.

Returns:

  • (String)

    The user name.



325
326
327
# File 'lib/ronin/db/email_address.rb', line 325

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