Vetinari's $HOME


Qpsmtpd::ContentType - parse and access the contents of the Content-Type header


This plugin parses the contents of the given Content-Type: header according to RFC 1521 ``MIME (Multipurpose Internet Mail Extensions) Part One: Mechanisms for Specifying and Describing the Format of Internet Message Bodies''


 sub hook_data_post {
    my ($self,$transaction) = @_;
    my $ct = $transaction->notes('Content-Type');
    unless ($ct) {
         my $ct_head = $transaction->header->get('Content-Type');
         $ct         = Qpsmtpd::ContentType->parse($ct_head);
         $transaction->notes('Content-Type', $ct);
    if ($ct->type eq 'text') {
        return (DENY, "HTML only mails not accepted here")
          if ($ct->subtype eq 'html');
        [... do something else ... ]
    return (DECLINED);


parse( $value_of_Content_Type_header )

Parses the contents of the Content-Type: header and returns an object where the fields can be accessed.

illegal( )

True, if an error occured.

error( )

The error message if illegal() returned true.

type( )

The main type of the MIME-Type, e.g. text for a text/plain type.

subtype( )

The subtype if the MIME-Type, e.g. plain for a text/plain type.

param(NAME [,VALUE])

Returns the value of the parameter NAME or undef() if not present in the Content-Type header. If a VALUE is given, it sets the parameter NAME to VALUE, useful with format().

format( )

Returns a string, which may be used to replace the current Content-Type header

  $transaction->header->replace("Content-Type", $ct->format);