File: address_lists_parser_spec.rb

package info (click to toggle)
ruby-mail 2.7.1%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,436 kB
  • sloc: ruby: 71,596; makefile: 3
file content (61 lines) | stat: -rw-r--r-- 2,024 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# encoding: utf-8
# frozen_string_literal: true
require 'spec_helper'

describe "AddressListsParser" do
  it "should parse an address" do
    text = 'Mikel Lindsaar <test@lindsaar.net>, Friends: test2@lindsaar.net, Ada <test3@lindsaar.net>;'
    a = Mail::Parsers::AddressListsParser
    expect(a.parse(text)).not_to be_nil
  end

  it "should parse an address list separated by semicolons" do
    text = 'Mikel Lindsaar <test@lindsaar.net>; Friends: test2@lindsaar.net; Ada <test3@lindsaar.net>;'
    a = Mail::Parsers::AddressListsParser
    expect(a.parse(text)).not_to be_nil
  end

  context "parsing an address with a space at the end" do
    it "only finds a single address" do
      text = 'Mikel Lindsaar <test@lindsaar.net> '
      a = Mail::Parsers::AddressListsParser
      expect(a.parse(text).addresses.size).to eq 1
    end
  end

  context "parsing an address which begins with a comment" do
    it "extracts local string correctly" do
      text = '(xxxx xxxxxx xxxx)ababab@example.com'

      a = Mail::Parsers::AddressListsParser
      expect(a.parse(text).addresses.size).to eq 1
      expect(a.parse(text).addresses.first.local).to eq 'ababab'
    end
  end

  context "RFC6532 UTF-8 headers" do
    it "extracts UTF-8 local string" do
      text = '"🌈" (😁) <💌@👉.com>, 🤠:test@example.com;'

      a = Mail::Parsers::AddressListsParser
      result = a.parse(text)
      expect(result.addresses.size).to eq 2

      address = result.addresses[0]
      expect(address.display_name).to eq '🌈'
      expect(address.local).to eq '💌'
      expect(address.domain).to eq '👉.com'

      address = result.addresses[1]
      expect(address.group).to eq '🤠'
      expect(address.local).to eq 'test'
      expect(address.domain).to eq 'example.com'
    end

    it "should parse an address" do
      text = '"💌" <💌@💌.com>, 🤠: test2@lindsaar.net, Ada <test3@lindsaar.net>;'
      a = Mail::Parsers::AddressListsParser
      expect(a.parse(text)).not_to be_nil
    end
  end
end