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

Issues with iOS Mail app #9

Closed
xMonty opened this issue Apr 12, 2021 · 9 comments
Closed

Issues with iOS Mail app #9

xMonty opened this issue Apr 12, 2021 · 9 comments
Assignees
Labels
bug Something isn't working

Comments

@xMonty
Copy link

xMonty commented Apr 12, 2021

Hi,
if i send mail using iphone mail app (attached with gmail) and i just send an inline image along with text "sent from iphone"
i am getting error
Error: no binary decoder found for [7bit].
the image is not displayed the text part is displayed

the mime message looks something like this

`Return-Path:
X-Original-To:
Delivered-To:
Received:
Received:
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
..
..
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:content-transfer-encoding:from:mime-version:date
:subject:message-id:to;
..
..

X-Gm-Message-State: ...
X-Google-Smtp-Source: ...
X-Received:
Received:
Content-Type: multipart/mixed;
boundary="Apple-Mail-----------"
Content-Transfer-Encoding: 7bit
From: ...............
Mime-Version: 1.0 (1.0)
Date: Mon, 12 Apr 2021 18:38:07 +0530
Subject: Mail
Message-Id: ........
To: ..............
X-Mailer: iPhone Mail (18B121)

--Apple-Mail--------------------
Content-Type: image/jpeg;
name=image0.jpeg;
x-apple-part-url=------------------
Content-Disposition: inline;
filename=image0.jpeg
Content-Transfer-Encoding: base64

/9j/2wCEAAEBAQEBAQIBAQIDAgICAwQDAwMDBAUEBAQEBAUGBQUFBQUFBgYGBgYGBgYHBwcHBwcI
CAgICAkJCQkJC...NIs1t/
tRv9qjooKP/Z
--Apple-Mail---------------------
Content-Type: text/plain;
charset=us-ascii
Content-Transfer-Encoding: 7bit

Sent from my iPhone
--Apple-Mail----------
`

@robert-virkus
Copy link
Member

Thanks for the report, can you upload a complete example (make sure to remove any private information) of such a mail here? Alternatively send me such a message to robert -at- enough --dot-- de.

@robert-virkus robert-virkus added the bug Something isn't working label Apr 13, 2021
@xMonty
Copy link
Author

xMonty commented Apr 14, 2021

I mailed you a sample email

@robert-virkus robert-virkus self-assigned this Apr 14, 2021
@robert-virkus
Copy link
Member

Thanks again for the test mail and your report!

You need to update your packages:

enough_mail: ^1.2.2
enough_mail_html: ^1.1.0
enough_mail_flutter: ^1.1.0

The problem was that the inline part did not have a Content-ID header, so the html package now detects this and uses fetch:// link to instead link to to the fetchID rather than the CID. Additionally, it turned out that the MimeMessage.getPart(fetchId) implementation was broken for the case of the fetchID being 1.

@xMonty
Copy link
Author

xMonty commented Apr 15, 2021

Hi, looks fixed the email is loading correctly now.
However there is another mail thats crashing not sure if the issue is related
E/flutter ( 6452): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: Bad state: No element E/flutter ( 6452): #0 List.last (dart:core-patch/growable_array.dart:337:5) E/flutter ( 6452): #1 TextMimeData._parseContent package:enough_mail/mime_data.dart:128 E/flutter ( 6452): #2 MimeData.parse package:enough_mail/mime_data.dart:59 E/flutter ( 6452): #3 MimePart.parse package:enough_mail/mime_message.dart:301 E/flutter ( 6452): #4 MimeMessage.parseFromText package:enough_mail/mime_message.dart:502 E/flutter ( 6452): #5 _MessageViewState.loadMessage package:instantmb_flutter/…/inbox/message_view.dart:85 E/flutter ( 6452): <asynchronous suspension>

i am emailing the mail that causes this to you

@robert-virkus
Copy link
Member

robert-virkus commented Apr 15, 2021

Strange, I cannot reproduce the problem with the mail text you sent me.
From the stacktrace I would assume that the boudary was somehow misinterepreted, the relevant code part seem to be:

final splitBoundary = '--' + contentTypeHeader!.boundary! + '\r\n';
final childParts = bodyText.split(splitBoundary);
if (!bodyText.startsWith(splitBoundary)) {
  // mime-readers can ignore the preamble:
  childParts.removeAt(0);
}
var lastPart = childParts.last; // <-- in your case childParts seems to be empty

Do you have any other way how to reproduce this?

@xMonty
Copy link
Author

xMonty commented Apr 15, 2021

The issue seems to be because of this code
if (headerParseResult.bodyStartIndex! >= text.length) { bodyText = ''; } else { bodyText = text.substring(headerParseResult.bodyStartIndex!); }

bodyText is set to '' as headerParseResult.bodyStartIndex is 10319 and text.length is 10317

since bodyText is ''
final childParts = bodyText.split(splitBoundary);
childParts is 0 length array

Also just FYI i am importing enough mail like this in yaml
enough_mail_flutter: #any git: url: https://github.com/Enough-Software/enough_mail_flutter.git ref: main

i am not importing any other dependencies from enough mail directly

@robert-virkus
Copy link
Member

Thanks, this seems to imply there is no body detected at all. Could it be that the text lines are not separated by \r\n, perhaps only with \n? Still, I'm still puzzled about me not being able to reproduce this problem with the message you sent me...

@xMonty
Copy link
Author

xMonty commented Apr 15, 2021

I think this could be some issue at my end as my mails are being saved in a database and when i send a new mail its working.
another thing though when i am sending the email i am adding image first and then the text "Sent from my iPhone" but when its being rendered the text comes first and then the image is being rendered

@robert-virkus
Copy link
Member

You could try to replace newlines with the MIME line breaks like this:

final mimeText = text.replaceAll('\n', '\r\n');
final mime = MimeMessage.parseFromText(mimeText);

And yes, I am aware about the ordering of inline parts and have created this bug to track it:
Enough-Software/enough_mail_html#7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants