NAME

Mail::Make::Headers::Subject - RFC 2047 Aware Subject Header for Mail::Make

SYNOPSIS

use Mail::Make::Headers::Subject;

# Pure ASCII: passed through unchanged
my $s = Mail::Make::Headers::Subject->new;
$s->value( 'Quarterly Report' );
print $s->as_string;
# Quarterly Report

# Non-ASCII: automatically encoded per RFC 2047
$s->value( "Yamato, Inc. — Newsletter" );
print $s->as_string;
# =?UTF-8?B?QW5nZWxzLCBJbmMuIOKAlCBOZXdzbGV0dGVy?=

# Long Japanese subject: folded into multiple encoded-words
$s->value( "株式会社ヤマト・インク 第3四半期ニュースレター 2026年3月号" );
print $s->as_string;
# =?UTF-8?B?...?=\r\n =?UTF-8?B?...?=\r\n =?UTF-8?B?...?=

# Round-trip decode
my $decoded = $s->decode( $s->as_string );
# "株式会社ヤマト・インク 第3四半期ニュースレター 2026年3月号"

VERSION

v0.1.1

DESCRIPTION

A typed header object for the Subject field that implements RFC 2047 encoded-word encoding and decoding.

Key properties:

  • Pure printable ASCII subjects are passed through without modification.

    No unnecessary =?UTF-8?B?...?= wrapping.

  • Non-ASCII subjects are encoded as one or more =?UTF-8?B?...?= encoded-words using Base64.

  • Long values are split into chunks of at most 45 UTF-8 bytes each, keeping every encoded-word within the RFC 2047 maximum of 75 characters.

  • Chunks are joined with CRLF SP (header folding), producing a correctly folded multi-line header value.

  • Chunk boundaries are chosen so as never to split a multi-byte UTF-8 sequence.

  • The "decode" method handles both ?B? (Base64) and ?Q? (Quoted-Printable) encoded-words, and collapses inter-word whitespace per RFC 2047 §6.2.

METHODS

new

Instantiates a new object. Optionally accepts a subject string via the value key in a hash argument, consistent with Module::Generic init conventions.

as_string

Returns the encoded form of the subject, suitable for the wire. Pure ASCII values are returned unchanged. Non-ASCII values are encoded in RFC 2047 =?UTF-8?B?...?= form, folded at CRLF SP as required.

This method is also invoked by the "" overload.

decode( $encoded_string )

Class or instance method. Decodes all RFC 2047 encoded-words present in $encoded_string and returns the result as a Perl Unicode string.

field_name

Returns the string Subject.

raw

Returns the stored Perl Unicode string, before any RFC 2047 encoding.

value( [ $text ] )

Sets or gets the subject text as a Perl Unicode string. On assignment, the encoded cache is invalidated so that the next call to "as_string" re-encodes the new value.

STANDARDS

RFC 2047 — MIME Part Three: Message Header Extensions for Non-ASCII Text
RFC 2822 §2.2 — Header Fields

AUTHOR

Jacques Deguest <jack@deguest.jp>

SEE ALSO

Mail::Make, Mail::Make::Headers, Mail::Make::Headers::Generic

COPYRIGHT & LICENSE

Copyright(c) 2026 DEGUEST Pte. Ltd.

All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.