tmail_es 1.2.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES +83 -0
  3. data/LICENSE +21 -0
  4. data/NOTES +7 -0
  5. data/README +182 -0
  6. data/Rakefile +2 -0
  7. data/ext/Makefile +20 -0
  8. data/ext/tmailscanner/tmail/MANIFEST +4 -0
  9. data/ext/tmailscanner/tmail/depend +1 -0
  10. data/ext/tmailscanner/tmail/extconf.rb +33 -0
  11. data/ext/tmailscanner/tmail/tmailscanner.c +614 -0
  12. data/lib/tmail/Makefile +18 -0
  13. data/lib/tmail/address.rb +392 -0
  14. data/lib/tmail/attachments.rb +65 -0
  15. data/lib/tmail/base64.rb +46 -0
  16. data/lib/tmail/compat.rb +41 -0
  17. data/lib/tmail/config.rb +67 -0
  18. data/lib/tmail/core_extensions.rb +63 -0
  19. data/lib/tmail/encode.rb +590 -0
  20. data/lib/tmail/header.rb +962 -0
  21. data/lib/tmail/index.rb +9 -0
  22. data/lib/tmail/interface.rb +1162 -0
  23. data/lib/tmail/loader.rb +3 -0
  24. data/lib/tmail/mail.rb +578 -0
  25. data/lib/tmail/mailbox.rb +496 -0
  26. data/lib/tmail/main.rb +6 -0
  27. data/lib/tmail/mbox.rb +3 -0
  28. data/lib/tmail/net.rb +250 -0
  29. data/lib/tmail/obsolete.rb +132 -0
  30. data/lib/tmail/parser.rb +1060 -0
  31. data/lib/tmail/parser.y +416 -0
  32. data/lib/tmail/port.rb +379 -0
  33. data/lib/tmail/quoting.rb +164 -0
  34. data/lib/tmail/require_arch.rb +58 -0
  35. data/lib/tmail/scanner.rb +49 -0
  36. data/lib/tmail/scanner_r.rb +261 -0
  37. data/lib/tmail/stringio.rb +280 -0
  38. data/lib/tmail/utils.rb +361 -0
  39. data/lib/tmail/vendor/rchardet-1.3/COPYING +504 -0
  40. data/lib/tmail/vendor/rchardet-1.3/README +12 -0
  41. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/big5freq.rb +927 -0
  42. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/big5prober.rb +42 -0
  43. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/chardistribution.rb +238 -0
  44. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/charsetgroupprober.rb +112 -0
  45. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/charsetprober.rb +75 -0
  46. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/codingstatemachine.rb +64 -0
  47. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/constants.rb +42 -0
  48. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/escprober.rb +89 -0
  49. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/escsm.rb +244 -0
  50. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/eucjpprober.rb +88 -0
  51. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/euckrfreq.rb +596 -0
  52. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/euckrprober.rb +42 -0
  53. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/euctwfreq.rb +430 -0
  54. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/euctwprober.rb +42 -0
  55. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/gb2312freq.rb +474 -0
  56. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/gb2312prober.rb +42 -0
  57. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/hebrewprober.rb +289 -0
  58. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/jisfreq.rb +570 -0
  59. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/jpcntx.rb +229 -0
  60. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/langbulgarianmodel.rb +229 -0
  61. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/langcyrillicmodel.rb +330 -0
  62. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/langgreekmodel.rb +227 -0
  63. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/langhebrewmodel.rb +202 -0
  64. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/langhungarianmodel.rb +226 -0
  65. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/langthaimodel.rb +201 -0
  66. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/latin1prober.rb +147 -0
  67. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/mbcharsetprober.rb +89 -0
  68. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/mbcsgroupprober.rb +45 -0
  69. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/mbcssm.rb +542 -0
  70. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/sbcharsetprober.rb +124 -0
  71. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/sbcsgroupprober.rb +56 -0
  72. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/sjisprober.rb +88 -0
  73. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/universaldetector.rb +167 -0
  74. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet/utf8prober.rb +87 -0
  75. data/lib/tmail/vendor/rchardet-1.3/lib/rchardet.rb +67 -0
  76. data/lib/tmail/version.rb +40 -0
  77. data/lib/tmail.rb +6 -0
  78. data/setup.rb +1482 -0
  79. data/test/extctrl.rb +6 -0
  80. data/test/fixtures/apple_unquoted_content_type +44 -0
  81. data/test/fixtures/inline_attachment.txt +2095 -0
  82. data/test/fixtures/iso_8859_1_email_without_encoding_and_message_id.txt +16 -0
  83. data/test/fixtures/mailbox +414 -0
  84. data/test/fixtures/mailbox.zip +0 -0
  85. data/test/fixtures/mailbox_without_any_from_or_sender +10 -0
  86. data/test/fixtures/mailbox_without_from +11 -0
  87. data/test/fixtures/mailbox_without_return_path +12 -0
  88. data/test/fixtures/marked_as_iso_8859_1_but_it_is_utf_8.txt +33 -0
  89. data/test/fixtures/marked_as_utf_8_but_it_is_iso_8859_1.txt +56 -0
  90. data/test/fixtures/raw_attack_email_with_zero_length_whitespace +29 -0
  91. data/test/fixtures/raw_base64_decoded_string +0 -0
  92. data/test/fixtures/raw_base64_email +83 -0
  93. data/test/fixtures/raw_base64_encoded_string +1 -0
  94. data/test/fixtures/raw_email +14 -0
  95. data/test/fixtures/raw_email10 +20 -0
  96. data/test/fixtures/raw_email11 +34 -0
  97. data/test/fixtures/raw_email12 +32 -0
  98. data/test/fixtures/raw_email13 +29 -0
  99. data/test/fixtures/raw_email2 +114 -0
  100. data/test/fixtures/raw_email3 +70 -0
  101. data/test/fixtures/raw_email4 +59 -0
  102. data/test/fixtures/raw_email5 +19 -0
  103. data/test/fixtures/raw_email6 +20 -0
  104. data/test/fixtures/raw_email7 +66 -0
  105. data/test/fixtures/raw_email8 +47 -0
  106. data/test/fixtures/raw_email9 +28 -0
  107. data/test/fixtures/raw_email_bad_time +62 -0
  108. data/test/fixtures/raw_email_double_at_in_header +14 -0
  109. data/test/fixtures/raw_email_multiple_from +30 -0
  110. data/test/fixtures/raw_email_only_attachment +17 -0
  111. data/test/fixtures/raw_email_quoted_with_0d0a +14 -0
  112. data/test/fixtures/raw_email_reply +32 -0
  113. data/test/fixtures/raw_email_simple +11 -0
  114. data/test/fixtures/raw_email_string_in_date_field +17 -0
  115. data/test/fixtures/raw_email_trailing_dot +21 -0
  116. data/test/fixtures/raw_email_with_bad_date +48 -0
  117. data/test/fixtures/raw_email_with_illegal_boundary +58 -0
  118. data/test/fixtures/raw_email_with_mimepart_without_content_type +94 -0
  119. data/test/fixtures/raw_email_with_multipart_mixed_quoted_boundary +50 -0
  120. data/test/fixtures/raw_email_with_nested_attachment +100 -0
  121. data/test/fixtures/raw_email_with_partially_quoted_subject +14 -0
  122. data/test/fixtures/raw_email_with_quoted_attachment_filename +60 -0
  123. data/test/fixtures/raw_email_with_quoted_illegal_boundary +58 -0
  124. data/test/fixtures/raw_email_with_wrong_splitted_multibyte_encoded_word_subject +15 -0
  125. data/test/fixtures/the_only_part_is_a_word_document.txt +425 -0
  126. data/test/fixtures/unquoted_filename_in_attachment +177 -0
  127. data/test/kcode.rb +14 -0
  128. data/test/temp_test_one.rb +46 -0
  129. data/test/test_address.rb +1216 -0
  130. data/test/test_attachments.rb +133 -0
  131. data/test/test_base64.rb +64 -0
  132. data/test/test_encode.rb +139 -0
  133. data/test/test_header.rb +1021 -0
  134. data/test/test_helper.rb +9 -0
  135. data/test/test_mail.rb +756 -0
  136. data/test/test_mbox.rb +184 -0
  137. data/test/test_port.rb +440 -0
  138. data/test/test_quote.rb +107 -0
  139. data/test/test_scanner.rb +209 -0
  140. data/test/test_utils.rb +36 -0
  141. data/tmail_es.gemspec +35 -0
  142. metadata +257 -0
data/lib/tmail/net.rb ADDED
@@ -0,0 +1,250 @@
1
+ #--
2
+ # Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net>
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #
23
+ # Note: Originally licensed under LGPL v2+. Using MIT license for Rails
24
+ # with permission of Minero Aoki.
25
+ #++
26
+
27
+ #:stopdoc:
28
+ require 'nkf'
29
+ #:startdoc:
30
+
31
+ module TMail
32
+
33
+ class Mail
34
+
35
+ def send_to( smtp )
36
+ do_send_to(smtp) do
37
+ ready_to_send
38
+ end
39
+ end
40
+
41
+ def send_text_to( smtp )
42
+ do_send_to(smtp) do
43
+ ready_to_send
44
+ mime_encode
45
+ end
46
+ end
47
+
48
+ def do_send_to( smtp )
49
+ from = from_address or raise ArgumentError, 'no from address'
50
+ (dests = destinations).empty? and raise ArgumentError, 'no receipient'
51
+ yield
52
+ send_to_0 smtp, from, dests
53
+ end
54
+ private :do_send_to
55
+
56
+ def send_to_0( smtp, from, to )
57
+ smtp.ready(from, to) do |f|
58
+ encoded "\r\n", 'j', f, ''
59
+ end
60
+ end
61
+
62
+ def ready_to_send
63
+ delete_no_send_fields
64
+ add_message_id
65
+ add_date
66
+ end
67
+
68
+ NOSEND_FIELDS = %w(
69
+ received
70
+ bcc
71
+ )
72
+
73
+ def delete_no_send_fields
74
+ NOSEND_FIELDS.each do |nm|
75
+ delete nm
76
+ end
77
+ delete_if {|n,v| v.empty? }
78
+ end
79
+
80
+ def add_message_id( fqdn = nil )
81
+ unless @message_id_enforced
82
+ self.message_id = ::TMail::new_message_id(fqdn)
83
+ end
84
+ end
85
+
86
+ def add_date
87
+ self.date = Time.now
88
+ end
89
+
90
+ def mime_encode
91
+ if parts.empty?
92
+ mime_encode_singlepart
93
+ else
94
+ mime_encode_multipart true
95
+ end
96
+ end
97
+
98
+ def mime_encode_singlepart
99
+ self.mime_version = '1.0'
100
+ b = body
101
+ if NKF.guess(b) != NKF::BINARY
102
+ mime_encode_text b
103
+ else
104
+ mime_encode_binary b
105
+ end
106
+ end
107
+
108
+ def mime_encode_text( body )
109
+ self.body = NKF.nkf('-j -m0', body)
110
+ self.set_content_type 'text', 'plain', {'charset' => 'iso-2022-jp'}
111
+ self.encoding = '7bit'
112
+ end
113
+
114
+ def mime_encode_binary( body )
115
+ self.body = [body].pack('m')
116
+ self.set_content_type 'application', 'octet-stream'
117
+ self.encoding = 'Base64'
118
+ end
119
+
120
+ def mime_encode_multipart( top = true )
121
+ self.mime_version = '1.0' if top
122
+ self.set_content_type 'multipart', 'mixed'
123
+ e = encoding(nil)
124
+ if e and not /\A(?:7bit|8bit|binary)\z/i === e
125
+ raise ArgumentError,
126
+ 'using C.T.Encoding with multipart mail is not permitted'
127
+ end
128
+ end
129
+
130
+ end
131
+
132
+ #:stopdoc:
133
+ class DeleteFields
134
+
135
+ NOSEND_FIELDS = %w(
136
+ received
137
+ bcc
138
+ )
139
+
140
+ def initialize( nosend = nil, delempty = true )
141
+ @no_send_fields = nosend || NOSEND_FIELDS.dup
142
+ @delete_empty_fields = delempty
143
+ end
144
+
145
+ attr :no_send_fields
146
+ attr :delete_empty_fields, true
147
+
148
+ def exec( mail )
149
+ @no_send_fields.each do |nm|
150
+ delete nm
151
+ end
152
+ delete_if {|n,v| v.empty? } if @delete_empty_fields
153
+ end
154
+
155
+ end
156
+ #:startdoc:
157
+
158
+ #:stopdoc:
159
+ class AddMessageId
160
+
161
+ def initialize( fqdn = nil )
162
+ @fqdn = fqdn
163
+ end
164
+
165
+ attr :fqdn, true
166
+
167
+ def exec( mail )
168
+ mail.message_id = ::TMail::new_msgid(@fqdn)
169
+ end
170
+
171
+ end
172
+ #:startdoc:
173
+
174
+ #:stopdoc:
175
+ class AddDate
176
+
177
+ def exec( mail )
178
+ mail.date = Time.now
179
+ end
180
+
181
+ end
182
+ #:startdoc:
183
+
184
+ #:stopdoc:
185
+ class MimeEncodeAuto
186
+
187
+ def initialize( s = nil, m = nil )
188
+ @singlepart_composer = s || MimeEncodeSingle.new
189
+ @multipart_composer = m || MimeEncodeMulti.new
190
+ end
191
+
192
+ attr :singlepart_composer
193
+ attr :multipart_composer
194
+
195
+ def exec( mail )
196
+ if mail._builtin_multipart?
197
+ then @multipart_composer
198
+ else @singlepart_composer end.exec mail
199
+ end
200
+
201
+ end
202
+ #:startdoc:
203
+
204
+ #:stopdoc:
205
+ class MimeEncodeSingle
206
+
207
+ def exec( mail )
208
+ mail.mime_version = '1.0'
209
+ b = mail.body
210
+ if NKF.guess(b) != NKF::BINARY
211
+ on_text b
212
+ else
213
+ on_binary b
214
+ end
215
+ end
216
+
217
+ def on_text( body )
218
+ mail.body = NKF.nkf('-j -m0', body)
219
+ mail.set_content_type 'text', 'plain', {'charset' => 'iso-2022-jp'}
220
+ mail.encoding = '7bit'
221
+ end
222
+
223
+ def on_binary( body )
224
+ mail.body = [body].pack('m')
225
+ mail.set_content_type 'application', 'octet-stream'
226
+ mail.encoding = 'Base64'
227
+ end
228
+
229
+ end
230
+ #:startdoc:
231
+
232
+ #:stopdoc:
233
+ class MimeEncodeMulti
234
+
235
+ def exec( mail, top = true )
236
+ mail.mime_version = '1.0' if top
237
+ mail.set_content_type 'multipart', 'mixed'
238
+ e = encoding(nil)
239
+ if e and not /\A(?:7bit|8bit|binary)\z/i === e
240
+ raise ArgumentError,
241
+ 'using C.T.Encoding with multipart mail is not permitted'
242
+ end
243
+ mail.parts.each do |m|
244
+ exec m, false if m._builtin_multipart?
245
+ end
246
+ end
247
+
248
+ end
249
+ #:startdoc:
250
+ end # module TMail
@@ -0,0 +1,132 @@
1
+ =begin rdoc
2
+
3
+ = Obsolete methods that are depriciated
4
+
5
+ If you really want to see them, go to lib/tmail/obsolete.rb and view to your
6
+ heart's content.
7
+
8
+ =end
9
+ #--
10
+ # Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net>
11
+ #
12
+ # Permission is hereby granted, free of charge, to any person obtaining
13
+ # a copy of this software and associated documentation files (the
14
+ # "Software"), to deal in the Software without restriction, including
15
+ # without limitation the rights to use, copy, modify, merge, publish,
16
+ # distribute, sublicense, and/or sell copies of the Software, and to
17
+ # permit persons to whom the Software is furnished to do so, subject to
18
+ # the following conditions:
19
+ #
20
+ # The above copyright notice and this permission notice shall be
21
+ # included in all copies or substantial portions of the Software.
22
+ #
23
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
+ #
31
+ # Note: Originally licensed under LGPL v2+. Using MIT license for Rails
32
+ # with permission of Minero Aoki.
33
+ #++
34
+ #:stopdoc:
35
+ module TMail #:nodoc:
36
+
37
+ class Mail
38
+ alias include? key?
39
+ alias has_key? key?
40
+
41
+ def values
42
+ ret = []
43
+ each_field {|v| ret.push v }
44
+ ret
45
+ end
46
+
47
+ def value?( val )
48
+ HeaderField === val or return false
49
+
50
+ [ @header[val.name.downcase] ].flatten.include? val
51
+ end
52
+
53
+ alias has_value? value?
54
+ end
55
+
56
+ class Mail
57
+ def from_addr( default = nil )
58
+ addr, = from_addrs(nil)
59
+ addr || default
60
+ end
61
+
62
+ def from_address( default = nil )
63
+ if a = from_addr(nil)
64
+ a.spec
65
+ else
66
+ default
67
+ end
68
+ end
69
+
70
+ alias from_address= from_addrs=
71
+
72
+ def from_phrase( default = nil )
73
+ if a = from_addr(nil)
74
+ a.phrase
75
+ else
76
+ default
77
+ end
78
+ end
79
+
80
+ alias msgid message_id
81
+ alias msgid= message_id=
82
+
83
+ alias each_dest each_destination
84
+ end
85
+
86
+ class Address
87
+ alias route routes
88
+ alias addr spec
89
+
90
+ def spec=( str )
91
+ @local, @domain = str.split(/@/,2).map {|s| s.split(/\./) }
92
+ end
93
+
94
+ alias addr= spec=
95
+ alias address= spec=
96
+ end
97
+
98
+ class MhMailbox
99
+ alias new_mail new_port
100
+ alias each_mail each_port
101
+ alias each_newmail each_new_port
102
+ end
103
+ class UNIXMbox
104
+ alias new_mail new_port
105
+ alias each_mail each_port
106
+ alias each_newmail each_new_port
107
+ end
108
+ class Maildir
109
+ alias new_mail new_port
110
+ alias each_mail each_port
111
+ alias each_newmail each_new_port
112
+ end
113
+
114
+ extend TextUtils
115
+
116
+ class << self
117
+ alias msgid? message_id?
118
+ alias boundary new_boundary
119
+ alias msgid new_message_id
120
+ alias new_msgid new_message_id
121
+ end
122
+
123
+ def Mail.boundary
124
+ ::TMail.new_boundary
125
+ end
126
+
127
+ def Mail.msgid
128
+ ::TMail.new_message_id
129
+ end
130
+
131
+ end # module TMail
132
+ #:startdoc: