File: EcoEncode.pod

package info (click to toggle)
libmime-ecoencode-perl 0.95-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 184 kB
  • sloc: perl: 2,122; makefile: 2; sh: 1
file content (143 lines) | stat: -rw-r--r-- 4,321 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
=head1 NAME

MIME::EcoEncode - MIME Encoding (Economical)

=head1 SYNOPSIS

 use MIME::EcoEncode;
 $encoded = mime_eco($str, 'UTF-8');        # encode utf8 string
 $encoded = mime_eco($str, 'UTF-8?B');      # ditto ("B" encoding)
 $encoded = mime_eco($str, 'UTF-8?Q');      # ditto ("Q" encoding)
 $encoded = mime_eco($str, 'UTF-8*XX');     # XX is RFC2231's language
 $encoded = mime_eco($str, 'UTF-8*XX?B');   # ditto ("B" encoding)
 $encoded = mime_eco($str, 'UTF-8*XX?Q');   # ditto ("Q" encoding)
 $encoded = mime_eco($str, 'GB2312');       # encode euc-cn string
 $encoded = mime_eco($str, 'EUC-KR');       # encode euc-kr string
 $encoded = mime_eco($str, 'Big5');         # encode big5 string
 $encoded = mime_eco($str, 'Shift_JIS');    # encode cp932 string
 $encoded = mime_eco($str, 'ISO-2022-JP');  # encode 7bit-jis string
 $encoded = mime_eco($str, $sbcs);          # $sbcs :
                                            #   single-byte charset
                                            #     (e.g. 'ISO-8859-1')

 $decoded = mime_deco($encoded);            # decode encoded string
                                            #   (for single charset)

 ($decoded, $charset, $language)            # return array
          = mime_deco($encoded);            #   (for single charset)

 use Encode;
 $decoded = mime_deco($encoded, \&cb);      # cb is callback subroutine
                                            #   (for multiple charsets)

 # Example of callback subroutine
 sub cb {
   my ($encoded_word, $charset, $language, $decoded_word) = @_;
   encode_utf8(decode($charset, $decoded_word));
 }

=head1 DESCRIPTION

This module implements RFC 2047 Mime Header Encoding.

=head2 Options

  $encoded = mime_eco($str, $charset, $lf, $bpl, $mode, $lss);
               # $charset : 'UTF-8' / 'UTF-8?Q' / 'UTF-8*XX' /
               #            'GB2312' / 'EUC-KR' / 'Big5' /
               #            'Shift_JIS' / 'ISO-2022-JP' / ...
               #            (default: 'UTF-8')
               #              Note: "B" encoding is all defaults.
               #                    The others are all encoded as
               #                    single-byte string.
               # $lf      : line feed (default: "\n")
               # $bpl     : bytes per line (default: 76)
               # $mode    : 0 : unstructured header (e.g. Subject)
               #            1 : structured header (e.g. To, Cc, From)
               #            2 : auto (Subject or Comments ? 0 : 1)
               #            (default: 2)
               # $lss     : length of security space (default: 25)

=head2 Examples

Ex1 - normal (structured header)

  use MIME::EcoEncode;
  my $str = "From: Sakura <sakura\@example.jp> (\xe6\xa1\x9c)\n";
  print mime_eco($str);

Ex1's output:

  From: Sakura <sakura@example.jp> (=?UTF-8?B?5qGc?=)

Ex2 - "Q" encoding + RFC2231's language

  use MIME::EcoEncode;
  my $str = "From: Sakura <sakura\@example.jp> (\xe6\xa1\x9c)\n";
  print mime_eco($str, 'UTF-8*ja-JP?Q');

Ex2's output:

  From: Sakura <sakura@example.jp> (=?UTF-8*ja-JP?Q?=E6=A1=9C?=)

Ex3 - continuous spaces

  use MIME::EcoEncode;
  my $str = "From: Sakura  <sakura\@example.jp>    (\xe6\xa1\x9c)\n";
  print mime_eco($str);

Ex3's output:

  From: Sakura  <sakura@example.jp>    (=?UTF-8?B?5qGc?=)

Ex4 - unstructured header (1)

  use MIME::EcoEncode;
  my $str = "Subject: Sakura (\xe6\xa1\x9c)\n";
  print mime_eco($str);

Ex4's output:

  Subject: Sakura =?UTF-8?B?KOahnCk=?=

Ex5 - unstructured header (2)

  use MIME::EcoEncode;
  my $str = "Subject: \xe6\xa1\x9c  Sakura\n";
  print mime_eco($str);

Ex5's output:

  Subject: =?UTF-8?B?5qGc?=  Sakura

Ex6 - 7bit-jis string

  use Encode;
  use MIME::EcoEncode;
  my $str = "Subject: \xe6\xa1\x9c  Sakura\n";
  print mime_eco(encode('7bit-jis', decode_utf8($str)), 'ISO-2022-JP');

Ex6's output:

  Subject: =?ISO-2022-JP?B?GyRCOnkbKEI=?=  Sakura

=head1 SEE ALSO

L<MIME::EcoEncode::Param>, L<MIME::EcoEncode::Fold>

For more information, please visit F<http://www.nips.ac.jp/~murata/mimeeco/>

=head1 AUTHOR

MURATA Yasuhisa E<lt>murata@nips.ac.jpE<gt>

=head1 COPYRIGHT

Copyright (C) 2011-2013 MURATA Yasuhisa

=head1 LICENSE

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

=cut