rack-mail_exception 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (321) hide show
  1. data/.document +5 -0
  2. data/.gitignore +22 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +38 -0
  5. data/Rakefile +56 -0
  6. data/VERSION +1 -0
  7. data/lib/rack/mail_exception.rb +103 -0
  8. data/test/helper.rb +13 -0
  9. data/test/test_rack_mail_exception.rb +93 -0
  10. data/vendor/mail/.bundle/config +2 -0
  11. data/vendor/mail/CHANGELOG.rdoc +370 -0
  12. data/vendor/mail/Dependencies.txt +3 -0
  13. data/vendor/mail/Gemfile +17 -0
  14. data/vendor/mail/README.rdoc +572 -0
  15. data/vendor/mail/ROADMAP +92 -0
  16. data/vendor/mail/Rakefile +41 -0
  17. data/vendor/mail/TODO.rdoc +9 -0
  18. data/vendor/mail/lib/mail.rb +76 -0
  19. data/vendor/mail/lib/mail/attachments_list.rb +99 -0
  20. data/vendor/mail/lib/mail/body.rb +287 -0
  21. data/vendor/mail/lib/mail/configuration.rb +67 -0
  22. data/vendor/mail/lib/mail/core_extensions/blank.rb +26 -0
  23. data/vendor/mail/lib/mail/core_extensions/nil.rb +11 -0
  24. data/vendor/mail/lib/mail/core_extensions/string.rb +27 -0
  25. data/vendor/mail/lib/mail/elements.rb +14 -0
  26. data/vendor/mail/lib/mail/elements/address.rb +306 -0
  27. data/vendor/mail/lib/mail/elements/address_list.rb +74 -0
  28. data/vendor/mail/lib/mail/elements/content_disposition_element.rb +30 -0
  29. data/vendor/mail/lib/mail/elements/content_location_element.rb +25 -0
  30. data/vendor/mail/lib/mail/elements/content_transfer_encoding_element.rb +24 -0
  31. data/vendor/mail/lib/mail/elements/content_type_element.rb +35 -0
  32. data/vendor/mail/lib/mail/elements/date_time_element.rb +26 -0
  33. data/vendor/mail/lib/mail/elements/envelope_from_element.rb +34 -0
  34. data/vendor/mail/lib/mail/elements/message_ids_element.rb +29 -0
  35. data/vendor/mail/lib/mail/elements/mime_version_element.rb +26 -0
  36. data/vendor/mail/lib/mail/elements/phrase_list.rb +21 -0
  37. data/vendor/mail/lib/mail/elements/received_element.rb +30 -0
  38. data/vendor/mail/lib/mail/encodings.rb +258 -0
  39. data/vendor/mail/lib/mail/encodings/7bit.rb +31 -0
  40. data/vendor/mail/lib/mail/encodings/8bit.rb +31 -0
  41. data/vendor/mail/lib/mail/encodings/base64.rb +33 -0
  42. data/vendor/mail/lib/mail/encodings/binary.rb +31 -0
  43. data/vendor/mail/lib/mail/encodings/quoted_printable.rb +38 -0
  44. data/vendor/mail/lib/mail/encodings/transfer_encoding.rb +58 -0
  45. data/vendor/mail/lib/mail/envelope.rb +35 -0
  46. data/vendor/mail/lib/mail/field.rb +223 -0
  47. data/vendor/mail/lib/mail/field_list.rb +33 -0
  48. data/vendor/mail/lib/mail/fields.rb +35 -0
  49. data/vendor/mail/lib/mail/fields/bcc_field.rb +56 -0
  50. data/vendor/mail/lib/mail/fields/cc_field.rb +55 -0
  51. data/vendor/mail/lib/mail/fields/comments_field.rb +41 -0
  52. data/vendor/mail/lib/mail/fields/common/address_container.rb +16 -0
  53. data/vendor/mail/lib/mail/fields/common/common_address.rb +125 -0
  54. data/vendor/mail/lib/mail/fields/common/common_date.rb +42 -0
  55. data/vendor/mail/lib/mail/fields/common/common_field.rb +50 -0
  56. data/vendor/mail/lib/mail/fields/common/common_message_id.rb +43 -0
  57. data/vendor/mail/lib/mail/fields/common/parameter_hash.rb +52 -0
  58. data/vendor/mail/lib/mail/fields/content_description_field.rb +19 -0
  59. data/vendor/mail/lib/mail/fields/content_disposition_field.rb +69 -0
  60. data/vendor/mail/lib/mail/fields/content_id_field.rb +63 -0
  61. data/vendor/mail/lib/mail/fields/content_location_field.rb +42 -0
  62. data/vendor/mail/lib/mail/fields/content_transfer_encoding_field.rb +50 -0
  63. data/vendor/mail/lib/mail/fields/content_type_field.rb +185 -0
  64. data/vendor/mail/lib/mail/fields/date_field.rb +55 -0
  65. data/vendor/mail/lib/mail/fields/from_field.rb +55 -0
  66. data/vendor/mail/lib/mail/fields/in_reply_to_field.rb +55 -0
  67. data/vendor/mail/lib/mail/fields/keywords_field.rb +44 -0
  68. data/vendor/mail/lib/mail/fields/message_id_field.rb +83 -0
  69. data/vendor/mail/lib/mail/fields/mime_version_field.rb +53 -0
  70. data/vendor/mail/lib/mail/fields/optional_field.rb +13 -0
  71. data/vendor/mail/lib/mail/fields/received_field.rb +67 -0
  72. data/vendor/mail/lib/mail/fields/references_field.rb +55 -0
  73. data/vendor/mail/lib/mail/fields/reply_to_field.rb +55 -0
  74. data/vendor/mail/lib/mail/fields/resent_bcc_field.rb +55 -0
  75. data/vendor/mail/lib/mail/fields/resent_cc_field.rb +55 -0
  76. data/vendor/mail/lib/mail/fields/resent_date_field.rb +35 -0
  77. data/vendor/mail/lib/mail/fields/resent_from_field.rb +55 -0
  78. data/vendor/mail/lib/mail/fields/resent_message_id_field.rb +34 -0
  79. data/vendor/mail/lib/mail/fields/resent_sender_field.rb +62 -0
  80. data/vendor/mail/lib/mail/fields/resent_to_field.rb +55 -0
  81. data/vendor/mail/lib/mail/fields/return_path_field.rb +64 -0
  82. data/vendor/mail/lib/mail/fields/sender_field.rb +67 -0
  83. data/vendor/mail/lib/mail/fields/structured_field.rb +51 -0
  84. data/vendor/mail/lib/mail/fields/subject_field.rb +16 -0
  85. data/vendor/mail/lib/mail/fields/to_field.rb +55 -0
  86. data/vendor/mail/lib/mail/fields/unstructured_field.rb +166 -0
  87. data/vendor/mail/lib/mail/header.rb +262 -0
  88. data/vendor/mail/lib/mail/mail.rb +234 -0
  89. data/vendor/mail/lib/mail/message.rb +1867 -0
  90. data/vendor/mail/lib/mail/network.rb +9 -0
  91. data/vendor/mail/lib/mail/network/delivery_methods/file_delivery.rb +40 -0
  92. data/vendor/mail/lib/mail/network/delivery_methods/sendmail.rb +62 -0
  93. data/vendor/mail/lib/mail/network/delivery_methods/smtp.rb +110 -0
  94. data/vendor/mail/lib/mail/network/delivery_methods/test_mailer.rb +40 -0
  95. data/vendor/mail/lib/mail/network/retriever_methods/imap.rb +18 -0
  96. data/vendor/mail/lib/mail/network/retriever_methods/pop3.rb +149 -0
  97. data/vendor/mail/lib/mail/parsers/address_lists.rb +64 -0
  98. data/vendor/mail/lib/mail/parsers/address_lists.treetop +19 -0
  99. data/vendor/mail/lib/mail/parsers/content_disposition.rb +387 -0
  100. data/vendor/mail/lib/mail/parsers/content_disposition.treetop +46 -0
  101. data/vendor/mail/lib/mail/parsers/content_location.rb +139 -0
  102. data/vendor/mail/lib/mail/parsers/content_location.treetop +20 -0
  103. data/vendor/mail/lib/mail/parsers/content_transfer_encoding.rb +162 -0
  104. data/vendor/mail/lib/mail/parsers/content_transfer_encoding.treetop +20 -0
  105. data/vendor/mail/lib/mail/parsers/content_type.rb +539 -0
  106. data/vendor/mail/lib/mail/parsers/content_type.treetop +58 -0
  107. data/vendor/mail/lib/mail/parsers/date_time.rb +114 -0
  108. data/vendor/mail/lib/mail/parsers/date_time.treetop +11 -0
  109. data/vendor/mail/lib/mail/parsers/envelope_from.rb +194 -0
  110. data/vendor/mail/lib/mail/parsers/envelope_from.treetop +32 -0
  111. data/vendor/mail/lib/mail/parsers/message_ids.rb +45 -0
  112. data/vendor/mail/lib/mail/parsers/message_ids.treetop +15 -0
  113. data/vendor/mail/lib/mail/parsers/mime_version.rb +144 -0
  114. data/vendor/mail/lib/mail/parsers/mime_version.treetop +19 -0
  115. data/vendor/mail/lib/mail/parsers/phrase_lists.rb +45 -0
  116. data/vendor/mail/lib/mail/parsers/phrase_lists.treetop +15 -0
  117. data/vendor/mail/lib/mail/parsers/received.rb +71 -0
  118. data/vendor/mail/lib/mail/parsers/received.treetop +11 -0
  119. data/vendor/mail/lib/mail/parsers/rfc2045.rb +464 -0
  120. data/vendor/mail/lib/mail/parsers/rfc2045.treetop +36 -0
  121. data/vendor/mail/lib/mail/parsers/rfc2822.rb +5318 -0
  122. data/vendor/mail/lib/mail/parsers/rfc2822.treetop +410 -0
  123. data/vendor/mail/lib/mail/parsers/rfc2822_obsolete.rb +3757 -0
  124. data/vendor/mail/lib/mail/parsers/rfc2822_obsolete.treetop +241 -0
  125. data/vendor/mail/lib/mail/part.rb +102 -0
  126. data/vendor/mail/lib/mail/parts_list.rb +34 -0
  127. data/vendor/mail/lib/mail/patterns.rb +30 -0
  128. data/vendor/mail/lib/mail/utilities.rb +181 -0
  129. data/vendor/mail/lib/mail/version.rb +10 -0
  130. data/vendor/mail/lib/mail/version_specific/ruby_1_8.rb +97 -0
  131. data/vendor/mail/lib/mail/version_specific/ruby_1_9.rb +87 -0
  132. data/vendor/mail/lib/tasks/corpus.rake +125 -0
  133. data/vendor/mail/lib/tasks/treetop.rake +10 -0
  134. data/vendor/mail/mail.gemspec +20 -0
  135. data/vendor/mail/reference/US ASCII Table.txt +130 -0
  136. data/vendor/mail/reference/rfc1035 Domain Implementation and Specification.txt +3083 -0
  137. data/vendor/mail/reference/rfc1049 Content-Type Header Field for Internet Messages.txt +451 -0
  138. data/vendor/mail/reference/rfc1344 Implications of MIME for Internet Mail Gateways.txt +586 -0
  139. data/vendor/mail/reference/rfc1345 Character Mnemonics & Character Sets.txt +5761 -0
  140. data/vendor/mail/reference/rfc1524 A User Agent Configuration Mechanism For Multimedia Mail Format Information.txt +675 -0
  141. data/vendor/mail/reference/rfc1652 SMTP Service Extension for 8bit-MIMEtransport.txt +339 -0
  142. data/vendor/mail/reference/rfc1892 Multipart Report .txt +227 -0
  143. data/vendor/mail/reference/rfc1893 Mail System Status Codes.txt +843 -0
  144. data/vendor/mail/reference/rfc2045 Multipurpose Internet Mail Extensions (1).txt +1739 -0
  145. data/vendor/mail/reference/rfc2046 Multipurpose Internet Mail Extensions (2).txt +2467 -0
  146. data/vendor/mail/reference/rfc2047 Multipurpose Internet Mail Extensions (3).txt +843 -0
  147. data/vendor/mail/reference/rfc2048 Multipurpose Internet Mail Extensions (4).txt +1180 -0
  148. data/vendor/mail/reference/rfc2049 Multipurpose Internet Mail Extensions (5).txt +1347 -0
  149. data/vendor/mail/reference/rfc2111 Content-ID and Message-ID URLs.txt +283 -0
  150. data/vendor/mail/reference/rfc2183 Content-Disposition Header Field.txt +675 -0
  151. data/vendor/mail/reference/rfc2231 MIME Parameter Value and Encoded Word Extensions.txt +563 -0
  152. data/vendor/mail/reference/rfc2387 MIME Multipart-Related Content-type.txt +563 -0
  153. data/vendor/mail/reference/rfc2821 Simple Mail Transfer Protocol.txt +3711 -0
  154. data/vendor/mail/reference/rfc2822 Internet Message Format.txt +2859 -0
  155. data/vendor/mail/reference/rfc3462 Reporting of Mail System Administrative Messages.txt +396 -0
  156. data/vendor/mail/reference/rfc3696 Checking and Transformation of Names.txt +898 -0
  157. data/vendor/mail/reference/rfc4155 The application-mbox Media Type.txt +502 -0
  158. data/vendor/mail/reference/rfc4234 Augmented BNF for Syntax Specifications: ABNF.txt +899 -0
  159. data/vendor/mail/reference/rfc822 Standard for the Format of ARPA Internet Text Messages.txt +2900 -0
  160. data/vendor/mail/spec/environment.rb +15 -0
  161. data/vendor/mail/spec/features/making_a_new_message.feature +14 -0
  162. data/vendor/mail/spec/features/steps/env.rb +6 -0
  163. data/vendor/mail/spec/features/steps/making_a_new_message_steps.rb +11 -0
  164. data/vendor/mail/spec/fixtures/attachments/basic_email.eml +31 -0
  165. data/vendor/mail/spec/fixtures/attachments/test.gif +0 -0
  166. data/vendor/mail/spec/fixtures/attachments/test.jpg +0 -0
  167. data/vendor/mail/spec/fixtures/attachments/test.pdf +0 -0
  168. data/vendor/mail/spec/fixtures/attachments/test.png +0 -0
  169. data/vendor/mail/spec/fixtures/attachments/test.tiff +0 -0
  170. data/vendor/mail/spec/fixtures/attachments/test.zip +0 -0
  171. data/vendor/mail/spec/fixtures/attachments//343/201/246/343/201/231/343/201/250.txt +2 -0
  172. data/vendor/mail/spec/fixtures/emails/attachment_emails/attachment_content_disposition.eml +29 -0
  173. data/vendor/mail/spec/fixtures/emails/attachment_emails/attachment_content_location.eml +32 -0
  174. data/vendor/mail/spec/fixtures/emails/attachment_emails/attachment_message_rfc822.eml +92 -0
  175. data/vendor/mail/spec/fixtures/emails/attachment_emails/attachment_only_email.eml +17 -0
  176. data/vendor/mail/spec/fixtures/emails/attachment_emails/attachment_pdf.eml +70 -0
  177. data/vendor/mail/spec/fixtures/emails/attachment_emails/attachment_with_encoded_name.eml +47 -0
  178. data/vendor/mail/spec/fixtures/emails/attachment_emails/attachment_with_quoted_filename.eml +60 -0
  179. data/vendor/mail/spec/fixtures/emails/error_emails/cant_parse_from.eml +33 -0
  180. data/vendor/mail/spec/fixtures/emails/error_emails/content_transfer_encoding_7-bit.eml +231 -0
  181. data/vendor/mail/spec/fixtures/emails/error_emails/content_transfer_encoding_empty.eml +33 -0
  182. data/vendor/mail/spec/fixtures/emails/error_emails/content_transfer_encoding_plain.eml +148 -0
  183. data/vendor/mail/spec/fixtures/emails/error_emails/content_transfer_encoding_qp_with_space.eml +53 -0
  184. data/vendor/mail/spec/fixtures/emails/error_emails/content_transfer_encoding_spam.eml +44 -0
  185. data/vendor/mail/spec/fixtures/emails/error_emails/content_transfer_encoding_text-html.eml +50 -0
  186. data/vendor/mail/spec/fixtures/emails/error_emails/content_transfer_encoding_with_8bits.eml +770 -0
  187. data/vendor/mail/spec/fixtures/emails/error_emails/content_transfer_encoding_with_semi_colon.eml +269 -0
  188. data/vendor/mail/spec/fixtures/emails/error_emails/content_transfer_encoding_x_uuencode.eml +79 -0
  189. data/vendor/mail/spec/fixtures/emails/error_emails/empty_group_lists.eml +162 -0
  190. data/vendor/mail/spec/fixtures/emails/error_emails/header_fields_with_empty_values.eml +33 -0
  191. data/vendor/mail/spec/fixtures/emails/error_emails/missing_body.eml +16 -0
  192. data/vendor/mail/spec/fixtures/emails/error_emails/missing_content_disposition.eml +43 -0
  193. data/vendor/mail/spec/fixtures/emails/error_emails/multiple_content_types.eml +25 -0
  194. data/vendor/mail/spec/fixtures/emails/mime_emails/raw_email11.eml +34 -0
  195. data/vendor/mail/spec/fixtures/emails/mime_emails/raw_email12.eml +32 -0
  196. data/vendor/mail/spec/fixtures/emails/mime_emails/raw_email2.eml +114 -0
  197. data/vendor/mail/spec/fixtures/emails/mime_emails/raw_email4.eml +59 -0
  198. data/vendor/mail/spec/fixtures/emails/mime_emails/raw_email7.eml +66 -0
  199. data/vendor/mail/spec/fixtures/emails/mime_emails/raw_email_encoded_stack_level_too_deep.eml +53 -0
  200. data/vendor/mail/spec/fixtures/emails/mime_emails/raw_email_with_illegal_boundary.eml +58 -0
  201. data/vendor/mail/spec/fixtures/emails/mime_emails/raw_email_with_mimepart_without_content_type.eml +94 -0
  202. data/vendor/mail/spec/fixtures/emails/mime_emails/raw_email_with_multipart_mixed_quoted_boundary.eml +50 -0
  203. data/vendor/mail/spec/fixtures/emails/mime_emails/raw_email_with_nested_attachment.eml +100 -0
  204. data/vendor/mail/spec/fixtures/emails/mime_emails/raw_email_with_quoted_illegal_boundary.eml +58 -0
  205. data/vendor/mail/spec/fixtures/emails/mime_emails/sig_only_email.eml +29 -0
  206. data/vendor/mail/spec/fixtures/emails/mime_emails/two_from_in_message.eml +42 -0
  207. data/vendor/mail/spec/fixtures/emails/multi_charset/japanese.eml +9 -0
  208. data/vendor/mail/spec/fixtures/emails/multi_charset/japanese_attachment.eml +27 -0
  209. data/vendor/mail/spec/fixtures/emails/multi_charset/japanese_attachment_long_name.eml +44 -0
  210. data/vendor/mail/spec/fixtures/emails/multipart_report_emails/multi_address_bounce1.eml +179 -0
  211. data/vendor/mail/spec/fixtures/emails/multipart_report_emails/multi_address_bounce2.eml +179 -0
  212. data/vendor/mail/spec/fixtures/emails/multipart_report_emails/report_422.eml +98 -0
  213. data/vendor/mail/spec/fixtures/emails/multipart_report_emails/report_530.eml +97 -0
  214. data/vendor/mail/spec/fixtures/emails/plain_emails/basic_email.eml +31 -0
  215. data/vendor/mail/spec/fixtures/emails/plain_emails/raw_email.eml +14 -0
  216. data/vendor/mail/spec/fixtures/emails/plain_emails/raw_email10.eml +20 -0
  217. data/vendor/mail/spec/fixtures/emails/plain_emails/raw_email5.eml +19 -0
  218. data/vendor/mail/spec/fixtures/emails/plain_emails/raw_email6.eml +20 -0
  219. data/vendor/mail/spec/fixtures/emails/plain_emails/raw_email8.eml +47 -0
  220. data/vendor/mail/spec/fixtures/emails/plain_emails/raw_email_bad_time.eml +62 -0
  221. data/vendor/mail/spec/fixtures/emails/plain_emails/raw_email_double_at_in_header.eml +14 -0
  222. data/vendor/mail/spec/fixtures/emails/plain_emails/raw_email_incorrect_header.eml +28 -0
  223. data/vendor/mail/spec/fixtures/emails/plain_emails/raw_email_multiple_from.eml +30 -0
  224. data/vendor/mail/spec/fixtures/emails/plain_emails/raw_email_quoted_with_0d0a.eml +14 -0
  225. data/vendor/mail/spec/fixtures/emails/plain_emails/raw_email_reply.eml +32 -0
  226. data/vendor/mail/spec/fixtures/emails/plain_emails/raw_email_simple.eml +11 -0
  227. data/vendor/mail/spec/fixtures/emails/plain_emails/raw_email_string_in_date_field.eml +17 -0
  228. data/vendor/mail/spec/fixtures/emails/plain_emails/raw_email_trailing_dot.eml +21 -0
  229. data/vendor/mail/spec/fixtures/emails/plain_emails/raw_email_with_bad_date.eml +48 -0
  230. data/vendor/mail/spec/fixtures/emails/plain_emails/raw_email_with_partially_quoted_subject.eml +14 -0
  231. data/vendor/mail/spec/fixtures/emails/rfc2822/example01.eml +8 -0
  232. data/vendor/mail/spec/fixtures/emails/rfc2822/example02.eml +9 -0
  233. data/vendor/mail/spec/fixtures/emails/rfc2822/example03.eml +7 -0
  234. data/vendor/mail/spec/fixtures/emails/rfc2822/example04.eml +7 -0
  235. data/vendor/mail/spec/fixtures/emails/rfc2822/example05.eml +8 -0
  236. data/vendor/mail/spec/fixtures/emails/rfc2822/example06.eml +10 -0
  237. data/vendor/mail/spec/fixtures/emails/rfc2822/example07.eml +9 -0
  238. data/vendor/mail/spec/fixtures/emails/rfc2822/example08.eml +12 -0
  239. data/vendor/mail/spec/fixtures/emails/rfc2822/example09.eml +15 -0
  240. data/vendor/mail/spec/fixtures/emails/rfc2822/example10.eml +15 -0
  241. data/vendor/mail/spec/fixtures/emails/rfc2822/example11.eml +6 -0
  242. data/vendor/mail/spec/fixtures/emails/rfc2822/example12.eml +8 -0
  243. data/vendor/mail/spec/fixtures/emails/rfc2822/example13.eml +10 -0
  244. data/vendor/mail/spec/fixtures/emails/sample_output_multipart +0 -0
  245. data/vendor/mail/spec/mail/attachments_list_spec.rb +214 -0
  246. data/vendor/mail/spec/mail/body_spec.rb +385 -0
  247. data/vendor/mail/spec/mail/configuration_spec.rb +19 -0
  248. data/vendor/mail/spec/mail/core_extensions/string_spec.rb +62 -0
  249. data/vendor/mail/spec/mail/core_extensions_spec.rb +99 -0
  250. data/vendor/mail/spec/mail/elements/address_list_spec.rb +109 -0
  251. data/vendor/mail/spec/mail/elements/address_spec.rb +609 -0
  252. data/vendor/mail/spec/mail/elements/date_time_element_spec.rb +20 -0
  253. data/vendor/mail/spec/mail/elements/envelope_from_element_spec.rb +31 -0
  254. data/vendor/mail/spec/mail/elements/message_ids_element_spec.rb +43 -0
  255. data/vendor/mail/spec/mail/elements/phrase_list_spec.rb +22 -0
  256. data/vendor/mail/spec/mail/elements/received_element_spec.rb +34 -0
  257. data/vendor/mail/spec/mail/encoding_spec.rb +189 -0
  258. data/vendor/mail/spec/mail/encodings/base64_spec.rb +25 -0
  259. data/vendor/mail/spec/mail/encodings/quoted_printable_spec.rb +25 -0
  260. data/vendor/mail/spec/mail/encodings_spec.rb +664 -0
  261. data/vendor/mail/spec/mail/example_emails_spec.rb +303 -0
  262. data/vendor/mail/spec/mail/field_list_spec.rb +33 -0
  263. data/vendor/mail/spec/mail/field_spec.rb +198 -0
  264. data/vendor/mail/spec/mail/fields/bcc_field_spec.rb +89 -0
  265. data/vendor/mail/spec/mail/fields/cc_field_spec.rb +79 -0
  266. data/vendor/mail/spec/mail/fields/comments_field_spec.rb +25 -0
  267. data/vendor/mail/spec/mail/fields/common/address_container_spec.rb +18 -0
  268. data/vendor/mail/spec/mail/fields/common/common_address_spec.rb +132 -0
  269. data/vendor/mail/spec/mail/fields/common/common_date_spec.rb +25 -0
  270. data/vendor/mail/spec/mail/fields/common/common_field_spec.rb +69 -0
  271. data/vendor/mail/spec/mail/fields/common/common_message_id_spec.rb +30 -0
  272. data/vendor/mail/spec/mail/fields/common/parameter_hash_spec.rb +56 -0
  273. data/vendor/mail/spec/mail/fields/content_description_field_spec.rb +39 -0
  274. data/vendor/mail/spec/mail/fields/content_disposition_field_spec.rb +55 -0
  275. data/vendor/mail/spec/mail/fields/content_id_field_spec.rb +117 -0
  276. data/vendor/mail/spec/mail/fields/content_location_field_spec.rb +46 -0
  277. data/vendor/mail/spec/mail/fields/content_transfer_encoding_field_spec.rb +113 -0
  278. data/vendor/mail/spec/mail/fields/content_type_field_spec.rb +678 -0
  279. data/vendor/mail/spec/mail/fields/date_field_spec.rb +73 -0
  280. data/vendor/mail/spec/mail/fields/envelope_spec.rb +48 -0
  281. data/vendor/mail/spec/mail/fields/from_field_spec.rb +89 -0
  282. data/vendor/mail/spec/mail/fields/in_reply_to_field_spec.rb +62 -0
  283. data/vendor/mail/spec/mail/fields/keywords_field_spec.rb +66 -0
  284. data/vendor/mail/spec/mail/fields/message_id_field_spec.rb +147 -0
  285. data/vendor/mail/spec/mail/fields/mime_version_field_spec.rb +166 -0
  286. data/vendor/mail/spec/mail/fields/received_field_spec.rb +44 -0
  287. data/vendor/mail/spec/mail/fields/references_field_spec.rb +35 -0
  288. data/vendor/mail/spec/mail/fields/reply_to_field_spec.rb +67 -0
  289. data/vendor/mail/spec/mail/fields/resent_bcc_field_spec.rb +66 -0
  290. data/vendor/mail/spec/mail/fields/resent_cc_field_spec.rb +66 -0
  291. data/vendor/mail/spec/mail/fields/resent_date_field_spec.rb +39 -0
  292. data/vendor/mail/spec/mail/fields/resent_from_field_spec.rb +66 -0
  293. data/vendor/mail/spec/mail/fields/resent_message_id_field_spec.rb +24 -0
  294. data/vendor/mail/spec/mail/fields/resent_sender_field_spec.rb +58 -0
  295. data/vendor/mail/spec/mail/fields/resent_to_field_spec.rb +66 -0
  296. data/vendor/mail/spec/mail/fields/return_path_field_spec.rb +52 -0
  297. data/vendor/mail/spec/mail/fields/sender_field_spec.rb +58 -0
  298. data/vendor/mail/spec/mail/fields/structured_field_spec.rb +72 -0
  299. data/vendor/mail/spec/mail/fields/to_field_spec.rb +92 -0
  300. data/vendor/mail/spec/mail/fields/unstructured_field_spec.rb +134 -0
  301. data/vendor/mail/spec/mail/header_spec.rb +578 -0
  302. data/vendor/mail/spec/mail/mail_spec.rb +34 -0
  303. data/vendor/mail/spec/mail/message_spec.rb +1409 -0
  304. data/vendor/mail/spec/mail/mime_messages_spec.rb +435 -0
  305. data/vendor/mail/spec/mail/multipart_report_spec.rb +112 -0
  306. data/vendor/mail/spec/mail/network/delivery_methods/file_delivery_spec.rb +79 -0
  307. data/vendor/mail/spec/mail/network/delivery_methods/sendmail_spec.rb +125 -0
  308. data/vendor/mail/spec/mail/network/delivery_methods/smtp_spec.rb +133 -0
  309. data/vendor/mail/spec/mail/network/delivery_methods/test_mailer_spec.rb +57 -0
  310. data/vendor/mail/spec/mail/network/retriever_methods/pop3_spec.rb +180 -0
  311. data/vendor/mail/spec/mail/network_spec.rb +359 -0
  312. data/vendor/mail/spec/mail/parsers/address_lists_parser_spec.rb +15 -0
  313. data/vendor/mail/spec/mail/parsers/content_transfer_encoding_parser_spec.rb +72 -0
  314. data/vendor/mail/spec/mail/part_spec.rb +129 -0
  315. data/vendor/mail/spec/mail/parts_list_spec.rb +12 -0
  316. data/vendor/mail/spec/mail/round_tripping_spec.rb +44 -0
  317. data/vendor/mail/spec/mail/utilities_spec.rb +327 -0
  318. data/vendor/mail/spec/mail/version_specific/escape_paren_1_8_spec.rb +32 -0
  319. data/vendor/mail/spec/matchers/break_down_to.rb +35 -0
  320. data/vendor/mail/spec/spec_helper.rb +163 -0
  321. metadata +442 -0
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+ require 'mail/fields/common/parameter_hash'
3
+
4
+ describe Mail::ParameterHash do
5
+ it "should return the values in the hash" do
6
+ hash = Mail::ParameterHash.new
7
+ hash.merge!({'value1' => 'one', 'value2' => 'two'})
8
+ hash.keys.should == ['value1', 'value2']
9
+ hash.values.should == ['one', 'two']
10
+ end
11
+
12
+ it "should return the values in the hash regardless of symbol or string" do
13
+ hash = Mail::ParameterHash.new
14
+ hash.merge!({'value1' => 'one', 'value2' => 'two'})
15
+ hash['value1'].should == 'one'
16
+ hash['value2'].should == 'two'
17
+ hash[:value1].should == 'one'
18
+ hash[:value2].should == 'two'
19
+ end
20
+
21
+ it "should return the correct value if they are not encoded" do
22
+ hash = Mail::ParameterHash.new
23
+ hash.merge!({'value1' => 'one', 'value2' => 'two'})
24
+ hash['value1'].should == 'one'
25
+ hash['value2'].should == 'two'
26
+ end
27
+
28
+ it "should return a name list concatenated" do
29
+ hash = Mail::ParameterHash.new
30
+ hash.merge!({'value*1' => 'one', 'value*2' => 'two'})
31
+ hash['value'].should == 'onetwo'
32
+ end
33
+
34
+ it "should return a name list concatenated and unencoded" do
35
+ hash = Mail::ParameterHash.new
36
+ hash.merge!({'value*0*' => "us-ascii'en'This%20is%20even%20more%20",
37
+ 'value*1*' => "%2A%2A%2Afun%2A%2A%2A%20",
38
+ 'value*2' => "isn't it"})
39
+ hash['value'].should == "This is even more ***fun*** isn't it"
40
+ end
41
+
42
+ it "should allow us to add a value" do
43
+ hash = Mail::ParameterHash.new
44
+ hash['value'] = 'bob'
45
+ hash['value'].should == 'bob'
46
+ end
47
+
48
+ it "should return an encoded value" do
49
+ hash = Mail::ParameterHash.new
50
+ hash.merge!({'value*0*' => "us-ascii'en'This%20is%20even%20more%20",
51
+ 'value*1*' => "%2A%2A%2Afun%2A%2A%2A%20",
52
+ 'value*2' => "isn't it"})
53
+ hash.encoded.should == %Q{value*0*=us-ascii'en'This%20is%20even%20more%20;\r\n\tvalue*1*=%2A%2A%2Afun%2A%2A%2A%20;\r\n\tvalue*2="isn't it"}
54
+ end
55
+
56
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mail::ContentDescriptionField do
4
+ # Content-Description Header Field
5
+ #
6
+ # The ability to associate some descriptive information with a given
7
+ # body is often desirable. For example, it may be useful to mark an
8
+ # "image" body as "a picture of the Space Shuttle Endeavor." Such text
9
+ # may be placed in the Content-Description header field. This header
10
+ # field is always optional.
11
+ #
12
+ # description := "Content-Description" ":" *text
13
+ #
14
+ # The description is presumed to be given in the US-ASCII character
15
+ # set, although the mechanism specified in RFC 2047 may be used for
16
+ # non-US-ASCII Content-Description values.
17
+ #
18
+
19
+ describe "initialization" do
20
+
21
+ it "should initialize" do
22
+ doing { Mail::ContentDescriptionField.new("Content-Description: This is a description") }.should_not raise_error
23
+ end
24
+
25
+ it "should accept a string with the field name" do
26
+ t = Mail::ContentDescriptionField.new('Content-Description: This is a description')
27
+ t.name.should == 'Content-Description'
28
+ t.value.should == 'This is a description'
29
+ end
30
+
31
+ it "should accept a string without the field name" do
32
+ t = Mail::ContentDescriptionField.new('This is a description')
33
+ t.name.should == 'Content-Description'
34
+ t.value.should == 'This is a description'
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mail::ContentDispositionField do
4
+
5
+ describe "initialization" do
6
+
7
+ it "should initialize" do
8
+ doing { Mail::ContentDispositionField.new("attachment; filename=File") }.should_not raise_error
9
+ end
10
+
11
+ it "should accept a string with the field name" do
12
+ c = Mail::ContentDispositionField.new('Content-Disposition: attachment; filename=File')
13
+ c.name.should == 'Content-Disposition'
14
+ c.value.should == 'attachment; filename=File'
15
+ end
16
+
17
+ it "should accept a string without the field name" do
18
+ c = Mail::ContentDispositionField.new('attachment; filename=File')
19
+ c.name.should == 'Content-Disposition'
20
+ c.value.should == 'attachment; filename=File'
21
+ end
22
+
23
+ it "should accept a nil value and generate a disposition type" do
24
+ c = Mail::ContentDispositionField.new(nil)
25
+ c.name.should == 'Content-Disposition'
26
+ c.value.should_not be_nil
27
+ end
28
+
29
+ it "should render encoded" do
30
+ c = Mail::ContentDispositionField.new('Content-Disposition: attachment; filename=File')
31
+ c.encoded.should == "Content-Disposition: attachment;\r\n\tfilename=File\r\n"
32
+ end
33
+
34
+ it "should render decoded" do
35
+ c = Mail::ContentDispositionField.new('Content-Disposition: attachment; filename=File')
36
+ c.decoded.should == 'attachment; filename=File'
37
+ end
38
+
39
+ end
40
+
41
+ describe "instance methods" do
42
+ it "should give it's disposition type" do
43
+ c = Mail::ContentDispositionField.new('Content-Disposition: attachment; filename=File')
44
+ c.disposition_type.should == 'attachment'
45
+ c.parameters.should == {'filename' => 'File'}
46
+ end
47
+
48
+ # see spec/fixtures/trec_2005_corpus/missing_content_disposition.eml
49
+ it "should accept a blank disposition type" do
50
+ c = Mail::ContentDispositionField.new('Content-Disposition: ')
51
+ c.disposition_type.should_not be_nil
52
+ end
53
+ end
54
+
55
+ end
@@ -0,0 +1,117 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mail::ContentIdField do
4
+ # Content-ID Header Field
5
+ #
6
+ # In constructing a high-level user agent, it may be desirable to allow
7
+ # one body to make reference to another. Accordingly, bodies may be
8
+ # labelled using the "Content-ID" header field, which is syntactically
9
+ # identical to the "Content-ID" header field:
10
+ #
11
+ # id := "Content-ID" ":" msg-id
12
+ #
13
+ # Like the Content-ID values, Content-ID values must be generated to be
14
+ # world-unique.
15
+ #
16
+ # The Content-ID value may be used for uniquely identifying MIME
17
+ # entities in several contexts, particularly for caching data
18
+ # referenced by the message/external-body mechanism. Although the
19
+ # Content-ID header is generally optional, its use is MANDATORY in
20
+ # implementations which generate data of the optional MIME media type
21
+ # "message/external-body". That is, each message/external-body entity
22
+ # must have a Content-ID field to permit caching of such data.
23
+ #
24
+ # It is also worth noting that the Content-ID value has special
25
+ # semantics in the case of the multipart/alternative media type. This
26
+ # is explained in the section of RFC 2046 dealing with
27
+ # multipart/alternative.
28
+
29
+
30
+ describe "initialization" do
31
+
32
+ it "should initialize" do
33
+ doing { Mail::ContentIdField.new("<1234@test.lindsaar.net>") }.should_not raise_error
34
+ end
35
+
36
+ it "should accept a string with the field name" do
37
+ c = Mail::ContentIdField.new('Content-ID: <1234@test.lindsaar.net>')
38
+ c.name.should == 'Content-ID'
39
+ c.value.should == '<1234@test.lindsaar.net>'
40
+ c.content_id.should == '1234@test.lindsaar.net'
41
+ end
42
+
43
+ it "should accept a string without the field name" do
44
+ m = Mail::ContentIdField.new('<1234@test.lindsaar.net>')
45
+ m.name.should == 'Content-ID'
46
+ m.value.should == '<1234@test.lindsaar.net>'
47
+ m.content_id.should == '1234@test.lindsaar.net'
48
+ end
49
+
50
+ it "should accept a nil value and generate a content_id" do
51
+ m = Mail::ContentIdField.new(nil)
52
+ m.name.should == 'Content-ID'
53
+ m.value.should_not be_nil
54
+ end
55
+
56
+ it "should allow it to be encoded" do
57
+ m = Mail::ContentIdField.new('<1234@test.lindsaar.net>')
58
+ m.encoded.should == "Content-ID: <1234@test.lindsaar.net>\r\n"
59
+ end
60
+
61
+ it "should allow it to be decoded" do
62
+ m = Mail::ContentIdField.new('<1234@test.lindsaar.net>')
63
+ m.decoded.should == "<1234@test.lindsaar.net>"
64
+ end
65
+
66
+ end
67
+
68
+ describe "ensuring only one message ID" do
69
+
70
+ it "should not accept a string with multiple message IDs but only return the first" do
71
+ m = Mail::ContentIdField.new('<1234@test.lindsaar.net> <4567@test.lindsaar.net>')
72
+ m.name.should == 'Content-ID'
73
+ m.to_s.should == '<1234@test.lindsaar.net>'
74
+ m.content_id.should == '1234@test.lindsaar.net'
75
+ end
76
+
77
+ it "should change the message id if given a new message id" do
78
+ m = Mail::ContentIdField.new('<1234@test.lindsaar.net>')
79
+ m.to_s.should == '<1234@test.lindsaar.net>'
80
+ m.value = '<4567@test.lindsaar.net>'
81
+ m.to_s.should == '<4567@test.lindsaar.net>'
82
+ end
83
+
84
+ end
85
+
86
+ describe "instance methods" do
87
+ it "should provide to_s" do
88
+ m = Mail::ContentIdField.new('<1234@test.lindsaar.net>')
89
+ m.to_s.should == '<1234@test.lindsaar.net>'
90
+ m.content_id.to_s.should == '1234@test.lindsaar.net'
91
+ end
92
+
93
+ it "should provide encoded" do
94
+ m = Mail::ContentIdField.new('<1234@test.lindsaar.net>')
95
+ m.encoded.should == "Content-ID: <1234@test.lindsaar.net>\r\n"
96
+ end
97
+
98
+ it "should respond to :responsible_for?" do
99
+ m = Mail::ContentIdField.new('<1234@test.lindsaar.net>')
100
+ m.should respond_to(:responsible_for?)
101
+ end
102
+ end
103
+
104
+ describe "generating a message id" do
105
+ it "should generate a message ID if it has no value" do
106
+ m = Mail::ContentIdField.new
107
+ m.content_id.should_not be_blank
108
+ end
109
+
110
+ it "should generate a random message ID" do
111
+ m = Mail::ContentIdField.new
112
+ 1.upto(100) do
113
+ m.content_id.should_not == Mail::ContentIdField.new.content_id
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mail::ContentLocationField do
4
+
5
+ # Content-Location Header Field
6
+ #
7
+ describe "initialization" do
8
+
9
+ it "should initialize" do
10
+ doing { Mail::ContentLocationField.new("Content-Location", "7bit") }.should_not raise_error
11
+ end
12
+
13
+ it "should accept a string with the field name" do
14
+ t = Mail::ContentLocationField.new('Content-Location: photo.jpg')
15
+ t.name.should == 'Content-Location'
16
+ t.value.should == 'photo.jpg'
17
+ end
18
+
19
+ it "should accept a string without the field name" do
20
+ t = Mail::ContentLocationField.new('photo.jpg')
21
+ t.name.should == 'Content-Location'
22
+ t.value.should == 'photo.jpg'
23
+ end
24
+
25
+ it "should render an encoded field" do
26
+ t = Mail::ContentLocationField.new('photo.jpg')
27
+ t.encoded.should == "Content-Location: photo.jpg\r\n"
28
+ end
29
+
30
+ it "should render a decoded field" do
31
+ t = Mail::ContentLocationField.new('photo.jpg')
32
+ t.decoded.should == 'photo.jpg'
33
+ end
34
+
35
+ end
36
+
37
+ describe "parsing the value" do
38
+
39
+ it "should return an encoding string unquoted" do
40
+ t = Mail::ContentLocationField.new('"A quoted filename.jpg"')
41
+ t.location.should == 'A quoted filename.jpg'
42
+ end
43
+
44
+ end
45
+
46
+ end
@@ -0,0 +1,113 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mail::ContentTransferEncodingField do
4
+
5
+ # Content-Transfer-Encoding Header Field
6
+ #
7
+ # Many media types which could be usefully transported via email are
8
+ # represented, in their "natural" format, as 8bit character or binary
9
+ # data. Such data cannot be transmitted over some transfer protocols.
10
+ # For example, RFC 821 (SMTP) restricts mail messages to 7bit US-ASCII
11
+ # data with lines no longer than 1000 characters including any trailing
12
+ # CRLF line separator.
13
+ #
14
+ # It is necessary, therefore, to define a standard mechanism for
15
+ # encoding such data into a 7bit short line format. Proper labelling
16
+ # of unencoded material in less restrictive formats for direct use over
17
+ # less restrictive transports is also desireable. This document
18
+ # specifies that such encodings will be indicated by a new "Content-
19
+ # Transfer-Encoding" header field. This field has not been defined by
20
+ # any previous standard.
21
+ #
22
+ # 6.1. Content-Transfer-Encoding Syntax
23
+ #
24
+ # The Content-Transfer-Encoding field's value is a single token
25
+ # specifying the type of encoding, as enumerated below. Formally:
26
+ #
27
+ # encoding := "Content-Transfer-Encoding" ":" mechanism
28
+ #
29
+ # mechanism := "7bit" / "8bit" / "binary" /
30
+ # "quoted-printable" / "base64" /
31
+ # ietf-token / x-token
32
+ #
33
+ # These values are not case sensitive -- Base64 and BASE64 and bAsE64
34
+ # are all equivalent. An encoding type of 7BIT requires that the body
35
+ #
36
+ # is already in a 7bit mail-ready representation. This is the default
37
+ # value -- that is, "Content-Transfer-Encoding: 7BIT" is assumed if the
38
+ # Content-Transfer-Encoding header field is not present.
39
+ #
40
+ describe "initialization" do
41
+
42
+ it "should initialize" do
43
+ doing { Mail::ContentTransferEncodingField.new("Content-Transfer-Encoding: 7bit") }.should_not raise_error
44
+ end
45
+
46
+ it "should accept a string with the field name" do
47
+ t = Mail::ContentTransferEncodingField.new('Content-Transfer-Encoding: 7bit')
48
+ t.name.should == 'Content-Transfer-Encoding'
49
+ t.value.should == '7bit'
50
+ end
51
+
52
+ it "should accept a string without the field name" do
53
+ t = Mail::ContentTransferEncodingField.new('7bit')
54
+ t.name.should == 'Content-Transfer-Encoding'
55
+ t.value.should == '7bit'
56
+ end
57
+
58
+ it "should render an encoded field" do
59
+ t = Mail::ContentTransferEncodingField.new('7bit')
60
+ t.encoded.should == "Content-Transfer-Encoding: 7bit\r\n"
61
+ end
62
+
63
+ it "should render a decoded field" do
64
+ t = Mail::ContentTransferEncodingField.new('7bit')
65
+ t.decoded.should == '7bit'
66
+ end
67
+
68
+ end
69
+
70
+ describe "parsing the value" do
71
+
72
+ it "should return an encoding string" do
73
+ ["7bit", "8bit", "binary", 'quoted-printable', "base64"].each do |encoding|
74
+ t = Mail::ContentTransferEncodingField.new(encoding)
75
+ t.encoding.should == encoding
76
+ end
77
+ end
78
+
79
+ it "should handle any valid 'x-token' value" do
80
+ t = Mail::ContentTransferEncodingField.new('X-This-is_MY-encoding')
81
+ t.encoding.should == 'x-this-is_my-encoding'
82
+ end
83
+
84
+ it "should handle an x-encoding" do
85
+ t = Mail::ContentTransferEncodingField.new("x-uuencode")
86
+ t.encoding.should == "x-uuencode"
87
+ end
88
+
89
+ it "should replace the existing value" do
90
+ t = Mail::ContentTransferEncodingField.new("7bit")
91
+ t.parse("quoted-printable")
92
+ t.encoding.should == 'quoted-printable'
93
+ end
94
+
95
+ it "should raise an error on bogus values" do
96
+ doing { Mail::ContentTransferEncodingField.new("broken@foo") }.should raise_error
97
+ end
98
+
99
+ it "should handle an empty content transfer encoding" do
100
+ t = Mail::ContentTransferEncodingField.new("")
101
+ t.encoding.should == ""
102
+ end
103
+
104
+ it "should handle a hyphen" do
105
+ t = Mail::ContentTransferEncodingField.new('7-bit')
106
+ t.decoded.should == '7bit'
107
+ t = Mail::ContentTransferEncodingField.new('8-bit')
108
+ t.decoded.should == '8bit'
109
+ end
110
+
111
+ end
112
+
113
+ end
@@ -0,0 +1,678 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mail::ContentTypeField do
4
+ # Content-Type Header Field
5
+ #
6
+ # The purpose of the Content-Type field is to describe the data
7
+ # contained in the body fully enough that the receiving user agent can
8
+ # pick an appropriate agent or mechanism to present the data to the
9
+ # user, or otherwise deal with the data in an appropriate manner. The
10
+ # value in this field is called a media type.
11
+ #
12
+ # HISTORICAL NOTE: The Content-Type header field was first defined in
13
+ # RFC 1049. RFC 1049 used a simpler and less powerful syntax, but one
14
+ # that is largely compatible with the mechanism given here.
15
+ #
16
+ # The Content-Type header field specifies the nature of the data in the
17
+ # body of an entity by giving media type and subtype identifiers, and
18
+ # by providing auxiliary information that may be required for certain
19
+ # media types. After the media type and subtype names, the remainder
20
+ # of the header field is simply a set of parameters, specified in an
21
+ # attribute=value notation. The ordering of parameters is not
22
+ # significant.
23
+ #
24
+ # In general, the top-level media type is used to declare the general
25
+ # type of data, while the subtype specifies a specific format for that
26
+ # type of data. Thus, a media type of "image/xyz" is enough to tell a
27
+ # user agent that the data is an image, even if the user agent has no
28
+ # knowledge of the specific image format "xyz". Such information can
29
+ # be used, for example, to decide whether or not to show a user the raw
30
+ # data from an unrecognized subtype -- such an action might be
31
+ # reasonable for unrecognized subtypes of text, but not for
32
+ # unrecognized subtypes of image or audio. For this reason, registered
33
+ # subtypes of text, image, audio, and video should not contain embedded
34
+ # information that is really of a different type. Such compound
35
+ # formats should be represented using the "multipart" or "application"
36
+ # types.
37
+ #
38
+ # Parameters are modifiers of the media subtype, and as such do not
39
+ # fundamentally affect the nature of the content. The set of
40
+ # meaningful parameters depends on the media type and subtype. Most
41
+ # parameters are associated with a single specific subtype. However, a
42
+ # given top-level media type may define parameters which are applicable
43
+ # to any subtype of that type. Parameters may be required by their
44
+ # defining content type or subtype or they may be optional. MIME
45
+ # implementations must ignore any parameters whose names they do not
46
+ # recognize.
47
+ #
48
+ # For example, the "charset" parameter is applicable to any subtype of
49
+ # "text", while the "boundary" parameter is required for any subtype of
50
+ # the "multipart" media type.
51
+ #
52
+ # There are NO globally-meaningful parameters that apply to all media
53
+ # types. Truly global mechanisms are best addressed, in the MIME
54
+ # model, by the definition of additional Content-* header fields.
55
+ #
56
+ # An initial set of seven top-level media types is defined in RFC 2046.
57
+ # Five of these are discrete types whose content is essentially opaque
58
+ # as far as MIME processing is concerned. The remaining two are
59
+ # composite types whose contents require additional handling by MIME
60
+ # processors.
61
+ #
62
+ # This set of top-level media types is intended to be substantially
63
+ # complete. It is expected that additions to the larger set of
64
+ # supported types can generally be accomplished by the creation of new
65
+ # subtypes of these initial types. In the future, more top-level types
66
+ # may be defined only by a standards-track extension to this standard.
67
+ # If another top-level type is to be used for any reason, it must be
68
+ # given a name starting with "X-" to indicate its non-standard status
69
+ # and to avoid a potential conflict with a future official name.
70
+ #
71
+ describe "initialization" do
72
+
73
+ it "should initialize" do
74
+ doing { Mail::ContentTypeField.new("<1234@test.lindsaar.net>") }.should_not raise_error
75
+ end
76
+
77
+ it "should accept a string with the field name" do
78
+ c = Mail::ContentTypeField.new('Content-Type: text/plain')
79
+ c.name.should == 'Content-Type'
80
+ c.value.should == 'text/plain'
81
+ end
82
+
83
+ it "should accept a string without the field name" do
84
+ c = Mail::ContentTypeField.new('text/plain')
85
+ c.name.should == 'Content-Type'
86
+ c.value.should == 'text/plain'
87
+ end
88
+
89
+ it "should accept a nil value and generate a content_type" do
90
+ c = Mail::ContentTypeField.new('Content-Type', nil)
91
+ c.name.should == 'Content-Type'
92
+ c.value.should_not be_nil
93
+ end
94
+
95
+ it "should render encoded" do
96
+ c = Mail::ContentTypeField.new('text/plain; charset=US-ASCII; format=flowed')
97
+ c.encoded.should == %Q{Content-Type: text/plain;\r\n\tcharset=US-ASCII;\r\n\tformat=flowed\r\n}
98
+ end
99
+
100
+ it "should render quoted values encoded" do
101
+ c = Mail::ContentTypeField.new('text/plain; example="foo bar"')
102
+ c.encoded.should == %Q{Content-Type: text/plain;\r\n\texample="foo bar"\r\n}
103
+ end
104
+
105
+ it "should render decoded" do
106
+ c = Mail::ContentTypeField.new('text/plain; charset=US-ASCII; format=flowed')
107
+ c.decoded.should == 'text/plain; charset=US-ASCII; format=flowed'
108
+ end
109
+
110
+ it "should render quoted values decoded" do
111
+ c = Mail::ContentTypeField.new('text/plain; example="foo bar"')
112
+ c.decoded.should == 'text/plain; example="foo bar"'
113
+ end
114
+
115
+ it "should render " do
116
+ c = Mail::ContentTypeField.new('message/delivery-status')
117
+ c.main_type.should == 'message'
118
+ c.sub_type.should == 'delivery-status'
119
+ end
120
+ end
121
+
122
+ describe "instance methods" do
123
+ it "should return a content_type" do
124
+ c = Mail::ContentTypeField.new('text/plain')
125
+ c.content_type.should == 'text/plain'
126
+ end
127
+
128
+ it "should return a content_type for the :string method" do
129
+ c = Mail::ContentTypeField.new('text/plain')
130
+ c.string.should == 'text/plain'
131
+ end
132
+
133
+ it "should return a main_type" do
134
+ c = Mail::ContentTypeField.new('text/plain')
135
+ c.main_type.should == 'text'
136
+ end
137
+
138
+ it "should return a sub_type" do
139
+ c = Mail::ContentTypeField.new('text/plain')
140
+ c.main_type.should == 'text'
141
+ end
142
+
143
+ it "should return a parameter as a hash" do
144
+ c = Mail::ContentTypeField.new('text/plain; charset=US-ASCII')
145
+ c.parameters.should == {'charset' => 'US-ASCII'}
146
+ end
147
+
148
+ it "should return multiple parameters as a hash" do
149
+ c = Mail::ContentTypeField.new('text/plain; charset=US-ASCII; format=flowed')
150
+ c.parameters.should == {'charset' => 'US-ASCII', 'format' => 'flowed'}
151
+ end
152
+
153
+ it "should return boundry parameters" do
154
+ c = Mail::ContentTypeField.new('multipart/mixed; boundary=Apple-Mail-13-196941151')
155
+ c.parameters.should == {'boundary' => 'Apple-Mail-13-196941151'}
156
+ end
157
+
158
+ it "should be indifferent with the access" do
159
+ c = Mail::ContentTypeField.new('multipart/mixed; boundary=Apple')
160
+ c.parameters[:boundary].should == "Apple"
161
+ c.parameters['boundary'].should == "Apple"
162
+ end
163
+
164
+ end
165
+
166
+ describe "class methods" do
167
+ it "should give back an initialized instance with a unique boundary" do
168
+ boundary = Mail::ContentTypeField.with_boundary('multipart/mixed')
169
+ boundary.encoded.should =~ %r{Content-Type: multipart/mixed;\r\n\tboundary="--==_mimepart_[\w\d]+_[\w\d]+"\r\n}
170
+ end
171
+
172
+ it "should give back an initialized instance with different type with a unique boundary" do
173
+ boundary = Mail::ContentTypeField.with_boundary('multipart/alternative')
174
+ boundary.encoded.should =~ %r{Content-Type: multipart/alternative;\r\n\tboundary="--==_mimepart_[\w\d]+_[\w\d]+"\r\n}
175
+ end
176
+
177
+ it "should give unique boundaries" do
178
+ boundary1 = Mail::ContentTypeField.with_boundary('multipart/alternative').parameters['boundary']
179
+ 0.upto(250) do
180
+ boundary2 = Mail::ContentTypeField.with_boundary('multipart/alternative').parameters['boundary']
181
+ boundary1.should_not == boundary2
182
+ end
183
+ end
184
+
185
+ end
186
+
187
+ describe "Testing a bunch of email Content-Type fields" do
188
+
189
+ it "should handle 'application/octet-stream; name*=iso-2022-jp'ja'01%20Quien%20Te%20Dij%8aat.%20Pitbull.mp3'" do
190
+ string = %q{application/octet-stream; name*=iso-2022-jp'ja'01%20Quien%20Te%20Dij%8aat.%20Pitbull.mp3}
191
+ c = Mail::ContentTypeField.new(string)
192
+ c.content_type.should == 'application/octet-stream'
193
+ c.main_type.should == 'application'
194
+ c.sub_type.should == 'octet-stream'
195
+ c.parameters.should == {'name*' => "iso-2022-jp'ja'01%20Quien%20Te%20Dij%8aat.%20Pitbull.mp3"}
196
+ end
197
+
198
+ it "should handle 'application/pdf;'" do
199
+ string = %q{application/pdf;}
200
+ c = Mail::ContentTypeField.new(string)
201
+ c.content_type.should == 'application/pdf'
202
+ c.main_type.should == 'application'
203
+ c.sub_type.should == 'pdf'
204
+ c.parameters.should == {}
205
+ end
206
+
207
+ it "should handle 'application/pdf; name=\"broken.pdf\"'" do
208
+ string = %q{application/pdf; name="broken.pdf"}
209
+ c = Mail::ContentTypeField.new(string)
210
+ c.content_type.should == 'application/pdf'
211
+ c.main_type.should == 'application'
212
+ c.sub_type.should == 'pdf'
213
+ c.parameters.should == {"name" => "broken.pdf"}
214
+ end
215
+
216
+ it "should handle 'application/pkcs7-signature;'" do
217
+ string = %q{application/pkcs7-signature;}
218
+ c = Mail::ContentTypeField.new(string)
219
+ c.content_type.should == 'application/pkcs7-signature'
220
+ c.main_type.should == 'application'
221
+ c.sub_type.should == 'pkcs7-signature'
222
+ c.parameters.should == {}
223
+ end
224
+
225
+ it "should handle 'application/pkcs7-signature; name=smime.p7s'" do
226
+ string = %q{application/pkcs7-signature; name=smime.p7s}
227
+ c = Mail::ContentTypeField.new(string)
228
+ c.content_type.should == 'application/pkcs7-signature'
229
+ c.main_type.should == 'application'
230
+ c.sub_type.should == 'pkcs7-signature'
231
+ c.parameters.should == {"name" => "smime.p7s"}
232
+ end
233
+
234
+ it "should handle 'application/x-gzip; NAME=blah.gz'" do
235
+ string = %q{application/x-gzip; NAME=blah.gz}
236
+ c = Mail::ContentTypeField.new(string)
237
+ c.content_type.should == 'application/x-gzip'
238
+ c.main_type.should == 'application'
239
+ c.sub_type.should == 'x-gzip'
240
+ c.parameters.should == {"NAME" => "blah.gz"}
241
+ end
242
+
243
+ it "should handle 'image/jpeg'" do
244
+ string = %q{image/jpeg}
245
+ c = Mail::ContentTypeField.new(string)
246
+ c.content_type.should == 'image/jpeg'
247
+ c.main_type.should == 'image'
248
+ c.sub_type.should == 'jpeg'
249
+ c.parameters.should == {}
250
+ end
251
+
252
+ it "should handle 'image/jpeg'" do
253
+ string = %q{image/jpeg}
254
+ c = Mail::ContentTypeField.new(string)
255
+ c.content_type.should == 'image/jpeg'
256
+ c.main_type.should == 'image'
257
+ c.sub_type.should == 'jpeg'
258
+ c.parameters.should == {}
259
+ end
260
+
261
+ it "should handle 'image/jpeg;'" do
262
+ string = %q{image/jpeg}
263
+ c = Mail::ContentTypeField.new(string)
264
+ c.content_type.should == 'image/jpeg'
265
+ c.main_type.should == 'image'
266
+ c.sub_type.should == 'jpeg'
267
+ c.parameters.should == {}
268
+ end
269
+
270
+ it "should handle 'image/png;'" do
271
+ string = %q{image/png}
272
+ c = Mail::ContentTypeField.new(string)
273
+ c.content_type.should == 'image/png'
274
+ c.main_type.should == 'image'
275
+ c.sub_type.should == 'png'
276
+ c.parameters.should == {}
277
+ end
278
+
279
+ it "should handle 'message/delivery-status'" do
280
+ string = %q{message/delivery-status}
281
+ c = Mail::ContentTypeField.new(string)
282
+ c.content_type.should == 'message/delivery-status'
283
+ c.main_type.should == 'message'
284
+ c.sub_type.should == 'delivery-status'
285
+ c.parameters.should == {}
286
+ end
287
+
288
+ it "should handle 'message/rfc822'" do
289
+ string = %q{message/rfc822}
290
+ c = Mail::ContentTypeField.new(string)
291
+ c.content_type.should == 'message/rfc822'
292
+ c.main_type.should == 'message'
293
+ c.sub_type.should == 'rfc822'
294
+ c.parameters.should == {}
295
+ end
296
+
297
+ it "should handle 'multipart/alternative;'" do
298
+ string = %q{multipart/alternative;}
299
+ c = Mail::ContentTypeField.new(string)
300
+ c.content_type.should == 'multipart/alternative'
301
+ c.main_type.should == 'multipart'
302
+ c.sub_type.should == 'alternative'
303
+ c.parameters.should == {}
304
+ end
305
+
306
+ it "should handle 'multipart/alternative; boundary=\"----=_NextPart_000_0093_01C81419.EB75E850\"'" do
307
+ string = %q{multipart/alternative; boundary="----=_NextPart_000_0093_01C81419.EB75E850"}
308
+ c = Mail::ContentTypeField.new(string)
309
+ c.content_type.should == 'multipart/alternative'
310
+ c.main_type.should == 'multipart'
311
+ c.sub_type.should == 'alternative'
312
+ c.parameters.should == {"boundary" =>"----=_NextPart_000_0093_01C81419.EB75E850"}
313
+ end
314
+
315
+ it "should handle 'multipart/alternative; boundary=----=_NextPart_000_0093_01C81419.EB75E850'" do
316
+ string = %q{multipart/alternative; boundary="----=_NextPart_000_0093_01C81419.EB75E850"}
317
+ c = Mail::ContentTypeField.new(string)
318
+ c.content_type.should == 'multipart/alternative'
319
+ c.main_type.should == 'multipart'
320
+ c.sub_type.should == 'alternative'
321
+ c.parameters.should == {"boundary" =>"----=_NextPart_000_0093_01C81419.EB75E850"}
322
+ end
323
+
324
+ it "should handle 'multipart/mixed'" do
325
+ string = %q{multipart/mixed}
326
+ c = Mail::ContentTypeField.new(string)
327
+ c.content_type.should == 'multipart/mixed'
328
+ c.main_type.should == 'multipart'
329
+ c.sub_type.should == 'mixed'
330
+ c.parameters.should == {}
331
+ end
332
+
333
+ it "should handle 'multipart/mixed;'" do
334
+ string = %q{multipart/mixed;}
335
+ c = Mail::ContentTypeField.new(string)
336
+ c.content_type.should == 'multipart/mixed'
337
+ c.main_type.should == 'multipart'
338
+ c.sub_type.should == 'mixed'
339
+ c.parameters.should == {}
340
+ end
341
+
342
+ it "should handle 'multipart/mixed; boundary=Apple-Mail-13-196941151'" do
343
+ string = %q{multipart/mixed; boundary=Apple-Mail-13-196941151}
344
+ c = Mail::ContentTypeField.new(string)
345
+ c.content_type.should == 'multipart/mixed'
346
+ c.main_type.should == 'multipart'
347
+ c.sub_type.should == 'mixed'
348
+ c.parameters.should == {"boundary" => "Apple-Mail-13-196941151"}
349
+ end
350
+
351
+ it "should handle 'multipart/mixed; boundary=mimepart_427e4cb4ca329_133ae40413c81ef'" do
352
+ string = %q{multipart/mixed; boundary=mimepart_427e4cb4ca329_133ae40413c81ef}
353
+ c = Mail::ContentTypeField.new(string)
354
+ c.content_type.should == 'multipart/mixed'
355
+ c.main_type.should == 'multipart'
356
+ c.sub_type.should == 'mixed'
357
+ c.parameters.should == {"boundary" => "mimepart_427e4cb4ca329_133ae40413c81ef"}
358
+ end
359
+
360
+ it "should handle 'multipart/report; report-type=delivery-status;'" do
361
+ string = %q{multipart/report; report-type=delivery-status;}
362
+ c = Mail::ContentTypeField.new(string)
363
+ c.content_type.should == 'multipart/report'
364
+ c.main_type.should == 'multipart'
365
+ c.sub_type.should == 'report'
366
+ c.parameters.should == {"report-type" => "delivery-status"}
367
+ end
368
+
369
+ it "should handle 'multipart/signed;'" do
370
+ string = %q{multipart/signed;}
371
+ c = Mail::ContentTypeField.new(string)
372
+ c.content_type.should == 'multipart/signed'
373
+ c.main_type.should == 'multipart'
374
+ c.sub_type.should == 'signed'
375
+ c.parameters.should == {}
376
+ end
377
+
378
+ it "should handle 'text/enriched;'" do
379
+ string = %q{text/enriched;}
380
+ c = Mail::ContentTypeField.new(string)
381
+ c.content_type.should == 'text/enriched'
382
+ c.main_type.should == 'text'
383
+ c.sub_type.should == 'enriched'
384
+ c.parameters.should == {}
385
+ end
386
+
387
+ it "should handle 'text/html;'" do
388
+ string = %q{text/html;}
389
+ c = Mail::ContentTypeField.new(string)
390
+ c.content_type.should == 'text/html'
391
+ c.main_type.should == 'text'
392
+ c.sub_type.should == 'html'
393
+ c.parameters.should == {}
394
+ end
395
+
396
+ it "should handle 'text/html; charset=iso-8859-1;'" do
397
+ string = %q{text/html; charset=iso-8859-1;}
398
+ c = Mail::ContentTypeField.new(string)
399
+ c.content_type.should == 'text/html'
400
+ c.main_type.should == 'text'
401
+ c.sub_type.should == 'html'
402
+ c.parameters.should == {'charset' => 'iso-8859-1'}
403
+ end
404
+
405
+ it "should handle 'text/plain'" do
406
+ string = %q{text/plain}
407
+ c = Mail::ContentTypeField.new(string)
408
+ c.content_type.should == 'text/plain'
409
+ c.main_type.should == 'text'
410
+ c.sub_type.should == 'plain'
411
+ c.parameters.should == {}
412
+ end
413
+
414
+ it "should handle 'text/plain;'" do
415
+ string = %q{text/plain;}
416
+ c = Mail::ContentTypeField.new(string)
417
+ c.content_type.should == 'text/plain'
418
+ c.main_type.should == 'text'
419
+ c.sub_type.should == 'plain'
420
+ c.parameters.should == {}
421
+ end
422
+
423
+ it "should handle 'text/plain; charset=ISO-8859-1'" do
424
+ string = %q{text/plain; charset=ISO-8859-1}
425
+ c = Mail::ContentTypeField.new(string)
426
+ c.content_type.should == 'text/plain'
427
+ c.main_type.should == 'text'
428
+ c.sub_type.should == 'plain'
429
+ c.parameters.should == {'charset' => 'ISO-8859-1'}
430
+ end
431
+
432
+ it "should handle 'text/plain; charset=ISO-8859-1;'" do
433
+ string = %q{text/plain; charset=ISO-8859-1; format=flowed}
434
+ c = Mail::ContentTypeField.new(string)
435
+ c.content_type.should == 'text/plain'
436
+ c.main_type.should == 'text'
437
+ c.sub_type.should == 'plain'
438
+ c.parameters.should == {'charset' => 'ISO-8859-1', 'format' => 'flowed'}
439
+ end
440
+
441
+ it "should handle 'text/plain; charset=us-ascii;'" do
442
+ string = %q{text/plain; charset=us-ascii}
443
+ c = Mail::ContentTypeField.new(string)
444
+ c.content_type.should == 'text/plain'
445
+ c.main_type.should == 'text'
446
+ c.sub_type.should == 'plain'
447
+ c.parameters.should == {'charset' => 'us-ascii'}
448
+ end
449
+
450
+ it "should handle 'text/plain; charset=US-ASCII; format=flowed'" do
451
+ string = %q{text/plain; charset=US-ASCII; format=flowed}
452
+ c = Mail::ContentTypeField.new(string)
453
+ c.content_type.should == 'text/plain'
454
+ c.main_type.should == 'text'
455
+ c.sub_type.should == 'plain'
456
+ c.parameters.should == {'charset' => 'US-ASCII', 'format' => 'flowed'}
457
+ end
458
+
459
+ it "should handle 'text/plain; charset=US-ASCII; format=flowed'" do
460
+ string = %q{text/plain; charset=US-ASCII; format=flowed}
461
+ c = Mail::ContentTypeField.new(string)
462
+ c.content_type.should == 'text/plain'
463
+ c.main_type.should == 'text'
464
+ c.sub_type.should == 'plain'
465
+ c.parameters.should == {'charset' => 'US-ASCII', 'format' => 'flowed'}
466
+ end
467
+
468
+ it "should handle 'text/plain; charset=utf-8'" do
469
+ string = %q{text/plain; charset=utf-8}
470
+ c = Mail::ContentTypeField.new(string)
471
+ c.content_type.should == 'text/plain'
472
+ c.main_type.should == 'text'
473
+ c.sub_type.should == 'plain'
474
+ c.parameters.should == {'charset' => 'utf-8'}
475
+ end
476
+
477
+ it "should handle 'text/plain; charset=utf-8'" do
478
+ string = %q{text/plain; charset=X-UNKNOWN}
479
+ c = Mail::ContentTypeField.new(string)
480
+ c.content_type.should == 'text/plain'
481
+ c.main_type.should == 'text'
482
+ c.sub_type.should == 'plain'
483
+ c.parameters.should == {'charset' => 'X-UNKNOWN'}
484
+ end
485
+
486
+ it "should handle 'text/x-ruby-script;'" do
487
+ string = %q{text/x-ruby-script;}
488
+ c = Mail::ContentTypeField.new(string)
489
+ c.content_type.should == 'text/x-ruby-script'
490
+ c.main_type.should == 'text'
491
+ c.sub_type.should == 'x-ruby-script'
492
+ c.parameters.should == {}
493
+ end
494
+
495
+ it "should handle 'text/x-ruby-script; name=\"hello.rb\"'" do
496
+ string = %q{text/x-ruby-script; name="hello.rb"}
497
+ c = Mail::ContentTypeField.new(string)
498
+ c.content_type.should == 'text/x-ruby-script'
499
+ c.main_type.should == 'text'
500
+ c.sub_type.should == 'x-ruby-script'
501
+ c.parameters.should == {'name' => 'hello.rb'}
502
+ end
503
+
504
+ it "should handle 'multipart/mixed; boundary=\"=_NextPart_Lycos_15031600484464_ID\"" do
505
+ string = %q{multipart/mixed; boundary="=_NextPart_Lycos_15031600484464_ID"}
506
+ c = Mail::ContentTypeField.new(string)
507
+ c.content_type.should == 'multipart/mixed'
508
+ c.main_type.should == 'multipart'
509
+ c.sub_type.should == 'mixed'
510
+ c.parameters.should == {'boundary' => '=_NextPart_Lycos_15031600484464_ID'}
511
+ end
512
+
513
+ it "should handle 'multipart/alternative; boundary=----=_=NextPart_000_0093_01C81419.EB75E850" do
514
+ string = %q{multipart/alternative; boundary=----=_=NextPart_000_0093_01C81419.EB75E850}
515
+ c = Mail::ContentTypeField.new(string)
516
+ c.content_type.should == 'multipart/alternative'
517
+ c.main_type.should == 'multipart'
518
+ c.sub_type.should == 'alternative'
519
+ c.parameters.should == {'boundary' => '----=_=NextPart_000_0093_01C81419.EB75E850'}
520
+ end
521
+
522
+ it "should handle 'multipart/alternative; boundary=\"----=_=NextPart_000_0093_01C81419.EB75E850\"" do
523
+ string = %q{multipart/alternative; boundary="----=_=NextPart_000_0093_01C81419.EB75E850"}
524
+ c = Mail::ContentTypeField.new(string)
525
+ c.content_type.should == 'multipart/alternative'
526
+ c.main_type.should == 'multipart'
527
+ c.sub_type.should == 'alternative'
528
+ c.parameters.should == {'boundary' => '----=_=NextPart_000_0093_01C81419.EB75E850'}
529
+ end
530
+
531
+ it "should handle 'multipart/related;boundary=1_4626B816_9F1690;Type=\"application/smil\";Start=\"<mms.smil.txt>\"'" do
532
+ string = %q{multipart/related;boundary=1_4626B816_9F1690;Type="application/smil";Start="<mms.smil.txt>"}
533
+ c = Mail::ContentTypeField.new(string)
534
+ c.content_type.should == 'multipart/related'
535
+ c.main_type.should == 'multipart'
536
+ c.sub_type.should == 'related'
537
+ c.parameters.should == {'boundary' => '1_4626B816_9F1690', 'Type' => 'application/smil', 'Start' => '<mms.smil.txt>'}
538
+ end
539
+
540
+ end
541
+
542
+ describe "finding a filename" do
543
+
544
+ it "should locate a filename if there is a filename" do
545
+ string = %q{application/octet-stream; filename=mikel.jpg}
546
+ c = Mail::ContentTypeField.new(string)
547
+ c.filename.should == 'mikel.jpg'
548
+ end
549
+
550
+ it "should locate a name if there is no filename" do
551
+ string = %q{application/octet-stream; name=mikel.jpg}
552
+ c = Mail::ContentTypeField.new(string)
553
+ c.filename.should == 'mikel.jpg'
554
+ end
555
+
556
+ it "should locate an encoded name as a filename" do
557
+ string = %q{application/octet-stream; name*=iso-2022-jp'ja'01%20Quien%20Te%20Dij%91at.%20Pitbull.mp3}
558
+ c = Mail::ContentTypeField.new(string)
559
+ if RUBY_VERSION >= '1.9'
560
+ expected = "01 Quien Te Dij\221at. Pitbull.mp3".force_encoding(Encoding::BINARY)
561
+ result = c.filename.force_encoding(Encoding::BINARY)
562
+ else
563
+ expected = "01 Quien Te Dij\221at. Pitbull.mp3"
564
+ result = c.filename
565
+ end
566
+ expected.should == result
567
+ end
568
+
569
+ it "should encode a non us-ascii filename" do
570
+ @original = $KCODE if RUBY_VERSION < '1.9'
571
+ Mail.defaults do
572
+ param_encode_language('jp')
573
+ end
574
+ c = Mail::ContentTypeField.new('application/octet-stream')
575
+ string = "01 Quien Te Dij\221at. Pitbull.mp3"
576
+ if RUBY_VERSION >= '1.9'
577
+ string.force_encoding('SJIS')
578
+ result = %Q{Content-Type: application/octet-stream;\r\n\tfilename*=shift_jis'jp'01%20Quien%20Te%20Dij%91%61t.%20Pitbull.mp3\r\n}
579
+ else
580
+ storedkcode = $KCODE
581
+ $KCODE = 'SJIS'
582
+ result = %Q{Content-Type: application/octet-stream;\r\n\tfilename*=sjis'jp'01%20Quien%20Te%20Dij%91at.%20Pitbull.mp3\r\n}
583
+ end
584
+ c.filename = string
585
+ c.parameters.should == {'filename' => string}
586
+ c.encoded.should == result
587
+ $KCODE = @original if RUBY_VERSION < '1.9'
588
+ end
589
+
590
+ end
591
+
592
+ describe "handling badly formated content-type fields" do
593
+
594
+ it "should handle missing sub-type on a text content type" do
595
+ c = Mail::ContentTypeField.new('Content-Type: text')
596
+ c.content_type.should == 'text/plain'
597
+ end
598
+
599
+ it "should handle missing ; after content-type" do
600
+ c = Mail::ContentTypeField.new('Content-Type: multipart/mixed boundary="----=_NextPart_000_000F_01C17754.8C3CAF30"')
601
+ c.content_type.should == 'multipart/mixed'
602
+ c.parameters['boundary'].should == '----=_NextPart_000_000F_01C17754.8C3CAF30'
603
+ end
604
+
605
+ end
606
+
607
+ describe "initializing with an array" do
608
+ it "should initialize with an array" do
609
+ c = Mail::ContentTypeField.new(['text', 'html', {'charset' => 'UTF-8'}])
610
+ c.content_type.should == 'text/html'
611
+ c.parameters['charset'].should == 'UTF-8'
612
+ end
613
+
614
+ it "should allow many parameters to be passed in" do
615
+ c = Mail::ContentTypeField.new(['text', 'html', {"format"=>"flowed", "charset"=>"utf-8"}])
616
+ c.content_type.should == 'text/html'
617
+ c.parameters['charset'].should == 'utf-8'
618
+ c.parameters['format'].should == 'flowed'
619
+ end
620
+ end
621
+
622
+ describe "special case values needing sanity" do
623
+ it "should handle 'text/plain;ISO-8559-1'" do
624
+ c = Mail::ContentTypeField.new('text/plain;ISO-8559-1')
625
+ c.string.should == 'text/plain'
626
+ c.parameters['charset'].should == 'ISO-8559-1'
627
+ end
628
+
629
+ it "should handle text; params" do
630
+ c = Mail::ContentTypeField.new('text; charset=utf-8')
631
+ c.string.should == 'text/plain'
632
+ c.parameters['charset'].should == 'utf-8'
633
+ end
634
+
635
+ it 'should handle text/html; charset="charset="GB2312""' do
636
+ c = Mail::ContentTypeField.new('text/html; charset="charset="GB2312""')
637
+ c.string.should == 'text/html'
638
+ c.parameters['charset'].should == 'GB2312'
639
+ end
640
+
641
+ it "should handle application/octet-stream; name=archiveshelp1[1].htm" do
642
+ c = Mail::ContentTypeField.new('application/octet-stream; name=archiveshelp1[1].htm')
643
+ c.string.should == 'application/octet-stream'
644
+ c.parameters['name'].should == 'archiveshelp1[1].htm'
645
+ end
646
+
647
+ it 'should handle text/plain;; format="flowed"' do
648
+ c = Mail::ContentTypeField.new('text/plain;; format="flowed"')
649
+ c.string.should == 'text/plain'
650
+ c.parameters['format'].should == 'flowed'
651
+ end
652
+
653
+ it 'set an empty content type to text/plain' do
654
+ c = Mail::ContentTypeField.new('')
655
+ c.string.should == 'text/plain'
656
+ end
657
+
658
+ it "should just ignore illegal params like audio/x-midi;\r\n\tname=Part .exe" do
659
+ c = Mail::ContentTypeField.new("audio/x-midi;\r\n\tname=Part .exe")
660
+ c.string.should == 'audio/x-midi'
661
+ c.parameters['name'].should == nil
662
+ end
663
+
664
+ it "should handle: rfc822; format=flowed; charset=iso-8859-15" do
665
+ c = Mail::ContentTypeField.new("rfc822; format=flowed; charset=iso-8859-15")
666
+ c.string.should == 'text/plain'
667
+ c.parameters['format'].should == 'flowed'
668
+ c.parameters['charset'].should == 'iso-8859-15'
669
+ end
670
+
671
+ it "should just get the mime type if all else fails with some real garbage" do
672
+ c = Mail::ContentTypeField.new("text/html; format=flowed; charset=iso-8859-15 Mime-Version: 1.0")
673
+ c.string.should == 'text/html'
674
+ end
675
+
676
+ end
677
+
678
+ end