MailCore / mailcore2

MailCore 2 provide a simple and asynchronous API to work with e-mail protocols IMAP, POP and SMTP. The API has been redesigned from ground up.
Other
2.62k stars 627 forks source link

Corrupted image attachments #1069

Closed kjakm closed 9 years ago

kjakm commented 9 years ago

First of all, I'm not sure if this is a Mailcore issue or something I'm doing wrong so if it needs to be moved to StackOverflow please let me know.

I am trying to forward a message and I want to attach some images to it. The images display correctly in my app. I add them to message builder using addAttachment:MCOAttachment.

When I receive the forwarded message and view it on Mail on my Mac the images are attached but show as a '?' icon and can't open. This only happens intermittently - sometimes the images send correctly (the same images). I am also testing using PDF's and have not noticed the same issue with PDF files.

Here is my code:

        NSArray *arr = [[Storage getInstance] getAllAttachmentsForMessage:_forwardMsg];
        for (MyAttachmentModel *att in arr) {
            MCOAttachment *a = [att convertAttachmentToMailcoreAttachment];
            [self.attachmentsToForward addObject:a];
        }

        for (MCOAttachment *a in self.attachmentsToForward) {
            [msgBuilder addAttachment:a];
        }

        - (MCOAttachment *)convertAttachmentToMailcoreAttachment {
            MCOAttachment *att = [MCOAttachment attachmentWithContentsOfFile:self.localFilePath];
            att.mimeType = self.content_type;
            return att;
        } 
dinhvh commented 9 years ago

Could you show an example of a RFC822 source of a "corrupted" message? (use gist)

kjakm commented 9 years ago

Here is the source of a message where the attachment is broken. I've changed the email addresses in the source and remove a line of text (just for privacy reasons). It was created using the code above.

Return-path: <secrettestacc@gmail.com>
Envelope-to: myemail@account.com
Delivery-date: Tue, 24 Feb 2015 09:09:11 -0600
Received: from mail-we0-f176.google.com ([74.125.82.176]:33065)
    by gator4084.hostgator.com with esmtps (UNKNOWN:AES128-GCM-SHA256:128)
    (Exim 4.82)
    (envelope-from <secrettestacc@gmail.com>)
    id 1YQH6l-00041b-7w
    for myemail@account.com; Tue, 24 Feb 2015 09:09:11 -0600
Received: by wevk48 with SMTP id k48so25810155wev.0
        for <myemail@account.com>; Tue, 24 Feb 2015 07:09:10 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:subject:mime-version:content-type;
        bh=EkTp7jkeQ39zgc0OAjVxRnaUk0JWjNJ43xj2fpOMpUk=;
        b=j4/Tjed4jXN0OstC55aNv3/GtVupZKObJz8fB/J32Krorcfceo/1o5s+pqmLXLP8/t
         UGcUWIFRM9DHy0pyv+qwVVuLmVsGYo6LNYuUaQUvWiSsoDGmH3BKPzlewL7A88t6yseY
         hlUN+QrSlM1+qj6K22G4vxI3wQGenLzvN01eXUwg05XVx2o1B1OpJbSRg4tdOfAsiFU0
         ZaH92KoA6SoDPi83Xjoh2HjUy9p/yZn82wiw/nhFR0K0TOT7t2olcz2mNBLv+cBGzKu+
         f8wogpz/fydij7ytHpfQtLYZSxSE91CUQ2NCOjKN8pTsNMAMlIyrbVG5+h1Wy+eg2OlT
         8f6g==
X-Received: by 10.180.12.84 with SMTP id w20mr31916370wib.9.1424790550120;
        Tue, 24 Feb 2015 07:09:10 -0800 (PST)
Received: from my-iPad (188-39-145-210.static.enta.net. [188.39.145.210])
        by mx.google.com with ESMTPSA id dt7sm20899136wib.19.2015.02.24.07.09.09
        for <myemail@account.com>
        (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Tue, 24 Feb 2015 07:09:09 -0800 (PST)
Date: Tue, 24 Feb 2015 15:09:11 +0000
From: Gmail <secrettestacc@gmail.com>
To: myemail@account.com
Message-ID: <73369b6f-7f77-419f-ad40-cb47b8dfb133@my-iPad>
Subject: FWD: Covent Garden
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="54ec9417_19495cff_4db"

--54ec9417_19495cff_4db
Content-Type: multipart/alternative; boundary="54ec9417_74b0dc51_4db"

--54ec9417_74b0dc51_4db
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

---------------------------------------
On 11 Feb 2015, at 14:23, Gmail secrettestacc@gmail.com wrote:

> 
> 
>  
> - My_Attachment_1.jpg, 5.5 MB 
--54ec9417_74b0dc51_4db
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

<html>
<body>
<div> <br> <br> <br><br><br>-------------------------=
--------------<br>On 11 =46eb 2015, at 14:23, Gmail secrettestacc=40gm=
ail.com wrote:<br><br> </div><br> <div><blockquote style=3D=22color:blue;=
margin-left:20px;=22> <div style=3D=22padding-bottom: 20px;=22></div><div=
><html xmlns=3D=22http://www.w3.org/1999/xhtml=22>
<head>
<title></title>
</head>
<body>
<div><br />
<br />
<br />
</div>
<br />
<div></div>
</body>
</html>
<hr/>                 <div>- My=5FAttachment=5F1.jpg, 5.5 MB</div>=
                                                   </div> </blockquote></=
div></body>
</html>
--54ec9417_74b0dc51_4db--

--54ec9417_19495cff_4db
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-Disposition: attachment; 
 filename="=?utf-8?Q?748=5F0=My=5FAttachment=5F1.jpg?="

--54ec9417_19495cff_4db--
dinhvh commented 9 years ago

It sounds like the file is empty or did not exist. Are you sure self.localFilePath existed when you created the RFC 822 data of the message?

kjakm commented 9 years ago

I think the issue was that I was attempting the forward sometimes while the attachment was still being fetched (but I had the name as the name was set prior to the fetch completing). I'll close for now. Thanks.