NAME

Mail::DKIM2::Fold - Fold a DKIM2 header field where its grammar allows

SYNOPSIS

use Mail::DKIM2::Fold qw(fold_header);

my $field = fold_header("DKIM2-Signature: i=1; m=1; ...");

DESCRIPTION

Only for a header this code is creating. A header read from anywhere else is never refolded: a fold where there was no whitespace changes its canonical form and breaks every signature over it. "as_header()" in Mail::DKIM2::MessageInstance and "as_folded_string()" in Mail::DKIM2::Signature call this for you. Nothing is exported by default; Mail::DKIM2::Common exports fold_header too, as it did before it moved here in 0.31.

See "CONVENTIONS" in Mail::DKIM2 for the conventions every module follows.

FUNCTIONS

fold_header($line, [$margin], %opts)

Folds a complete header line at $margin characters (default 72) with CRLF-tab continuations, breaking at ; first, then at a space, then where a DKIM2 field's grammar allows folding whitespace: inside a base64 value (mf=, rt=, r=, an h= digest, an s= signature value), beside the :s of an s= or h= item, or after a list comma other than in s=. It never splits a domain, selector, algorithm or hash name: such a token that will not fit stays whole on a longer line, and a line that would exceed RFC 5322's 998 characters croaks. With delimiters_only => 1 it breaks only after ; or ,, never inside a token, leaving a value that fits nowhere whole on an over-long line (the rule for X-DKIM2-Info).

AUTHOR

Bron Gondwana <brong@fastmailteam.com>

COPYRIGHT AND LICENSE

Copyright (c) 2025-2026 Fastmail Pty Ltd. This is free software; you can redistribute it and/or modify it under the same terms as Perl itself.