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

StreamTransport issues new lines as CRLF despite setting "unix" newline #1639

Open
Ymmy833y opened this issue Apr 3, 2024 · 3 comments
Open

Comments

@Ymmy833y
Copy link

Ymmy833y commented Apr 3, 2024

Issue Description:

When setting the newline option to 'unix' in StreamTransport, the returned newlines are still CRLF (Windows-style) instead of the expected LF (Unix-style).

The official documentation states:

Additionally, you can define which kind of newlines to use, either the 'windows' style (<CR><LF>) or the 'unix' style (<LF>)

However, when running the following test code based on the sample code provided in the documentation, the returned newline characters are still \r\n, failing the test.

Test Code:

'use strict';

const { describe, it } = require('node:test');
const assert = require('node:assert/strict');
const {createTransport} = require('../lib/nodemailer');

describe('Stream Transport Tests', { timeout: 10000 }, () => {
  it('Should send mail using unix newlines', (t, done) => {    
    let transporter = createTransport({
      streamTransport: true,
      newline: 'unix',
      buffer: true
    });
    transporter.sendMail(
      {
        from: 'sender@example.com',
        to: 'recipient@example.com',
        subject: 'Message',
        text: 'I hope this message gets buffered!',
      }, (err, info) => {
        console.log(`info message: \n${JSON.stringify(info.message.toString())}`);
        assert.ok(!err);
        assert.strictEqual(info.message.toString().includes('\r\n'), false);
        done();
      })
  });
});
info message: 
"From: sender@example.com\r\nTo: recipient@example.com\r\nSubject: Message\r\nMessage-ID: <9752b1b9-6018-2b96-42e8-ac945c62cf11@example.com>\r\nContent-Transfer-Encoding: 7bit\r\nDate: Wed, 03 Apr 2024 09:23:52 +0000\r\nMIME-Version: 1.0\r\nContent-Type: text/plain; charset=utf-8\r\n\r\nI hope this message gets buffered!\r\n"

Possible Root Cause:

The root cause seems to be that the newline: 'unix' option set in options is not being passed to the MailComposer at Mail#sendMail L182.

Possible Solution:

The easiest workaround would be to set newline: 'unix' in the first argument of sendMail. However, this approach may not be appropriate since newline is not a property of email data. (Additionally, while Nodemailer itself does not have an issue, the newline option is not defined in the Mail.Options type definition for Nodemailer. see: https://github.com/DefinitelyTyped/DefinitelyTyped)

If this solution is not viable, unfortunately, I cannot suggest an optimal solution.

I understand that you are incredibly busy, I would appreciate your confirmation and feedback.


Environment:

  • node: v20.12.0
  • npm: v10.5.0
  • nodemailer: v6.9.13
@andris9
Copy link
Member

andris9 commented Apr 3, 2024

I checked, and you are right. However, at this point, as this feature is so old and no one has ever complained about it, the correct way would probably be to completely remove this feature instead of fixing it. Is there are reason why you need the eml to be using unix newlines?

@Ymmy833y
Copy link
Author

Ymmy833y commented Apr 3, 2024

Thank you for your confirmation!

I was considering using this feature as a new feature in aws-ses-v2-local and saw this issue.

If there are currently few cases where this feature is being used, and the cost of fixing it is substantial, then I would agree with removing this feature in the future.

Or, if no defects occur in functions otherthan newline, how about considering abolishing only the 'newline' property?

Copy link
Contributor

github-actions bot commented May 4, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants