📄 quotedprint.pm
字号:
package MIME::QuotedPrint;# $Id: QuotedPrint.pm,v 3.7 2005/11/29 20:49:46 gisle Exp $use strict;use vars qw(@ISA @EXPORT $VERSION);require Exporter;@ISA = qw(Exporter);@EXPORT = qw(encode_qp decode_qp);$VERSION = "3.07";use MIME::Base64; # will load XS version of {en,de}code_qp()*encode = \&encode_qp;*decode = \&decode_qp;1;__END__=head1 NAMEMIME::QuotedPrint - Encoding and decoding of quoted-printable strings=head1 SYNOPSIS use MIME::QuotedPrint; $encoded = encode_qp($decoded); $decoded = decode_qp($encoded);=head1 DESCRIPTIONThis module provides functions to encode and decode strings into and from thequoted-printable encoding specified in RFC 2045 - I<MIME (MultipurposeInternet Mail Extensions)>. The quoted-printable encoding is intendedto represent data that largely consists of bytes that correspond toprintable characters in the ASCII character set. Each non-printablecharacter (as defined by English Americans) is represented by atriplet consisting of the character "=" followed by two hexadecimaldigits.The following functions are provided:=over 4=item encode_qp($str)=item encode_qp($str, $eol)=item encode_qp($str, $eol, $binmode)This function returns an encoded version of the string ($str) given asargument.The second argument ($eol) is the line-ending sequence to use. It isoptional and defaults to "\n". Every occurrence of "\n" is replacedwith this string, and it is also used for additional "soft linebreaks" to ensure that no line end up longer than 76 characters. Passit as "\015\012" to produce data suitable for external consumption.The string "\r\n" produces the same result on many platforms, but notall.The third argument ($binmode) will select binary mode if passed as aTRUE value. In binary mode "\n" will be encoded in the same way asany other non-printable character. This ensures that a decoder willend up with exactly the same string whatever line ending sequence ituses. In general it is preferable to use the base64 encoding forbinary data; see L<MIME::Base64>.An $eol of "" (the empty string) is special. In this case, no "softline breaks" are introduced and binary mode is effectively enabled sothat any "\n" in the original data is encoded as well.=item decode_qp($str);This function returns the plain text version of the string givenas argument. The lines of the result are "\n" terminated, even ifthe $str argument contains "\r\n" terminated lines.=backIf you prefer not to import these routines into your namespace, you cancall them as: use MIME::QuotedPrint (); $encoded = MIME::QuotedPrint::encode($decoded); $decoded = MIME::QuotedPrint::decode($encoded);Perl v5.8 and better allow extended Unicode characters in strings.Such strings cannot be encoded directly, as the quoted-printableencoding is only defined for single-byte characters. The solution isto use the Encode module to select the byte encoding you want. Forexample: use MIME::QuotedPrint qw(encode_qp); use Encode qw(encode); $encoded = encode_qp(encode("UTF-8", "\x{FFFF}\n")); print $encoded;=head1 COPYRIGHTCopyright 1995-1997,2002-2004 Gisle Aas.This library is free software; you can redistribute it and/ormodify it under the same terms as Perl itself.=head1 SEE ALSOL<MIME::Base64>=cut
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -