Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attachments and Body Resources #88

Merged
merged 1 commit into from
Jan 31, 2024
Merged

Attachments and Body Resources #88

merged 1 commit into from
Jan 31, 2024

Conversation

manveru
Copy link
Contributor

@manveru manveru commented Jan 27, 2024

This allows adding Attachments when specifying an Email.

The fields of Carbon::Attachment were chosen based on the ones required in the SMTP library carbon_smtp_adapter uses: https://github.com/arcage/crystal-email/blob/master/src/email/message.cr#L353-L382

I'd imagine the same data may be used by all other adapters.

example usage:

class TestEmail < BaseEmail
  from Carbon::Address.new("My App Name", "support@myapp.com")
  to "fred@example.org"
  subject "Test Subject"
  templates text, html
  attachment hello

  def bye
    {
      io: IO::Memory.new("Bye"),
      cid: "unique_bar@myapp.com",
      file_name: "bye.txt",
      mime_type: "text/plain"
    }
  end
end

Please note that I did fold both attachments and body resources into a single Array, this is mostly to keep our API simple, the only difference being the presence of the cid property.

Copy link
Member

@jwoertink jwoertink left a comment

Choose a reason for hiding this comment

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

This looks pretty simple for a start. The only thing I worry about is somebody calling that method and duplicating the attachements

email = SendReceiptEmail.new
total = email.attachements.size
email.attachements.each do |a|
  puts a
end

I think this could give weird results on the iteration because it would append the attachment again, right?

@manveru
Copy link
Contributor Author

manveru commented Jan 27, 2024

Attachments can be duplicated according to the spec. Except when you set the Content-ID, but in that case the upstream message_resource method will raise an exception about duplicated entries.

I didn't expect this will be much of an issue in practice, so I opted for not using a Hash, which simplifies our implementation a lot, given that there's not really a foolproof way to decide on a key for said Hash, and it would be a runtime error either way.

@jwoertink jwoertink merged commit b47843b into luckyframework:main Jan 31, 2024
4 checks passed
@manveru manveru deleted the attachments branch January 31, 2024 16:20
This was referenced Feb 14, 2024
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.

2 participants