jstedfast/MailKit

Can't set correct or ignore long header trimming

Closed this issue · 4 comments

Describe the bug
I'm trying to send a email with a long X-IB header. The SMTPClient is converting this long string and breaking it in multiple lines. I know that this may be the "correct way" per RFCs but the server on the other side is not accepting this... ironically, it accepts the big string. Here is a sample log

C: MAIL FROM:<noreply@xxxxxx> SIZE=627
S: 250 Ok
C: RCPT TO:<index.xp@gmail.com>
S: 250 Ok
C: DATA
S: 354 End data with <CR><LF>.<CR><LF>
C: From: xxxx <noreply@xxxxxxx>
C: Date: Sat, 24 Aug 2024 18:46:33 -0300
C: Subject: teste
C: Message-Id: <YVPOK10AXNU4.16WZMJV8DHP73@macbook-pro.local>
C: X-IB-notify-url: =?utf-8?q?https=3A=2F=2Fapi-d=2Exxxxx=2Exxxxxx=2Ecom=2Fshared=5Fpost=5Foffice=2Fv1=2FEmailD?=
C:  =?utf-8?q?eliveryReportWebhook=3Fsubscription-key=xxxxxxxx?=
C:  =?utf-8?q?94abfa17d&operationid=3D938bde062caa2fb3d92fde1772834279-04eaac?=
C:  =?utf-8?q?01d74b8da4?=
C: X-IB-notify-content-type: application/json
C: To: "index.xp@gmail.com" <index.xp@gmail.com>
C: MIME-Version: 1.0
C: Content-Type: text/html; charset=utf-8
C: 
C: teste
C: .
S: 451 Could not process message.
C: RSET
S: 250 Ok

and here is a screenshot using regular telnet proving that the server on the other side accepts the long string if presented all at once

Screenshot 2024-08-24 at 18 40 36

Platform (please complete the following information):

  • OS: MacOS and Alpine
  • .NET Runtime: .Net 8
  • MailKit Version: 4.7.1.1

Exception
No Exception

To Reproduce
Try sending a big header value

Expected behavior
string goes as informed, not parsed or broken in lines

Code Snippets
If applicable, add code snippets to help explain your problem.

// Add your code snippet here.

Additional context
Add any other context about the problem here.

You can override MimeKit's header folding by setting the Header.RawValue property:

var header = new Header ("X-IB-notify-url", string.Empty);
header.SetRawValue (Encoding.ASCII.GetBytes ("https://api-d.xxxxx.xxxxxx.com/shared_post_office/v1/EmailDeliveryReportWebhook?subscription-key=xxxxxxxx94abfa17d&operationid=938bde062caa2fb3d92fde1772834279-04eaac01d74b8da4\r\n"));
message.Headers.Add (header);

hey @jstedfast thanks for the suggestion but it appears that RawValue is a read only property
image

actually there's a SetRawValue method

Sorry about that, I'll fix my code snippet.