Skip to content

Conversation

mpghf
Copy link
Collaborator

@mpghf mpghf commented Jun 27, 2018

…$addr was undefined if no object was parsed. Now, using Email::Address:XS (since version 1.01), an empty Email::Address::XS object is returned.

…addr was undefined if no object was parsed. Now, using Email::Address:XS (since version 1.01), an empty Email::Address::XS object is returned.
@pali
Copy link

pali commented Jun 27, 2018

Maybe you should add dependency on version 1.01 if you are using method which was introduced in this version.

@mpghf
Copy link
Collaborator Author

mpghf commented Jun 27, 2018

pali,

Build.PL already requires: 'Email::Address::XS' => '1.03'

Surely this should do the trick?

@pali
Copy link

pali commented Jun 27, 2018

That should be enough.

@mpghf mpghf requested a review from theory June 28, 2018 16:57
@pali
Copy link

pali commented Jun 29, 2018

@mpghf Email::Address::XS->parse() takes one string and in list context returns N objects (N can be also zero). Therefore your logic join ', ', map { my ($addr) = ...; $addr->format } @_ is not correct.

Check that $addr is defined before trying to use it.  For empty strings as input (at least), $addr can be undef.
@mpghf
Copy link
Collaborator Author

mpghf commented Jun 29, 2018

@pali Thanks. See if you approve of the updated fix.

@pali
Copy link

pali commented Jun 29, 2018

If you are want to take only the first address and drop all remaining, then call Email::Address::XS->parse() in scalar context in which it always returns object (and call to is_valid() would work for validation)

@mpghf
Copy link
Collaborator Author

mpghf commented Jun 29, 2018

@pali Ok, thanks. I see where you're going. I'll try and figure out whether we can reasonably expect more than one address.

Email::Address::XS->parse will always return a valid scalar object, and is->valid() can be used to test if the result is empty or not.

john@example.com -> not empty
john -> empty
'' -> empty

The addresses are passed individually to $norm, so there will never be multiple addresses.
@mpghf
Copy link
Collaborator Author

mpghf commented Jun 29, 2018

@pali It looks like we're passing the To and From addresses individually to $norm for formatting, so I've taken your advice.

@pali
Copy link

pali commented Jun 29, 2018

Ok, seems better.

Copy link
Owner

@theory theory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking that $addr is defined causes warnings?

@@ -1475,7 +1475,7 @@ sub output_headers {
$norm = sub {
return join ', ' => map {
my ($addr) = Email::Address::XS->parse($_);
if ($addr) {
if ($addr->is_valid()) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know for sure that $addr is never undef? Looks like it could be. Maybe this should be:

my $addr = Email::Address::XS->parse($_);
if ($addr && $addr->is_valid) {

Though reading the docs for parse linked above, it seems as though is_valid could return false if there were more than one object parsed? Kinda weird.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In scalar context since 1.01 it always returns Email::Address::XS object.

In scalar context this function returns just first parsed object. If more then one object was parsed then is_valid method on returned object returns false. If no object was parsed then empty Email::Address::XS object is returned.

@theory you are looking at old version of patches in this pull request
@mpghf Ideally squash changes, so there would not be any reverts or old versions

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, missed that @pali, thanks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running if($addr) on an empty address caused the warnings - I'm not familiar enough with perl's behaviour in that case to understand why.

Using if(defined $addr) instead worked, but @pali has given a better option where $addr will never be undef.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running if($addr) on an empty address caused the warnings

That is probably because of stringification operator which calls format() method? (Now just guessing).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pali Thanks. Good to know.

@theory
Copy link
Owner

theory commented Jun 29, 2018

@pali would you like co-maint as well? Seems like you and @mpghf make a good team.

mpghf added 2 commits June 29, 2018 16:39
Email::Address::XS->parse will always return a valid scalar object, and is->valid() can be used to test if the result is empty or not.

'john@example.com' -> not empty
'john' -> empty
'' -> empty

The addresses are passed individually to $norm, so there will never be multiple addresses.
@mpghf
Copy link
Collaborator Author

mpghf commented Jun 29, 2018

@pali Regarding squashing the commits - I'll do so when I merge. I tried on my local copy, but I'm not honestly sure if I got it right.

Regarding co-maint - I'd appreciate the assistance. You're far more of a perl expert than I am.

@mpghf mpghf merged commit ed01261 into theory:master Jun 29, 2018
@mpghf mpghf deleted the cherrypick branch June 29, 2018 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants