mime_recommended_filename( MIME::Head|MIME::Entity )
# mimic our own recommended_filename # since MIME-tools 5.501, head->recommended_filename requires the head are # mime encoded, we don't meet this yet.
CanonicalizeContentType( TYPE )
Parses TYPE and returns it re-serialized in a form with a single possible interpretation, so that matching it against known content types gives the same answer as parsing the Content-Type header built from it.
Returns the empty string unless TYPE holds exactly one content type of the form type/subtype, followed by parameters that all have a value as RFC 2045 section 5.1 requires. Callers are expected to fall back to a type of their own choosing on an empty return.
sanitize_filename( $filename )
Returns a basename safe to use as an attachment filename: directory components (Unix or Windows) are stripped, control bytes are replaced with underscores, surrounding whitespace is trimmed, and pure-dot names (., .., ...) become undef. Returns undef for undefined, empty, or fully-stripped input.
constant_time_eq($a, $b)
Compares two strings for equality in constant-time. Replacement for the eq operator designed to avoid timing side-channel vulnerabilities. Returns zero or one.
This is intended for use in cryptographic subsystems for comparing well-formed data such as hashes - not for direct use with user input or as a general replacement for the eq operator.
The two string arguments MUST be of equal length. If the lengths differ, this function will call die(), as proceeding with execution would create a timing vulnerability. Length is defined by characters, not bytes.
Strings that should be treated as binary octets rather than Unicode text should pass a true value for the binary flag.
This code has been tested to do what it claims. Do not change it without thorough statistical timing analysis to validate the changes.
Added to resolve CVE-2017-5361
For more on timing attacks, see this Wikipedia article: https://en.wikipedia.org/wiki/Timing_attack
random_bytes($count)
Returns $count random octets.
Returns undef, having logged the reason, if the platform cannot supply random data or supplies less than was asked for.
random_hex($count)
Returns a string of $count lowercase hexadecimal digits drawn from "random_bytes", so $count characters carry $count * 4 bits of entropy. Convenient where a random value has to survive as text, in a URL or an ascii database column.
Returns undef under the same conditions as "random_bytes".
EntityLooksLikeEmailMessage( MIME::Entity )
Check MIME type headers for entities that look like email.
EmailContentTypes
Return MIME types that indicate email messages.
RecursiveSub
When you need an anonymous sub that calls itself, you can't just use:
my $sub;
$sub = sub {
my @args = @_;
...
$sub->(@args);
...
};
as that will create a circular reference and leak memory. Instead, you should:
my $sub = RecursiveSub(sub {
my $self_cb = shift;
my @args = @_;
...
$self_cb->(@args);
,,,
});
RecursiveSub will handle weakening the reference to allow the memory to be reclaimed.
InlineCSS CONTENT CSS_INLINER_OPTIONS
For html CONTENT, convert CSS <style> blocks to inline styles.
← Back to index