kbaum-mail 2.1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +289 -0
- data/README.rdoc +575 -0
- data/Rakefile +72 -0
- data/TODO.rdoc +19 -0
- data/lib/mail.rb +113 -0
- data/lib/mail/attachments_list.rb +76 -0
- data/lib/mail/body.rb +243 -0
- data/lib/mail/configuration.rb +69 -0
- data/lib/mail/core_extensions/nil.rb +11 -0
- data/lib/mail/core_extensions/string.rb +19 -0
- data/lib/mail/elements/address.rb +306 -0
- data/lib/mail/elements/address_list.rb +74 -0
- data/lib/mail/elements/content_disposition_element.rb +30 -0
- data/lib/mail/elements/content_location_element.rb +25 -0
- data/lib/mail/elements/content_transfer_encoding_element.rb +21 -0
- data/lib/mail/elements/content_type_element.rb +35 -0
- data/lib/mail/elements/date_time_element.rb +26 -0
- data/lib/mail/elements/envelope_from_element.rb +34 -0
- data/lib/mail/elements/message_ids_element.rb +29 -0
- data/lib/mail/elements/mime_version_element.rb +26 -0
- data/lib/mail/elements/phrase_list.rb +21 -0
- data/lib/mail/elements/received_element.rb +30 -0
- data/lib/mail/encodings/base64.rb +18 -0
- data/lib/mail/encodings/encodings.rb +201 -0
- data/lib/mail/encodings/quoted_printable.rb +26 -0
- data/lib/mail/envelope.rb +35 -0
- data/lib/mail/field.rb +219 -0
- data/lib/mail/field_list.rb +33 -0
- data/lib/mail/fields/bcc_field.rb +53 -0
- data/lib/mail/fields/cc_field.rb +52 -0
- data/lib/mail/fields/comments_field.rb +41 -0
- data/lib/mail/fields/common/address_container.rb +16 -0
- data/lib/mail/fields/common/common_address.rb +128 -0
- data/lib/mail/fields/common/common_date.rb +51 -0
- data/lib/mail/fields/common/common_field.rb +64 -0
- data/lib/mail/fields/common/common_message_id.rb +57 -0
- data/lib/mail/fields/common/parameter_hash.rb +39 -0
- data/lib/mail/fields/content_description_field.rb +19 -0
- data/lib/mail/fields/content_disposition_field.rb +60 -0
- data/lib/mail/fields/content_id_field.rb +63 -0
- data/lib/mail/fields/content_location_field.rb +42 -0
- data/lib/mail/fields/content_transfer_encoding_field.rb +45 -0
- data/lib/mail/fields/content_type_field.rb +175 -0
- data/lib/mail/fields/date_field.rb +53 -0
- data/lib/mail/fields/from_field.rb +53 -0
- data/lib/mail/fields/in_reply_to_field.rb +52 -0
- data/lib/mail/fields/keywords_field.rb +43 -0
- data/lib/mail/fields/message_id_field.rb +80 -0
- data/lib/mail/fields/mime_version_field.rb +54 -0
- data/lib/mail/fields/optional_field.rb +11 -0
- data/lib/mail/fields/received_field.rb +62 -0
- data/lib/mail/fields/references_field.rb +53 -0
- data/lib/mail/fields/reply_to_field.rb +53 -0
- data/lib/mail/fields/resent_bcc_field.rb +53 -0
- data/lib/mail/fields/resent_cc_field.rb +53 -0
- data/lib/mail/fields/resent_date_field.rb +33 -0
- data/lib/mail/fields/resent_from_field.rb +53 -0
- data/lib/mail/fields/resent_message_id_field.rb +32 -0
- data/lib/mail/fields/resent_sender_field.rb +60 -0
- data/lib/mail/fields/resent_to_field.rb +53 -0
- data/lib/mail/fields/return_path_field.rb +62 -0
- data/lib/mail/fields/sender_field.rb +65 -0
- data/lib/mail/fields/structured_field.rb +36 -0
- data/lib/mail/fields/subject_field.rb +15 -0
- data/lib/mail/fields/to_field.rb +53 -0
- data/lib/mail/fields/unstructured_field.rb +117 -0
- data/lib/mail/header.rb +235 -0
- data/lib/mail/mail.rb +194 -0
- data/lib/mail/message.rb +1780 -0
- data/lib/mail/network/delivery_methods/file_delivery.rb +40 -0
- data/lib/mail/network/delivery_methods/sendmail.rb +62 -0
- data/lib/mail/network/delivery_methods/smtp.rb +110 -0
- data/lib/mail/network/delivery_methods/test_mailer.rb +40 -0
- data/lib/mail/network/retriever_methods/imap.rb +31 -0
- data/lib/mail/network/retriever_methods/pop3.rb +149 -0
- data/lib/mail/parsers/address_lists.rb +61 -0
- data/lib/mail/parsers/address_lists.treetop +19 -0
- data/lib/mail/parsers/content_disposition.rb +369 -0
- data/lib/mail/parsers/content_disposition.treetop +46 -0
- data/lib/mail/parsers/content_location.rb +133 -0
- data/lib/mail/parsers/content_location.treetop +20 -0
- data/lib/mail/parsers/content_transfer_encoding.rb +179 -0
- data/lib/mail/parsers/content_transfer_encoding.treetop +25 -0
- data/lib/mail/parsers/content_type.rb +512 -0
- data/lib/mail/parsers/content_type.treetop +58 -0
- data/lib/mail/parsers/date_time.rb +111 -0
- data/lib/mail/parsers/date_time.treetop +11 -0
- data/lib/mail/parsers/envelope_from.rb +188 -0
- data/lib/mail/parsers/envelope_from.treetop +32 -0
- data/lib/mail/parsers/message_ids.rb +42 -0
- data/lib/mail/parsers/message_ids.treetop +15 -0
- data/lib/mail/parsers/mime_version.rb +141 -0
- data/lib/mail/parsers/mime_version.treetop +19 -0
- data/lib/mail/parsers/phrase_lists.rb +42 -0
- data/lib/mail/parsers/phrase_lists.treetop +15 -0
- data/lib/mail/parsers/received.rb +68 -0
- data/lib/mail/parsers/received.treetop +11 -0
- data/lib/mail/parsers/rfc2045.rb +406 -0
- data/lib/mail/parsers/rfc2045.treetop +35 -0
- data/lib/mail/parsers/rfc2822.rb +5081 -0
- data/lib/mail/parsers/rfc2822.treetop +410 -0
- data/lib/mail/parsers/rfc2822_obsolete.rb +3607 -0
- data/lib/mail/parsers/rfc2822_obsolete.treetop +241 -0
- data/lib/mail/part.rb +82 -0
- data/lib/mail/parts_list.rb +34 -0
- data/lib/mail/patterns.rb +43 -0
- data/lib/mail/utilities.rb +163 -0
- data/lib/mail/vendor/treetop.rb +4 -0
- data/lib/mail/version.rb +10 -0
- data/lib/mail/version_specific/ruby_1_8.rb +84 -0
- data/lib/mail/version_specific/ruby_1_9.rb +77 -0
- data/lib/tasks/corpus.rake +125 -0
- data/lib/tasks/treetop.rake +10 -0
- metadata +188 -0
data/CHANGELOG.rdoc
ADDED
@@ -0,0 +1,289 @@
|
|
1
|
+
== Thu Jan 28 00:25:02 UTC 2010 Mikel Lindsaar <raasdnil@gmail.com>
|
2
|
+
|
3
|
+
* Added TMM1's patch to not raise errors if a email is not multipart/report
|
4
|
+
* Added html_part and text_part now return the first text/html or text/plain part they find. Order is from top to bottom of the email, all parts, flattened.
|
5
|
+
* Version bump to 2.1.2
|
6
|
+
|
7
|
+
== Mon Jan 25 11:36:13 UTC 2010 Mikel Lindsaar <raasdnil@gmail.com>
|
8
|
+
|
9
|
+
* Added ability for address fields to init on an array instead of just a string.
|
10
|
+
* Version bump to 2.1.1
|
11
|
+
|
12
|
+
== Mon Jan 25 10:36:33 UTC 2010 Mikel Lindsaar <raasdnil@gmail.com>
|
13
|
+
|
14
|
+
* Now passes a block to the delivery handler, which can just call yield if it want's Mail to just do it's normal delivery method
|
15
|
+
* Moved Mail.deliveries into Mail::TestMailer.deliveries. Now only gets mail appended to it if you are sending with the :test delivery_method (only for testing)
|
16
|
+
* Version bump to 2.1.0
|
17
|
+
|
18
|
+
== Mon Jan 25 01:44:13 UTC 2010 Mikel Lindsaar <raasdnil@gmail.com>
|
19
|
+
|
20
|
+
* Change :deliver! to deliver a mail object, bypassing the :perform_deliveries and :raise_delivery_errors flags, also does not append the mail object to Mail.deliveries, thus the ! (dangerous). The intended use for :deliver! is for people wanting to have their own delivery_handler (like ActionMailer uses) to track and handle delivery failures.
|
21
|
+
* Added :delivery_handler to Message. Allows you to pass an object that will be sent :deliver_mail(self) by the Mail::Message instance when it is sent :deliver and bypasses the usual delivery method.
|
22
|
+
* Changed :perform_deliveries flag to be more consistent with it's name, mail will not append itself to the Mail.deliveries collection if :perform_deliveries is false
|
23
|
+
|
24
|
+
== Sat Jan 23 23:49:50 UTC 2010 Mikel Lindsaar <raasdnil@gmail.com>
|
25
|
+
|
26
|
+
* Version bump to 2.0.5
|
27
|
+
* Added :raise_delivery_errors to Mail::Message, if set to false will silently rescue all errors raised by the delivery methods, set to true by default
|
28
|
+
|
29
|
+
== Sat Jan 23 23:28:42 UTC 2010 Mikel Lindsaar <raasdnil@gmail.com>
|
30
|
+
|
31
|
+
* Version bump to 2.0.4
|
32
|
+
* Added :perform_deliveries to mail, will not actually call deliver on the delivery method if this is set to false, set to true by default.
|
33
|
+
* Added @delivery_notification_observers to mail messages, you can register an observer with mail by calling mail.register_for_delivery_notification(observer) and then when mail is told to :deliver it will call your observer with observer.delivered_email(self). It will call your observer if it actually performed the delivery or not (that is, irregardless of the :perform_deliveries flag)
|
34
|
+
* Added ability to overwrite the Mail.deliveries store with an object of your choice instead of just an array, this is a good way to find out if something actually got delivered as if :perform_deliveries is false, this collection will not get the mail message appended
|
35
|
+
|
36
|
+
== Sat Jan 23 05:32:53 UTC 2010 Mikel Lindsaar <raasdnil@gmail.com>
|
37
|
+
|
38
|
+
* Version bump to 2.0.3
|
39
|
+
* Made body.sort_parts! recursive, to do the entire body
|
40
|
+
* Added ability to use << on the results returned by the various address fields, ie, mail.to << 'new@address' now works
|
41
|
+
* Message now adds multipart/mixed as the content type if nothing is set and there are parts to the message
|
42
|
+
* Added #display_names and #addrs to all address fields. #addrs returns the actual Mail::Address object for each address in the field.
|
43
|
+
* Body should call to_s on given input... incase someone gave it an IO.readlines result (Array)
|
44
|
+
*
|
45
|
+
|
46
|
+
== Thu Jan 21 05:27:17 UTC 2010 Mikel Lindsaar <raasdnil@gmail.com>
|
47
|
+
|
48
|
+
* Version bump to 2.0.2
|
49
|
+
* Major change to attachments, add_file now only accepts
|
50
|
+
{:filename => 'full/path/to/file.png'} or
|
51
|
+
{:filename => 'file.png', :content => 'string of file content'}
|
52
|
+
you can also now do mail.attachments['filename.png'] = File.read('path/to/file.png')
|
53
|
+
which is nice too!
|
54
|
+
|
55
|
+
== Fri Jan 15 09:20:51 UTC 2010 Mikel Lindsaar <raasdnil@gmail.com>
|
56
|
+
|
57
|
+
* Rewrote all network classes to not use singletons. Means different Mail::Message objects can have different delivery methods.
|
58
|
+
* Added examples for how to send via GMail, MobileMe, Sendmail, File etc.
|
59
|
+
* Version bump to 2.0.0 as Network API changed drastically, now not a singleton class.
|
60
|
+
* Fixed that return-path should only return one address
|
61
|
+
|
62
|
+
== Thu Jan 14 10:41:22 UTC 2010 Mikel Lindsaar <raasdnil@gmail.com>
|
63
|
+
|
64
|
+
* Version update to 1.6.0 - API change on mail.address_fields to always return arrays
|
65
|
+
* Updated all message.address_field methods to always return arrays, so mail.from #=> ['one@address.com'] now, is least surprise
|
66
|
+
* Updated handling of empty group lists so it didn't crash
|
67
|
+
|
68
|
+
== Thu Jan 12 10:41:47 UTC 2010 Mikel Lindsaar <raasdnil@gmail.com>
|
69
|
+
|
70
|
+
* Version 1.5.3, handling invalid input on fields. Highly recommended update
|
71
|
+
* Updated fields to always try parsing the given data (unless blank). This allows mail to catch invalid input and return UnstructuredFields. Makes mail a lot more resistant to invalid input.
|
72
|
+
|
73
|
+
== Fri 8 Jan 2010 00:00:08 UTC Mikel Lindsaar <raasdnil@gmail.com>
|
74
|
+
|
75
|
+
* Version bump to 1.5.2
|
76
|
+
|
77
|
+
== Fri 8 Jan 8:55:49 2010 +1100 Mikel Lindsaar <raasdnil@gmail.com>
|
78
|
+
|
79
|
+
* Updated Sendmail and SMTP delivery methods to use return-path if present
|
80
|
+
* Fix up a lot of content-type parsing problems
|
81
|
+
* Updating compat listing
|
82
|
+
* Moving error emails into one directory
|
83
|
+
* Moving error emails into one directory
|
84
|
+
* Initializing @tls variable to remove warnings
|
85
|
+
* Moved default corpus directory
|
86
|
+
* Fixed up git ignore file
|
87
|
+
|
88
|
+
== Thu 6 Jan 2010 23:59:29 UTC Mikel Lindsaar <raasdnil@gmail.com>
|
89
|
+
|
90
|
+
* Added compatibility list to Readme.rdoc
|
91
|
+
* Fixing encoding of return path to be per RFC 2822, adding angle brackets around the addr_spec
|
92
|
+
* Specs covering return path setting and preserving
|
93
|
+
|
94
|
+
== Thu 5 Jan 2010 23:59:48 UTC Mikel Lindsaar <raasdnil@gmail.com>
|
95
|
+
|
96
|
+
* Moving the require for tlsmail for Ruby 1.8.6 into mail.rb
|
97
|
+
|
98
|
+
== Sun Jan 3 00:08:06 UTC 2010 Mikel Lindsaar <raasdnil@gmail.com>
|
99
|
+
|
100
|
+
* Version bump to 1.5.0
|
101
|
+
|
102
|
+
* Major API change in Message#field_name. This WILL break your applications that use Mail. Message#field_name now returns good, intelligent, default values. You can still access the field object by calling Message#[:field_name] or Message#['field_name'].
|
103
|
+
|
104
|
+
== Sat Jan 2 04:12:53 UTC 2010 Mikel Lindsaar <raasdnil@gmail.com>
|
105
|
+
|
106
|
+
* Message-ID, Content-ID, References et al, now return the default value of the message ID without the angle brackets, as per RFC 2822, "Semantically, the angle bracket characters are not part of the msg-id; the msg-id is what is contained between the two angle bracket characters."
|
107
|
+
|
108
|
+
* Message class now has getter and setter methods for all the supported field types explicitly. This allows us to return a "default" value for all fields.
|
109
|
+
|
110
|
+
* All address fields, when called from Message#to or Message#from or the like, return either a string of the address spec (mikel@test.lindsaar.net) if it is a single entry, or an array of address specs if there is more than one ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
|
111
|
+
|
112
|
+
== Mon 28 Dec 2009 01:21:52 UTC Mikel Lindsaar <raasdnil@gmail.com>
|
113
|
+
|
114
|
+
* Added sorting of parts, default is text/plain, then text/enriched and text/html. Access through Body#set_sort_order and Body#sort_parts! (called from Body#encode automatically)
|
115
|
+
* Version bump to 1.4.2
|
116
|
+
|
117
|
+
== Sun Dec 27 10:38:24 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
118
|
+
|
119
|
+
* Updating treetop and mail to initialize uninitialized instance variables to
|
120
|
+
nil
|
121
|
+
* Version bump to 1.4.1
|
122
|
+
|
123
|
+
== Sun Dec 27 09:51:27 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
124
|
+
|
125
|
+
* Version bump to 1.4 because now :to_s calls :decoded for all fields and body
|
126
|
+
while :to_s calls :encoded for Message and Header containers. Makes sense...
|
127
|
+
really.
|
128
|
+
|
129
|
+
== Sun Dec 27 07:30:02 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
130
|
+
|
131
|
+
* Changed fields to default to :decoded on :to_s, all container objects
|
132
|
+
retain :encoded as the default for :to_s
|
133
|
+
|
134
|
+
== Thu Dec 17 06:35:05 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
135
|
+
|
136
|
+
* Fixed parsing error 'Subject: =?ISO-8859-1?Q?Re=3A_ol=E1?=' (has a new line embedded)
|
137
|
+
|
138
|
+
== Thu Dec 17 02:14:23 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
139
|
+
|
140
|
+
* Version 1.3.4
|
141
|
+
* Vendor'd treetop
|
142
|
+
|
143
|
+
== Thu Dec 17 01:32:00 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
144
|
+
|
145
|
+
* Version 1.3.3
|
146
|
+
* Removed dependency on treetop, don't need it at runtime
|
147
|
+
|
148
|
+
== Wed Dec 16 23:48:46 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
149
|
+
|
150
|
+
* Version 1.3.2
|
151
|
+
* Resolved Ruby 1.9.1-head not working because File.basename only accepts US-ASCII or 8Bit
|
152
|
+
|
153
|
+
== Sun Dec 13 01:06:17 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
154
|
+
|
155
|
+
* Version 1.3.1
|
156
|
+
* Resolved Issue #18 - Wrong instance variable name
|
157
|
+
* Resolved Issue #15 - Duplicate block call
|
158
|
+
|
159
|
+
== Thu Dec 10 21:25:37 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
160
|
+
|
161
|
+
* Resolved Issue #13 - replacing From field results in from field becoming optional field.
|
162
|
+
|
163
|
+
== Thu 3 Dec 2009 00:52:12 UTC Mikel Lindsaar <raasdnil@gmail.com>
|
164
|
+
|
165
|
+
* Added POP upgrades from Nicolas Fouché
|
166
|
+
* Added patch to handle multiple from lines in email from Luke Grimstrup
|
167
|
+
|
168
|
+
== Mon Nov 23 23:34:22 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
169
|
+
|
170
|
+
* Resolved Issue #12 - Wrong comment in smtp.rb
|
171
|
+
|
172
|
+
== Mon Nov 23 22:35:50 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
173
|
+
|
174
|
+
* Changed the way attachments are added so that it does not break depending on the order of the Hash passed in.
|
175
|
+
* Version bump to 1.3.0 - Now works with Edge ActionMailer, MRI 1.8.6, 1.8.7, 1.9.1, all tests passing
|
176
|
+
|
177
|
+
== Sun Nov 22 12:19:44 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
178
|
+
|
179
|
+
* Added check on add_part to make sure if there is already a body, and if so, make a text_part of the body
|
180
|
+
* Fixing up attachment adding and making sure multipart emails always have boundaries
|
181
|
+
* Change Message#attachments to now recursively return all attachments in the email in an ordered flattened array
|
182
|
+
* Added ability for Mail::Message to accept {:headers => {'custom-header' => 'value', 'another-custom-header' => 'value'}} as a param on init
|
183
|
+
* Adding ability to Mail::Message to add a part via :part(params) with optional block
|
184
|
+
* Fixed up QP encoding forcing underscores into everything with a space
|
185
|
+
* Added ReturnPathField#address
|
186
|
+
* Updating gem loads and active support loads
|
187
|
+
|
188
|
+
== Sat Nov 21 12:52:46 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
189
|
+
|
190
|
+
* Changed Mail::Encodings to clean it up, added in unquote_and_convert_to as well as refactor in this area
|
191
|
+
|
192
|
+
== Thu Nov 19 04:16:10 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
193
|
+
|
194
|
+
* Added sendmail support from (Simon Rozet)
|
195
|
+
* Changed to bundler for gem dependancies and moved gem generation into rakefile (Simon Rozet)
|
196
|
+
* Bumped to 1.2.6 for sendmail support
|
197
|
+
|
198
|
+
== Wed Nov 18 04:26:21 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
199
|
+
|
200
|
+
* Changed Encodings.param_encode(string) so it intelligently encodes and quotes needed
|
201
|
+
items and leaves plain, no special char, US-ASCII alone unquoted.
|
202
|
+
|
203
|
+
== Sat Nov 14 08:20:21 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
204
|
+
|
205
|
+
* Resolved Issue #10 - empty/nil cc/bcc field causes exception (Mail::Field::ParseError)
|
206
|
+
|
207
|
+
== Fri Nov 13 00:31:04 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
208
|
+
|
209
|
+
* Hacked and mutilated the network section, made it easier to extend out with other
|
210
|
+
delivery and retriever methods. API changed SLIGHTLY with this. Please check the
|
211
|
+
readme
|
212
|
+
* Resolved Issue #8 - Mail::SMTP now delivers to all mail.destinations
|
213
|
+
* Version bump to 1.2.5
|
214
|
+
|
215
|
+
== Thu Nov 12 02:58:01 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
216
|
+
|
217
|
+
* Resolved Issue #5 - Message ID not handling multiple periods in left hand side
|
218
|
+
* Resolved Issue #6 - Ordering of add_file and body items causes invalid emails
|
219
|
+
|
220
|
+
== Tue Nov 10 08:15:14 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
221
|
+
|
222
|
+
* Resolved Issue #5 - Message ID generation issue
|
223
|
+
* Resolved Issue #7 - README add_file examples don't seem to work - Updated readme and
|
224
|
+
rdoc in Message#add_file
|
225
|
+
|
226
|
+
== Mon Nov 9 23:38:33 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
227
|
+
|
228
|
+
* Added ability to create new email via a hash or hash-like object. <mikel>
|
229
|
+
* Moved all of the Part init into the Message class. Part now just uses Message's init,
|
230
|
+
also moved all the attachment related functions into Message. As Part is a subclass
|
231
|
+
of message, you shouldn't see any interface changes here.
|
232
|
+
|
233
|
+
== Fri Nov 6 22:52:10 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
234
|
+
|
235
|
+
* a6ef2b4: Fixed Issue #4 - Can't call encoding on non existant
|
236
|
+
content-transer-encoding header
|
237
|
+
|
238
|
+
== Fri Nov 6 00:51:55 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
239
|
+
|
240
|
+
* Handled unstructured field folding "blank" lines
|
241
|
+
* Fixed error in header.rb that created fields into an array, instead of a FieldList, resulting
|
242
|
+
in mail.encode returning a random sort order on the header.
|
243
|
+
* Made unstructured fields attempt to decode their values on :decode
|
244
|
+
|
245
|
+
== Thu Nov 5 04:45:31 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
246
|
+
|
247
|
+
* 2acb70a: Closes Issue #1 - Handling badly formatted content-type fields <mikel>
|
248
|
+
|
249
|
+
== Wed Nov 4 23:24:32 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
250
|
+
|
251
|
+
* 2b5d608: Closes Issue #2 - Empty header field values not parsing <mikel>
|
252
|
+
* Version bumb to 1.2.1
|
253
|
+
|
254
|
+
== Wed Nov 4 12:54:43 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
255
|
+
|
256
|
+
* Renamed Mail::Message.encode! to Mail::Message.ready_to_send!, deprecated :encode! <mikel>
|
257
|
+
* Rewrote encoding and decoding methods on all classes. Adds a lot of boiler plate code, but allows us to
|
258
|
+
be really precise in each field type that needs custom encoding. Now all encoding is done by the field_type
|
259
|
+
itself. Need to follow through on the body. <mikel>
|
260
|
+
* Bump version to 1.2.0 due to changes of :encoded, :decoded behaviour <mikel>
|
261
|
+
|
262
|
+
== Tue Nov 3 00:59:45 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
263
|
+
|
264
|
+
* Tested mail against entire Enron set (2.3gb) and the Trec 2005 set (0.5gb), ~ half a million emails without crashing <jlindley>
|
265
|
+
* Some headers only can appear once, enforce during header parse assignment. <jlindley>
|
266
|
+
* Convert empty bodies into empty arrays instead of nil. <jlindley>
|
267
|
+
* Handle blank content dispositions. <jlindley>
|
268
|
+
* Mention Trec 2005 Spam Corpus in readme <jlindley>
|
269
|
+
* Add 'rake corpus:verify_all' to allow parse checks in bulk. <jlindley>
|
270
|
+
* Added handling of multi value parameters, like filename*1*="us-ascii'en'blah" filename*2="bleh" <mikel>
|
271
|
+
* Added dependency on ActiveSupport 2.3 or higher <mikel>
|
272
|
+
|
273
|
+
== Sun Nov 1 12:00:00 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
274
|
+
|
275
|
+
* handle OpenSSL::SSL::VERIFY_NONE returning 0 <jlindley>
|
276
|
+
* doing Mail.new { content_type [text, plain, { charset => UTF-8 }] } is now
|
277
|
+
possible (content type accepts an array) <mikel>
|
278
|
+
|
279
|
+
== Sat Oct 31 11:00:41 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
280
|
+
|
281
|
+
* Fixed attachment handling, so mail can find attachment from a content-type,
|
282
|
+
content-disposition or content-location
|
283
|
+
* Added content-location field and parser
|
284
|
+
* Added message.has_attachments? for ActionMailer friendliness
|
285
|
+
* Added attachment.original_filename for ActionMailer friendliness
|
286
|
+
|
287
|
+
== Sat Oct 25 13:38:01 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
|
288
|
+
|
289
|
+
* Birthday, Mail released as a gem... phew
|
data/README.rdoc
ADDED
@@ -0,0 +1,575 @@
|
|
1
|
+
= Mail
|
2
|
+
|
3
|
+
== Introduction
|
4
|
+
|
5
|
+
Mail is an internet library for Ruby that is designed to handle emails
|
6
|
+
generation, parsing and sending in a simple, rubyesque manner.
|
7
|
+
|
8
|
+
The purpose of this library is to provide a single point of access to handle
|
9
|
+
all email functions, including sending and receiving emails. All network
|
10
|
+
type actions are done through proxy methods to Net::SMTP, Net::POP3 etc.
|
11
|
+
|
12
|
+
Built from my experience with TMail, it is designed to be a pure ruby
|
13
|
+
implementation that makes generating, sending and parsing emails a no
|
14
|
+
brainer.
|
15
|
+
|
16
|
+
It is also designed form the ground up to work with Ruby 1.9. This is because
|
17
|
+
Ruby 1.9 handles text encodings much more magically than Ruby 1.8.x and so
|
18
|
+
these features have been taken full advantage of in this library allowing
|
19
|
+
Mail to handle a lot more messages more cleanly than TMail. Mail does run on
|
20
|
+
Ruby 1.8.x... it's just not as fun to code.
|
21
|
+
|
22
|
+
Finally, Mail has been designed with a very simple object oriented system
|
23
|
+
that really opens up the email messages you are parsing, if you know what
|
24
|
+
you are doing, you can fiddle with every last bit of your email directly.
|
25
|
+
|
26
|
+
== Compatibility
|
27
|
+
|
28
|
+
Mail is tested and works on the following platforms:
|
29
|
+
|
30
|
+
* ree-1.8.7-2009.10 [ x86_64 ]
|
31
|
+
* ruby-1.8.6-p383 [ x86_64 ]
|
32
|
+
* ruby-1.8.7-p248 [ x86_64 ]
|
33
|
+
* ruby-1.9.1-head [ x86_64 ]
|
34
|
+
* ruby-1.9.1-p376 [ x86_64 ]
|
35
|
+
|
36
|
+
Mail seems to work fine on JRuby as well, however, the Base64 and Quoted-Printable
|
37
|
+
encoding methods are implemented differently and return different values so 6
|
38
|
+
specs fail. This needs to be triple checked if all OK.
|
39
|
+
|
40
|
+
* jruby-1.4.0 [x86_64-java]
|
41
|
+
|
42
|
+
== Discussion
|
43
|
+
|
44
|
+
If you want to discuss mail with like minded individuals, please subscribe to
|
45
|
+
the Google Group http://groups.google.com/group/mail-ruby
|
46
|
+
|
47
|
+
== Current Capabilities of Mail
|
48
|
+
|
49
|
+
* RFC2822 Support, Reading and Writing
|
50
|
+
* RFC2045-2049 Support for multipart emails
|
51
|
+
* Support for creating multipart alternate emails
|
52
|
+
* Support for reading multipart/report emails & getting details from such
|
53
|
+
* Support for multibyte emails - needs quite a lot of work and testing
|
54
|
+
* Wrappers for File, Net/POP3, Net/SMTP
|
55
|
+
|
56
|
+
Mail is RFC2822 compliant now, that is, it can parse and generate valid US-ASCII
|
57
|
+
emails. There are a few obsoleted syntax emails that it will have problems with, but
|
58
|
+
it also is quite robust, meaning, if it finds something it doesn't understand it will
|
59
|
+
not crash, instead, it will skip the problem and keep parsing. In the case of a header
|
60
|
+
it doesn't understand, it will initialise the header as an optional unstructured
|
61
|
+
field and continue parsing.
|
62
|
+
|
63
|
+
This means Mail won't (ever) crunch your data (I think).
|
64
|
+
|
65
|
+
You can also create MIME emails. There are helper methods for making a
|
66
|
+
multipart/alternate email for text/plain and text/html (the most common pair)
|
67
|
+
and you can manually create any other type of MIME email.
|
68
|
+
|
69
|
+
== Roadmap
|
70
|
+
|
71
|
+
Next TODO:
|
72
|
+
|
73
|
+
* Improve MIME support for character sets in headers, currently works, mostly, needs
|
74
|
+
refinement.
|
75
|
+
* Add IMAP wrapper
|
76
|
+
|
77
|
+
== Testing Policy
|
78
|
+
|
79
|
+
Basically... we do BDD on Mail. No method gets written in Mail without a
|
80
|
+
corresponding or covering spec. We expect as a minimum 100% coverage
|
81
|
+
measured by RCov. While this is not perfect by any measure, it is pretty
|
82
|
+
good. Additionally, all functional tests from TMail are to be passing before
|
83
|
+
the gem gets released.
|
84
|
+
|
85
|
+
It also means you can be sure Mail will behave correctly.
|
86
|
+
|
87
|
+
== API Policy
|
88
|
+
|
89
|
+
No API removals within a single point release. All removals to be depreciated with
|
90
|
+
warnings for at least one MINOR point release before removal.
|
91
|
+
|
92
|
+
Also, all private or protected methods to be declared as such - though this is still I/P.
|
93
|
+
|
94
|
+
== Installation
|
95
|
+
|
96
|
+
Installation is fairly simple, I host mail on gemcutter, so you can just do:
|
97
|
+
|
98
|
+
# gem install mail
|
99
|
+
|
100
|
+
if you are on gemcutter, if you aren't, you can by doing:
|
101
|
+
|
102
|
+
# gem install gemcutter
|
103
|
+
# gem tumble
|
104
|
+
# gem install mail
|
105
|
+
|
106
|
+
Warning though, the above will change your first gem repository to gemcutter, this
|
107
|
+
may or may not be a problem for you.
|
108
|
+
|
109
|
+
If you want to install mail manually, you can download the gem from github and do:
|
110
|
+
|
111
|
+
# gem install mail-1.2.1.gem
|
112
|
+
|
113
|
+
== Encodings
|
114
|
+
|
115
|
+
If you didn't know, handling encodings in Emails is not as straight forward as you
|
116
|
+
would hope.
|
117
|
+
|
118
|
+
I have tried to simplify it some:
|
119
|
+
|
120
|
+
1. All objects that can render into an email, have an :encoded method. Encoded will
|
121
|
+
return the object as a complete string ready to send in the mail system, that is,
|
122
|
+
it will include the header field and value and CRLF at the end and wrapped as
|
123
|
+
needed.
|
124
|
+
|
125
|
+
2. All objects that can render into an email, have a :decoded method. Decoded will
|
126
|
+
return the object's "value" only as a string. This means it will not include
|
127
|
+
the header fields (like 'To:' or 'Subject:').
|
128
|
+
|
129
|
+
3. By default, calling :to_s on a container object will call it's encoded method, while
|
130
|
+
:to_s on a field object will call it's decoded method. So calling :to_s on a Mail
|
131
|
+
object will return the mail, all encoded ready to send, while calling :to_s on the
|
132
|
+
From field or the body will return the decoded value of the object. The header object
|
133
|
+
of Mail is considered a container. If you are in doubt, call :encoded, or :decoded
|
134
|
+
explicitly, this is safer if you are not sure.
|
135
|
+
|
136
|
+
4. Structured fields that have parameter values that can be encoded (e.g. Content-Type) will
|
137
|
+
provide decoded parameter values when you call the parameter names as methods against
|
138
|
+
the object.
|
139
|
+
|
140
|
+
5. Structured fields that have parameter values that can be encoded (e.g. Content-Type) will
|
141
|
+
provide encoded parameter values when you call the parameter names through the
|
142
|
+
object.parameters['<parameter_name>'] method call.
|
143
|
+
|
144
|
+
== Contributing
|
145
|
+
|
146
|
+
Please do! Contributing is easy in Mail:
|
147
|
+
|
148
|
+
1. Check the Reference RFCs, they are in the References directory, so no excuses.
|
149
|
+
2. Open a ticket on github, maybe someone else has the problem too
|
150
|
+
3. Make a fork of my github repository
|
151
|
+
4. Make a spec driven change to the code base
|
152
|
+
5. Make sure it works and all specs pass, on Ruby versions 1.8.6, 1.8.7 and 1.9
|
153
|
+
6. Update the README if needed to reflect your change / addition
|
154
|
+
7. With all specs passing push your changes back to your fork
|
155
|
+
8. Send me a pull request
|
156
|
+
|
157
|
+
== Usage
|
158
|
+
|
159
|
+
All major mail functions should be able to happen from the Mail::module.
|
160
|
+
So, you should be able to just "require 'mail'" to get started.
|
161
|
+
|
162
|
+
=== Making an email
|
163
|
+
|
164
|
+
require 'mail'
|
165
|
+
|
166
|
+
mail = Mail.new do
|
167
|
+
from 'mikel@test.lindsaar.net'
|
168
|
+
to 'you@test.lindsaar.net'
|
169
|
+
subject 'This is a test email'
|
170
|
+
body File.read('body.txt')
|
171
|
+
end
|
172
|
+
|
173
|
+
mail.to_s #=> "From: mikel@test.lindsaar.net\r\nTo: you@...
|
174
|
+
|
175
|
+
=== Making an email, have it your way:
|
176
|
+
|
177
|
+
require 'mail'
|
178
|
+
|
179
|
+
mail = Mail.new do
|
180
|
+
body File.read('body.txt')
|
181
|
+
end
|
182
|
+
|
183
|
+
mail['from'] = 'mikel@test.lindsaar.net'
|
184
|
+
mail[:to] = 'you@test.lindsaar.net'
|
185
|
+
mail.subject = 'This is a test email'
|
186
|
+
|
187
|
+
mail.to_s #=> "From: mikel@test.lindsaar.net\r\nTo: you@...
|
188
|
+
|
189
|
+
=== Don't Worry About Message IDs:
|
190
|
+
|
191
|
+
require 'mail'
|
192
|
+
|
193
|
+
mail = Mail.new do
|
194
|
+
to 'you@test.lindsaar.net'
|
195
|
+
body 'Some simple body'
|
196
|
+
end
|
197
|
+
|
198
|
+
mail.to_s =~ /Message\-ID: <[\d\w_]+@.+.mail/ #=> 27
|
199
|
+
|
200
|
+
Mail will automatically add a Message-ID field if it is missing and
|
201
|
+
give it a unique, random Message-ID along the lines of:
|
202
|
+
|
203
|
+
<4a7ff76d7016_13a81ab802e1@local.fqdn.mail>
|
204
|
+
|
205
|
+
=== Or do worry about Message-IDs:
|
206
|
+
|
207
|
+
require 'mail'
|
208
|
+
|
209
|
+
mail = Mail.new do
|
210
|
+
to 'you@test.lindsaar.net'
|
211
|
+
message_id '<ThisIsMyMessageId@some.domain.com>'
|
212
|
+
body 'Some simple body'
|
213
|
+
end
|
214
|
+
|
215
|
+
mail.to_s =~ /Message\-ID: <ThisIsMyMessageId@some.domain.com>/ #=> 27
|
216
|
+
|
217
|
+
Mail will take the message_id you assign to it trusting that you know
|
218
|
+
what you are doing.
|
219
|
+
|
220
|
+
=== Sending an email:
|
221
|
+
|
222
|
+
Mail defaults to sending via SMTP to local host port 25. If you have a
|
223
|
+
sendmail or postfix daemon running on on this port, sending email is as
|
224
|
+
easy as:
|
225
|
+
|
226
|
+
Mail.deliver do
|
227
|
+
from 'me@test.lindsaar.net'
|
228
|
+
to 'you@test.lindsaar.net'
|
229
|
+
subject 'Here is the image you wanted'
|
230
|
+
body File.read('body.txt')
|
231
|
+
add_file '/full/path/to/somefile.png'
|
232
|
+
end
|
233
|
+
|
234
|
+
or
|
235
|
+
|
236
|
+
mail = Mail.new do
|
237
|
+
from 'me@test.lindsaar.net'
|
238
|
+
to 'you@test.lindsaar.net'
|
239
|
+
subject 'Here is the image you wanted'
|
240
|
+
body File.read('body.txt')
|
241
|
+
add_file {:filename => 'somefile.png', :content => File.read('/somefile.png')}
|
242
|
+
end
|
243
|
+
|
244
|
+
mail.deliver!
|
245
|
+
|
246
|
+
Sending via sendmail can be done like so:
|
247
|
+
|
248
|
+
mail = Mail.new do
|
249
|
+
from 'me@test.lindsaar.net'
|
250
|
+
to 'you@test.lindsaar.net'
|
251
|
+
subject 'Here is the image you wanted'
|
252
|
+
body File.read('body.txt')
|
253
|
+
add_file {:filename => 'somefile.png', :content => File.read('/somefile.png')}
|
254
|
+
end
|
255
|
+
|
256
|
+
mail.delivery_method :sendmail
|
257
|
+
|
258
|
+
mail.deliver
|
259
|
+
|
260
|
+
mail.deliver!
|
261
|
+
|
262
|
+
|
263
|
+
=== Getting emails from a pop server:
|
264
|
+
|
265
|
+
The most recent email:
|
266
|
+
|
267
|
+
require 'mail'
|
268
|
+
|
269
|
+
Mail.defaults do
|
270
|
+
pop3 'mail.myhost.com.au', 110 do
|
271
|
+
user 'mikel'
|
272
|
+
pass 'mypass'
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
emails = Mail.last do |email|
|
277
|
+
email.reply!("I'll be back on Monday, please be patient!") # +reply!+ still not implemented ^^
|
278
|
+
end
|
279
|
+
|
280
|
+
The 3 oldest emails sorted by date in descendent order:
|
281
|
+
|
282
|
+
require 'mail'
|
283
|
+
|
284
|
+
Mail.defaults do
|
285
|
+
pop3 'mail.myhost.co.jp', 995 do
|
286
|
+
user 'mikel'
|
287
|
+
pass 'mypass'
|
288
|
+
enable_tls
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
emails = Mail.first(:count => 3, :order => :desc) do |email|
|
293
|
+
email.date
|
294
|
+
end
|
295
|
+
|
296
|
+
Or even all emails:
|
297
|
+
|
298
|
+
require 'mail'
|
299
|
+
|
300
|
+
Mail.defaults do
|
301
|
+
pop3 'mail.myhost.com.au' do
|
302
|
+
user 'mikel'
|
303
|
+
pass 'mypass'
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
emails = Mail.all
|
308
|
+
|
309
|
+
emails.length #=> 12
|
310
|
+
|
311
|
+
=== Reading an Email
|
312
|
+
|
313
|
+
require 'mail'
|
314
|
+
|
315
|
+
mail = Mail.read('/path/to/message.eml')
|
316
|
+
|
317
|
+
mail.envelope.from #=> 'mikel@test.lindsaar.net'
|
318
|
+
mail.from.addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
|
319
|
+
mail.sender.address #=> 'mikel@test.lindsaar.net'
|
320
|
+
mail.to #=> 'bob@test.lindsaar.net'
|
321
|
+
mail.cc #=> 'sam@test.lindsaar.net'
|
322
|
+
mail.subject #=> "This is the subject"
|
323
|
+
mail.date.to_s #=> '21 Nov 1997 09:55:06 -0600'
|
324
|
+
mail.message_id #=> '<4D6AA7EB.6490534@xxx.xxx>'
|
325
|
+
mail.body.decoded #=> 'This is the body of the email...
|
326
|
+
|
327
|
+
Many more methods available.
|
328
|
+
|
329
|
+
=== Reading a Multipart Email
|
330
|
+
|
331
|
+
require 'mail'
|
332
|
+
|
333
|
+
mail = Mail.read('multipart_email')
|
334
|
+
|
335
|
+
mail.multipart? #=> true
|
336
|
+
mail.parts.length #=> 2
|
337
|
+
mail.preamble #=> "Text before the first part"
|
338
|
+
mail.epilogue #=> "Text after the last part"
|
339
|
+
mail.parts.map { |p| p.content_type } #=> ['text/plain', 'application/pdf']
|
340
|
+
mail.parts.map { |p| p.class } #=> [Mail::Message, Mail::Message]
|
341
|
+
mail.parts[0].content_type_parameters #=> {'charset' => 'ISO-8859-1'}
|
342
|
+
mail.parts[1].content_type_parameters #=> {'name' => 'my.pdf'}
|
343
|
+
|
344
|
+
Mail generates a tree of parts. Each message has many or no parts. Each part
|
345
|
+
is another message which can have many or no parts.
|
346
|
+
|
347
|
+
A message will only have parts if it is a multipart/mixed or related/mixed
|
348
|
+
content type and has a boundary defined.
|
349
|
+
|
350
|
+
=== Writing and sending a multipart/alternative (html and text) email
|
351
|
+
|
352
|
+
Mail makes some basic assumptions and makes doing the common thing as
|
353
|
+
simple as possible.... (asking a lot from a mail library)
|
354
|
+
|
355
|
+
require 'mail'
|
356
|
+
|
357
|
+
mail = Mail.deliver do
|
358
|
+
to 'nicolas@test.lindsaar.net.au'
|
359
|
+
from 'Mikel Lindsaar <mikel@test.lindsaar.net.au>'
|
360
|
+
subject 'First multipart email sent with Mail'
|
361
|
+
text_part do
|
362
|
+
body 'This is plain text'
|
363
|
+
end
|
364
|
+
html_part do
|
365
|
+
content_type 'text/html; charset=UTF-8'
|
366
|
+
body '<h1>This is HTML</h1>'
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
Mail then delivers the email at the end of the block and returns the
|
371
|
+
resulting Mail::Message object, which you can then inspect if you
|
372
|
+
so desire...
|
373
|
+
|
374
|
+
puts mail.to_s #=>
|
375
|
+
|
376
|
+
To: nicolas@test.lindsaar.net.au
|
377
|
+
From: Mikel Lindsaar <mikel@test.lindsaar.net.au>
|
378
|
+
Subject: First multipart email sent with Mail
|
379
|
+
Content-Type: multipart/alternative;
|
380
|
+
boundary=--==_mimepart_4a914f0c911be_6f0f1ab8026659
|
381
|
+
Message-ID: <4a914f12ac7e_6f0f1ab80267d1@baci.local.mail>
|
382
|
+
Date: Mon, 24 Aug 2009 00:15:46 +1000
|
383
|
+
Mime-Version: 1.0
|
384
|
+
Content-Transfer-Encoding: 7bit
|
385
|
+
|
386
|
+
|
387
|
+
----==_mimepart_4a914f0c911be_6f0f1ab8026659
|
388
|
+
Content-ID: <4a914f12c8c4_6f0f1ab80268d6@baci.local.mail>
|
389
|
+
Date: Mon, 24 Aug 2009 00:15:46 +1000
|
390
|
+
Mime-Version: 1.0
|
391
|
+
Content-Type: text/plain
|
392
|
+
Content-Transfer-Encoding: 7bit
|
393
|
+
|
394
|
+
This is plain text
|
395
|
+
----==_mimepart_4a914f0c911be_6f0f1ab8026659
|
396
|
+
Content-Type: text/html; charset=UTF-8
|
397
|
+
Content-ID: <4a914f12cf86_6f0f1ab802692c@baci.local.mail>
|
398
|
+
Date: Mon, 24 Aug 2009 00:15:46 +1000
|
399
|
+
Mime-Version: 1.0
|
400
|
+
Content-Transfer-Encoding: 7bit
|
401
|
+
|
402
|
+
<h1>This is HTML</h1>
|
403
|
+
----==_mimepart_4a914f0c911be_6f0f1ab8026659--
|
404
|
+
|
405
|
+
Mail inserts the content transfer encoding, the mime version,
|
406
|
+
the content-id's and handles the content-type and boundary.
|
407
|
+
|
408
|
+
Mail assumes that if your text in the body is only us-ascii, that your
|
409
|
+
transfer encoding is 7bit and it is text/plain. You can override this
|
410
|
+
by explicitly declaring it.
|
411
|
+
|
412
|
+
=== Making Multipart/Alternate, without a block
|
413
|
+
|
414
|
+
You don't have to use a block with the text and html part included, you
|
415
|
+
can just do it declaratively. However, you need to add Mail::Parts to
|
416
|
+
an email, not Mail::Messages.
|
417
|
+
|
418
|
+
require 'mail'
|
419
|
+
|
420
|
+
mail = Mail.new do
|
421
|
+
to 'nicolas@test.lindsaar.net.au'
|
422
|
+
from 'Mikel Lindsaar <mikel@test.lindsaar.net.au>'
|
423
|
+
subject 'First multipart email sent with Mail'
|
424
|
+
end
|
425
|
+
|
426
|
+
text_part = Mail::Part.new do
|
427
|
+
body 'This is plain text'
|
428
|
+
end
|
429
|
+
|
430
|
+
html_part = Mail::Part.new do
|
431
|
+
content_type 'text/html; charset=UTF-8'
|
432
|
+
body '<h1>This is HTML</h1>'
|
433
|
+
end
|
434
|
+
|
435
|
+
mail.text_part = text_part
|
436
|
+
mail.html_part = html_part
|
437
|
+
|
438
|
+
Results in the same email as done using the block form
|
439
|
+
|
440
|
+
=== Getting error reports from an email:
|
441
|
+
|
442
|
+
require 'mail'
|
443
|
+
|
444
|
+
@mail = Mail.read('/path/to/bounce_message.eml')
|
445
|
+
|
446
|
+
@mail.bounced? #=> true
|
447
|
+
@mail.final_recipient #=> rfc822;mikel@dont.exist.com
|
448
|
+
@mail.action #=> failed
|
449
|
+
@mail.error_status #=> 5.5.0
|
450
|
+
@mail.diagnostic_code #=> smtp;550 Requested action not taken: mailbox unavailable
|
451
|
+
@mail.retryable? #=> false
|
452
|
+
|
453
|
+
=== Attaching and Detaching Files
|
454
|
+
|
455
|
+
require 'mail'
|
456
|
+
|
457
|
+
You can just read the file off an absolute path, Mail will try
|
458
|
+
to guess the mime_type and will encode the file in Base64 for you.
|
459
|
+
|
460
|
+
@mail = Mail.new
|
461
|
+
@mail.add_file("/path/to/file.jpg")
|
462
|
+
@mail.parts.first.attachment? #=> true
|
463
|
+
@mail.parts.first.content_transfer_encoding.to_s #=> 'base64'
|
464
|
+
@mail.attachments.first.mime_type #=> 'image/jpg'
|
465
|
+
@mail.attachments.first.filename #=> 'file.jpg'
|
466
|
+
@mail.attachments.first.decoded == File.read('/path/to/file.jpg') #=> true
|
467
|
+
|
468
|
+
Or You can pass in file_data and give it a filename, again, mail
|
469
|
+
will try and guess the mime_type for you.
|
470
|
+
|
471
|
+
@mail = Mail.new
|
472
|
+
@mail.attachments['myfile.pdf'] = File.read('path/to/myfile.pdf')
|
473
|
+
@mail.parts.first.attachment? #=> true
|
474
|
+
@mail.attachments.first.mime_type #=> 'application/pdf'
|
475
|
+
@mail.attachments.first.decoded == File.read('path/to/myfile.pdf') #=> true
|
476
|
+
|
477
|
+
You can also override the guessed mime type if you really know better
|
478
|
+
than mail (this should be rarely needed)
|
479
|
+
|
480
|
+
@mail = Mail.new
|
481
|
+
file_data = File.read('path/to/myfile.pdf')
|
482
|
+
@mail.attachments['myfile.pdf'] = { :mime_type => 'application/x-pdf',
|
483
|
+
:content => File.read('path/to/myfile.pdf') }
|
484
|
+
@mail.parts.first.mime_type #=> 'application/x-pdf'
|
485
|
+
|
486
|
+
Of course... Mail will round trip an attachment as well
|
487
|
+
|
488
|
+
@mail = Mail.new do
|
489
|
+
to 'nicolas@test.lindsaar.net.au'
|
490
|
+
from 'Mikel Lindsaar <mikel@test.lindsaar.net.au>'
|
491
|
+
subject 'First multipart email sent with Mail'
|
492
|
+
text_part do
|
493
|
+
body 'Here is the attachment you wanted'
|
494
|
+
end
|
495
|
+
html_part do
|
496
|
+
content_type 'text/html; charset=UTF-8'
|
497
|
+
body '<h1>Funky Title</h1><p>Here is the attachment you wanted</p>'
|
498
|
+
end
|
499
|
+
add_file '/path/to/myfile.pdf'
|
500
|
+
end
|
501
|
+
|
502
|
+
@round_tripped_mail = Mail.new(@mail.encoded)
|
503
|
+
|
504
|
+
@round_tripped_mail.attachments.length #=> 1
|
505
|
+
@round_tripped_mail.attachments.first.filename #=> 'myfile.pdf'
|
506
|
+
|
507
|
+
== Using Mail with Testing or Spec'ing Libraries
|
508
|
+
|
509
|
+
If mail is part of your system, you'll need a way to test it without actually
|
510
|
+
sending emails, the TestMailer can do this for you.
|
511
|
+
|
512
|
+
require 'mail'
|
513
|
+
=> true
|
514
|
+
Mail.defaults do
|
515
|
+
delivery_method :test
|
516
|
+
end
|
517
|
+
=> #<Mail::Configuration:0x19345a8 @delivery_method=Mail::TestMailer>
|
518
|
+
Mail.deliveries
|
519
|
+
=> []
|
520
|
+
Mail.deliver do
|
521
|
+
to 'mikel@me.com'
|
522
|
+
from 'you@you.com'
|
523
|
+
subject 'testing'
|
524
|
+
body 'hello'
|
525
|
+
end
|
526
|
+
=> #<Mail::Message:0x19284ec ...
|
527
|
+
Mail.deliveries.length
|
528
|
+
=> 1
|
529
|
+
Mail.deliveries.first
|
530
|
+
=> #<Mail::Message:0x19284ec ...
|
531
|
+
Mail.deliveries.clear
|
532
|
+
=> []
|
533
|
+
|
534
|
+
== Excerpts from TREC Spam Corpus 2005
|
535
|
+
|
536
|
+
The spec fixture files in spec/fixtures/emails/from_trec_2005 are from the
|
537
|
+
2005 TREC Public Spam Corpus. They remain copyrighted under the terms of
|
538
|
+
that project and license agreement. They are used in this project to verify
|
539
|
+
and describe the development of this email parser implementation.
|
540
|
+
|
541
|
+
http://plg.uwaterloo.ca/~gvcormac/treccorpus/
|
542
|
+
|
543
|
+
They are used as allowed by 'Permitted Uses, Clause 3':
|
544
|
+
|
545
|
+
"Small excerpts of the information may be displayed to others
|
546
|
+
or published in a scientific or technical context, solely for
|
547
|
+
the purpose of describing the research and development and
|
548
|
+
related issues."
|
549
|
+
|
550
|
+
-- http://plg.uwaterloo.ca/~gvcormac/treccorpus/
|
551
|
+
|
552
|
+
== License:
|
553
|
+
|
554
|
+
(The MIT License)
|
555
|
+
|
556
|
+
Copyright (c) 2009
|
557
|
+
|
558
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
559
|
+
a copy of this software and associated documentation files (the
|
560
|
+
'Software'), to deal in the Software without restriction, including
|
561
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
562
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
563
|
+
permit persons to whom the Software is furnished to do so, subject to
|
564
|
+
the following conditions:
|
565
|
+
|
566
|
+
The above copyright notice and this permission notice shall be
|
567
|
+
included in all copies or substantial portions of the Software.
|
568
|
+
|
569
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
570
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
571
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
572
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
573
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
574
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
575
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|