Skip to content

Mail doesn't parse parts if plain/text contain ’ symbol #1315

Description

@iggant

create email file mail.msg

MIME-Version: 1.0
Content-Type: multipart/alternative;
 boundary="=_081e3772855208a6e4fd5e0fc0226ac6"
Date: Wed, 06 Feb 2019 11:40:26 -0500
From: Some Person <person@example.com>
To: Other Person <person@example.com>
Subject: Re: question [Thread: goUYOWlr.1]
User-Agent: Roundcube Webmail/1.3.8

--=_081e3772855208a6e4fd5e0fc0226ac6
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=UTF-8

FIRSTNAME O’LASTNAME, CPA
--=_081e3772855208a6e4fd5e0fc0226ac6
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<div><strong>FIRSTNAME O&rsquo;LASTNAME, CPA </strong></div>

--=_081e3772855208a6e4fd5e0fc0226ac6--

create example file:

require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'
  gem 'mail'
end


file = File.open('mail.msg')
email = Mail.read(file)
puts email.parts.inspect

Actual output:
[#<Mail::Part:47308565129460, Multipart: false, Headers: <Content-Type: text/plain; charset=UTF-8>, <Content-Transfer-Encoding: 8bit>>]

Expected output:

[#<Mail::Part:47220814372500, Multipart: false, Headers: <Content-Type: text/plain; charset=UTF-8>, <Content-Transfer-Encoding: 8bit>>, #<Mail::Part:47220814403800, Multipart: false, Headers: <Content-Type: text/html; charset=UTF-8>, <Content-Transfer-Encoding: quoted-printable>>]

Due to ’ in the text/plain part of the mail, gem doesn't parse email correctly

Activity

  1. jeremy commented on Feb 11, 2019

    @jeremy
    Collaborator

    It's because the email has LF line endings, not CRLF, and we can't detect that it's safe to automatically convert them LF → CRLF.

    Highly recommend switching to CRLF line endings if you can. This mostly affects test fixtures that have been saved with UNIX line endings (\n) instead of DOS line endings (\r\n). CRLF is required, but Mail has long attempted to support LF for convenience. But that results in sometimes mangling binary values, no good.

    See #1159 and #1160 for more.

  2. iggant commented on Feb 13, 2019

    @iggant
    Author

    @jeremy but the problem is that we are not in charge of this email, this is real email from postfix, that we have to parse and process ((

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

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