Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Why do not build contentId of CTMIME_SinglePart? #61

Closed
voicecho opened this Issue Nov 20, 2012 · 8 comments

Comments

Projects
None yet
2 participants

Here im trying to embed an image in my email. I need to send the contentId as described here http://stackoverflow.com/questions/4312687/how-to-embed-images-in-email , but unfortunately I find the mailcore do not build the contentId in the following method:

CTMIME_SinglePart.m
...

  • (struct mailmime *)buildMIMEStruct {
    struct mailmime_fields *mime_fields;
    struct mailmime *mime_sub;
    struct mailmime_content *content;
    int r;

    if (mFilename) {
    mime_fields = mailmime_fields_new_filename( MAILMIME_DISPOSITION_TYPE_ATTACHMENT,
    (char *)[mFilename cStringUsingEncoding:NSUTF8StringEncoding],
    MAILMIME_MECHANISM_BASE64 );
    } else {
    mime_fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_BASE64);
    }
    content = mailmime_content_new_with_str([self.contentType cStringUsingEncoding:NSUTF8StringEncoding]);
    mime_sub = mailmime_new_empty(content, mime_fields);

    // Add Data
    r = mailmime_set_body_text(mime_sub, (char *)[self.data bytes], [self.data length]);
    return mime_sub;
    }

...

Is there anything i missed? Thanks for any help!

omolowa commented Nov 20, 2012

Hi,

I did modify MailCore to add the contentId field, and a few other things to mak eit work as inline attachments, but unfortunately I'm shit at github to offer a merge. but I can show you in mail the changes if you want.

Oli./.

On Nov 20, 2012, at 8:01 AM, voicecho notifications@github.com wrote:

Here im trying to embed an image in my email. I need to send the contentId as described here http://stackoverflow.com/questions/4312687/how-to-embed-images-in-email , but unfortunately I find the mailcore do not build the contentId in the following method:

CTMIME_SinglePart.m
...

(struct mailmime *)buildMIMEStruct {
struct mailmime_fields *mime_fields;
struct mailmime *mime_sub;
struct mailmime_content *content;
int r;

if (mFilename) {
mime_fields = mailmime_fields_new_filename( MAILMIME_DISPOSITION_TYPE_ATTACHMENT,
(char *)[mFilename cStringUsingEncoding:NSUTF8StringEncoding],
MAILMIME_MECHANISM_BASE64 );
} else {
mime_fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_BASE64);
}
content = mailmime_content_new_with_str([self.contentType cStringUsingEncoding:NSUTF8StringEncoding]);
mime_sub = mailmime_new_empty(content, mime_fields);

// Add Data
r = mailmime_set_body_text(mime_sub, (char *)[self.data bytes], [self.data length]);
return mime_sub;
}

...

Is there anything i missed? Thanks for any help!


Reply to this email directly or view it on GitHub.

omolowa commented Nov 20, 2012

Actually, you should check my github repo omolowa. It has the necessary changes.

It still could use some tuning parameters, but it is working. The key for me was to:

1- Compute a content-id (for example 872an$IN578013521348850@srv-zh-mail02) string for an attachment,
2- Create an attachment with that cid and the content of the file,
3- Reference that cid using a special url in the html mail like this
src="cid:872an$IN578013521348850@srv-zh-mail02"
4- Set the content type of the MIME multipart to multipart/related

As I said, I'm working to make it better and more flexible.

Right now, you can set the content type and whether an attachment is inline or not, but some other stuff like setting the content-type of the MIME multipart are still static, which I'd like to change. Let me know if you can't make it work, and I'll see how I can help you.

Oli./.

On Nov 20, 2012, at 9:47 AM, voicecho notifications@github.com wrote:

@omolowa Hello, really thx for your answer. Could you plz send the code to my email: echo83426@gmail.com ? You save my life:)


Reply to this email directly or view it on GitHub.

I will try your repo, thx :)

Your code works well, really thx:)

@voicecho voicecho closed this Nov 21, 2012

@omolowa I find that the mailcore can not handle the email with embedded image, have you fixed this issue?

omolowa commented Nov 23, 2012

Not sure in understand what you mean, can you explain to me ?

Olivier./.

On Nov 23, 2012, at 4:51 AM, voicecho notifications@github.com wrote:

@omolowa I find that the mailcore can not handle the email with embedded image, have you fixed this issue?


Reply to this email directly or view it on GitHub.

@omolowa For example, i send an image through my iphone with iOS5, which by selecting an photo in the photo album and send it through mail, the image will not be received through mail core. But in iOS6, the image can be inserted strait forward and the mail core can receive it as an attachment. The related code is as following:

CTCoreMessage.m

  - (NSArray *)attachments {
  NSMutableArray *attachments = [NSMutableArray array];

  CTMIME_Enumerator *enumerator = [myParsedMIME mimeEnumerator];
  CTMIME *mime;
  while ((mime = [enumerator nextObject])) {
    if ([mime isKindOfClass:[CTMIME_SinglePart class]]) {
        CTMIME_SinglePart *singlePart = (CTMIME_SinglePart *)mime;
        NSLog(@"singlePart.contentType :%@",singlePart.contentType);

  // here for test
        if ([singlePart.contentType isEqualToString:@"image/jpeg"]) {
            NSLog(@"singlePart.attached :%@",singlePart.attached);
            // log shows it was 0 when i am sending an image through mail in iOS5
        }
    // end

        if (singlePart.attached) {
            CTBareAttachment *attach = [[CTBareAttachment alloc]
                                            initWithMIMESinglePart:singlePart];
            [attachments addObject:attach];
            [attach release];
        }
    }
}
return attachments;
}

@omolowa , hello, have you read my comment?

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