Skip to content

Conversation

grosser
Copy link
Contributor

@grosser grosser commented Jul 31, 2014

@bf4 @jeremy @mikel

calling afield with it's own name seems like a pretty useless feature, removing this breaks ~30 specs, that I'd fix if we decide to go this way ...

#720

Ideally the .to_s would not be necessary, but something in mail or action_mailer passes in a class for content_transfer_encoding :/

fix:

# https://github.com/mikel/mail/pull/766
Mail::CommonField.class_eval do
  def strip_field(field_name, value)
    value.to_s
  end
end

@jeremy
Copy link
Collaborator

jeremy commented Aug 1, 2014

Agree, but it's a breaking API change. We could introduce a new API to instantiate a field with a value only, like Field.build value, or change #initialize to take either a string or value: ... argument.

The current Field.new "header: value" API may be deprecated and either removed or moved to a Field.parse ... API.

@kjg
Copy link
Contributor

kjg commented Aug 1, 2014

Does this completely remove the need for strip_field? If so, #719 might not be needed if this gets accepted.

@grosser
Copy link
Contributor Author

grosser commented Aug 1, 2014

yes, this kills strip_field

I never saw anyone use the field api directly, mostly either parsing whole mails or building them via actionmailer, so not sure if that's a real use-case. It's also very easy to change offending code to be Field.new "Name", "Value" instead of `"Name: Value", right ?

@grosser
Copy link
Contributor Author

grosser commented Aug 1, 2014

all green now (at least locally)

@grosser
Copy link
Contributor Author

grosser commented Aug 6, 2014

Anything missing here ?

@jeremy
Copy link
Collaborator

jeremy commented Aug 7, 2014

You'll need to deprecate the API—or introduce new API—rather than making a breaking change.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Note that strip_field used to always return a string. Now we may be supering with a range of values that we didn't design for (or test).

@grosser
Copy link
Contributor Author

grosser commented Aug 8, 2014

made all values || "" to not influence the other code

not sure why we need any new api, this seems to work fine:

>> Mail::Field.new "Subject", "Fppp"
=> #<Mail::Field 0x7fec1d8304f8 @name="Subject" @value="Fppp" @raw_value=nil @charset="utf-8">

also very few people should be using Field directly ...

@grosser
Copy link
Contributor Author

grosser commented Aug 12, 2014

does this need more or can it get merged ?

@grosser
Copy link
Contributor Author

grosser commented Aug 16, 2014

@jeremy what do I need to do to get this merged ?

@jeremy
Copy link
Collaborator

jeremy commented Aug 26, 2014

You'll need to deprecate the API—or introduce new API—rather than making a breaking change.

@grosser
Copy link
Contributor Author

grosser commented Aug 26, 2014

It's still possible to create a field with a name and value, so no new api needed, right ?
Any kind of deprecation notice I add would catch normal usecases / be misleading since we cannot know if the "foo:" in a field is supposed to be the name or actual content (that's basically the bug...).
So maybe leave this hanging here until the project is ready for a bigger bump ?
Change should be pretty obvious to anyone using this kind of internal api (if anyone actually uses it...) since there will be duplicate fields everywhere...

@jeremy
Copy link
Collaborator

jeremy commented Aug 27, 2014

We could introduce a new API to instantiate a field with a value only, like Field.build value, or change #initialize to take either a string or value: ... argument.

The current Field.new "header: value" API may be deprecated and either removed or moved to a Field.parse ... API.

@grosser
Copy link
Contributor Author

grosser commented Sep 3, 2014

If someone needs the split feature they can just to Field.new *thing.split(":", 2), do you think it's a commonly used feature ?

@grosser
Copy link
Contributor Author

grosser commented Sep 3, 2014

and Field without name would just be Field.new nil, 'foo'

@grosser
Copy link
Contributor Author

grosser commented Sep 3, 2014

This is also not affecting basic Field usage, only subclasses, so ToField.new("To: abc") would have a different and obviously wrong result. Only usecase would be people reading in headers by themself, which seems a little weird ...

@grosser
Copy link
Contributor Author

grosser commented Jul 25, 2015

ran into this gain when doing outbound email ... would love to get this merged ... I don't see anyone using this api anyway ...

@grosser grosser force-pushed the grosser/subject-double branch from 4ab36b5 to c0bfa2c Compare September 30, 2015 04:31
@grosser
Copy link
Contributor Author

grosser commented Sep 30, 2015

@jeremy rebased, can we get this merged now ?

(using this patch in apps that both handle inbound and outbound mail without any issues since over a year now ... )

@kjg
Copy link
Contributor

kjg commented Sep 30, 2015

@grosser You might have to rebase this again

@grosser
Copy link
Contributor Author

grosser commented Sep 30, 2015

done!

@grosser grosser force-pushed the grosser/subject-double branch from c0bfa2c to b7de62f Compare September 30, 2015 15:49
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we leave this spec in place?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

feels useless to me ... but added it back if that makes you happy ...

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks! It's to prove that this bug is still fixed: https://github.com/mikel/mail/pull/719/files

jeremy added a commit that referenced this pull request May 22, 2017
Fixes mail with a legit "Subject: subject: foo" header. We'd split that
into a subject field with a "subject: foo" value. When we instantiate
the SubjectField and pass that value, we'd strip the leading "subject: "
from it again! So we'd end up with a "foo" subject.

This fixes the issue at the cost of some obscure backward compatibility.

1. If you instantiate internal header fields directly, bypassing
Mail::Field, then using them to parse raw headers will now fail.
This will now be treated as a literal value:

    Mail::ToField.new('To: foo@example.com')
    # => Mail::Field::IncompleteParseError: Mail::AddressList can not parse |To: foo@example.com|: Only able to parse up to "To: foo@example.com"

Instead, use Mail::Field.parse:

    Mail::Field.parse('To: foo@example.com')
    # => #<Mail::ToField …>

2. If you parse fields by instantiating Mail::Field.new with a raw header,
it'll now warn you with a deprecation error. That behavior will go away in
Mail 2.8.0.

    Mail::Field.new('To: foo@example.com')
    # => Passing an unparsed header field to Mail::Field.new is deprecated and will be removed in Mail 2.8.0. Use Mail::Field.parse instead.
    # => #<Mail::Field 0x7fa401026910 @charset="utf-8" @name="To" @value="foo">

Instead, use Mail::Field.parse:

    Mail::Field.parse('To: foo@example.com')
    # => #<Mail::ToField …>

Thanks to @grosser for #766 ❤️

Closes #1111
@jeremy
Copy link
Collaborator

jeremy commented May 22, 2017

#1111

@jeremy jeremy closed this May 22, 2017
@jeremy jeremy added this to the 2.7.0 milestone May 22, 2017
@seb-sykio
Copy link

since I updated to 2.7.0, I have this issue :

  Failure/Error: mm = Dkim.sign(mm, :domain => xxx, :selector => 'mail', :private_key => OpenSSL::PKey::RSA.new(xxx))
  
  NoMethodError:
    undefined method `strip_field' for #<Mail::DkimField:0x0000564a55a59bf0 @charset="utf-8">
  # /xxx/.rvm/gems/ruby-2.4.2@xxx/gems/dkim-1.0.0/lib/mail/dkim_field.rb:12:in `initialize'

@mariozaizar mariozaizar deleted the grosser/subject-double branch July 26, 2018 22:48
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.

4 participants