haraka / node-address-rfc2822

Parser for RFC2822 (Header) format email addresses
https://www.npmjs.com/package/address-rfc2822
53 stars 16 forks source link

Bug when parsing a string with quotations #71

Closed xinbenlv closed 4 months ago

xinbenlv commented 4 months ago

Describe the bug

It can't hanlde apostrophe properly

Run this javascript

const addrparser = require('address-rfc2822');
const parsedEmail = addrparser.parse("'foo@bar.com'"); // please note there is a apostrophe (') before and after foo@bar.com
console.log('parsedEmail: ', parsedEmail);

It can't hanlde apostrophe properly

A clear and concise description of what the bug is.

Expected behavior

Observed behavior

It outputs a parsed email address with apostrophe

parsedEmail:  [ Address { phrase: '', address: "'foo@bar.com'", comment: '' } ]

Steps To Reproduce

Version:

address-rfc2822@^2.1.0:
  version "2.1.0"
  resolved "https://registry.npmjs.org/address-rfc2822/-/address-rfc2822-2.1.0.tgz"
  integrity sha512-TwoTmJcYzS+CLw/h+AO3zOzRFGSMNowmp/tlOXcYPygkr2vMAWLs0pDajJiJK/dtVPpFx1utw/CzzLfmmtkagw==
  dependencies:
    email-addresses "^4.0.0"

System Info

Please report your OS, Node version, and Haraka version by running this shell script on your Haraka server and replacing this section with the output.

Haraka bash: haraka: command not found
Node v18.20.3
OS Linux moon-m-zzn-im 6.1.0-21-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.90-1 (2024-05-03) x86_64 GNU/Linux
openssl OpenSSL 3.0.11 19 Sep 2023 (Library: OpenSSL 3.0.11 19 Sep 2023)

Additional context

Add any other context about the problem here.

msimerson commented 4 months ago

Please read RFC 2822 and RFC 5322 and their successors and point out exactly where we are handling the address incorrectly.

xinbenlv commented 4 months ago

@msimerson thanks for pointing it out. What's your suggestion? Shall there be another node-address-rfc5322 instead or do you think it makes sense to continue to update this repository here?

msimerson commented 4 months ago

I suspect the only bug here is your expectations. For further reading, see the RFCs and https://github.com/jackbearheart/email-addresses/issues/53