safe_email_name 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/safe_email_name.rb +11 -8
  3. metadata +17 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e2cad3fb69aa0faa761be3e2bb610fd51cf1b68
4
- data.tar.gz: 5668c8ba25a1880e1908c2db4b722f61ab674cfc
3
+ metadata.gz: ef4931c824880cc5166d0934a5460d628652beed
4
+ data.tar.gz: '099909bd0b3df0a36022618dab95ffff87247d39'
5
5
  SHA512:
6
- metadata.gz: 1f7f1e2d4bd457cb943e352a2af11c434062ea68f94d73de4d36742f9f130103c80a02b057a0456b022007dd13ee5762511387c180e4b525963587921b5ec4a1
7
- data.tar.gz: 8e7b7fd88ec816bca11f1387c6fc67f9b38c00f807f9279ac3328d5472cbda071b5682b1570cd728e7fcadb5aae1eec1b1e4d93267852d2a4aafb9bbbc63e289
6
+ metadata.gz: 89a2bd984fc06f251d19028116a98a8d374fa9d8b574fe1eeec08117a0ce2159ede5b5937b6a3f8b8340df5af5b5bb1bb5e321a4aa3982a431ba6bccc7cf58c7
7
+ data.tar.gz: ff8395f0d3c9bba8c0a833f19d065a676dfc19ed1027a48fc7714d1ce64817ec47ae5eafc2a4ca26dae848db589f694da29dd446913328393856c3ea9daba36a
@@ -1,18 +1,21 @@
1
+ require 'mail'
1
2
  require 'active_support'
2
3
  require 'active_support/core_ext/object/blank'
3
4
  require 'active_support/core_ext/string/filters' # squish
4
5
 
5
6
  module SafeEmailName
7
+ REMOVED_EMAIL_CHARACTERS = /[<>"]+/.freeze
8
+ private_constant :REMOVED_EMAIL_CHARACTERS
9
+
6
10
  def safe_email_name(name, email)
7
- escaped_chars = /["<>]/
11
+ email = email.gsub(REMOVED_EMAIL_CHARACTERS, '')
12
+ name = name.to_s.squish
13
+ return email if name.blank?
8
14
 
9
- email = email.gsub(escaped_chars, '')
10
- name = (name || "").gsub(escaped_chars, '').squish
11
- if name.blank?
12
- email
13
- else
14
- "#{name} <#{email}>"
15
- end
15
+ address = Mail::Address.new
16
+ address.display_name = name
17
+ address.address = email
18
+ address.to_s
16
19
  end
17
20
 
18
21
  # Make method available as a class method as well.
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: safe_email_name
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sunny Ripert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-03 00:00:00.000000000 Z
11
+ date: 2019-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mail
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: activesupport
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -66,9 +80,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
80
  version: '0'
67
81
  requirements: []
68
82
  rubyforge_project:
69
- rubygems_version: 2.4.5
83
+ rubygems_version: 2.5.2.3
70
84
  signing_key:
71
85
  specification_version: 4
72
86
  summary: Escape To and From fields in emails
73
87
  test_files: []
74
- has_rdoc: