Courri...entType(3pm)

πŸ’– Courriel::Header::ContentType πŸ’–

okay bestie, welcome to the Courriel::Header::ContentType page from the User Contributed Perl Documentation ✨ (yes the header is all smushed in the terminal, we don't talk about it πŸ’…) β€” it's the content type for an email part, and she's lowkey iconic.


✨ VERSION ✨

version 0.49 β€” she's got a number and she's proud of it πŸŽ€


🌸 SYNOPSIS 🌸

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";
}

see how easy that is?? no cap, that's the whole vibe check right there πŸ¦‹


πŸ’œ DESCRIPTION πŸ’œ

So this class is literally the main character version of a "Content-Type" header that's attached to an email part. Every single one of these headers always has a mime type β€” that part's non-negotiable β€” and then it may also carry extra info like a charset or whatever other attributes it's feeling that day πŸ’…

Here's some typical headers, so you can see the range:

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

Content-Type: multipart/alternative; boundary=abcdefghijk

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

not me getting emotional over multipart/alternative 😭 she's so versatile.


πŸ‘‘ API πŸ‘‘

This class supports the following methods, and honestly? she ate.

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

This one takes two parameters, name and value. The name is optional and defaults to Content-Type (she's flexible like that ✨).

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

πŸ“ Courriel::Header::ContentType->new( ... )

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

  • name β€” defaults to 'Content-Type'.
  • value β€” this is the full header value.
  • mime_type β€” a string like "text/plain" or "multipart/alternative". This one is required, bestie, you cannot skip it.
  • attributes β€” a hash reference of attributes from the header, like a boundary, charset, etc. The keys are attribute names and the values can either be strings or Courriel::HeaderAttribute objects. Any values that are strings get inflated into objects by the constructor. This is optional, and it can be an empty hash reference or omitted entirely.

🌈 $ct->name()

The header name, usually "Content-Type".

⭐ $ct->value()

The raw header value.

πŸ’– $ct->mime_type()

Returns the mime type value that was passed to the constructor. BUT β€” plot twist β€” this value will be in all lower-case, no matter what original casing you handed over to the constructor. she normalizes, she doesn't judge πŸ’…

πŸ¦‹ $ct->charset()

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

πŸŽ€ $ct->attributes()

Returns a hash (not a reference, okay, a hash) 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. so the lowercase is just for the keys, the original vibe is still in there ✨

πŸ’€ $ct->is_binary()

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

πŸ”₯ $ct->attribute($key)

Given a key, returns the named Courriel::HeaderAttribute object. Obviously, this value can be undef if the attribute doesn't exist (no attribute, no object, that's just the rules πŸ™ˆ). Name lookup is case-insensitive.

🫢 $ct->attribute_value($key)

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.

🌸 $ct->as_header_value()

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 β€” so the lowercase glow-up from mime_type() does not apply here, iykyk πŸ’…


πŸ’œ EXTENDS πŸ’œ

This class extends Courriel::Header. family tree moment πŸ‘‘


✨ ROLES ✨

This class does the "Courriel::Role::HeaderWithAttributes" role. she's got range, she's got roles, she's booked and busy πŸŽ€


πŸ¦‹ SUPPORT πŸ¦‹

Bugs may be submitted at <https://github.com/houseabsolute/Courriel/issues>.

I am also usually active on IRC as 'autarch' on "irc://irc.perl.org". come say hi, bestie πŸ’–


🌈 SOURCE 🌈

The source code repository for Courriel can be found at <https://github.com/houseabsolute/Courriel>.


πŸ‘‘ AUTHOR πŸ‘‘

Dave Rolsky <autarch@urth.org> β€” the icon, the legend, the moment ⭐


This software is Copyright (c) 2021 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. read it, bestie, it's giving responsible 🫢


and that's the whole page!! πŸ’– this was Courri...entType(3pm) (yes the terminal clipped her name, she's mysterious like that πŸ’€) from perl v5.32.1, dated 2021-08-22. slay, no cap, go write some email-parsing code βœ¨πŸŽ€πŸ¦‹