View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Dave Rolsky > Courriel > Courriel::Header::ContentType



Annotate this POD


View/Report Bugs
Module Version: 0.47   Source  


Courriel::Header::ContentType - The content type for an email part


version 0.47


    my $ct = $part->content_type();
    print $ct->mime_type();
    print $ct->charset();

    my %attr = $ct->attributes();
    while ( my ( $k, $v ) = each %attr ) {
        print "$k => $v\n";


This class represents the contents of a "Content-Type" header attached to an email part. Such headers always include a mime type, and may also include additional information such as a charset or other attributes.

Here are some typical headers:

  Content-Type: text/plain; charset=utf-8

  Content-Type: multipart/alternative; boundary=abcdefghijk

  Content-Type: image/jpeg; name="Filename.jpg"


This class supports the following methods:

Courriel::Header::ContentType->new_from_value( ... )

This takes two parameters, name and value. The name is optional, and defaults to "Content-Type".

The value is parsed and split up into the mime type and attributes.

Courriel::Header::ContentType->new( ... )

This method creates a new object. It accepts the following parameters:


The header name, usually "Content-Type".


The raw header value.


Returns the mime type value passed to the constructor. However, this value will be in all lower-case, regardless of the original casing passed to the constructor.


Returns the charset for the content type, which will be the value found in the attributes, if one exists.


Returns a hash (not a reference) of the attributes passed to the constructor.

Attributes are Courriel::HeaderAttribute objects.

The keys of the hash are all lower case, though the original casing is preserved in the name() returned by the Courriel::HeaderAttribute object.


Returns true unless the attachment looks like text data. Currently, this means that is has a charset defined and the charset is not "binary".


Given a key, returns the named Courriel::HeaderAttribute object. Obviously, this value can be undef if the attribute doesn't exist. Name lookup is case-insensitive.


Given a key, returns the named attribute's value as a string. Obviously, this value can be undef if the attribute doesn't exist. Name lookup is case-insensitive.

The attribute is a Courriel::HeaderAttribute object.


Returns the object as a string suitable for a header value (but not folded). Note that this uses the original casing of the mime type as passed to the constructor.


This class extends Courriel::Header.


This class does the Courriel::Role::HeaderWithAttributes role.


Bugs may be submitted at

I am also usually active on IRC as 'autarch' on irc://


The source code repository for Courriel can be found at


Dave Rolsky <>


This software is Copyright (c) 2018 by Dave Rolsky.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)

The full text of the license can be found in the LICENSE file included with this distribution.

syntax highlighting: