Class: Ronin::DB::EmailAddress
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Ronin::DB::EmailAddress
- 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
-
#address ⇒ String
The raw string of the email address.
-
#created_at ⇒ Time
Tracks when the email address was created at.
-
#credentials ⇒ Array<Credential>
Any web credentials that are associated with the email address.
-
#host_name ⇒ HostName
The host-name component of the email address.
-
#id ⇒ Integer
The primary key of the email address.
-
#ip_addresses ⇒ Array<IPAddress>
Any IP addresses associated with the host name.
-
#notes ⇒ Array<Note>
The associated notes.
-
#organization_department ⇒ OrganizationDepartment?
The organization department that uses the email address.
-
#organization_email_address ⇒ OrganizationEmailAddress?
The association of the organization that use the email address.
-
#organization_members ⇒ OrganizationMember?
The organization member that uses the email address.
-
#passwords ⇒ Array<EmailAddress>
Any passwords used with the email address.
-
#people ⇒ Array<Person>
The people that use the email address.
-
#personal_email_addresses ⇒ Array<PersonalEmailAddress>
The association between people and the email address.
-
#service_credentials ⇒ Array<ServiceCredential>
The service credentials that use the email address.
-
#user_name ⇒ UserName
The user-name component of the email address.
-
#web_credentials ⇒ Array<WebCredential>
Any web credentials that use the email address.
Class Method Summary collapse
-
.for_organization(name) ⇒ Array<EmailAddress>
Queries all email addresses that are associated with the organization.
-
.for_person(full_name) ⇒ Array<EmailAddress>
Queries all email addresses that are associated with the person.
-
.import(email) ⇒ EmailAddress
Imports an email address.
-
.lookup(email) ⇒ EmailAddress?
Looks up the email address.
-
.with_host_name(name) ⇒ Array<EmailAddress>
Searches for email addresses associated with the given host name(s).
-
.with_ip_address(ip) ⇒ Array<EmailAddress>
Searches for email addresses associated with the given IP address(es).
-
.with_password(password) ⇒ Array<EmailAddress>
Queries all email addresses that are associated with the password.
-
.with_user_name(name) ⇒ Array<EmailAddress>
Searches for email addresses associated with the given user name(s).
Instance Method Summary collapse
-
#host ⇒ String
The host of the email address.
-
#to_s ⇒ String
Converts the email address into a String.
-
#user ⇒ String
The user of the email address.
Methods included from Model::Importable
Methods included from Model
Instance Attribute Details
#address ⇒ String
The raw string of the email address.
48 |
# File 'lib/ronin/db/email_address.rb', line 48 attribute :address, :string |
#created_at ⇒ Time
Tracks when the email address was created at.
111 |
# File 'lib/ronin/db/email_address.rb', line 111 attribute :created_at, :datetime |
#credentials ⇒ Array<Credential>
Any web credentials that are associated with the email address.
81 |
# File 'lib/ronin/db/email_address.rb', line 81 has_many :credentials, dependent: :destroy |
#host_name ⇒ HostName
The host-name component of the email address.
68 |
# File 'lib/ronin/db/email_address.rb', line 68 belongs_to :host_name, required: true |
#id ⇒ Integer
The primary key of the email address.
42 |
# File 'lib/ronin/db/email_address.rb', line 42 attribute :id, :integer |
#ip_addresses ⇒ Array<IPAddress>
Any IP addresses associated with the host name.
74 75 |
# File 'lib/ronin/db/email_address.rb', line 74 has_many :ip_addresses, through: :host_name, class_name: 'IPAddress' |
#notes ⇒ Array<Note>
The associated notes.
159 |
# File 'lib/ronin/db/email_address.rb', line 159 has_many :notes, dependent: :destroy |
#organization_department ⇒ OrganizationDepartment?
The organization department that uses the email address.
143 |
# File 'lib/ronin/db/email_address.rb', line 143 has_one :organization_department, dependent: :nullify |
#organization_email_address ⇒ OrganizationEmailAddress?
The association of the organization that use the email address.
135 |
# File 'lib/ronin/db/email_address.rb', line 135 has_one :organization_email_address, dependent: :destroy |
#organization_members ⇒ OrganizationMember?
The organization member that uses the email address.
151 |
# File 'lib/ronin/db/email_address.rb', line 151 has_one :organization_member, dependent: :nullify |
#passwords ⇒ Array<EmailAddress>
Any passwords used with the email address.
89 |
# File 'lib/ronin/db/email_address.rb', line 89 has_many :passwords, through: :credentials |
#people ⇒ Array<Person>
The people that use the email address.
127 |
# File 'lib/ronin/db/email_address.rb', line 127 has_many :people, through: :personal_email_addresses |
#personal_email_addresses ⇒ Array<PersonalEmailAddress>
The association between people and the email address.
119 |
# File 'lib/ronin/db/email_address.rb', line 119 has_many :personal_email_addresses, dependent: :destroy |
#service_credentials ⇒ Array<ServiceCredential>
The service credentials that use the email address.
97 |
# File 'lib/ronin/db/email_address.rb', line 97 has_many :service_credentials, through: :credentials |
#user_name ⇒ UserName
The user-name component of the email address.
61 |
# File 'lib/ronin/db/email_address.rb', line 61 belongs_to :user_name, required: true |
#web_credentials ⇒ Array<WebCredential>
Any web credentials that use the email address.
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.
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.
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.
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.
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).
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).
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.
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).
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
#host ⇒ String
The host of the email address.
337 338 339 |
# File 'lib/ronin/db/email_address.rb', line 337 def host self.host_name.name if self.host_name end |
#to_s ⇒ String
Converts the email address into a String.
349 350 351 |
# File 'lib/ronin/db/email_address.rb', line 349 def to_s "#{self.user_name}@#{self.host_name}" end |
#user ⇒ String
The user of the email address.
325 326 327 |
# File 'lib/ronin/db/email_address.rb', line 325 def user self.user_name.name if self.user_name end |