librelist archives

« back to archive

ContentType not detected

ContentType not detected

From:
Jan Chaloupecky
Date:
2012-07-27 @ 12:51
Hi,
I'm fetching one email via imap and I'd like to get its ContentType header
but it does not seem to work. I'm geting all the time a "message/rfc822"
for a message with a "text/plain" content type:


// last received email
CTCoreMessage *ctCoreMessage = [messages objectAtIndex:messages.count-1];

NSLog(@"Test ContentType: %@", [[ctCoreMessage mime] contentType]);

NSLog(@"Rendered Headers: \n%@", [[ctCoreMessage mime] render]);



The output is:

2012-07-27 14:43:49.705 TestMailCore[48754:11303] *Test ContentType:
> message/rfc822*
> 2012-07-27 14:43:49.706 TestMailCore[48754:11303] Rendered Headers:
> Date: Fri, 27 Jul 2012 14:22:27 +0200
> Subject: text plain
> From: Jan Chaloupecky <chaljan@gmail.com>
> Reply-To: Jan Chaloupecky <chaljan@gmail.com>
> To: MyRecipient <myrecipient@gmail.com>
> Message-ID: <76CC86C5-3CCD-4BB2-8EFE-E0E99F917354@xxxxxxxxxx.com>
> MIME-Version: 1.0
> *Content-Type: text/plain; charset="UTF-8"*
> Content-Transfer-Encoding: 8bit
>



I'm I doing something wrong?

cheers

-- 
Jan

Re: [mailcore] ContentType not detected

From:
Matt Ronge
Date:
2012-07-29 @ 20:44
The message is contained within the message/rfc822 type. So you'll have to
recurse into the message to find what you are looking for. For example 
here is what CTCoreMessage does to find "text/plain" types (notice it 
recurses):

- (void)_buildUpBodyText:(CTMIME *)mime result:(NSMutableString *)result {
    if (mime == nil)
        return;

    if ([mime isKindOfClass:[CTMIME_MessagePart class]]) {
        [self _buildUpBodyText:[mime content] result:result];
    }
    else if ([mime isKindOfClass:[CTMIME_TextPart class]]) {
        if ([[mime.contentType lowercaseString] 
rangeOfString:@"text/plain"].location != NSNotFound) {
            [(CTMIME_TextPart *)mime fetchPart];
            NSString* y = [mime content];
            if(y != nil) {
                [result appendString:y];
            }
        }
    }
    else if ([mime isKindOfClass:[CTMIME_MultiPart class]]) {
        //TODO need to take into account the different kinds of multipart
        NSEnumerator *enumer = [[mime content] objectEnumerator];
        CTMIME *subpart;
        while ((subpart = [enumer nextObject])) {
            [self _buildUpBodyText:subpart result:result];
        }
    }
}


--
Matt Ronge
mronge@mronge.com
iOS Developer & Consultant
Central Atomics Inc.




On Jul 27, 2012, at 7:51 AM, Jan Chaloupecky wrote:

> Hi,
> I'm fetching one email via imap and I'd like to get its ContentType 
header but it does not seem to work. I'm geting all the time a 
"message/rfc822" for a message with a "text/plain" content type:
> 
> 
> // last received email
> CTCoreMessage *ctCoreMessage = [messages objectAtIndex:messages.count-1];
> 
> NSLog(@"Test ContentType: %@", [[ctCoreMessage mime] contentType]);
> NSLog(@"Rendered Headers: \n%@", [[ctCoreMessage mime] render]);
> 
> 
> The output is:
> 
> 2012-07-27 14:43:49.705 TestMailCore[48754:11303] Test ContentType: 
message/rfc822
> 2012-07-27 14:43:49.706 TestMailCore[48754:11303] Rendered Headers:
> Date: Fri, 27 Jul 2012 14:22:27 +0200
> Subject: text plain
> From: Jan Chaloupecky <chaljan@gmail.com>
> Reply-To: Jan Chaloupecky <chaljan@gmail.com>
> To: MyRecipient <myrecipient@gmail.com>
> Message-ID: <76CC86C5-3CCD-4BB2-8EFE-E0E99F917354@xxxxxxxxxx.com>
> MIME-Version: 1.0
> Content-Type: text/plain; charset="UTF-8"
> Content-Transfer-Encoding: 8bit
> 
> 
> 
> I'm I doing something wrong?
> 
> cheers
> 
> -- 
> Jan

Re: [mailcore] ContentType not detected

From:
Jan Chaloupecky
Date:
2012-07-30 @ 06:45
But all e-mails are message/rfc822 aren't they? In which cases *[[ctCoreMessage
mime] contentType]* does not return message/rfc822?

It's a pretty common task to determine the Content-Type of the message it
self so wouldn't it be convenient to add a method *-[CTCoreMessage
contentType]* to the CTCoreMessage? Or, more generally talking, a method to
get any rfc 822 header by its name *-[CTCoreMessage header:]*



cheers,
Jan






On Sun, Jul 29, 2012 at 10:44 PM, Matt Ronge <mronge@mronge.com> wrote:

> The message is contained within the message/rfc822 type. So you'll have to
> recurse into the message to find what you are looking for. For example here
> is what CTCoreMessage does to find "text/plain" types (notice it recurses):
>
> - (void)_buildUpBodyText:(CTMIME *)mime result:(NSMutableString *)result {
>     if (mime == nil)
>         return;
>
>     if ([mime isKindOfClass:[CTMIME_MessagePart class]]) {
>         [self _buildUpBodyText:[mime content] result:result];
>     }
>     else if ([mime isKindOfClass:[CTMIME_TextPart class]]) {
>         if ([[mime.contentType lowercaseString] 
rangeOfString:@"text/plain"].location
> != NSNotFound) {
>             [(CTMIME_TextPart *)mime fetchPart];
>             NSString* y = [mime content];
>             if(y != nil) {
>                 [result appendString:y];
>             }
>         }
>     }
>     else if ([mime isKindOfClass:[CTMIME_MultiPart class]]) {
>         //TODO need to take into account the different kinds of multipart
>         NSEnumerator *enumer = [[mime content] objectEnumerator];
>         CTMIME *subpart;
>         while ((subpart = [enumer nextObject])) {
>             [self _buildUpBodyText:subpart result:result];
>         }
>     }
> }
>
>
> --
> Matt Ronge
> mronge@mronge.com
> iOS Developer & Consultant
> Central Atomics Inc.
>
>
>
>
> On Jul 27, 2012, at 7:51 AM, Jan Chaloupecky wrote:
>
> > Hi,
> > I'm fetching one email via imap and I'd like to get its ContentType
> header but it does not seem to work. I'm geting all the time a
> "message/rfc822" for a message with a "text/plain" content type:
> >
> >
> > // last received email
> > CTCoreMessage *ctCoreMessage = [messages objectAtIndex:messages.count-1];
> >
> > NSLog(@"Test ContentType: %@", [[ctCoreMessage mime] contentType]);
> > NSLog(@"Rendered Headers: \n%@", [[ctCoreMessage mime] render]);
> >
> >
> > The output is:
> >
> > 2012-07-27 14:43:49.705 TestMailCore[48754:11303] Test ContentType:
> message/rfc822
> > 2012-07-27 14:43:49.706 TestMailCore[48754:11303] Rendered Headers:
> > Date: Fri, 27 Jul 2012 14:22:27 +0200
> > Subject: text plain
> > From: Jan Chaloupecky <chaljan@gmail.com>
> > Reply-To: Jan Chaloupecky <chaljan@gmail.com>
> > To: MyRecipient <myrecipient@gmail.com>
> > Message-ID: <76CC86C5-3CCD-4BB2-8EFE-E0E99F917354@xxxxxxxxxx.com>
> > MIME-Version: 1.0
> > Content-Type: text/plain; charset="UTF-8"
> > Content-Transfer-Encoding: 8bit
> >
> >
> >
> > I'm I doing something wrong?
> >
> > cheers
> >
> > --
> > Jan
>
>


-- 
Jan

Re: [mailcore] ContentType not detected

From:
Jan Chaloupecky
Date:
2012-07-30 @ 06:56
Ok, to get the main content type, this should do it

*[[[ctCoreMessage mime] content] contentType]*




On Mon, Jul 30, 2012 at 8:45 AM, Jan Chaloupecky <chaljan@gmail.com> wrote:

> But all e-mails are message/rfc822 aren't they? In which cases *[[ctCoreMessage
> mime] contentType]* does not return message/rfc822?
>
> It's a pretty common task to determine the Content-Type of the message it
> self so wouldn't it be convenient to add a method *-[CTCoreMessage
> contentType]* to the CTCoreMessage? Or, more generally talking, a method
> to get any rfc 822 header by its name *-[CTCoreMessage header:]*
>
>
>
> cheers,
> Jan
>
>
>
>
>
>
> On Sun, Jul 29, 2012 at 10:44 PM, Matt Ronge <mronge@mronge.com> wrote:
>
>> The message is contained within the message/rfc822 type. So you'll have
>> to recurse into the message to find what you are looking for. For example
>> here is what CTCoreMessage does to find "text/plain" types (notice it
>> recurses):
>>
>> - (void)_buildUpBodyText:(CTMIME *)mime result:(NSMutableString *)result {
>>     if (mime == nil)
>>         return;
>>
>>     if ([mime isKindOfClass:[CTMIME_MessagePart class]]) {
>>         [self _buildUpBodyText:[mime content] result:result];
>>     }
>>     else if ([mime isKindOfClass:[CTMIME_TextPart class]]) {
>>         if ([[mime.contentType lowercaseString] 
rangeOfString:@"text/plain"].location
>> != NSNotFound) {
>>             [(CTMIME_TextPart *)mime fetchPart];
>>             NSString* y = [mime content];
>>             if(y != nil) {
>>                 [result appendString:y];
>>             }
>>         }
>>     }
>>     else if ([mime isKindOfClass:[CTMIME_MultiPart class]]) {
>>         //TODO need to take into account the different kinds of multipart
>>         NSEnumerator *enumer = [[mime content] objectEnumerator];
>>         CTMIME *subpart;
>>         while ((subpart = [enumer nextObject])) {
>>             [self _buildUpBodyText:subpart result:result];
>>         }
>>     }
>> }
>>
>>
>> --
>> Matt Ronge
>> mronge@mronge.com
>> iOS Developer & Consultant
>> Central Atomics Inc.
>>
>>
>>
>>
>> On Jul 27, 2012, at 7:51 AM, Jan Chaloupecky wrote:
>>
>> > Hi,
>> > I'm fetching one email via imap and I'd like to get its ContentType
>> header but it does not seem to work. I'm geting all the time a
>> "message/rfc822" for a message with a "text/plain" content type:
>> >
>> >
>> > // last received email
>> > CTCoreMessage *ctCoreMessage = [messages
>> objectAtIndex:messages.count-1];
>> >
>> > NSLog(@"Test ContentType: %@", [[ctCoreMessage mime] contentType]);
>> > NSLog(@"Rendered Headers: \n%@", [[ctCoreMessage mime] render]);
>> >
>> >
>> > The output is:
>> >
>> > 2012-07-27 14:43:49.705 TestMailCore[48754:11303] Test ContentType:
>> message/rfc822
>> > 2012-07-27 14:43:49.706 TestMailCore[48754:11303] Rendered Headers:
>> > Date: Fri, 27 Jul 2012 14:22:27 +0200
>> > Subject: text plain
>> > From: Jan Chaloupecky <chaljan@gmail.com>
>> > Reply-To: Jan Chaloupecky <chaljan@gmail.com>
>> > To: MyRecipient <myrecipient@gmail.com>
>> > Message-ID: <76CC86C5-3CCD-4BB2-8EFE-E0E99F917354@xxxxxxxxxx.com>
>> > MIME-Version: 1.0
>> > Content-Type: text/plain; charset="UTF-8"
>> > Content-Transfer-Encoding: 8bit
>> >
>> >
>> >
>> > I'm I doing something wrong?
>> >
>> > cheers
>> >
>> > --
>> > Jan
>>
>>
>
>
> --
> Jan
>



-- 
Jan