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

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

Open
dudilugasi opened this issue Oct 22, 2024 · 5 comments
Open

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

dudilugasi opened this issue Oct 22, 2024 · 5 comments
Labels

Comments

@dudilugasi
Copy link

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

  • OS: sending http with Windows , node js with axios
  • Version 3.3.4
@willpower232
Copy link
Collaborator

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
Copy link
Author

dudilugasi commented Oct 27, 2024

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

@willpower232
Copy link
Collaborator

willpower232 commented Oct 28, 2024

Ah good to know. I did a little digging and there are a few bits and pieces about using \r\n when sending the message to its recipients so perhaps it is being converted on the way out in spite of being stored as you intended?

@dudilugasi
Copy link
Author

Thing is, when im going to the outgoing messages and click on the message i can see in the attachments tab the attachment, and when i click to download it is already changed
so the base64 is stored in the db (i guess) and when its converting it to text when im downloading the attachment its adding the \r maybe

BTW when im sending directly through smtp using a node.js library called nodemailer it is sending the file without changing it

const transporter = nodemailer.createTransport({
    "host" : "***",
    "secureConnection" : true,
    "port" : 587,
    "tls" : {
      "rejectUnauthorized" : false
    },
    auth: {
      user: '***',
      pass: '****'
    }
  })

  let info = await transporter.sendMail({
    to: '[email protected]',
    from: '[email protected]',
    subject: 'Hello ✔',
    text: 'Hello world?',
    html: '<b>Hello world?</b>',
    attachments: [
      {
        filename: 'test.sh',
        content: 'ClVzaW5nIEdOVSBjb21waWxlcnM6IGdjYyBhbmQgZ2ZvcnRyYW4KCiQgZ2NjIC1jIGMtY2FsbC1mLmMKJCBnZm9ydHJhbiAtZmZyZWUtZm9ybSAtYyBmX3N1Yi5mCiQgZ2NjIC1vIGMtY2FsbC1mLWdjYyAgYy1jYWxsLWYubyBmX3N1Yi5vICAtbGdmb3J0cmFuCiQgLi9jLWNhbGwtZi1nY2MvVm9sdW1lcy9teU9yYW5nZS9Vc2Vycy9kZWxlZXV3L215U3R1ZmYvbXlDb3Vyc2VzL1JfZmxpLzA1X2RvdEZvcnRyYW4vc3dlZXAvY19jYWxsX2Yvc2NyaXB0LnNo',
        encoding: 'base64'
      }
    ]
  });

//works fine

Copy link
Contributor

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the stale label Nov 29, 2024
@willpower232 willpower232 added bug and removed stale labels Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants