Skip to content

Commit e27527b

Browse files
Merge pull request #110 from genkgo/punycode_local_domain
add method to get punycoded local part and domain
2 parents 69ac3ae + 396cd16 commit e27527b

14 files changed

+40
-26
lines changed

src/EmailAddress.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function __construct(string $address)
3636
throw new \InvalidArgumentException('Invalid e-mail address: ' . $address);
3737
}
3838

39+
/** @var array{0: non-empty-string, 1: non-empty-string, 2: non-empty-string} $matches */
3940
[$this->address, $this->localPart, $this->domain] = $matches;
4041
}
4142

@@ -68,11 +69,23 @@ public function getDomain(): string
6869
*/
6970
public function getPunyCode(): string
7071
{
71-
return \sprintf(
72-
'%s@%s',
73-
\idn_to_ascii($this->localPart, 0, INTL_IDNA_VARIANT_UTS46) ?: $this->localPart,
74-
\idn_to_ascii($this->domain, 0, INTL_IDNA_VARIANT_UTS46) ?: $this->domain
75-
);
72+
return \sprintf('%s@%s', $this->getPunyCodeLocalPart(), $this->getPunyCodeDomain());
73+
}
74+
75+
/**
76+
* @return string
77+
*/
78+
public function getPunyCodeLocalPart(): string
79+
{
80+
return \idn_to_ascii($this->localPart, 0, INTL_IDNA_VARIANT_UTS46) ?: $this->localPart;
81+
}
82+
83+
/**
84+
* @return string
85+
*/
86+
public function getPunyCodeDomain(): string
87+
{
88+
return \idn_to_ascii($this->domain, 0, INTL_IDNA_VARIANT_UTS46) ?: $this->domain;
7689
}
7790

7891
/**

src/Protocol/Imap/Response/CompletionResult.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public static function fromLine(string $line): self
7777
return new self($line);
7878
}
7979

80+
/** @var array{0: non-empty-string, 1: non-empty-string} $matches */
8081
return new self($matches[1]);
8182
}
8283

test/Stub/Quote/base64-quoted.eml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Content-Transfer-Encoding: quoted-printable
99
1010
Hello Universe
1111
12-
me (Jan 1, 2017, 12:00:00 AM):
12+
me (Jan 1, 2017, 12:00:00=E2=80=AFAM):
1313
>Lorem Ipsum
1414
>Lorem Ipsum
1515
>
@@ -24,8 +24,8 @@ Content-Type: text/html; charset=UTF-8
2424
Content-Transfer-Encoding: quoted-printable
2525

2626
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html; charset=
27-
=3DUTF-8"></head><body><p>Hello Universe</p><p>me (Jan 1, 2017, 12:00:00 AM):=
28-
</p><blockquote type=3D"cite"><p>Lorem Ipsum<br>Lorem
27+
=3DUTF-8"></head><body><p>Hello Universe</p><p>me (Jan 1, 2017, 12:00:00=E2=
28+
=80=AFAM):</p><blockquote type=3D"cite"><p>Lorem Ipsum<br>Lorem
2929
Ipsum</p><p>me (Jan 1, 2015, 12:00:00 AM):</p><blockquote type=3D"cite">Hello
3030
Universe<p>me (Jan 1, 2017, 12:00:00 AM):</p><blockquote type=3D"cite"><p>Hel=
3131
lo
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Hello Universe €
22

3-
me (Jan 1, 2017, 12:00:00 AM):
3+
me (Jan 1, 2017, 12:00:00AM):
44
>Hello World
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<html><head><title>Universe Title</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body>Hello Universe €<p>me (Jan 1, 2017, 12:00:00 AM):</p><blockquote type="cite"><p>Hello World</p></blockquote></body></html>
1+
<html><head><title>Universe Title</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body>Hello Universe €<p>me (Jan 1, 2017, 12:00:00AM):</p><blockquote type="cite"><p>Hello World</p></blockquote></body></html>

test/Stub/Quote/deep-text-quoted.crlf.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Hello Universe
22

3-
me (Jan 1, 2017, 12:00:00 AM):
3+
me (Jan 1, 2017, 12:00:00AM):
44
>>Hello Universe
55
>>
66
>>me (Jan 1, 2017, 12:00:00 AM):

test/Stub/Quote/double-quoted-html-and-text.eml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ Content-Transfer-Encoding: quoted-printable
1010
Lorem Ipsum
1111
Lorem Ipsum
1212
13-
me (Jan 1, 2015, 12:00:00 AM):
13+
me (Jan 1, 2015, 12:00:00=E2=80=AFAM):
1414
>Hello Universe
1515
>
16-
>me (Jan 1, 2017, 12:00:00 AM):
16+
>me (Jan 1, 2017, 12:00:00=E2=80=AFAM):
1717
>>Hello World
1818
1919
--GenkgoMailV2Part09d54671f9f5
2020
Content-Type: text/html; charset=UTF-8
21-
Content-Transfer-Encoding: 7bit
21+
Content-Transfer-Encoding: quoted-printable
2222

23-
<html><head><title>Quoted Quoted</title><meta http-equiv="Content-Type"
24-
content="text/html; charset=UTF-8"></head><body><p>Lorem Ipsum<br>Lorem
25-
Ipsum</p><p>me (Jan 1, 2015, 12:00:00 AM):</p><blockquote type="cite">Hello
26-
Universe<p>me (Jan 1, 2017, 12:00:00 AM):</p><blockquote type="cite"><p>Hello
27-
World</p></blockquote></blockquote></body></html>
23+
<html><head><title>Quoted Quoted</title><meta http-equiv=3D"Content-Type" con=
24+
tent=3D"text/html; charset=3DUTF-8"></head><body><p>Lorem Ipsum<br>Lorem Ipsu=
25+
m</p><p>me (Jan 1, 2015, 12:00:00=E2=80=AFAM):</p><blockquote type=3D"cite">H=
26+
ello Universe<p>me (Jan 1, 2017, 12:00:00=E2=80=AFAM):</p><blockquote type=3D=
27+
"cite"><p>Hello World</p></blockquote></blockquote></body></html>
2828
--GenkgoMailV2Part09d54671f9f5--
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Hello Universe
22

3-
me (Jan 1, 2017, 12:00:00 AM):
3+
me (Jan 1, 2017, 12:00:00AM):
44
>Hello World
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<html><head><title>Universe Title</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body>Hello Universe<p>me (Jan 1, 2017, 12:00:00 AM):</p><blockquote type="cite"><p>Hello World</p></blockquote></body></html>
1+
<html><head><title>Universe Title</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body>Hello Universe<p>me (Jan 1, 2017, 12:00:00AM):</p><blockquote type="cite"><p>Hello World</p></blockquote></body></html>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Hello Universe
22

3-
me (Jan 1, 2017, 12:00:00 AM):
3+
me (Jan 1, 2017, 12:00:00AM):
44
>Hello World

0 commit comments

Comments
 (0)