muratgozel / MIMEText

RFC-2822, RFC-2045 and RFC-2049 compliant raw email message generator.
https://muratgozel.github.io/MIMEText/
MIT License
80 stars 35 forks source link

Line length not taken into consideration from RFC-2822 #21

Closed toteto closed 1 year ago

toteto commented 2 years ago

In RFC-2822 section 2.1.1

2.1.1. Line Length Limits There are two limits that this standard places on the number of characters in a line. Each line of characters MUST be no more than 998 characters, and SHOULD be no more than 78 characters, excluding the CRLF.

The 998 character limit is due to limitations in many implementations which send, receive, or store Internet Message Format messages that simply cannot handle more than 998 characters on a line. Receiving implementations would do well to handle an arbitrarily large number of characters in a line for robustness sake. However, there are so many implementations which (in compliance with the transport requirements of [RFC2821]) do not accept messages containing more than 1000 character including the CR and LF per line, it is important for implementations not to create such messages.

The more conservative 78 character recommendation is to accommodate the many implementations of user interfaces that display these messages which may truncate, or disastrously wrap, the display of more than 78 characters per line, in spite of the fact that such implementations are non-conformant to the intent of this specification (and that of [RFC2821] if they actually cause information to be lost). Again, even though this limitation is put on messages, it is encumbant upon implementations which display messages

The recommendation is for the line lengths to not exceed 78, but there is hard limit on the 998 characters.

From my observations of the popular mail clients like Gmail and Outlook, the content and subject is folded at 78 characters.

@muratgozel What do you think of accepting this recommendation into the library?

muratgozel commented 2 years ago

hi @toteto thanks for pointing this out. this should be implemented obviously. i just checked Gmail and as you said, they use 76 chars line length (excluding line break). i don't know why it is not 78 but I'm sure they have a good reason for that.

i think asRaw and asEncoded methods in MIMEMessage.js file and dump method of the subject header in MIMEMessageHeader.js file, are proper places to implement this.

Let me know please, if you would like to contribute on this so we handle it together.

glr0221 commented 1 year ago

Hello @muratgozel @toteto ,

Just my two cents. I think libmime might simplify the fix for this issue?

Thanks

muratgozel commented 1 year ago

Hi @toteto @glr0221 i just implemented this, as of v2.1. closing this issue now.

note: it turned out 80 chars length was for printing, initially, and it seems like it is still a standard for generating emails.