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,34 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe "mail" do
5
+
6
+ it "should be able to be instantiated" do
7
+ doing { Mail }.should_not raise_error
8
+ end
9
+
10
+ it "should be able to make a new email" do
11
+ Mail.new.class.should == Mail::Message
12
+ end
13
+
14
+ it "should accept headers and body" do
15
+ # Full tests in Message Spec
16
+ message = Mail.new do
17
+ from 'mikel@me.com'
18
+ to 'mikel@you.com'
19
+ subject 'Hello there Mikel'
20
+ body 'This is a body of text'
21
+ end
22
+ message.from.should == ['mikel@me.com']
23
+ message.to.should == ['mikel@you.com']
24
+ message.subject.should == 'Hello there Mikel'
25
+ message.body.to_s.should == 'This is a body of text'
26
+ end
27
+
28
+ it "should read a file" do
29
+ wrap_method = Mail.read(fixture('emails', 'plain_emails', 'raw_email.eml')).to_s
30
+ file_method = Mail.new(File.read(fixture('emails', 'plain_emails', 'raw_email.eml'))).to_s
31
+ wrap_method.should == file_method
32
+ end
33
+
34
+ end
@@ -0,0 +1,1409 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Mail::Message do
5
+
6
+ def basic_email
7
+ "To: mikel\r\nFrom: bob\r\nSubject: Hello!\r\n\r\nemail message\r\n"
8
+ end
9
+
10
+ describe "initialization" do
11
+
12
+ it "should instantiate empty" do
13
+ Mail::Message.new.class.should == Mail::Message
14
+ end
15
+
16
+ it "should instantiate with a string" do
17
+ Mail::Message.new(basic_email).class.should == Mail::Message
18
+ end
19
+
20
+ it "should allow us to pass it a block" do
21
+ mail = Mail::Message.new do
22
+ from 'mikel@me.com'
23
+ to 'lindsaar@you.com'
24
+ end
25
+ mail.from.should == ['mikel@me.com']
26
+ mail.to.should == ['lindsaar@you.com']
27
+ end
28
+
29
+ it "should initialize a body and header class even if called with nothing to begin with" do
30
+ mail = Mail::Message.new
31
+ mail.header.class.should == Mail::Header
32
+ mail.body.class.should == Mail::Body
33
+ end
34
+
35
+ it "should not report basic emails as bounced" do
36
+ Mail::Message.new.should_not be_bounced
37
+ end
38
+
39
+ it "should be able to parse a basic email" do
40
+ doing { Mail::Message.new(File.read(fixture('emails', 'plain_emails', 'basic_email.eml'))) }.should_not raise_error
41
+ end
42
+
43
+ it "should be able to parse an email with only blank lines as body" do
44
+ doing { Mail::Message.new(File.read(fixture('emails', 'error_emails', 'missing_body.eml'))) }.should_not raise_error
45
+ end
46
+
47
+ it "should be able to parse every email example we have without raising an exception" do
48
+ emails = Dir.glob( fixture('emails/**/*') ).delete_if { |f| File.directory?(f) }
49
+ STDERR.stub!(:puts) # Don't want to get noisy about any warnings
50
+ errors = false
51
+ emails.each do |email|
52
+ begin
53
+ Mail::Message.new(File.read(email))
54
+ rescue => e
55
+ puts "Failed on email #{email}"
56
+ puts "Failure was:\n#{e}"
57
+ errors = true
58
+ end
59
+ end
60
+ errors.should be_false
61
+ end
62
+
63
+ it "should not raise a warning on having non US-ASCII characters in the header (should just handle it)" do
64
+ STDERR.should_not_receive(:puts)
65
+ Mail::Message.new(File.read(fixture('emails', 'plain_emails', 'raw_email_string_in_date_field.eml')))
66
+ end
67
+
68
+ it "should raise a warning (and keep parsing) on having an incorrectly formatted header" do
69
+ STDERR.should_receive(:puts).with("WARNING: Could not parse (and so ignorning) 'quite Delivered-To: xxx@xxx.xxx'")
70
+ Mail::Message.new(File.read(fixture('emails', 'plain_emails', 'raw_email_incorrect_header.eml')))
71
+ end
72
+
73
+ it "should read in an email message and basically parse it" do
74
+ mail = Mail::Message.new(File.read(fixture('emails', 'plain_emails', 'basic_email.eml')))
75
+ mail.to.should == ["raasdnil@gmail.com"]
76
+ end
77
+
78
+ end
79
+
80
+ describe "envelope line handling" do
81
+ it "should respond to 'envelope from'" do
82
+ Mail::Message.new.should respond_to(:envelope_from)
83
+ end
84
+
85
+ it "should strip off the envelope from field if present" do
86
+ message = Mail::Message.new(File.read(fixture('emails', 'plain_emails', 'raw_email.eml')))
87
+ message.envelope_from.should == "jamis_buck@byu.edu"
88
+ message.envelope_date.should == ::DateTime.parse("Mon May 2 16:07:05 2005")
89
+ end
90
+
91
+ it "should strip off the envelope from field if present" do
92
+ message = Mail::Message.new(File.read(fixture('emails', 'plain_emails', 'raw_email.eml')))
93
+ message.raw_envelope.should == "jamis_buck@byu.edu Mon May 2 16:07:05 2005"
94
+ message.from.should == ["jamis@37signals.com"]
95
+ end
96
+
97
+ it "should not cause any problems if there is no envelope from present" do
98
+ message = Mail::Message.new(File.read(fixture('emails', 'plain_emails', 'basic_email.eml')))
99
+ message.from.should == ["test@lindsaar.net"]
100
+ end
101
+
102
+ it "should ignore a plain text body that starts with ^From" do
103
+ m = Mail::Message.new("From: mikel@test.lindsaar.net\r\n\r\nThis is a way to break mail by putting\r\nFrom at the start of a body\r\nor elsewhere.")
104
+ m.from.should_not be_nil
105
+ m.from.should == ['mikel@test.lindsaar.net']
106
+ end
107
+
108
+ it "should handle a multipart message that has ^From in it" do
109
+ m = Mail::Message.new(File.read(fixture('emails', 'error_emails', 'cant_parse_from.eml')))
110
+ m.from.should_not be_nil
111
+ m.from.should == ["News@InsideApple.Apple.com"]
112
+ m.should be_multipart
113
+ end
114
+
115
+ end
116
+
117
+ describe "accepting a plain text string email" do
118
+
119
+ it "should accept some email text to parse and return an email" do
120
+ mail = Mail::Message.new(basic_email)
121
+ mail.class.should == Mail::Message
122
+ end
123
+
124
+ it "should set a raw source instance variable to equal the passed in message" do
125
+ mail = Mail::Message.new(basic_email)
126
+ mail.raw_source.should == basic_email.strip
127
+ end
128
+
129
+ it "should set the raw source instance variable to '' if no message is passed in" do
130
+ mail = Mail::Message.new
131
+ mail.raw_source.should == ""
132
+ end
133
+
134
+ it "should give the header class the header to parse" do
135
+ header = Mail::Header.new("To: mikel\r\nFrom: bob\r\nSubject: Hello!")
136
+ Mail::Header.should_receive(:new).with("To: mikel\r\nFrom: bob\r\nSubject: Hello!", 'UTF-8').and_return(header)
137
+ mail = Mail::Message.new(basic_email)
138
+ end
139
+
140
+ it "should give the header class the header to parse even if there is no body" do
141
+ header = Mail::Header.new("To: mikel\r\nFrom: bob\r\nSubject: Hello!")
142
+ Mail::Header.should_receive(:new).with("To: mikel\r\nFrom: bob\r\nSubject: Hello!", 'UTF-8').and_return(header)
143
+ mail = Mail::Message.new("To: mikel\r\nFrom: bob\r\nSubject: Hello!")
144
+ end
145
+
146
+ it "should give the body class the body to parse" do
147
+ body = Mail::Body.new("email message")
148
+ Mail::Body.should_receive(:new).with("email message").and_return(body)
149
+ mail = Mail::Message.new(basic_email)
150
+ end
151
+
152
+ it "should still ask the body for a new instance even though these is nothing to parse, yet" do
153
+ Mail::Body.should_receive(:new)
154
+ mail = Mail::Message.new("To: mikel\r\nFrom: bob\r\nSubject: Hello!")
155
+ end
156
+
157
+ it "should give the header the part before the line without spaces and the body the part without" do
158
+ header = Mail::Header.new("To: mikel")
159
+ body = Mail::Body.new("G'Day!")
160
+ Mail::Header.should_receive(:new).with("To: mikel", 'UTF-8').and_return(header)
161
+ Mail::Body.should_receive(:new).with("G'Day!").and_return(body)
162
+ mail = Mail::Message.new("To: mikel\r\n\r\nG'Day!")
163
+ end
164
+
165
+ it "should give allow for whitespace on the gap line between header and body" do
166
+ header = Mail::Header.new("To: mikel")
167
+ body = Mail::Body.new("G'Day!")
168
+ Mail::Header.should_receive(:new).with("To: mikel", 'UTF-8').and_return(header)
169
+ Mail::Body.should_receive(:new).with("G'Day!").and_return(body)
170
+ mail = Mail::Message.new("To: mikel\r\n \r\nG'Day!")
171
+ end
172
+
173
+ it "should allow for whitespace at the start of the email" do
174
+ mail = Mail.new("\r\n\r\nFrom: mikel\r\n\r\nThis is the body")
175
+ mail.from.should == ['mikel']
176
+ mail.body.to_s.should == 'This is the body'
177
+ end
178
+
179
+ it "should read in an email message with the word 'From' in it multiple times and parse it" do
180
+ mail = Mail::Message.new(File.read(fixture('emails', 'mime_emails', 'two_from_in_message.eml')))
181
+ mail.to.should_not be_nil
182
+ mail.to.should == ["tester2@test.com"]
183
+ end
184
+
185
+ end
186
+
187
+ describe "directly setting values of a message" do
188
+
189
+ describe "accessing fields directly" do
190
+
191
+ before(:each) do
192
+ @mail = Mail::Message.new
193
+ end
194
+
195
+ it "should allow you to grab field objects if you really want to" do
196
+ @mail.header_fields.class.should == Mail::FieldList
197
+ end
198
+
199
+ it "should give you back the fields in the header" do
200
+ @mail['bar'] = 'abcd'
201
+ @mail.header_fields.length.should == 1
202
+ @mail['foo'] = '4321'
203
+ @mail.header_fields.length.should == 2
204
+ end
205
+
206
+ it "should delete a field if it is set to nil" do
207
+ @mail['foo'] = '4321'
208
+ @mail.header_fields.length.should == 1
209
+ @mail['foo'] = nil
210
+ @mail.header_fields.length.should == 0
211
+ end
212
+
213
+ end
214
+
215
+ describe "with :method=" do
216
+
217
+ before(:each) do
218
+ @mail = Mail::Message.new
219
+ end
220
+
221
+ it "should return the to field" do
222
+ @mail.to = "mikel"
223
+ @mail.to.should == ["mikel"]
224
+ end
225
+
226
+ it "should return the from field" do
227
+ @mail.from = "bob"
228
+ @mail.from.should == ["bob"]
229
+ end
230
+
231
+ it "should return the subject" do
232
+ @mail.subject = "Hello!"
233
+ @mail.subject.should == "Hello!"
234
+ end
235
+
236
+ it "should return the body decoded with to_s" do
237
+ @mail.body "email message\r\n"
238
+ @mail.body.to_s.should == "email message\n"
239
+ end
240
+
241
+ it "should return the body encoded if asked for" do
242
+ @mail.body "email message\r\n"
243
+ @mail.body.encoded.should == "email message\r\n"
244
+ end
245
+
246
+ it "should return the body decoded if asked for" do
247
+ @mail.body "email message\r\n"
248
+ @mail.body.decoded.should == "email message\n"
249
+ end
250
+ end
251
+
252
+ describe "with :method(value)" do
253
+
254
+ before(:each) do
255
+ @mail = Mail::Message.new
256
+ end
257
+
258
+ it "should return the to field" do
259
+ @mail.to "mikel"
260
+ @mail.to.should == ["mikel"]
261
+ end
262
+
263
+ it "should return the from field" do
264
+ @mail.from "bob"
265
+ @mail.from.should == ["bob"]
266
+ end
267
+
268
+ it "should return the subject" do
269
+ @mail.subject "Hello!"
270
+ @mail.subject.should == "Hello!"
271
+ end
272
+
273
+ it "should return the body decoded with to_s" do
274
+ @mail.body "email message\r\n"
275
+ @mail.body.to_s.should == "email message\n"
276
+ end
277
+
278
+ it "should return the body encoded if asked for" do
279
+ @mail.body "email message\r\n"
280
+ @mail.body.encoded.should == "email message\r\n"
281
+ end
282
+
283
+ it "should return the body decoded if asked for" do
284
+ @mail.body "email message\r\n"
285
+ @mail.body.decoded.should == "email message\n"
286
+ end
287
+ end
288
+
289
+ describe "setting arbitrary headers" do
290
+
291
+ before(:each) do
292
+ @mail = Mail::Message.new
293
+ end
294
+
295
+ it "should allow you to set them" do
296
+ doing {@mail['foo'] = 1234}.should_not raise_error
297
+ end
298
+
299
+ it "should allow you to read arbitrary headers" do
300
+ @mail['foo'] = 1234
301
+ @mail['foo'].value.to_s.should == '1234'
302
+ end
303
+
304
+ it "should instantiate a new Header" do
305
+ @mail['foo'] = 1234
306
+ @mail.header_fields.first.class.should == Mail::Field
307
+ end
308
+ end
309
+
310
+ describe "replacing header values" do
311
+
312
+ it "should allow you to replace a from field" do
313
+ mail = Mail.new
314
+ mail.from.should == nil
315
+ mail.from = 'mikel@test.lindsaar.net'
316
+ mail.from.should == ['mikel@test.lindsaar.net']
317
+ mail.from = 'bob@test.lindsaar.net'
318
+ mail.from.should == ['bob@test.lindsaar.net']
319
+ end
320
+
321
+ it "should maintain the class of the field" do
322
+ mail = Mail.new
323
+ mail.from = 'mikel@test.lindsaar.net'
324
+ mail[:from].field.class.should == Mail::FromField
325
+ mail.from = 'bob@test.lindsaar.net'
326
+ mail[:from].field.class.should == Mail::FromField
327
+ end
328
+ end
329
+
330
+ describe "setting headers" do
331
+
332
+ it "should accept them in block form" do
333
+ message = Mail.new do
334
+ bcc 'mikel@bcc.lindsaar.net'
335
+ cc 'mikel@cc.lindsaar.net'
336
+ comments 'this is a comment'
337
+ date '12 Aug 2009 00:00:01 GMT'
338
+ from 'mikel@from.lindsaar.net'
339
+ in_reply_to '<1234@in_reply_to.lindsaar.net>'
340
+ keywords 'test, "of the new mail", system'
341
+ message_id '<1234@message_id.lindsaar.net>'
342
+ received 'from machine.example by x.y.test; 12 Aug 2009 00:00:02 GMT'
343
+ references '<1234@references.lindsaar.net>'
344
+ reply_to 'mikel@reply-to.lindsaar.net'
345
+ resent_bcc 'mikel@resent-bcc.lindsaar.net'
346
+ resent_cc 'mikel@resent-cc.lindsaar.net'
347
+ resent_date '12 Aug 2009 00:00:03 GMT'
348
+ resent_from 'mikel@resent-from.lindsaar.net'
349
+ resent_message_id '<1234@resent_message_id.lindsaar.net>'
350
+ resent_sender 'mikel@resent-sender.lindsaar.net'
351
+ resent_to 'mikel@resent-to.lindsaar.net'
352
+ sender 'mikel@sender.lindsaar.net'
353
+ subject 'Hello there Mikel'
354
+ to 'mikel@to.lindsaar.net'
355
+ content_type 'text/plain; charset=UTF-8'
356
+ content_transfer_encoding '7bit'
357
+ content_description 'This is a test'
358
+ content_disposition 'attachment; filename=File'
359
+ content_id '<1234@message_id.lindsaar.net>'
360
+ mime_version '1.0'
361
+ body 'This is a body of text'
362
+ end
363
+
364
+ message.bcc.should == ['mikel@bcc.lindsaar.net']
365
+ message.cc.should == ['mikel@cc.lindsaar.net']
366
+ message.comments.should == 'this is a comment'
367
+ message.date.should == DateTime.parse('12 Aug 2009 00:00:01 GMT')
368
+ message.from.should == ['mikel@from.lindsaar.net']
369
+ message.in_reply_to.should == '1234@in_reply_to.lindsaar.net'
370
+ message.keywords.should == ["test", "of the new mail", "system"]
371
+ message.message_id.should == '1234@message_id.lindsaar.net'
372
+ message.received.date_time.should == DateTime.parse('12 Aug 2009 00:00:02 GMT')
373
+ message.references.should == '1234@references.lindsaar.net'
374
+ message.reply_to.should == ['mikel@reply-to.lindsaar.net']
375
+ message.resent_bcc.should == ['mikel@resent-bcc.lindsaar.net']
376
+ message.resent_cc.should == ['mikel@resent-cc.lindsaar.net']
377
+ message.resent_date.should == DateTime.parse('12 Aug 2009 00:00:03 GMT')
378
+ message.resent_from.should == ['mikel@resent-from.lindsaar.net']
379
+ message.resent_message_id.should == '1234@resent_message_id.lindsaar.net'
380
+ message.resent_sender.should == ['mikel@resent-sender.lindsaar.net']
381
+ message.resent_to.should == ['mikel@resent-to.lindsaar.net']
382
+ message.sender.should == 'mikel@sender.lindsaar.net'
383
+ message.subject.should == 'Hello there Mikel'
384
+ message.to.should == ['mikel@to.lindsaar.net']
385
+ message.content_type.should == 'text/plain; charset=UTF-8'
386
+ message.content_transfer_encoding.should == '7bit'
387
+ message.content_description.should == 'This is a test'
388
+ message.content_disposition.should == 'attachment; filename=File'
389
+ message.content_id.should == '<1234@message_id.lindsaar.net>'
390
+ message.mime_version.should == '1.0'
391
+ message.body.to_s.should == 'This is a body of text'
392
+ end
393
+
394
+ it "should accept them in assignment form" do
395
+ message = Mail.new
396
+ message.bcc = 'mikel@bcc.lindsaar.net'
397
+ message.cc = 'mikel@cc.lindsaar.net'
398
+ message.comments = 'this is a comment'
399
+ message.date = '12 Aug 2009 00:00:01 GMT'
400
+ message.from = 'mikel@from.lindsaar.net'
401
+ message.in_reply_to = '<1234@in_reply_to.lindsaar.net>'
402
+ message.keywords = 'test, "of the new mail", system'
403
+ message.message_id = '<1234@message_id.lindsaar.net>'
404
+ message.received = 'from machine.example by x.y.test; 12 Aug 2009 00:00:02 GMT'
405
+ message.references = '<1234@references.lindsaar.net>'
406
+ message.reply_to = 'mikel@reply-to.lindsaar.net'
407
+ message.resent_bcc = 'mikel@resent-bcc.lindsaar.net'
408
+ message.resent_cc = 'mikel@resent-cc.lindsaar.net'
409
+ message.resent_date = '12 Aug 2009 00:00:03 GMT'
410
+ message.resent_from = 'mikel@resent-from.lindsaar.net'
411
+ message.resent_message_id = '<1234@resent_message_id.lindsaar.net>'
412
+ message.resent_sender = 'mikel@resent-sender.lindsaar.net'
413
+ message.resent_to = 'mikel@resent-to.lindsaar.net'
414
+ message.sender = 'mikel@sender.lindsaar.net'
415
+ message.subject = 'Hello there Mikel'
416
+ message.to = 'mikel@to.lindsaar.net'
417
+ message.content_type = 'text/plain; charset=UTF-8'
418
+ message.content_transfer_encoding = '7bit'
419
+ message.content_description = 'This is a test'
420
+ message.content_disposition = 'attachment; filename=File'
421
+ message.content_id = '<1234@message_id.lindsaar.net>'
422
+ message.mime_version = '1.0'
423
+ message.body = 'This is a body of text'
424
+
425
+ message.bcc.should == ['mikel@bcc.lindsaar.net']
426
+ message.cc.should == ['mikel@cc.lindsaar.net']
427
+ message.comments.should == 'this is a comment'
428
+ message.date.should == DateTime.parse('12 Aug 2009 00:00:01 GMT')
429
+ message.from.should == ['mikel@from.lindsaar.net']
430
+ message.in_reply_to.should == '1234@in_reply_to.lindsaar.net'
431
+ message.keywords.should == ["test", "of the new mail", "system"]
432
+ message.message_id.should == '1234@message_id.lindsaar.net'
433
+ message.received.date_time.should == DateTime.parse('12 Aug 2009 00:00:02 GMT')
434
+ message.references.should == '1234@references.lindsaar.net'
435
+ message.reply_to.should == ['mikel@reply-to.lindsaar.net']
436
+ message.resent_bcc.should == ['mikel@resent-bcc.lindsaar.net']
437
+ message.resent_cc.should == ['mikel@resent-cc.lindsaar.net']
438
+ message.resent_date.should == DateTime.parse('12 Aug 2009 00:00:03 GMT')
439
+ message.resent_from.should == ['mikel@resent-from.lindsaar.net']
440
+ message.resent_message_id.should == '1234@resent_message_id.lindsaar.net'
441
+ message.resent_sender.should == ['mikel@resent-sender.lindsaar.net']
442
+ message.resent_to.should == ['mikel@resent-to.lindsaar.net']
443
+ message.sender.should == 'mikel@sender.lindsaar.net'
444
+ message.subject.should == 'Hello there Mikel'
445
+ message.to.should == ['mikel@to.lindsaar.net']
446
+ message.content_type.should == 'text/plain; charset=UTF-8'
447
+ message.content_transfer_encoding.should == '7bit'
448
+ message.content_description.should == 'This is a test'
449
+ message.content_disposition.should == 'attachment; filename=File'
450
+ message.content_id.should == '<1234@message_id.lindsaar.net>'
451
+ message.mime_version.should == '1.0'
452
+ message.body.to_s.should == 'This is a body of text'
453
+ end
454
+
455
+ it "should accept them in key, value form as symbols" do
456
+ message = Mail.new
457
+ message[:bcc] = 'mikel@bcc.lindsaar.net'
458
+ message[:cc] = 'mikel@cc.lindsaar.net'
459
+ message[:comments] = 'this is a comment'
460
+ message[:date] = '12 Aug 2009 00:00:01 GMT'
461
+ message[:from] = 'mikel@from.lindsaar.net'
462
+ message[:in_reply_to] = '<1234@in_reply_to.lindsaar.net>'
463
+ message[:keywords] = 'test, "of the new mail", system'
464
+ message[:message_id] = '<1234@message_id.lindsaar.net>'
465
+ message[:received] = 'from machine.example by x.y.test; 12 Aug 2009 00:00:02 GMT'
466
+ message[:references] = '<1234@references.lindsaar.net>'
467
+ message[:reply_to] = 'mikel@reply-to.lindsaar.net'
468
+ message[:resent_bcc] = 'mikel@resent-bcc.lindsaar.net'
469
+ message[:resent_cc] = 'mikel@resent-cc.lindsaar.net'
470
+ message[:resent_date] = '12 Aug 2009 00:00:03 GMT'
471
+ message[:resent_from] = 'mikel@resent-from.lindsaar.net'
472
+ message[:resent_message_id] = '<1234@resent_message_id.lindsaar.net>'
473
+ message[:resent_sender] = 'mikel@resent-sender.lindsaar.net'
474
+ message[:resent_to] = 'mikel@resent-to.lindsaar.net'
475
+ message[:sender] = 'mikel@sender.lindsaar.net'
476
+ message[:subject] = 'Hello there Mikel'
477
+ message[:to] = 'mikel@to.lindsaar.net'
478
+ message[:content_type] = 'text/plain; charset=UTF-8'
479
+ message[:content_transfer_encoding] = '7bit'
480
+ message[:content_description] = 'This is a test'
481
+ message[:content_disposition] = 'attachment; filename=File'
482
+ message[:content_id] = '<1234@message_id.lindsaar.net>'
483
+ message[:mime_version]= '1.0'
484
+ message[:body] = 'This is a body of text'
485
+
486
+ message.bcc.should == ['mikel@bcc.lindsaar.net']
487
+ message.cc.should == ['mikel@cc.lindsaar.net']
488
+ message.comments.should == 'this is a comment'
489
+ message.date.should == DateTime.parse('12 Aug 2009 00:00:01 GMT')
490
+ message.from.should == ['mikel@from.lindsaar.net']
491
+ message.in_reply_to.should == '1234@in_reply_to.lindsaar.net'
492
+ message.keywords.should == ["test", "of the new mail", "system"]
493
+ message.message_id.should == '1234@message_id.lindsaar.net'
494
+ message.received.date_time.should == DateTime.parse('12 Aug 2009 00:00:02 GMT')
495
+ message.references.should == '1234@references.lindsaar.net'
496
+ message.reply_to.should == ['mikel@reply-to.lindsaar.net']
497
+ message.resent_bcc.should == ['mikel@resent-bcc.lindsaar.net']
498
+ message.resent_cc.should == ['mikel@resent-cc.lindsaar.net']
499
+ message.resent_date.should == DateTime.parse('12 Aug 2009 00:00:03 GMT')
500
+ message.resent_from.should == ['mikel@resent-from.lindsaar.net']
501
+ message.resent_message_id.should == '1234@resent_message_id.lindsaar.net'
502
+ message.resent_sender.should == ['mikel@resent-sender.lindsaar.net']
503
+ message.resent_to.should == ['mikel@resent-to.lindsaar.net']
504
+ message.sender.should == 'mikel@sender.lindsaar.net'
505
+ message.subject.should == 'Hello there Mikel'
506
+ message.to.should == ['mikel@to.lindsaar.net']
507
+ message.content_type.should == 'text/plain; charset=UTF-8'
508
+ message.content_transfer_encoding.should == '7bit'
509
+ message.content_description.should == 'This is a test'
510
+ message.content_disposition.should == 'attachment; filename=File'
511
+ message.content_id.should == '<1234@message_id.lindsaar.net>'
512
+ message.mime_version.should == '1.0'
513
+ message.body.to_s.should == 'This is a body of text'
514
+ end
515
+
516
+ it "should accept them in key, value form as strings" do
517
+ message = Mail.new
518
+ message['bcc'] = 'mikel@bcc.lindsaar.net'
519
+ message['cc'] = 'mikel@cc.lindsaar.net'
520
+ message['comments'] = 'this is a comment'
521
+ message['date'] = '12 Aug 2009 00:00:01 GMT'
522
+ message['from'] = 'mikel@from.lindsaar.net'
523
+ message['in_reply_to'] = '<1234@in_reply_to.lindsaar.net>'
524
+ message['keywords'] = 'test, "of the new mail", system'
525
+ message['message_id'] = '<1234@message_id.lindsaar.net>'
526
+ message['received'] = 'from machine.example by x.y.test; 12 Aug 2009 00:00:02 GMT'
527
+ message['references'] = '<1234@references.lindsaar.net>'
528
+ message['reply_to'] = 'mikel@reply-to.lindsaar.net'
529
+ message['resent_bcc'] = 'mikel@resent-bcc.lindsaar.net'
530
+ message['resent_cc'] = 'mikel@resent-cc.lindsaar.net'
531
+ message['resent_date'] = '12 Aug 2009 00:00:03 GMT'
532
+ message['resent_from'] = 'mikel@resent-from.lindsaar.net'
533
+ message['resent_message_id'] = '<1234@resent_message_id.lindsaar.net>'
534
+ message['resent_sender'] = 'mikel@resent-sender.lindsaar.net'
535
+ message['resent_to'] = 'mikel@resent-to.lindsaar.net'
536
+ message['sender'] = 'mikel@sender.lindsaar.net'
537
+ message['subject'] = 'Hello there Mikel'
538
+ message['to'] = 'mikel@to.lindsaar.net'
539
+ message['content_type'] = 'text/plain; charset=UTF-8'
540
+ message['content_transfer_encoding'] = '7bit'
541
+ message['content_description'] = 'This is a test'
542
+ message['content_disposition'] = 'attachment; filename=File'
543
+ message['content_id'] = '<1234@message_id.lindsaar.net>'
544
+ message['mime_version'] = '1.0'
545
+ message['body'] = 'This is a body of text'
546
+
547
+ message.bcc.should == ['mikel@bcc.lindsaar.net']
548
+ message.cc.should == ['mikel@cc.lindsaar.net']
549
+ message.comments.should == 'this is a comment'
550
+ message.date.should == DateTime.parse('12 Aug 2009 00:00:01 GMT')
551
+ message.from.should == ['mikel@from.lindsaar.net']
552
+ message.in_reply_to.should == '1234@in_reply_to.lindsaar.net'
553
+ message.keywords.should == ["test", "of the new mail", "system"]
554
+ message.message_id.should == '1234@message_id.lindsaar.net'
555
+ message.received.date_time.should == DateTime.parse('12 Aug 2009 00:00:02 GMT')
556
+ message.references.should == '1234@references.lindsaar.net'
557
+ message.reply_to.should == ['mikel@reply-to.lindsaar.net']
558
+ message.resent_bcc.should == ['mikel@resent-bcc.lindsaar.net']
559
+ message.resent_cc.should == ['mikel@resent-cc.lindsaar.net']
560
+ message.resent_date.should == DateTime.parse('12 Aug 2009 00:00:03 GMT')
561
+ message.resent_from.should == ['mikel@resent-from.lindsaar.net']
562
+ message.resent_message_id.should == '1234@resent_message_id.lindsaar.net'
563
+ message.resent_sender.should == ['mikel@resent-sender.lindsaar.net']
564
+ message.resent_to.should == ['mikel@resent-to.lindsaar.net']
565
+ message.sender.should == 'mikel@sender.lindsaar.net'
566
+ message.subject.should == 'Hello there Mikel'
567
+ message.to.should == ['mikel@to.lindsaar.net']
568
+ message.content_type.should == 'text/plain; charset=UTF-8'
569
+ message.content_transfer_encoding.should == '7bit'
570
+ message.content_description.should == 'This is a test'
571
+ message.content_disposition.should == 'attachment; filename=File'
572
+ message.content_id.should == '<1234@message_id.lindsaar.net>'
573
+ message.mime_version.should == '1.0'
574
+ message.body.to_s.should == 'This is a body of text'
575
+ end
576
+
577
+ it "should accept them as a hash with symbols" do
578
+ message = Mail.new({
579
+ :bcc => 'mikel@bcc.lindsaar.net',
580
+ :cc => 'mikel@cc.lindsaar.net',
581
+ :comments => 'this is a comment',
582
+ :date => '12 Aug 2009 00:00:01 GMT',
583
+ :from => 'mikel@from.lindsaar.net',
584
+ :in_reply_to => '<1234@in_reply_to.lindsaar.net>',
585
+ :keywords => 'test, "of the new mail", system',
586
+ :message_id => '<1234@message_id.lindsaar.net>',
587
+ :received => 'from machine.example by x.y.test; 12 Aug 2009 00:00:02 GMT',
588
+ :references => '<1234@references.lindsaar.net>',
589
+ :reply_to => 'mikel@reply-to.lindsaar.net',
590
+ :resent_bcc => 'mikel@resent-bcc.lindsaar.net',
591
+ :resent_cc => 'mikel@resent-cc.lindsaar.net',
592
+ :resent_date => '12 Aug 2009 00:00:03 GMT',
593
+ :resent_from => 'mikel@resent-from.lindsaar.net',
594
+ :resent_message_id => '<1234@resent_message_id.lindsaar.net>',
595
+ :resent_sender => 'mikel@resent-sender.lindsaar.net',
596
+ :resent_to => 'mikel@resent-to.lindsaar.net',
597
+ :sender => 'mikel@sender.lindsaar.net',
598
+ :subject => 'Hello there Mikel',
599
+ :to => 'mikel@to.lindsaar.net',
600
+ :content_type => 'text/plain; charset=UTF-8',
601
+ :content_transfer_encoding => '7bit',
602
+ :content_description => 'This is a test',
603
+ :content_disposition => 'attachment; filename=File',
604
+ :content_id => '<1234@message_id.lindsaar.net>',
605
+ :mime_version => '1.0',
606
+ :body => 'This is a body of text'
607
+ })
608
+
609
+ message.bcc.should == ['mikel@bcc.lindsaar.net']
610
+ message.cc.should == ['mikel@cc.lindsaar.net']
611
+ message.comments.should == 'this is a comment'
612
+ message.date.should == DateTime.parse('12 Aug 2009 00:00:01 GMT')
613
+ message.from.should == ['mikel@from.lindsaar.net']
614
+ message.in_reply_to.should == '1234@in_reply_to.lindsaar.net'
615
+ message.keywords.should == ["test", "of the new mail", "system"]
616
+ message.message_id.should == '1234@message_id.lindsaar.net'
617
+ message.received.date_time.should == DateTime.parse('12 Aug 2009 00:00:02 GMT')
618
+ message.references.should == '1234@references.lindsaar.net'
619
+ message.reply_to.should == ['mikel@reply-to.lindsaar.net']
620
+ message.resent_bcc.should == ['mikel@resent-bcc.lindsaar.net']
621
+ message.resent_cc.should == ['mikel@resent-cc.lindsaar.net']
622
+ message.resent_date.should == DateTime.parse('12 Aug 2009 00:00:03 GMT')
623
+ message.resent_from.should == ['mikel@resent-from.lindsaar.net']
624
+ message.resent_message_id.should == '1234@resent_message_id.lindsaar.net'
625
+ message.resent_sender.should == ['mikel@resent-sender.lindsaar.net']
626
+ message.resent_to.should == ['mikel@resent-to.lindsaar.net']
627
+ message.sender.should == 'mikel@sender.lindsaar.net'
628
+ message.subject.should == 'Hello there Mikel'
629
+ message.to.should == ['mikel@to.lindsaar.net']
630
+ message.content_type.should == 'text/plain; charset=UTF-8'
631
+ message.content_transfer_encoding.should == '7bit'
632
+ message.content_description.should == 'This is a test'
633
+ message.content_disposition.should == 'attachment; filename=File'
634
+ message.content_id.should == '<1234@message_id.lindsaar.net>'
635
+ message.mime_version.should == '1.0'
636
+ message.body.to_s.should == 'This is a body of text'
637
+ end
638
+
639
+ it "should accept them as a hash with strings" do
640
+ message = Mail.new({
641
+ 'bcc' => 'mikel@bcc.lindsaar.net',
642
+ 'cc' => 'mikel@cc.lindsaar.net',
643
+ 'comments' => 'this is a comment',
644
+ 'date' => '12 Aug 2009 00:00:01 GMT',
645
+ 'from' => 'mikel@from.lindsaar.net',
646
+ 'in_reply_to' => '<1234@in_reply_to.lindsaar.net>',
647
+ 'keywords' => 'test, "of the new mail", system',
648
+ 'message_id' => '<1234@message_id.lindsaar.net>',
649
+ 'received' => 'from machine.example by x.y.test; 12 Aug 2009 00:00:02 GMT',
650
+ 'references' => '<1234@references.lindsaar.net>',
651
+ 'reply_to' => 'mikel@reply-to.lindsaar.net',
652
+ 'resent_bcc' => 'mikel@resent-bcc.lindsaar.net',
653
+ 'resent_cc' => 'mikel@resent-cc.lindsaar.net',
654
+ 'resent_date' => '12 Aug 2009 00:00:03 GMT',
655
+ 'resent_from' => 'mikel@resent-from.lindsaar.net',
656
+ 'resent_message_id' => '<1234@resent_message_id.lindsaar.net>',
657
+ 'resent_sender' => 'mikel@resent-sender.lindsaar.net',
658
+ 'resent_to' => 'mikel@resent-to.lindsaar.net',
659
+ 'sender' => 'mikel@sender.lindsaar.net',
660
+ 'subject' => 'Hello there Mikel',
661
+ 'to' => 'mikel@to.lindsaar.net',
662
+ 'content_type' => 'text/plain; charset=UTF-8',
663
+ 'content_transfer_encoding' => '7bit',
664
+ 'content_description' => 'This is a test',
665
+ 'content_disposition' => 'attachment; filename=File',
666
+ 'content_id' => '<1234@message_id.lindsaar.net>',
667
+ 'mime_version' => '1.0',
668
+ 'body' => 'This is a body of text'
669
+ })
670
+
671
+ message.bcc.should == ['mikel@bcc.lindsaar.net']
672
+ message.cc.should == ['mikel@cc.lindsaar.net']
673
+ message.comments.should == 'this is a comment'
674
+ message.date.should == DateTime.parse('12 Aug 2009 00:00:01 GMT')
675
+ message.from.should == ['mikel@from.lindsaar.net']
676
+ message.in_reply_to.should == '1234@in_reply_to.lindsaar.net'
677
+ message.keywords.should == ["test", "of the new mail", "system"]
678
+ message.message_id.should == '1234@message_id.lindsaar.net'
679
+ message.received.date_time.should == DateTime.parse('12 Aug 2009 00:00:02 GMT')
680
+ message.references.should == '1234@references.lindsaar.net'
681
+ message.reply_to.should == ['mikel@reply-to.lindsaar.net']
682
+ message.resent_bcc.should == ['mikel@resent-bcc.lindsaar.net']
683
+ message.resent_cc.should == ['mikel@resent-cc.lindsaar.net']
684
+ message.resent_date.should == DateTime.parse('12 Aug 2009 00:00:03 GMT')
685
+ message.resent_from.should == ['mikel@resent-from.lindsaar.net']
686
+ message.resent_message_id.should == '1234@resent_message_id.lindsaar.net'
687
+ message.resent_sender.should == ['mikel@resent-sender.lindsaar.net']
688
+ message.resent_to.should == ['mikel@resent-to.lindsaar.net']
689
+ message.sender.should == 'mikel@sender.lindsaar.net'
690
+ message.subject.should == 'Hello there Mikel'
691
+ message.to.should == ['mikel@to.lindsaar.net']
692
+ message.content_type.should == 'text/plain; charset=UTF-8'
693
+ message.content_transfer_encoding.should == '7bit'
694
+ message.content_description.should == 'This is a test'
695
+ message.content_disposition.should == 'attachment; filename=File'
696
+ message.content_id.should == '<1234@message_id.lindsaar.net>'
697
+ message.mime_version.should == '1.0'
698
+ message.body.to_s.should == 'This is a body of text'
699
+ end
700
+
701
+ it "should let you set custom headers with a :headers => {hash}" do
702
+ message = Mail.new(:headers => {'custom-header' => 'mikel'})
703
+ message['custom-header'].decoded.should == 'mikel'
704
+ end
705
+
706
+ it "should assign the body to a part on creation" do
707
+ message = Mail.new do
708
+ part({:content_type=>"multipart/alternative", :content_disposition=>"inline", :body=>"Nothing to see here."})
709
+ end
710
+ message.parts.first.body.decoded.should == "Nothing to see here."
711
+ end
712
+
713
+ it "should not overwrite bodies on creation" do
714
+ message = Mail.new do
715
+ part({:content_type=>"multipart/alternative", :content_disposition=>"inline", :body=>"Nothing to see here."}) do |p|
716
+ p.part :content_type => "text/html", :body => "<b>test</b> HTML<br/>"
717
+ end
718
+ end
719
+ message.parts.first.parts[0].body.decoded.should == "Nothing to see here."
720
+ message.parts.first.parts[1].body.decoded.should == "<b>test</b> HTML<br/>"
721
+ message.encoded.should match %r{Nothing to see here\.}
722
+ message.encoded.should match %r{<b>test</b> HTML<br/>}
723
+ end
724
+
725
+ it "should allow you to init on an array of addresses from a hash" do
726
+ mail = Mail.new(:to => ['test1@lindsaar.net', 'Mikel <test2@lindsaar.net>'])
727
+ mail.to.should == ['test1@lindsaar.net', 'test2@lindsaar.net']
728
+ end
729
+
730
+ it "should allow you to init on an array of addresses directly" do
731
+ mail = Mail.new
732
+ mail.to = ['test1@lindsaar.net', 'Mikel <test2@lindsaar.net>']
733
+ mail.to.should == ['test1@lindsaar.net', 'test2@lindsaar.net']
734
+ end
735
+
736
+ it "should allow you to init on an array of addresses directly" do
737
+ mail = Mail.new
738
+ mail[:to] = ['test1@lindsaar.net', 'Mikel <test2@lindsaar.net>']
739
+ mail.to.should == ['test1@lindsaar.net', 'test2@lindsaar.net']
740
+ end
741
+
742
+ end
743
+
744
+ end
745
+
746
+ describe "handling missing required fields:" do
747
+
748
+ describe "every email" do
749
+
750
+ describe "Message-ID" do
751
+ it "should say if it has a message id" do
752
+ mail = Mail.new do
753
+ from 'mikel@test.lindsaar.net'
754
+ to 'you@test.lindsaar.net'
755
+ subject 'This is a test email'
756
+ body 'This is a body of the email'
757
+ end
758
+ mail.should_not be_has_message_id
759
+ end
760
+
761
+ it "should preserve any message id that you pass it if add_message_id is called explicitly" do
762
+ mail = Mail.new do
763
+ from 'mikel@test.lindsaar.net'
764
+ to 'you@test.lindsaar.net'
765
+ subject 'This is a test email'
766
+ body 'This is a body of the email'
767
+ end
768
+ mail.add_message_id("<ThisIsANonUniqueMessageId@me.com>")
769
+ mail.to_s.should =~ /Message-ID: <ThisIsANonUniqueMessageId@me.com>\r\n/
770
+ end
771
+
772
+ it "should generate a random message ID if nothing is passed to add_message_id" do
773
+ mail = Mail.new do
774
+ from 'mikel@test.lindsaar.net'
775
+ to 'you@test.lindsaar.net'
776
+ subject 'This is a test email'
777
+ body 'This is a body of the email'
778
+ end
779
+ mail.add_message_id
780
+ fqdn ||= ::Socket.gethostname
781
+ mail.to_s.should =~ /Message-ID: <[\d\w_]+@#{fqdn}.mail>\r\n/
782
+ end
783
+
784
+ it "should make an email and inject a message ID if none was set if told to_s" do
785
+ mail = Mail.new do
786
+ from 'mikel@test.lindsaar.net'
787
+ to 'you@test.lindsaar.net'
788
+ subject 'This is a test email'
789
+ body 'This is a body of the email'
790
+ end
791
+ (mail.to_s =~ /Message-ID: <.+@.+.mail>/i).should_not be_nil
792
+ end
793
+
794
+ it "should add the message id to the message permanently once sent to_s" do
795
+ mail = Mail.new do
796
+ from 'mikel@test.lindsaar.net'
797
+ to 'you@test.lindsaar.net'
798
+ subject 'This is a test email'
799
+ body 'This is a body of the email'
800
+ end
801
+ mail.to_s
802
+ mail.should be_has_message_id
803
+ end
804
+
805
+ it "should add a body part if it is missing" do
806
+ mail = Mail.new
807
+ mail.to_s
808
+ mail.body.class.should == Mail::Body
809
+ end
810
+ end
811
+
812
+ describe "Date" do
813
+ it "should say if it has a date" do
814
+ mail = Mail.new do
815
+ from 'mikel@test.lindsaar.net'
816
+ to 'you@test.lindsaar.net'
817
+ subject 'This is a test email'
818
+ body 'This is a body of the email'
819
+ end
820
+ mail.should_not be_has_date
821
+ end
822
+
823
+ it "should preserve any date that you pass it if add_date is called explicitly" do
824
+ mail = Mail.new do
825
+ from 'mikel@test.lindsaar.net'
826
+ to 'you@test.lindsaar.net'
827
+ subject 'This is a test email'
828
+ body 'This is a body of the email'
829
+ end
830
+ mail.add_date("Mon, 24 Nov 1997 14:22:01 -0800")
831
+ mail.to_s.should =~ /Date: Mon, 24 Nov 1997 14:22:01 -0800/
832
+ end
833
+
834
+ it "should generate a current date if nothing is passed to add_date" do
835
+ mail = Mail.new do
836
+ from 'mikel@test.lindsaar.net'
837
+ to 'you@test.lindsaar.net'
838
+ subject 'This is a test email'
839
+ body 'This is a body of the email'
840
+ end
841
+ mail.add_date
842
+ mail.to_s.should =~ /Date: \w{3}, [\s\d]\d \w{3} \d{4} \d{2}:\d{2}:\d{2} [-+]?\d{4}\r\n/
843
+ end
844
+
845
+ it "should make an email and inject a date if none was set if told to_s" do
846
+ mail = Mail.new do
847
+ from 'mikel@test.lindsaar.net'
848
+ to 'you@test.lindsaar.net'
849
+ subject 'This is a test email'
850
+ body 'This is a body of the email'
851
+ end
852
+ mail.to_s.should =~ /Date: \w{3}, [\s\d]\d \w{3} \d{4} \d{2}:\d{2}:\d{2} [-+]?\d{4}\r\n/
853
+ end
854
+
855
+ it "should add the date to the message permanently once sent to_s" do
856
+ mail = Mail.new do
857
+ from 'mikel@test.lindsaar.net'
858
+ to 'you@test.lindsaar.net'
859
+ subject 'This is a test email'
860
+ body 'This is a body of the email'
861
+ end
862
+ mail.to_s
863
+ mail.should be_has_date
864
+ end
865
+ end
866
+
867
+ end
868
+
869
+ describe "mime emails" do
870
+
871
+ describe "mime-version" do
872
+ it "should say if it has a mime-version" do
873
+ mail = Mail.new do
874
+ from 'mikel@test.lindsaar.net'
875
+ to 'you@test.lindsaar.net'
876
+ subject 'This is a test email'
877
+ body 'This is a body of the email'
878
+ end
879
+ mail.should_not be_has_mime_version
880
+ end
881
+
882
+ it "should preserve any mime version that you pass it if add_mime_version is called explicitly" do
883
+ mail = Mail.new do
884
+ from 'mikel@test.lindsaar.net'
885
+ to 'you@test.lindsaar.net'
886
+ subject 'This is a test email'
887
+ body 'This is a body of the email'
888
+ end
889
+ mail.add_mime_version("3.0 (This is an unreal version number)")
890
+ mail.to_s.should =~ /Mime-Version: 3.0\r\n/
891
+ end
892
+
893
+ it "should generate a mime version if nothing is passed to add_date" do
894
+ mail = Mail.new do
895
+ from 'mikel@test.lindsaar.net'
896
+ to 'you@test.lindsaar.net'
897
+ subject 'This is a test email'
898
+ body 'This is a body of the email'
899
+ end
900
+ mail.add_mime_version
901
+ mail.to_s.should =~ /Mime-Version: 1.0\r\n/
902
+ end
903
+
904
+ it "should make an email and inject a mime_version if none was set if told to_s" do
905
+ mail = Mail.new do
906
+ from 'mikel@test.lindsaar.net'
907
+ to 'you@test.lindsaar.net'
908
+ subject 'This is a test email'
909
+ body 'This is a body of the email'
910
+ end
911
+ mail.to_s.should =~ /Mime-Version: 1.0\r\n/
912
+ end
913
+
914
+ it "should add the mime version to the message permanently once sent to_s" do
915
+ mail = Mail.new do
916
+ from 'mikel@test.lindsaar.net'
917
+ to 'you@test.lindsaar.net'
918
+ subject 'This is a test email'
919
+ body 'This is a body of the email'
920
+ end
921
+ mail.to_s
922
+ mail.should be_has_mime_version
923
+ end
924
+ end
925
+
926
+ describe "content type" do
927
+
928
+ it "should say if it has a content type" do
929
+ mail = Mail.new('Content-Type: text/plain')
930
+ mail.should be_has_content_type
931
+ end
932
+
933
+ it "should say if it does not have a content type" do
934
+ mail = Mail.new
935
+ mail.should_not be_has_content_type
936
+ end
937
+
938
+ it "should say if it has a charset" do
939
+ mail = Mail.new('Content-Type: text/plain; charset=US-ASCII')
940
+ mail.should be_has_charset
941
+ end
942
+
943
+ it "should say if it has a charset" do
944
+ mail = Mail.new('Content-Type: text/plain')
945
+ mail.should_not be_has_charset
946
+ end
947
+
948
+ it "should not raise a warning if there is no charset defined and only US-ASCII chars" do
949
+ body = "This is plain text US-ASCII"
950
+ mail = Mail.new
951
+ mail.body = body
952
+ STDERR.should_not_receive(:puts)
953
+ mail.to_s
954
+ end
955
+
956
+ it "should set the content type to text/plain; charset=us-ascii" do
957
+ body = "This is plain text US-ASCII"
958
+ mail = Mail.new
959
+ mail.body = body
960
+ mail.to_s =~ %r{Content-Type: text/plain; charset=US-ASCII}
961
+ end
962
+
963
+ it "should not set the charset if the file is an attachment" do
964
+ body = "This is plain text US-ASCII"
965
+ mail = Mail.new
966
+ mail.body = body
967
+ mail.content_disposition = 'attachment; filename="foo.jpg"'
968
+ mail.to_s =~ %r{Content-Type: text/plain;\r\n}
969
+ end
970
+
971
+ it "should raise a warning if there is no content type and there is non ascii chars and default to text/plain, UTF-8" do
972
+ body = "This is NOT plain text ASCII − かきくけこ"
973
+ mail = Mail.new
974
+ mail.body = body
975
+ mail.content_transfer_encoding = "8bit"
976
+ STDERR.should_receive(:puts).with(/Non US-ASCII detected and no charset defined.\nDefaulting to UTF-8, set your own if this is incorrect./m)
977
+ mail.to_s =~ %r{Content-Type: text/plain; charset=UTF-8}
978
+ end
979
+
980
+ it "should raise a warning if there is no charset parameter and there is non ascii chars and default to text/plain, UTF-8" do
981
+ body = "This is NOT plain text ASCII − かきくけこ"
982
+ mail = Mail.new
983
+ mail.body = body
984
+ mail.content_type = "text/plain"
985
+ mail.content_transfer_encoding = "8bit"
986
+ STDERR.should_receive(:puts).with(/Non US-ASCII detected and no charset defined.\nDefaulting to UTF-8, set your own if this is incorrect./m)
987
+ mail.to_s =~ %r{Content-Type: text/plain; charset=UTF-8}
988
+ end
989
+
990
+ it "should not raise a warning if there is a charset defined and there is non ascii chars" do
991
+ body = "This is NOT plain text ASCII − かきくけこ"
992
+ mail = Mail.new
993
+ mail.body = body
994
+ mail.content_transfer_encoding = "8bit"
995
+ mail.content_type = "text/plain; charset=UTF-8"
996
+ STDERR.should_not_receive(:puts)
997
+ mail.to_s
998
+ end
999
+
1000
+ it "should be able to set a content type with an array and hash" do
1001
+ mail = Mail.new
1002
+ mail.content_type = ["text", "plain", { "charset" => 'US-ASCII' }]
1003
+ mail[:content_type].encoded.should == %Q[Content-Type: text/plain;\r\n\tcharset=US-ASCII\r\n]
1004
+ mail.content_type_parameters.should == {"charset" => "US-ASCII"}
1005
+ end
1006
+
1007
+ it "should be able to set a content type with an array and hash with a non-usascii field" do
1008
+ mail = Mail.new
1009
+ mail.content_type = ["text", "plain", { "charset" => 'UTF-8' }]
1010
+ mail[:content_type].encoded.should == %Q[Content-Type: text/plain;\r\n\tcharset=UTF-8\r\n]
1011
+ mail.content_type_parameters.should == {"charset" => "UTF-8"}
1012
+ end
1013
+
1014
+ it "should allow us to specify a content type in a block" do
1015
+ mail = Mail.new { content_type ["text", "plain", { "charset" => "UTF-8" }] }
1016
+ mail.content_type_parameters.should == {"charset" => "UTF-8"}
1017
+ end
1018
+
1019
+ end
1020
+
1021
+ describe "content-transfer-encoding" do
1022
+
1023
+ it "should use 7bit for only US-ASCII chars" do
1024
+ body = "This is plain text US-ASCII"
1025
+ mail = Mail.new
1026
+ mail.body = body
1027
+ mail.to_s.should =~ %r{Content-Transfer-Encoding: 7bit}
1028
+ end
1029
+
1030
+ it "should use QP transfer encoding for 8bit text with only a few 8bit characters" do
1031
+ body = "Maxfeldstraße 5, 90409 Nürnberg"
1032
+ mail = Mail.new
1033
+ mail.charset = "UTF-8"
1034
+ mail.body = body
1035
+ mail.to_s.should =~ %r{Content-Transfer-Encoding: quoted-printable}
1036
+ end
1037
+
1038
+ it "should use base64 transfer encoding for 8-bit text with lots of 8bit characters" do
1039
+ body = "This is NOT plain text ASCII − かきくけこ"
1040
+ mail = Mail.new
1041
+ mail.charset = "UTF-8"
1042
+ mail.body = body
1043
+ mail.content_type = "text/plain; charset=utf-8"
1044
+ mail.should be_has_content_type
1045
+ mail.should be_has_charset
1046
+ mail.to_s.should =~ %r{Content-Transfer-Encoding: base64}
1047
+ end
1048
+
1049
+ it "should not use 8bit transfer encoding when 8bit is allowed" do
1050
+ body = "This is NOT plain text ASCII − かきくけこ"
1051
+ mail = Mail.new
1052
+ mail.charset = "UTF-8"
1053
+ mail.body = body
1054
+ mail.content_type = "text/plain; charset=utf-8"
1055
+ mail.transport_encoding = "8bit"
1056
+ mail.to_s.should =~ %r{Content-Transfer-Encoding: 8bit}
1057
+ end
1058
+
1059
+ end
1060
+
1061
+ end
1062
+
1063
+ end
1064
+
1065
+ describe "output" do
1066
+
1067
+ it "should make an email and allow you to call :to_s on it to get a string" do
1068
+ mail = Mail.new do
1069
+ from 'mikel@test.lindsaar.net'
1070
+ to 'you@test.lindsaar.net'
1071
+ subject 'This is a test email'
1072
+ body 'This is a body of the email'
1073
+ end
1074
+
1075
+ mail.to_s.should =~ /From: mikel@test.lindsaar.net\r\n/
1076
+ mail.to_s.should =~ /To: you@test.lindsaar.net\r\n/
1077
+ mail.to_s.should =~ /Subject: This is a test email\r\n/
1078
+ mail.to_s.should =~ /This is a body of the email/
1079
+
1080
+ end
1081
+
1082
+ it "should raise an error and message if you try and call decoded on a multipart email" do
1083
+ mail = Mail.new do
1084
+ to 'mikel@test.lindsaar.net'
1085
+ from 'bob@test.lindsaar.net'
1086
+ subject 'Multipart email'
1087
+ text_part do
1088
+ body 'This is plain text'
1089
+ end
1090
+ html_part do
1091
+ content_type 'text/html; charset=UTF-8'
1092
+ body '<h1>This is HTML</h1>'
1093
+ end
1094
+ end
1095
+ doing { mail.decoded }.should raise_error(NoMethodError, 'Can not decode an entire message, try calling #decoded on the various fields and body or parts if it is a multipart message.')
1096
+ end
1097
+
1098
+ it "should return the decoded body if you call decode and the message is not multipart" do
1099
+ mail = Mail.new do
1100
+ content_transfer_encoding 'base64'
1101
+ body "VGhlIGJvZHk=\n"
1102
+ end
1103
+ mail.decoded.should == "The body"
1104
+ end
1105
+
1106
+ describe "decoding bodies" do
1107
+
1108
+ it "should not change a body on decode if not given an encoding type to decode" do
1109
+ mail = Mail.new do
1110
+ body "The=3Dbody"
1111
+ end
1112
+ mail.body.decoded.should == "The=3Dbody"
1113
+ mail.body.encoded.should == "The=3Dbody"
1114
+ end
1115
+
1116
+ it "should change a body on decode if given an encoding type to decode" do
1117
+ mail = Mail.new do
1118
+ content_transfer_encoding 'quoted-printable'
1119
+ body "The=3Dbody"
1120
+ end
1121
+ mail.body.decoded.should == "The=body"
1122
+ mail.body.encoded.should == "The=3Dbody=\r\n"
1123
+ end
1124
+
1125
+ it "should change a body on decode if given an encoding type to decode" do
1126
+ mail = Mail.new do
1127
+ content_transfer_encoding 'base64'
1128
+ body "VGhlIGJvZHk=\n"
1129
+ end
1130
+ mail.body.decoded.should == "The body"
1131
+ mail.body.encoded.should == "VGhlIGJvZHk=\r\n"
1132
+ end
1133
+
1134
+ end
1135
+
1136
+ end
1137
+
1138
+ describe "helper methods" do
1139
+
1140
+ describe "==" do
1141
+ it "should be implemented" do
1142
+ doing { Mail.new == Mail.new }.should_not raise_error
1143
+ end
1144
+
1145
+ it "should ignore the message id value if both have a nil message id" do
1146
+ m1 = Mail.new("To: mikel@test.lindsaar.net\r\nSubject: Yo!\r\n\r\nHello there")
1147
+ m2 = Mail.new("To: mikel@test.lindsaar.net\r\nSubject: Yo!\r\n\r\nHello there")
1148
+ m1.should == m2
1149
+ end
1150
+
1151
+ it "should ignore the message id value if self has a nil message id" do
1152
+ m1 = Mail.new("To: mikel@test.lindsaar.net\r\nSubject: Yo!\r\n\r\nHello there")
1153
+ m2 = Mail.new("To: mikel@test.lindsaar.net\r\nMessage-ID: <1234@test.lindsaar.net>\r\nSubject: Yo!\r\n\r\nHello there")
1154
+ m1.should == m2
1155
+ end
1156
+
1157
+ it "should ignore the message id value if other has a nil message id" do
1158
+ m1 = Mail.new("To: mikel@test.lindsaar.net\r\nMessage-ID: <1234@test.lindsaar.net>\r\nSubject: Yo!\r\n\r\nHello there")
1159
+ m2 = Mail.new("To: mikel@test.lindsaar.net\r\nSubject: Yo!\r\n\r\nHello there")
1160
+ m1.should == m2
1161
+ end
1162
+
1163
+ it "should not be == if both emails have different Message IDs" do
1164
+ m1 = Mail.new("To: mikel@test.lindsaar.net\r\nMessage-ID: <4321@test.lindsaar.net>\r\nSubject: Yo!\r\n\r\nHello there")
1165
+ m2 = Mail.new("To: mikel@test.lindsaar.net\r\nMessage-ID: <1234@test.lindsaar.net>\r\nSubject: Yo!\r\n\r\nHello there")
1166
+ m1.should_not == m2
1167
+ end
1168
+
1169
+ it "should preserve the message id of self if set" do
1170
+ m1 = Mail.new("To: mikel@test.lindsaar.net\r\nMessage-ID: <1234@test.lindsaar.net>\r\nSubject: Yo!\r\n\r\nHello there")
1171
+ m2 = Mail.new("To: mikel@test.lindsaar.net\r\nSubject: Yo!\r\n\r\nHello there")
1172
+ m1 == m2
1173
+ m1.message_id.should == '1234@test.lindsaar.net'
1174
+ end
1175
+
1176
+ it "should preserve the message id of other if set" do
1177
+ m1 = Mail.new("To: mikel@test.lindsaar.net\r\nSubject: Yo!\r\n\r\nHello there")
1178
+ m2 = Mail.new("To: mikel@test.lindsaar.net\r\nMessage-ID: <1234@test.lindsaar.net>\r\nSubject: Yo!\r\n\r\nHello there")
1179
+ m1 == m2
1180
+ m2.message_id.should == '1234@test.lindsaar.net'
1181
+ end
1182
+
1183
+ it "should preserve the message id of both if set" do
1184
+ m1 = Mail.new("To: mikel@test.lindsaar.net\r\nMessage-ID: <4321@test.lindsaar.net>\r\nSubject: Yo!\r\n\r\nHello there")
1185
+ m2 = Mail.new("To: mikel@test.lindsaar.net\r\nMessage-ID: <1234@test.lindsaar.net>\r\nSubject: Yo!\r\n\r\nHello there")
1186
+ m1 == m2
1187
+ m1.message_id.should == '4321@test.lindsaar.net'
1188
+ m2.message_id.should == '1234@test.lindsaar.net'
1189
+ end
1190
+ end
1191
+
1192
+ it "should implement the spaceship operator on the date field" do
1193
+ now = Time.now
1194
+ mail1 = Mail.new do
1195
+ date(now)
1196
+ end
1197
+ mail2 = Mail.new do
1198
+ date(now - 10) # Make mail2 10 seconds 'older'
1199
+ end
1200
+ [mail2, mail1].sort.should == [mail2, mail1]
1201
+ end
1202
+
1203
+ it "should have a destinations method" do
1204
+ mail = Mail.new do
1205
+ to 'mikel@test.lindsaar.net'
1206
+ cc 'bob@test.lindsaar.net'
1207
+ bcc 'sam@test.lindsaar.net'
1208
+ end
1209
+ mail.destinations.length.should == 3
1210
+ end
1211
+
1212
+ it "should have a from_addrs method" do
1213
+ mail = Mail.new do
1214
+ from 'mikel@test.lindsaar.net'
1215
+ end
1216
+ mail.from_addrs.length.should == 1
1217
+ end
1218
+
1219
+ it "should have a from_addrs method that is empty if nil" do
1220
+ mail = Mail.new do
1221
+ end
1222
+ mail.from_addrs.length.should == 0
1223
+ end
1224
+
1225
+ it "should have a to_addrs method" do
1226
+ mail = Mail.new do
1227
+ to 'mikel@test.lindsaar.net'
1228
+ end
1229
+ mail.to_addrs.length.should == 1
1230
+ end
1231
+
1232
+ it "should have a to_addrs method that is empty if nil" do
1233
+ mail = Mail.new do
1234
+ end
1235
+ mail.to_addrs.length.should == 0
1236
+ end
1237
+
1238
+ it "should have a cc_addrs method" do
1239
+ mail = Mail.new do
1240
+ cc 'bob@test.lindsaar.net'
1241
+ end
1242
+ mail.cc_addrs.length.should == 1
1243
+ end
1244
+
1245
+ it "should have a cc_addrs method that is empty if nil" do
1246
+ mail = Mail.new do
1247
+ end
1248
+ mail.cc_addrs.length.should == 0
1249
+ end
1250
+
1251
+ it "should have a bcc_addrs method" do
1252
+ mail = Mail.new do
1253
+ bcc 'sam@test.lindsaar.net'
1254
+ end
1255
+ mail.bcc_addrs.length.should == 1
1256
+ end
1257
+
1258
+ it "should have a bcc_addrs method that is empty if nil" do
1259
+ mail = Mail.new do
1260
+ end
1261
+ mail.bcc_addrs.length.should == 0
1262
+ end
1263
+
1264
+ it "should give destinations even if some of the fields are blank" do
1265
+ mail = Mail.new do
1266
+ to 'mikel@test.lindsaar.net'
1267
+ end
1268
+ mail.destinations.length.should == 1
1269
+ end
1270
+
1271
+ it "should be able to encode with only one destination" do
1272
+ mail = Mail.new do
1273
+ to 'mikel@test.lindsaar.net'
1274
+ end
1275
+ mail.encoded
1276
+ end
1277
+
1278
+ end
1279
+
1280
+ describe "nested parts" do
1281
+ it "should provide a way to instantiate a new part as you go down" do
1282
+ mail = Mail.new do
1283
+ to 'mikel@test.lindsaar.net'
1284
+ subject "nested multipart"
1285
+ from "test@example.com"
1286
+ content_type "multipart/mixed"
1287
+
1288
+ part :content_type => "multipart/alternative", :content_disposition => "inline", :headers => { "foo" => "bar" } do |p|
1289
+ p.part :content_type => "text/plain", :body => "test text\nline #2"
1290
+ p.part :content_type => "text/html", :body => "<b>test</b> HTML<br/>\nline #2"
1291
+ end
1292
+
1293
+ end
1294
+
1295
+ mail.parts.first.should be_multipart
1296
+ mail.parts.first.parts.length.should == 2
1297
+ mail.parts.first.parts[0][:content_type].string.should == "text/plain"
1298
+ mail.parts.first.parts[0].body.decoded.should == "test text\nline #2"
1299
+ mail.parts.first.parts[1][:content_type].string.should == "text/html"
1300
+ mail.parts.first.parts[1].body.decoded.should == "<b>test</b> HTML<br/>\nline #2"
1301
+ end
1302
+ end
1303
+
1304
+ describe "deliver" do
1305
+ it "should return self after delivery" do
1306
+ mail = Mail.new
1307
+ mail.perform_deliveries = false
1308
+ mail.deliver.should == mail
1309
+ end
1310
+
1311
+ class DeliveryAgent
1312
+ def self.deliver_mail(mail)
1313
+ end
1314
+ end
1315
+
1316
+ it "should pass self to a delivery agent" do
1317
+ mail = Mail.new
1318
+ mail.delivery_handler = DeliveryAgent
1319
+ DeliveryAgent.should_receive(:deliver_mail).with(mail)
1320
+ mail.deliver
1321
+ end
1322
+
1323
+ class ObserverAgent
1324
+ def self.delivered_email(mail)
1325
+ end
1326
+ end
1327
+
1328
+ it "should inform observers that the mail was sent" do
1329
+ mail = Mail.new
1330
+ mail.delivery_method :test
1331
+ Mail.register_observer(ObserverAgent)
1332
+ ObserverAgent.should_receive(:delivered_email).with(mail)
1333
+ mail.deliver
1334
+ end
1335
+
1336
+ it "should inform observers that the mail was sent, even if a delivery agent is used" do
1337
+ mail = Mail.new
1338
+ mail.delivery_handler = DeliveryAgent
1339
+ Mail.register_observer(ObserverAgent)
1340
+ ObserverAgent.should_receive(:delivered_email).with(mail)
1341
+ mail.deliver
1342
+ end
1343
+
1344
+ class InterceptorAgent
1345
+ @@intercept = false
1346
+ def self.intercept=(val)
1347
+ @@intercept = val
1348
+ end
1349
+ def self.delivering_email(mail)
1350
+ if @@intercept
1351
+ mail.to = 'bob@example.com'
1352
+ end
1353
+ end
1354
+ end
1355
+
1356
+ it "should pass to the interceptor the email just before it gets sent" do
1357
+ mail = Mail.new
1358
+ mail.delivery_method :test
1359
+ Mail.register_interceptor(InterceptorAgent)
1360
+ InterceptorAgent.should_receive(:delivering_email).with(mail)
1361
+ InterceptorAgent.intercept = true
1362
+ mail.deliver
1363
+ InterceptorAgent.intercept = false
1364
+ end
1365
+
1366
+ it "should let the interceptor that the mail was sent" do
1367
+ mail = Mail.new
1368
+ mail.to = 'fred@example.com'
1369
+ mail.delivery_method :test
1370
+ Mail.register_interceptor(InterceptorAgent)
1371
+ InterceptorAgent.intercept = true
1372
+ mail.deliver
1373
+ InterceptorAgent.intercept = false
1374
+ mail.to.should == ['bob@example.com']
1375
+ end
1376
+
1377
+ end
1378
+
1379
+ describe "error handling" do
1380
+ describe "error handling" do
1381
+ it "should collect up any of its fields' errors" do
1382
+ mail = Mail.new("Content-Transfer-Encoding: vlad\r\nReply-To: a b b\r\n")
1383
+ mail.errors.should_not be_blank
1384
+ mail.errors.size.should == 2
1385
+ mail.errors[0][0].should == 'Content-Transfer-Encoding'
1386
+ mail.errors[0][1].should == 'vlad'
1387
+ mail.errors[1][0].should == 'Reply-To'
1388
+ mail.errors[1][1].should == 'a b b'
1389
+ end
1390
+ end
1391
+ end
1392
+
1393
+ describe "header case should be preserved" do
1394
+ it "should handle mail[] and keep the header case" do
1395
+ mail = Mail.new
1396
+ mail['X-Foo-Bar'] = "Some custom text"
1397
+ mail.to_s.should match(/X-Foo-Bar: Some custom text/)
1398
+ end
1399
+ end
1400
+
1401
+ describe "parsing emails with non usascii in the header" do
1402
+ it "should work" do
1403
+ mail = Mail.new('From: "Foo áëô îü" <extended@example.net>')
1404
+ mail.from.should == ['extended@example.net']
1405
+ mail[:from].decoded.should == '"Foo áëô îü" <extended@example.net>'
1406
+ mail[:from].encoded.should == "From: =?UTF-8?B?Rm9vIMOhw6vDtCDDrsO8?= <extended@example.net>\r\n"
1407
+ end
1408
+ end
1409
+ end