packlab5 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/06-02.html +81 -0
- package/06-02.js +72 -0
- package/06-03.js +7 -0
- package/06-04.js +7 -0
- package/AnswersLW5.pdf +0 -0
- package/m0603/m0603.js +30 -0
- package/m0603/node_modules/.package-lock.json +16 -0
- package/m0603/node_modules/nodemailer/.gitattributes +6 -0
- package/m0603/node_modules/nodemailer/.prettierrc.js +8 -0
- package/m0603/node_modules/nodemailer/CHANGELOG.md +725 -0
- package/m0603/node_modules/nodemailer/CODE_OF_CONDUCT.md +76 -0
- package/m0603/node_modules/nodemailer/CONTRIBUTING.md +67 -0
- package/m0603/node_modules/nodemailer/LICENSE +16 -0
- package/m0603/node_modules/nodemailer/README.md +97 -0
- package/m0603/node_modules/nodemailer/SECURITY.txt +22 -0
- package/m0603/node_modules/nodemailer/lib/addressparser/index.js +313 -0
- package/m0603/node_modules/nodemailer/lib/base64/index.js +142 -0
- package/m0603/node_modules/nodemailer/lib/dkim/index.js +251 -0
- package/m0603/node_modules/nodemailer/lib/dkim/message-parser.js +155 -0
- package/m0603/node_modules/nodemailer/lib/dkim/relaxed-body.js +154 -0
- package/m0603/node_modules/nodemailer/lib/dkim/sign.js +117 -0
- package/m0603/node_modules/nodemailer/lib/fetch/cookies.js +281 -0
- package/m0603/node_modules/nodemailer/lib/fetch/index.js +274 -0
- package/m0603/node_modules/nodemailer/lib/json-transport/index.js +82 -0
- package/m0603/node_modules/nodemailer/lib/mail-composer/index.js +558 -0
- package/m0603/node_modules/nodemailer/lib/mailer/index.js +427 -0
- package/m0603/node_modules/nodemailer/lib/mailer/mail-message.js +315 -0
- package/m0603/node_modules/nodemailer/lib/mime-funcs/index.js +625 -0
- package/m0603/node_modules/nodemailer/lib/mime-funcs/mime-types.js +2102 -0
- package/m0603/node_modules/nodemailer/lib/mime-node/index.js +1290 -0
- package/m0603/node_modules/nodemailer/lib/mime-node/last-newline.js +33 -0
- package/m0603/node_modules/nodemailer/lib/mime-node/le-unix.js +43 -0
- package/m0603/node_modules/nodemailer/lib/mime-node/le-windows.js +52 -0
- package/m0603/node_modules/nodemailer/lib/nodemailer.js +143 -0
- package/m0603/node_modules/nodemailer/lib/qp/index.js +219 -0
- package/m0603/node_modules/nodemailer/lib/sendmail-transport/index.js +210 -0
- package/m0603/node_modules/nodemailer/lib/ses-transport/index.js +349 -0
- package/m0603/node_modules/nodemailer/lib/shared/index.js +638 -0
- package/m0603/node_modules/nodemailer/lib/smtp-connection/data-stream.js +108 -0
- package/m0603/node_modules/nodemailer/lib/smtp-connection/http-proxy-client.js +143 -0
- package/m0603/node_modules/nodemailer/lib/smtp-connection/index.js +1796 -0
- package/m0603/node_modules/nodemailer/lib/smtp-pool/index.js +648 -0
- package/m0603/node_modules/nodemailer/lib/smtp-pool/pool-resource.js +253 -0
- package/m0603/node_modules/nodemailer/lib/smtp-transport/index.js +416 -0
- package/m0603/node_modules/nodemailer/lib/stream-transport/index.js +135 -0
- package/m0603/node_modules/nodemailer/lib/well-known/index.js +47 -0
- package/m0603/node_modules/nodemailer/lib/well-known/services.json +286 -0
- package/m0603/node_modules/nodemailer/lib/xoauth2/index.js +376 -0
- package/m0603/node_modules/nodemailer/package.json +46 -0
- package/m0603/node_modules/nodemailer/postinstall.js +101 -0
- package/m0603/package-lock.json +31 -0
- package/m0603/package.json +15 -0
- package/package.json +16 -0
@@ -0,0 +1,76 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
9
|
+
level of experience, education, socio-economic status, nationality, personal
|
10
|
+
appearance, race, religion, or sexual identity and orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at info@nodemailer.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
72
|
+
|
73
|
+
[homepage]: https://www.contributor-covenant.org
|
74
|
+
|
75
|
+
For answers to common questions about this code of conduct, see
|
76
|
+
https://www.contributor-covenant.org/faq
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# Contribute
|
2
|
+
|
3
|
+
## Introduction
|
4
|
+
|
5
|
+
First, thank you for considering contributing to nodemailer! It's people like you that make the open source community such a great community! 😊
|
6
|
+
|
7
|
+
We welcome any type of contribution, not only code. You can help with
|
8
|
+
- **QA**: file bug reports, the more details you can give the better (e.g. screenshots with the console open)
|
9
|
+
- **Marketing**: writing blog posts, howto's, printing stickers, ...
|
10
|
+
- **Community**: presenting the project at meetups, organizing a dedicated meetup for the local community, ...
|
11
|
+
- **Code**: take a look at the [open issues](https://github.com/nodemailer/nodemailer/issues). Even if you can't write code, commenting on them, showing that you care about a given issue matters. It helps us triage them.
|
12
|
+
- **Money**: we welcome financial contributions in full transparency on our [open collective](https://opencollective.com/nodemailer).
|
13
|
+
|
14
|
+
## Your First Contribution
|
15
|
+
|
16
|
+
Working on your first Pull Request? You can learn how from this *free* series, [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github).
|
17
|
+
|
18
|
+
## Submitting code
|
19
|
+
|
20
|
+
Any code change should be submitted as a pull request. The description should explain what the code does and give steps to execute it. The pull request should also contain tests.
|
21
|
+
|
22
|
+
## Code review process
|
23
|
+
|
24
|
+
The bigger the pull request, the longer it will take to review and merge. Try to break down large pull requests in smaller chunks that are easier to review and merge.
|
25
|
+
It is also always helpful to have some context for your pull request. What was the purpose? Why does it matter to you?
|
26
|
+
|
27
|
+
## Financial contributions
|
28
|
+
|
29
|
+
We also welcome financial contributions in full transparency on our [open collective](https://opencollective.com/nodemailer).
|
30
|
+
Anyone can file an expense. If the expense makes sense for the development of the community, it will be "merged" in the ledger of our open collective by the core contributors and the person who filed the expense will be reimbursed.
|
31
|
+
|
32
|
+
## Questions
|
33
|
+
|
34
|
+
If you have any questions, create an [issue](https://github.com/nodemailer/nodemailer/issues) (protip: do a quick search first to see if someone else didn't ask the same question before!).
|
35
|
+
You can also reach us at hello@nodemailer.opencollective.com.
|
36
|
+
|
37
|
+
## Credits
|
38
|
+
|
39
|
+
### Contributors
|
40
|
+
|
41
|
+
Thank you to all the people who have already contributed to nodemailer!
|
42
|
+
<a href="graphs/contributors"><img src="https://opencollective.com/nodemailer/contributors.svg?width=890" /></a>
|
43
|
+
|
44
|
+
|
45
|
+
### Backers
|
46
|
+
|
47
|
+
Thank you to all our backers! [[Become a backer](https://opencollective.com/nodemailer#backer)]
|
48
|
+
|
49
|
+
<a href="https://opencollective.com/nodemailer#backers" target="_blank"><img src="https://opencollective.com/nodemailer/backers.svg?width=890"></a>
|
50
|
+
|
51
|
+
|
52
|
+
### Sponsors
|
53
|
+
|
54
|
+
Thank you to all our sponsors! (please ask your company to also support this open source project by [becoming a sponsor](https://opencollective.com/nodemailer#sponsor))
|
55
|
+
|
56
|
+
<a href="https://opencollective.com/nodemailer/sponsor/0/website" target="_blank"><img src="https://opencollective.com/nodemailer/sponsor/0/avatar.svg"></a>
|
57
|
+
<a href="https://opencollective.com/nodemailer/sponsor/1/website" target="_blank"><img src="https://opencollective.com/nodemailer/sponsor/1/avatar.svg"></a>
|
58
|
+
<a href="https://opencollective.com/nodemailer/sponsor/2/website" target="_blank"><img src="https://opencollective.com/nodemailer/sponsor/2/avatar.svg"></a>
|
59
|
+
<a href="https://opencollective.com/nodemailer/sponsor/3/website" target="_blank"><img src="https://opencollective.com/nodemailer/sponsor/3/avatar.svg"></a>
|
60
|
+
<a href="https://opencollective.com/nodemailer/sponsor/4/website" target="_blank"><img src="https://opencollective.com/nodemailer/sponsor/4/avatar.svg"></a>
|
61
|
+
<a href="https://opencollective.com/nodemailer/sponsor/5/website" target="_blank"><img src="https://opencollective.com/nodemailer/sponsor/5/avatar.svg"></a>
|
62
|
+
<a href="https://opencollective.com/nodemailer/sponsor/6/website" target="_blank"><img src="https://opencollective.com/nodemailer/sponsor/6/avatar.svg"></a>
|
63
|
+
<a href="https://opencollective.com/nodemailer/sponsor/7/website" target="_blank"><img src="https://opencollective.com/nodemailer/sponsor/7/avatar.svg"></a>
|
64
|
+
<a href="https://opencollective.com/nodemailer/sponsor/8/website" target="_blank"><img src="https://opencollective.com/nodemailer/sponsor/8/avatar.svg"></a>
|
65
|
+
<a href="https://opencollective.com/nodemailer/sponsor/9/website" target="_blank"><img src="https://opencollective.com/nodemailer/sponsor/9/avatar.svg"></a>
|
66
|
+
|
67
|
+
<!-- This `CONTRIBUTING.md` is based on @nayafia's template https://github.com/nayafia/contributing-template -->
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Copyright (c) 2011-2019 Andris Reinman
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
11
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
12
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
13
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
14
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
15
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
16
|
+
SOFTWARE.
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# Nodemailer
|
2
|
+
|
3
|
+
[![Nodemailer](https://raw.githubusercontent.com/nodemailer/nodemailer/master/assets/nm_logo_200x136.png)](https://nodemailer.com/about/)
|
4
|
+
|
5
|
+
Send emails from Node.js – easy as cake! 🍰✉️
|
6
|
+
|
7
|
+
[![NPM](https://nodei.co/npm/nodemailer.png?downloads=true&downloadRank=true&stars=true)](https://nodemailer.com/about/)
|
8
|
+
|
9
|
+
See [nodemailer.com](https://nodemailer.com/) for documentation and terms.
|
10
|
+
|
11
|
+
---
|
12
|
+
|
13
|
+
> Check out **[EmailEngine](https://emailengine.app/?utm_source=github-nodemailer&utm_campaign=nodemailer&utm_medium=readme-link)** – a self-hosted email gateway that allows making **REST requests against IMAP and SMTP servers**. EmailEngine also sends webhooks whenever something changes on the registered accounts.\
|
14
|
+
> \
|
15
|
+
> Using the email accounts registered with EmailEngine, you can receive and [send emails](https://emailengine.app/sending-emails?utm_source=github-nodemailer&utm_campaign=nodemailer&utm_medium=readme-link). EmailEngine supports OAuth2, delayed sends, opens and clicks tracking, bounce detection, etc. All on top of regular email accounts without an external MTA service.
|
16
|
+
|
17
|
+
---
|
18
|
+
|
19
|
+
This project is supported by [Forward Email](https://forwardemail.net) – the 100% open-source and privacy-focused email service.
|
20
|
+
|
21
|
+
---
|
22
|
+
|
23
|
+
This project is supported by [Opensense](https://www.opensense.com) - The beautiful email signature management company for Office 365 and Google Workspace.
|
24
|
+
|
25
|
+
---
|
26
|
+
|
27
|
+
## Having an issue?
|
28
|
+
|
29
|
+
#### First review the docs
|
30
|
+
|
31
|
+
Documentation for Nodemailer can be found at [nodemailer.com](https://nodemailer.com/about/).
|
32
|
+
|
33
|
+
#### Nodemailer throws a SyntaxError for "..."
|
34
|
+
|
35
|
+
You are using an older Node.js version than v6.0. Upgrade Node.js to get support for the spread operator. Nodemailer supports all Node.js versions starting from Node.js@v6.0.0.
|
36
|
+
|
37
|
+
#### I'm having issues with Gmail
|
38
|
+
|
39
|
+
Gmail either works well, or it does not work at all. It is probably easier to switch to an alternative service instead of fixing issues with Gmail. If Gmail does not work for you, then don't use it. Read more about it [here](https://nodemailer.com/usage/using-gmail/).
|
40
|
+
|
41
|
+
#### I get ETIMEDOUT errors
|
42
|
+
|
43
|
+
Check your firewall settings. Timeout usually occurs when you try to open a connection to a firewalled port either on the server or on your machine. Some ISPs also block email ports to prevent spamming.
|
44
|
+
|
45
|
+
#### Nodemailer works on one machine but not in another
|
46
|
+
|
47
|
+
It's either a firewall issue, or your SMTP server blocks authentication attempts from some servers.
|
48
|
+
|
49
|
+
#### I get TLS errors
|
50
|
+
|
51
|
+
- If you are running the code on your machine, check your antivirus settings. Antiviruses often mess around with email ports usage. Node.js might not recognize the MITM cert your antivirus is using.
|
52
|
+
- Latest Node versions allow only TLS versions 1.2 and higher. Some servers might still use TLS 1.1 or lower. Check Node.js docs on how to get correct TLS support for your app. You can change this with [tls.minVersion](https://nodejs.org/dist/latest-v16.x/docs/api/tls.html#tls_tls_createsecurecontext_options) option
|
53
|
+
- You might have the wrong value for the `secure` option. This should be set to `true` only for port 465. For every other port, it should be `false`. Setting it to `false` does not mean that Nodemailer would not use TLS. Nodemailer would still try to upgrade the connection to use TLS if the server supports it.
|
54
|
+
- Older Node versions do not fully support the certificate chain of the newest Let's Encrypt certificates. Either set [tls.rejectUnauthorized](https://nodejs.org/dist/latest-v16.x/docs/api/tls.html#tlsconnectoptions-callback) to `false` to skip chain verification or upgrade your Node version
|
55
|
+
|
56
|
+
```
|
57
|
+
let configOptions = {
|
58
|
+
host: "smtp.example.com",
|
59
|
+
port: 587,
|
60
|
+
tls: {
|
61
|
+
rejectUnauthorized: true,
|
62
|
+
minVersion: "TLSv1.2"
|
63
|
+
}
|
64
|
+
}
|
65
|
+
```
|
66
|
+
|
67
|
+
#### I have issues with DNS / hosts file
|
68
|
+
|
69
|
+
Node.js uses [c-ares](https://nodejs.org/en/docs/meta/topics/dependencies/#c-ares) to resolve domain names, not the DNS library provided by the system, so if you have some custom DNS routing set up, it might be ignored. Nodemailer runs [dns.resolve4()](https://nodejs.org/dist/latest-v16.x/docs/api/dns.html#dnsresolve4hostname-options-callback) and [dns.resolve6()](https://nodejs.org/dist/latest-v16.x/docs/api/dns.html#dnsresolve6hostname-options-callback) to resolve hostname into an IP address. If both calls fail, then Nodemailer will fall back to [dns.lookup()](https://nodejs.org/dist/latest-v16.x/docs/api/dns.html#dnslookuphostname-options-callback). If this does not work for you, you can hard code the IP address into the configuration like shown below. In that case, Nodemailer would not perform any DNS lookups.
|
70
|
+
|
71
|
+
```
|
72
|
+
let configOptions = {
|
73
|
+
host: "1.2.3.4",
|
74
|
+
port: 465,
|
75
|
+
secure: true,
|
76
|
+
tls: {
|
77
|
+
// must provide server name, otherwise TLS certificate check will fail
|
78
|
+
servername: "example.com"
|
79
|
+
}
|
80
|
+
}
|
81
|
+
```
|
82
|
+
|
83
|
+
#### I have an issue with TypeScript types
|
84
|
+
|
85
|
+
Nodemailer has official support for Node.js only. For anything related to TypeScript, you need to directly contact the authors of the [type definitions](https://www.npmjs.com/package/@types/nodemailer).
|
86
|
+
|
87
|
+
#### I have a different problem
|
88
|
+
|
89
|
+
If you are having issues with Nodemailer, then the best way to find help would be [Stack Overflow](https://stackoverflow.com/search?q=nodemailer) or revisit the [docs](https://nodemailer.com/about/).
|
90
|
+
|
91
|
+
### License
|
92
|
+
|
93
|
+
Nodemailer is licensed under the **MIT license**
|
94
|
+
|
95
|
+
---
|
96
|
+
|
97
|
+
The Nodemailer logo was designed by [Sven Kristjansen](https://www.behance.net/kristjansen).
|
@@ -0,0 +1,22 @@
|
|
1
|
+
-----BEGIN PGP SIGNED MESSAGE-----
|
2
|
+
Hash: SHA256
|
3
|
+
|
4
|
+
Contact: mailto:andris@reinman.eu
|
5
|
+
Encryption: https://keys.openpgp.org/vks/v1/by-fingerprint/5D952A46E1D8C931F6364E01DC6C83F4D584D364
|
6
|
+
Preferred-Languages: en, et
|
7
|
+
-----BEGIN PGP SIGNATURE-----
|
8
|
+
|
9
|
+
iQIzBAEBCAAdFiEEXZUqRuHYyTH2Nk4B3GyD9NWE02QFAmFDnUgACgkQ3GyD9NWE
|
10
|
+
02RqUA/+MM3afmRYq874C7wp+uN6dTMCvUX5g5zqBZ2yKpFr46L+PYvM7o8TMm5h
|
11
|
+
hmLT2I1zZmi+xezOL3zHFizaw0tKkZIz9cWl3Jrgs0FLp0zOsSz1xucp9Q2tYM/Q
|
12
|
+
vbiP6ys0gbim4tkDGRmZOEiO23s0BuRnmHt7vZg210O+D105Yd8/Ohzbj6PSLBO5
|
13
|
+
W1tA7Xw5t0FQ14NNH5+MKyDIKoCX12n0FmrC6qLTXeojf291UgKhCUPda3LIGTmx
|
14
|
+
mTXz0y68149Mw+JikRCYP8HfGRY9eA4XZrYXF7Bl2T9OJpKD3JAH+69P3xBw19Gn
|
15
|
+
Csaw3twu8P1bxoVGjY4KRrBOp68W8TwZYjWVWbqY6oV8hb/JfrMxa+kaSxRuloFs
|
16
|
+
oL6+phrDSPTWdOj2LlEDBJbPOMeDFzIlsBBcJ/JHCEHTvlHl7LoWr3YuWce9PUwl
|
17
|
+
4r3JUovvaeuJxLgC0vu3WCB3Jeocsl3SreqNkrVc1IjvkSomn3YGm5nCNAd/2F0V
|
18
|
+
exCGRk/8wbkSjAY38GwQ8K/VuFsefWN3L9sVwIMAMu88KFCAN+GzVFiwvyIXehF5
|
19
|
+
eogP9mIXzdQ5YReQjUjApOzGz54XnDyv9RJ3sdvMHosLP+IOg+0q5t9agWv6aqSR
|
20
|
+
2HzCpiQnH/gmM5NS0AU4Koq/L7IBeLu1B8+61/+BiHgZJJmPdgU=
|
21
|
+
=BUZr
|
22
|
+
-----END PGP SIGNATURE-----
|
@@ -0,0 +1,313 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Converts tokens for a single address into an address object
|
5
|
+
*
|
6
|
+
* @param {Array} tokens Tokens object
|
7
|
+
* @return {Object} Address object
|
8
|
+
*/
|
9
|
+
function _handleAddress(tokens) {
|
10
|
+
let token;
|
11
|
+
let isGroup = false;
|
12
|
+
let state = 'text';
|
13
|
+
let address;
|
14
|
+
let addresses = [];
|
15
|
+
let data = {
|
16
|
+
address: [],
|
17
|
+
comment: [],
|
18
|
+
group: [],
|
19
|
+
text: []
|
20
|
+
};
|
21
|
+
let i;
|
22
|
+
let len;
|
23
|
+
|
24
|
+
// Filter out <addresses>, (comments) and regular text
|
25
|
+
for (i = 0, len = tokens.length; i < len; i++) {
|
26
|
+
token = tokens[i];
|
27
|
+
if (token.type === 'operator') {
|
28
|
+
switch (token.value) {
|
29
|
+
case '<':
|
30
|
+
state = 'address';
|
31
|
+
break;
|
32
|
+
case '(':
|
33
|
+
state = 'comment';
|
34
|
+
break;
|
35
|
+
case ':':
|
36
|
+
state = 'group';
|
37
|
+
isGroup = true;
|
38
|
+
break;
|
39
|
+
default:
|
40
|
+
state = 'text';
|
41
|
+
}
|
42
|
+
} else if (token.value) {
|
43
|
+
if (state === 'address') {
|
44
|
+
// handle use case where unquoted name includes a "<"
|
45
|
+
// Apple Mail truncates everything between an unexpected < and an address
|
46
|
+
// and so will we
|
47
|
+
token.value = token.value.replace(/^[^<]*<\s*/, '');
|
48
|
+
}
|
49
|
+
data[state].push(token.value);
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
// If there is no text but a comment, replace the two
|
54
|
+
if (!data.text.length && data.comment.length) {
|
55
|
+
data.text = data.comment;
|
56
|
+
data.comment = [];
|
57
|
+
}
|
58
|
+
|
59
|
+
if (isGroup) {
|
60
|
+
// http://tools.ietf.org/html/rfc2822#appendix-A.1.3
|
61
|
+
data.text = data.text.join(' ');
|
62
|
+
addresses.push({
|
63
|
+
name: data.text || (address && address.name),
|
64
|
+
group: data.group.length ? addressparser(data.group.join(',')) : []
|
65
|
+
});
|
66
|
+
} else {
|
67
|
+
// If no address was found, try to detect one from regular text
|
68
|
+
if (!data.address.length && data.text.length) {
|
69
|
+
for (i = data.text.length - 1; i >= 0; i--) {
|
70
|
+
if (data.text[i].match(/^[^@\s]+@[^@\s]+$/)) {
|
71
|
+
data.address = data.text.splice(i, 1);
|
72
|
+
break;
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
let _regexHandler = function (address) {
|
77
|
+
if (!data.address.length) {
|
78
|
+
data.address = [address.trim()];
|
79
|
+
return ' ';
|
80
|
+
} else {
|
81
|
+
return address;
|
82
|
+
}
|
83
|
+
};
|
84
|
+
|
85
|
+
// still no address
|
86
|
+
if (!data.address.length) {
|
87
|
+
for (i = data.text.length - 1; i >= 0; i--) {
|
88
|
+
// fixed the regex to parse email address correctly when email address has more than one @
|
89
|
+
data.text[i] = data.text[i].replace(/\s*\b[^@\s]+@[^\s]+\b\s*/, _regexHandler).trim();
|
90
|
+
if (data.address.length) {
|
91
|
+
break;
|
92
|
+
}
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
// If there's still is no text but a comment exixts, replace the two
|
98
|
+
if (!data.text.length && data.comment.length) {
|
99
|
+
data.text = data.comment;
|
100
|
+
data.comment = [];
|
101
|
+
}
|
102
|
+
|
103
|
+
// Keep only the first address occurence, push others to regular text
|
104
|
+
if (data.address.length > 1) {
|
105
|
+
data.text = data.text.concat(data.address.splice(1));
|
106
|
+
}
|
107
|
+
|
108
|
+
// Join values with spaces
|
109
|
+
data.text = data.text.join(' ');
|
110
|
+
data.address = data.address.join(' ');
|
111
|
+
|
112
|
+
if (!data.address && isGroup) {
|
113
|
+
return [];
|
114
|
+
} else {
|
115
|
+
address = {
|
116
|
+
address: data.address || data.text || '',
|
117
|
+
name: data.text || data.address || ''
|
118
|
+
};
|
119
|
+
|
120
|
+
if (address.address === address.name) {
|
121
|
+
if ((address.address || '').match(/@/)) {
|
122
|
+
address.name = '';
|
123
|
+
} else {
|
124
|
+
address.address = '';
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
128
|
+
addresses.push(address);
|
129
|
+
}
|
130
|
+
}
|
131
|
+
|
132
|
+
return addresses;
|
133
|
+
}
|
134
|
+
|
135
|
+
/**
|
136
|
+
* Creates a Tokenizer object for tokenizing address field strings
|
137
|
+
*
|
138
|
+
* @constructor
|
139
|
+
* @param {String} str Address field string
|
140
|
+
*/
|
141
|
+
class Tokenizer {
|
142
|
+
constructor(str) {
|
143
|
+
this.str = (str || '').toString();
|
144
|
+
this.operatorCurrent = '';
|
145
|
+
this.operatorExpecting = '';
|
146
|
+
this.node = null;
|
147
|
+
this.escaped = false;
|
148
|
+
|
149
|
+
this.list = [];
|
150
|
+
/**
|
151
|
+
* Operator tokens and which tokens are expected to end the sequence
|
152
|
+
*/
|
153
|
+
this.operators = {
|
154
|
+
'"': '"',
|
155
|
+
'(': ')',
|
156
|
+
'<': '>',
|
157
|
+
',': '',
|
158
|
+
':': ';',
|
159
|
+
// Semicolons are not a legal delimiter per the RFC2822 grammar other
|
160
|
+
// than for terminating a group, but they are also not valid for any
|
161
|
+
// other use in this context. Given that some mail clients have
|
162
|
+
// historically allowed the semicolon as a delimiter equivalent to the
|
163
|
+
// comma in their UI, it makes sense to treat them the same as a comma
|
164
|
+
// when used outside of a group.
|
165
|
+
';': ''
|
166
|
+
};
|
167
|
+
}
|
168
|
+
|
169
|
+
/**
|
170
|
+
* Tokenizes the original input string
|
171
|
+
*
|
172
|
+
* @return {Array} An array of operator|text tokens
|
173
|
+
*/
|
174
|
+
tokenize() {
|
175
|
+
let chr,
|
176
|
+
list = [];
|
177
|
+
for (let i = 0, len = this.str.length; i < len; i++) {
|
178
|
+
chr = this.str.charAt(i);
|
179
|
+
this.checkChar(chr);
|
180
|
+
}
|
181
|
+
|
182
|
+
this.list.forEach(node => {
|
183
|
+
node.value = (node.value || '').toString().trim();
|
184
|
+
if (node.value) {
|
185
|
+
list.push(node);
|
186
|
+
}
|
187
|
+
});
|
188
|
+
|
189
|
+
return list;
|
190
|
+
}
|
191
|
+
|
192
|
+
/**
|
193
|
+
* Checks if a character is an operator or text and acts accordingly
|
194
|
+
*
|
195
|
+
* @param {String} chr Character from the address field
|
196
|
+
*/
|
197
|
+
checkChar(chr) {
|
198
|
+
if (this.escaped) {
|
199
|
+
// ignore next condition blocks
|
200
|
+
} else if (chr === this.operatorExpecting) {
|
201
|
+
this.node = {
|
202
|
+
type: 'operator',
|
203
|
+
value: chr
|
204
|
+
};
|
205
|
+
this.list.push(this.node);
|
206
|
+
this.node = null;
|
207
|
+
this.operatorExpecting = '';
|
208
|
+
this.escaped = false;
|
209
|
+
return;
|
210
|
+
} else if (!this.operatorExpecting && chr in this.operators) {
|
211
|
+
this.node = {
|
212
|
+
type: 'operator',
|
213
|
+
value: chr
|
214
|
+
};
|
215
|
+
this.list.push(this.node);
|
216
|
+
this.node = null;
|
217
|
+
this.operatorExpecting = this.operators[chr];
|
218
|
+
this.escaped = false;
|
219
|
+
return;
|
220
|
+
} else if (['"', "'"].includes(this.operatorExpecting) && chr === '\\') {
|
221
|
+
this.escaped = true;
|
222
|
+
return;
|
223
|
+
}
|
224
|
+
|
225
|
+
if (!this.node) {
|
226
|
+
this.node = {
|
227
|
+
type: 'text',
|
228
|
+
value: ''
|
229
|
+
};
|
230
|
+
this.list.push(this.node);
|
231
|
+
}
|
232
|
+
|
233
|
+
if (chr === '\n') {
|
234
|
+
// Convert newlines to spaces. Carriage return is ignored as \r and \n usually
|
235
|
+
// go together anyway and there already is a WS for \n. Lone \r means something is fishy.
|
236
|
+
chr = ' ';
|
237
|
+
}
|
238
|
+
|
239
|
+
if (chr.charCodeAt(0) >= 0x21 || [' ', '\t'].includes(chr)) {
|
240
|
+
// skip command bytes
|
241
|
+
this.node.value += chr;
|
242
|
+
}
|
243
|
+
|
244
|
+
this.escaped = false;
|
245
|
+
}
|
246
|
+
}
|
247
|
+
|
248
|
+
/**
|
249
|
+
* Parses structured e-mail addresses from an address field
|
250
|
+
*
|
251
|
+
* Example:
|
252
|
+
*
|
253
|
+
* 'Name <address@domain>'
|
254
|
+
*
|
255
|
+
* will be converted to
|
256
|
+
*
|
257
|
+
* [{name: 'Name', address: 'address@domain'}]
|
258
|
+
*
|
259
|
+
* @param {String} str Address field
|
260
|
+
* @return {Array} An array of address objects
|
261
|
+
*/
|
262
|
+
function addressparser(str, options) {
|
263
|
+
options = options || {};
|
264
|
+
|
265
|
+
let tokenizer = new Tokenizer(str);
|
266
|
+
let tokens = tokenizer.tokenize();
|
267
|
+
|
268
|
+
let addresses = [];
|
269
|
+
let address = [];
|
270
|
+
let parsedAddresses = [];
|
271
|
+
|
272
|
+
tokens.forEach(token => {
|
273
|
+
if (token.type === 'operator' && (token.value === ',' || token.value === ';')) {
|
274
|
+
if (address.length) {
|
275
|
+
addresses.push(address);
|
276
|
+
}
|
277
|
+
address = [];
|
278
|
+
} else {
|
279
|
+
address.push(token);
|
280
|
+
}
|
281
|
+
});
|
282
|
+
|
283
|
+
if (address.length) {
|
284
|
+
addresses.push(address);
|
285
|
+
}
|
286
|
+
|
287
|
+
addresses.forEach(address => {
|
288
|
+
address = _handleAddress(address);
|
289
|
+
if (address.length) {
|
290
|
+
parsedAddresses = parsedAddresses.concat(address);
|
291
|
+
}
|
292
|
+
});
|
293
|
+
|
294
|
+
if (options.flatten) {
|
295
|
+
let addresses = [];
|
296
|
+
let walkAddressList = list => {
|
297
|
+
list.forEach(address => {
|
298
|
+
if (address.group) {
|
299
|
+
return walkAddressList(address.group);
|
300
|
+
} else {
|
301
|
+
addresses.push(address);
|
302
|
+
}
|
303
|
+
});
|
304
|
+
};
|
305
|
+
walkAddressList(parsedAddresses);
|
306
|
+
return addresses;
|
307
|
+
}
|
308
|
+
|
309
|
+
return parsedAddresses;
|
310
|
+
}
|
311
|
+
|
312
|
+
// expose to the world
|
313
|
+
module.exports = addressparser;
|