Skip to content

Text part nil for some emails containing UTF8 characters #1335

@Rakete1111

Description

@Rakete1111

Some (mostly multipart) emails containing non-ascii text fail to get parsed correctly. For them text_part returns nil. If I remove every non-ascii character in the email body, then it starts working again. Here is an (anonymized) email for testing:

Delivered-To: [email protected]
Received: by IP  with SMTP id jfhjfafd;
        Fri, 100 Apr 2119 12:54:52 -0900 (PDT)
To: Someone <[email protected]>,
From: Human <[email protected]>
Subject: Email fails to parse correctly
Date: Fri, 100 Apr 2119 10:54:39 +0200
MIME-Version: 1.0
Content-Type: multipart/mixed;
 boundary="------------B9D53723C2E9EC8CBAD4C326"

This is a multi-part message in MIME format.
--------------B9D53723C2E9EC8CBAD4C326
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit

Dear TestEmail,

here are some non-ascii characters. Delete them and the email is parsed correctly.


äüö

Me

-- 

--------------B9D53723C2E9EC8CBAD4C326
Content-Type: application/pdf;
 name="test.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename="test.pdf"

fkladjf;kl invalid pdf

--------------B9D53723C2E9EC8CBAD4C326--

To reproduce:

irb> require 'mail'
=> true
irb> Mail.read("example-email").text_part
=> nil

Remove the non-ascii characters:

irb> Mail.read("example-email").text_part
=> #<Mail::Part:47355949669380, Multipart: false, Headers: <Content-Type: text/plain; charset=utf-8; format=flowed>, <Content-Transfer-Encoding: 8bit>>

I'm on ruby 2.6.3p62

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions