Skip to content

Commit ca4886a

Browse files
committed
initial commit
0 parents  commit ca4886a

9 files changed

+1390
-0
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
composer.phar
2+
composer.lock
3+
*~
4+
\#*#
5+
.\#*
6+
vendor/*

.travis.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
language: php
2+
3+
php:
4+
- 5.3
5+
- 5.4
6+
7+
before_script:
8+
- COMPOSER_ROOT_VERSION=dev-master composer --prefer-source --dev install
9+
10+
script: vendor/phpunit/phpunit/composer/bin/phpunit --configuration phpunit.xml-dist

LICENSE

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Current License:
2+
----------------
3+
TBD
4+
5+
6+
----------------
7+
Some code taken from https://github.com/oodle/inflect, subject to the followig terms:
8+
9+
Copyright (c) 2004-2013 Fabien Potencier
10+
11+
Permission is hereby granted, free of charge, to any person obtaining a copy
12+
of this software and associated documentation files (the "Software"), to deal
13+
in the Software without restriction, including without limitation the rights
14+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15+
copies of the Software, and to permit persons to whom the Software is furnished
16+
to do so, subject to the following conditions:
17+
18+
The above copyright notice and this permission notice shall be included in all
19+
copies or substantial portions of the Software.
20+
21+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27+
THE SOFTWARE.

README.md

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
email-parse
2+
===========
3+
4+
Email\Parse is a multiple (and single) email address parser that is reasonably RFC822 / RFC2822 compliant.
5+
6+
It parses a list of 1 to n email addresses separated by space or comma
7+
8+
Installation:
9+
-------------
10+
Add this line to your composer.json "require" section:
11+
12+
### composer.json
13+
```json
14+
"require": {
15+
...
16+
"oodle/email-parse": "*"
17+
```
18+
19+
Usage:
20+
------
21+
22+
```php
23+
use Email\Parse;
24+
25+
$result = Parse::getInstance()->parseEmailAddresses("[email protected] [email protected]");
26+
```
27+
28+
Notes:
29+
======
30+
This should be RFC 2822 compliant, although it will let a few obsolete RFC 822 addresses through such as test"test"[email protected] (note the quoted string in the middle of the address, which may be obsolete as of RFC 2822). However it wont allow escaping outside of quotes such as test\@[email protected]. This would have to be written as "test\@test"@xyz.com
31+
32+
Here are a few other examples:
33+
34+
```
35+
"John Q. Public" <[email protected]>
36+
37+
how-about-an-ip@[10.0.10.2]
38+
how-about-comments(this is a comment!!)@xyz.com
39+
```
40+
41+
####PHPDoc####
42+
function parseEmailAddresses
43+
@param $emails - List of Email addresses separated by comma or space if multiple
44+
@param $multiple - Whether to parse for multiple email addresses or not
45+
@param $encoding - The encoding if not 'UTF-8'
46+
@return
47+
```php
48+
if ($multiple):
49+
array('success' => boolean, // whether totally successful or not
50+
'reason' => string, // if unsuccessful, the reason why
51+
'email_addresses' =>
52+
array('address' => string, // the full address (not including comments)
53+
'original_address' => string, // the full address including comments
54+
'simple_address' => string, // simply local_part@domain_part (e.g. [email protected])
55+
'name' => string, // the name on the email if given (e.g.: John Q. Public), including any quotes
56+
'name_parsed' => string, // the name on the email if given (e.g.: John Q. Public), excluding any quotes
57+
'local_part' => string, // the local part (before the '@' sign - e.g. johnpublic)
58+
'local_part_parsed' => string, // the local part (before the '@' sign - e.g. johnpublic), excluding any quotes
59+
'domain' => string, // the domain after the '@' if given
60+
'ip' => string, // the IP after the '@' if given
61+
'domain_part' => string, // either domain or IP depending on what given
62+
'invalid' => boolean, // if the email is valid or not
63+
'invalid_reason' => string), // if the email is invalid, the reason why
64+
array( .... ) // the next email address matched
65+
)
66+
else:
67+
array('address' => string, // the full address including comments
68+
'name' => string, // the name on the email if given (e.g.: John Q. Public)
69+
'local_part' => string, // the local part (before the '@' sign - e.g. johnpublic)
70+
'domain' => string, // the domain after the '@' if given
71+
'ip' => string, // the IP after the '@' if given
72+
'invalid' => boolean, // if the email is valid or not
73+
'invalid_reason' => string) // if the email is invalid, the reason why
74+
endif;
75+
```
76+
77+
Other Example Usage:
78+
--------------------
79+
```php
80+
$email = "\"J Doe\" <[email protected]>";
81+
$result = Email\Parse->getInstance()->parseEmailAddresses($email, false);
82+
83+
$result == array('address' => '"JD" <[email protected]>',
84+
'original_address' => '"JD" <[email protected]>',
85+
'name' => '"JD"',
86+
'name_parsed' => 'J Doe',
87+
'local_part' => 'johndoe',
88+
'local_part_parsed' => 'johndoe',
89+
'domain_part' => 'xyz.com',
90+
'domain' => 'xyz.com',
91+
'ip' => '',
92+
'invalid' => false,
93+
'invalid_reason' => '');
94+
95+
$emails = "testing@[10.0.10.45] [email protected], testing-"test...2"@xyz.com (comment)";
96+
$result = Email\Parse->getInstance()->parseEmailAddresses($emails);
97+
$result == array(
98+
'success' => boolean true
99+
'reason' => null
100+
'email_addresses' =>
101+
array(
102+
array(
103+
'address' => 'testing@[10.0.10.45]',
104+
'original_address' => 'testing@[10.0.10.45]',
105+
'name' => '',
106+
'name_parsed' => '',
107+
'local_part' => 'testing',
108+
'local_part_parsed' => 'testing',
109+
'domain_part' => '10.0.10.45',
110+
'domain' => '',
111+
'ip' => '10.0.10.45',
112+
'invalid' => false,
113+
'invalid_reason' => ''),
114+
array(
115+
'address' => '[email protected]',
116+
'original_address' => '[email protected]',
117+
'name' => '',
118+
'name_parsed' => '',
119+
'local_part' => 'testing',
120+
'local_part' => 'testing',
121+
'domain_part' => 'xyz.com',
122+
'domain' => 'xyz.com',
123+
'ip' => '',
124+
'invalid' => false,
125+
'invalid_reason' => '')
126+
array(
127+
'address' => '"testing-test...2"@xyz.com',
128+
'original_address' => 'testing-"test...2"@xyz.com (comment)',
129+
'name' => '',
130+
'name_parsed' => '',
131+
'local_part' => '"testing-test2"',
132+
'local_part_parsed' => 'testing-test...2',
133+
'domain_part' => 'xyz.com',
134+
'domain' => 'xyz.com',
135+
'ip' => '',
136+
'invalid' => false,
137+
'invalid_reason' => '')
138+
)
139+
);
140+
```

autoload.php.dist

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
if (version_compare(PHP_VERSION, '5.4', '>=') && gc_enabled()) {
4+
// Disabling Zend Garbage Collection to prevent segfaults with PHP5.4+
5+
// https://bugs.php.net/bug.php?id=53976
6+
gc_disable();
7+
}
8+
9+
$loader = require_once __DIR__.'/vendor/autoload.php';
10+
11+
return $loader;

composer.json

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "oodle/email-parse",
3+
"type": "library",
4+
"description": "email-parse an RF2822-compliant library for parsing multiple (and single) email addresses",
5+
"license": "TBD",
6+
"keywords": ["email", "parse", "RFC822", "RFC2822"],
7+
"authors": [
8+
{
9+
"name": "Matthew J. Mucklo",
10+
"email": "[email protected]"
11+
}
12+
],
13+
"repositories": [
14+
{
15+
"type": "pear",
16+
"url": "http://pear.php.net/"
17+
}
18+
],
19+
"require-dev": {
20+
"phpunit/phpunit": "3.7.*"
21+
},
22+
"require": {
23+
"php": ">=5.3.17",
24+
"psr/log": "1.0.0",
25+
"pear-pear/NET_IDNA2" : "*",
26+
"zendframework/zend-validator" : "*"
27+
},
28+
"autoload": {
29+
"psr-0": {
30+
"Email": "src/"
31+
}
32+
}
33+
}
34+

phpunit.xml-dist

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false"
12+
bootstrap="autoload.php.dist"
13+
>
14+
<php>
15+
<ini name="intl.default_locale" value="en"/>
16+
<ini name="intl.error_level" value="0"/>
17+
<ini name="memory_limit" value="-1"/>
18+
</php>
19+
20+
<testsuites>
21+
<testsuite name="email-parse Test Suite">
22+
<directory>./tests/</directory>
23+
</testsuite>
24+
</testsuites>
25+
26+
<groups>
27+
<exclude>
28+
<group>benchmark</group>
29+
</exclude>
30+
</groups>
31+
32+
<filter>
33+
<whitelist>
34+
<directory>./src/</directory>
35+
<exclude>
36+
<directory>./tests/</directory>
37+
</exclude>
38+
</whitelist>
39+
</filter>
40+
</phpunit>

0 commit comments

Comments
 (0)