FIX: Ensure oneboxed secure images which are optimized and also lightboxed optimized images are embedded in email (PR #11061)

GitHub

this confused me for a moment what upload is in the end. Maybe to somehow distinguish them we should have something like

post.uploads.each do |original_upload|
  ...
  attached_upload = optimized_1X || original_upload
  ...

I think it would be a little bit easier to read without that check

 sha1 =  filename_bare.partition('_').first # that should work for filenames without _ as well

Both branches if/else has that check if Upload.secure_media_url?(a['href'])

I guess we can extract it to guard above so it would unnest it a little bit:

doc.css('a[href]').each do |a|
  next if !Upload.secure_media_url?(a['href'])

I have minor comments, more like stylish things. Other than that I looks good to me! :slight_smile: