postalserver / postal

📮 A fully featured open source mail delivery platform for incoming & outgoing e-mail
https://postalserver.io
MIT License
14.85k stars 1.05k forks source link

Attachment with LF in body is being replaced to CR LF #3189

Open dudilugasi opened 5 days ago

dudilugasi commented 5 days ago

Describe the bug

I am sending an text attachment with LF in the api but the attachment is received with CR LF

this is an issue because my client is comparing hashes and becuase of that the hashes are not the same

To Reproduce

  1. Convert a file with LF to base64
  2. Send it using the api
  3. The attachment wiill be with CR LF instead of LF

Expected behaviour

The attachment should be exactly how sent it

Environment details

willpower232 commented 9 hours ago

Interesting, I don't know much about ruby or base64 decoding specifics but if you're able to try editing here

https://github.com/postalserver/postal/blob/da90e75036c27482699921613d838f4058a100e7/app/models/outgoing_message_prototype.rb#L102C57-L102C73

You can apparently swap it to Base64.strict_decode64 but I don't know if that is any better or worse. I doubt the database is doing any line ending conversion and this seems to be one of the few places the attachment could be altered.

dudilugasi commented 9 hours ago

I don't know if it is related to the decode64 i've tried this code block:

require "base64"
require "json"
str1 = Base64.decode64("dGVzdAp0ZXN0CnRlc3QK")
str2 = Base64.decode64("dGVzdA0KdGVzdA0KdGVzdA")
puts str1.to_json
puts str2.to_json

and got this output:

"test\ntest\ntest\n"
"test\r\ntest\r\ntest"

so the Base64.decode64 is actually working ok in ruby