mail 2.3.3 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of mail might be problematic. Click here for more details.

Files changed (38) hide show
  1. data/CHANGELOG.rdoc +26 -0
  2. data/CONTRIBUTING.md +45 -0
  3. data/Gemfile +2 -8
  4. data/Gemfile.lock +31 -0
  5. data/README.md +649 -0
  6. data/Rakefile +4 -30
  7. data/lib/VERSION +2 -2
  8. data/lib/mail.rb +3 -1
  9. data/lib/mail/attachments_list.rb +2 -3
  10. data/lib/mail/body.rb +1 -2
  11. data/lib/mail/configuration.rb +3 -3
  12. data/lib/mail/core_extensions/nil.rb +4 -0
  13. data/lib/mail/core_extensions/shellwords.rb +57 -0
  14. data/lib/mail/core_extensions/string.rb +6 -4
  15. data/lib/mail/core_extensions/string/access.rb +41 -0
  16. data/lib/mail/encodings.rb +8 -8
  17. data/lib/mail/field.rb +2 -0
  18. data/lib/mail/fields/common/parameter_hash.rb +1 -1
  19. data/lib/mail/fields/unstructured_field.rb +1 -1
  20. data/lib/mail/matchers/has_sent_mail.rb +124 -0
  21. data/lib/mail/message.rb +72 -19
  22. data/lib/mail/multibyte/chars.rb +2 -2
  23. data/lib/mail/multibyte/utils.rb +1 -1
  24. data/lib/mail/network/delivery_methods/exim.rb +5 -38
  25. data/lib/mail/network/delivery_methods/file_delivery.rb +2 -2
  26. data/lib/mail/network/delivery_methods/sendmail.rb +3 -3
  27. data/lib/mail/network/delivery_methods/smtp.rb +20 -4
  28. data/lib/mail/network/retriever_methods/imap.rb +4 -2
  29. data/lib/mail/parsers/rfc2822.treetop +1 -1
  30. data/lib/mail/parsers/rfc2822_obsolete.rb +14 -3
  31. data/lib/mail/parsers/rfc2822_obsolete.treetop +2 -2
  32. data/lib/mail/parts_list.rb +4 -0
  33. data/lib/mail/utilities.rb +6 -2
  34. data/lib/mail/version_specific/ruby_1_8.rb +1 -1
  35. data/lib/mail/version_specific/ruby_1_9.rb +8 -4
  36. metadata +18 -12
  37. data/README.rdoc +0 -563
  38. data/lib/mail/core_extensions/shell_escape.rb +0 -56
@@ -68,7 +68,7 @@ module Mail
68
68
  match = str.match(/\=\?(.+)?\?[Qq]\?(.+)?\?\=/m)
69
69
  if match
70
70
  encoding = match[1]
71
- str = Encodings::QuotedPrintable.decode(match[2])
71
+ str = Encodings::QuotedPrintable.decode(match[2].gsub(/_/, '=20'))
72
72
  str.force_encoding(fix_encoding(encoding))
73
73
  end
74
74
  decoded = str.encode("utf-8", :invalid => :replace, :replace => "")
@@ -76,7 +76,7 @@ module Mail
76
76
  end
77
77
 
78
78
  def Ruby19.param_decode(str, encoding)
79
- string = URI.unescape(str)
79
+ string = uri_parser.unescape(str)
80
80
  string.force_encoding(encoding) if encoding
81
81
  string
82
82
  end
@@ -84,7 +84,11 @@ module Mail
84
84
  def Ruby19.param_encode(str)
85
85
  encoding = str.encoding.to_s.downcase
86
86
  language = Configuration.instance.param_encode_language
87
- "#{encoding}'#{language}'#{URI.escape(str)}"
87
+ "#{encoding}'#{language}'#{uri_parser.escape(str)}"
88
+ end
89
+
90
+ def Ruby19.uri_parser
91
+ @uri_parser ||= URI::Parser.new
88
92
  end
89
93
 
90
94
  # mails somtimes includes invalid encodings like iso885915 or utf8 so we transform them to iso885915 or utf8
@@ -98,7 +102,7 @@ module Mail
98
102
  # "ISO-2022-JP-KDDI" and alike
99
103
  when /iso-?(\d{4})-?(\w{1,2})-?(\w*)/i then return "ISO-#{$1}-#{$2}-#{$3}"
100
104
  # UTF-8, UTF-32BE and alike
101
- when /utf-?(\d{1,2})?(\w{1,2})/i then return "UTF-#{$1}#{$2}"
105
+ when /utf-?(\d{1,2})?(\w{1,2})/i then return "UTF-#{$1}#{$2}".gsub(/\A(UTF-(?:16|32))\z/, '\\1BE')
102
106
  # Windows-1252 and alike
103
107
  when /Windows-?(.*)/i then return "Windows-#{$1}"
104
108
  #more aliases to be added if needed
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mail
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.3
4
+ version: 2.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-14 00:00:00.000000000Z
12
+ date: 2012-01-15 00:00:00.000000000 +10:30
13
+ default_executable:
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: mime-types
16
- requirement: &70098729210260 !ruby/object:Gem::Requirement
17
+ requirement: &70128923044060 !ruby/object:Gem::Requirement
17
18
  none: false
18
19
  requirements:
19
20
  - - ~>
@@ -21,10 +22,10 @@ dependencies:
21
22
  version: '1.16'
22
23
  type: :runtime
23
24
  prerelease: false
24
- version_requirements: *70098729210260
25
+ version_requirements: *70128923044060
25
26
  - !ruby/object:Gem::Dependency
26
27
  name: treetop
27
- requirement: &70098729209780 !ruby/object:Gem::Requirement
28
+ requirement: &70128923043580 !ruby/object:Gem::Requirement
28
29
  none: false
29
30
  requirements:
30
31
  - - ~>
@@ -32,10 +33,10 @@ dependencies:
32
33
  version: 1.4.8
33
34
  type: :runtime
34
35
  prerelease: false
35
- version_requirements: *70098729209780
36
+ version_requirements: *70128923043580
36
37
  - !ruby/object:Gem::Dependency
37
38
  name: i18n
38
- requirement: &70098729209320 !ruby/object:Gem::Requirement
39
+ requirement: &70128923043120 !ruby/object:Gem::Requirement
39
40
  none: false
40
41
  requirements:
41
42
  - - ! '>='
@@ -43,20 +44,23 @@ dependencies:
43
44
  version: 0.4.0
44
45
  type: :runtime
45
46
  prerelease: false
46
- version_requirements: *70098729209320
47
+ version_requirements: *70128923043120
47
48
  description: A really Ruby Mail handler.
48
49
  email: raasdnil@gmail.com
49
50
  executables: []
50
51
  extensions: []
51
52
  extra_rdoc_files:
52
- - README.rdoc
53
+ - README.md
54
+ - CONTRIBUTING.md
53
55
  - CHANGELOG.rdoc
54
56
  - TODO.rdoc
55
57
  files:
56
- - README.rdoc
58
+ - README.md
59
+ - CONTRIBUTING.md
57
60
  - CHANGELOG.rdoc
58
61
  - Dependencies.txt
59
62
  - Gemfile
63
+ - Gemfile.lock
60
64
  - Rakefile
61
65
  - TODO.rdoc
62
66
  - lib/mail/attachments_list.rb
@@ -64,7 +68,7 @@ files:
64
68
  - lib/mail/configuration.rb
65
69
  - lib/mail/core_extensions/nil.rb
66
70
  - lib/mail/core_extensions/object.rb
67
- - lib/mail/core_extensions/shell_escape.rb
71
+ - lib/mail/core_extensions/shellwords.rb
68
72
  - lib/mail/core_extensions/smtp.rb
69
73
  - lib/mail/core_extensions/string/access.rb
70
74
  - lib/mail/core_extensions/string/multibyte.rb
@@ -134,6 +138,7 @@ files:
134
138
  - lib/mail/header.rb
135
139
  - lib/mail/indifferent_hash.rb
136
140
  - lib/mail/mail.rb
141
+ - lib/mail/matchers/has_sent_mail.rb
137
142
  - lib/mail/message.rb
138
143
  - lib/mail/multibyte/chars.rb
139
144
  - lib/mail/multibyte/exceptions.rb
@@ -190,6 +195,7 @@ files:
190
195
  - lib/tasks/corpus.rake
191
196
  - lib/tasks/treetop.rake
192
197
  - lib/VERSION
198
+ has_rdoc: true
193
199
  homepage: http://github.com/mikel/mail
194
200
  licenses: []
195
201
  post_install_message:
@@ -210,7 +216,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
216
  version: '0'
211
217
  requirements: []
212
218
  rubyforge_project:
213
- rubygems_version: 1.8.15
219
+ rubygems_version: 1.6.2
214
220
  signing_key:
215
221
  specification_version: 3
216
222
  summary: Mail provides a nice Ruby DSL for making, sending and reading emails.
data/README.rdoc DELETED
@@ -1,563 +0,0 @@
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
- * jruby-1.5.2 [ [x86_64-java] ]
31
- * ree-1.8.7-2010.02 [ x86_64 ]
32
- * ruby-1.8.6-p399 [ x86_64 ]
33
- * ruby-1.8.7-p302 [ x86_64 ]
34
- * ruby-1.9.2-p0 [ x86_64 ]
35
-
36
- == Discussion
37
-
38
- If you want to discuss mail with like minded individuals, please subscribe to
39
- the Google Group http://groups.google.com/group/mail-ruby
40
-
41
- == Current Capabilities of Mail
42
-
43
- * RFC2822 Support, Reading and Writing
44
- * RFC2045-2049 Support for multipart emails
45
- * Support for creating multipart alternate emails
46
- * Support for reading multipart/report emails & getting details from such
47
- * Support for multibyte emails - needs quite a lot of work and testing
48
- * Wrappers for File, Net/POP3, Net/SMTP
49
- * Auto encoding of non US-ASCII header fields
50
- * Auto encoding of non US-ASCII bodies
51
-
52
- Mail is RFC2822 compliant now, that is, it can parse and generate valid US-ASCII
53
- emails. There are a few obsoleted syntax emails that it will have problems with, but
54
- it also is quite robust, meaning, if it finds something it doesn't understand it will
55
- not crash, instead, it will skip the problem and keep parsing. In the case of a header
56
- it doesn't understand, it will initialise the header as an optional unstructured
57
- field and continue parsing.
58
-
59
- This means Mail won't (ever) crunch your data (I think).
60
-
61
- You can also create MIME emails. There are helper methods for making a
62
- multipart/alternate email for text/plain and text/html (the most common pair)
63
- and you can manually create any other type of MIME email.
64
-
65
- == Roadmap
66
-
67
- Next TODO:
68
-
69
- * Improve MIME support for character sets in headers, currently works, mostly, needs
70
- refinement.
71
-
72
- == Testing Policy
73
-
74
- Basically... we do BDD on Mail. No method gets written in Mail without a
75
- corresponding or covering spec. We expect as a minimum 100% coverage
76
- measured by RCov. While this is not perfect by any measure, it is pretty
77
- good. Additionally, all functional tests from TMail are to be passing before
78
- the gem gets released.
79
-
80
- It also means you can be sure Mail will behave correctly.
81
-
82
- == API Policy
83
-
84
- No API removals within a single point release. All removals to be depreciated with
85
- warnings for at least one MINOR point release before removal.
86
-
87
- Also, all private or protected methods to be declared as such - though this is still I/P.
88
-
89
- == Installation
90
-
91
- Installation is fairly simple, I host mail on rubygems, so you can just do:
92
-
93
- # gem install mail
94
-
95
- == Encodings
96
-
97
- If you didn't know, handling encodings in Emails is not as straight forward as you
98
- would hope.
99
-
100
- I have tried to simplify it some:
101
-
102
- 1. All objects that can render into an email, have an :encoded method. Encoded will
103
- return the object as a complete string ready to send in the mail system, that is,
104
- it will include the header field and value and CRLF at the end and wrapped as
105
- needed.
106
-
107
- 2. All objects that can render into an email, have a :decoded method. Decoded will
108
- return the object's "value" only as a string. This means it will not include
109
- the header fields (like 'To:' or 'Subject:').
110
-
111
- 3. By default, calling :to_s on a container object will call it's encoded method, while
112
- :to_s on a field object will call it's decoded method. So calling :to_s on a Mail
113
- object will return the mail, all encoded ready to send, while calling :to_s on the
114
- From field or the body will return the decoded value of the object. The header object
115
- of Mail is considered a container. If you are in doubt, call :encoded, or :decoded
116
- explicitly, this is safer if you are not sure.
117
-
118
- 4. Structured fields that have parameter values that can be encoded (e.g. Content-Type) will
119
- provide decoded parameter values when you call the parameter names as methods against
120
- the object.
121
-
122
- 5. Structured fields that have parameter values that can be encoded (e.g. Content-Type) will
123
- provide encoded parameter values when you call the parameter names through the
124
- object.parameters['<parameter_name>'] method call.
125
-
126
- == Contributing
127
-
128
- Please do! Contributing is easy in Mail:
129
-
130
- 1. Check the Reference RFCs, they are in the References directory, so no excuses.
131
- 2. Open a ticket on github, maybe someone else has the problem too
132
- 3. Make a fork of my github repository
133
- 4. Make a spec driven change to the code base
134
- 5. Make sure it works and all specs pass, on Ruby versions 1.8.6, 1.8.7 and 1.9
135
- 6. Update the README if needed to reflect your change / addition
136
- 7. With all specs passing push your changes back to your fork
137
- 8. Send me a pull request
138
-
139
- == Usage
140
-
141
- All major mail functions should be able to happen from the Mail::module.
142
- So, you should be able to just "require 'mail'" to get started.
143
-
144
- === Making an email
145
-
146
- require 'mail'
147
-
148
- mail = Mail.new do
149
- from 'mikel@test.lindsaar.net'
150
- to 'you@test.lindsaar.net'
151
- subject 'This is a test email'
152
- body File.read('body.txt')
153
- end
154
-
155
- mail.to_s #=> "From: mikel@test.lindsaar.net\r\nTo: you@...
156
-
157
- === Making an email, have it your way:
158
-
159
- require 'mail'
160
-
161
- mail = Mail.new do
162
- body File.read('body.txt')
163
- end
164
-
165
- mail['from'] = 'mikel@test.lindsaar.net'
166
- mail[:to] = 'you@test.lindsaar.net'
167
- mail.subject = 'This is a test email'
168
-
169
- mail.to_s #=> "From: mikel@test.lindsaar.net\r\nTo: you@...
170
-
171
- === Don't Worry About Message IDs:
172
-
173
- require 'mail'
174
-
175
- mail = Mail.new do
176
- to 'you@test.lindsaar.net'
177
- body 'Some simple body'
178
- end
179
-
180
- mail.to_s =~ /Message\-ID: <[\d\w_]+@.+.mail/ #=> 27
181
-
182
- Mail will automatically add a Message-ID field if it is missing and
183
- give it a unique, random Message-ID along the lines of:
184
-
185
- <4a7ff76d7016_13a81ab802e1@local.fqdn.mail>
186
-
187
- === Or do worry about Message-IDs:
188
-
189
- require 'mail'
190
-
191
- mail = Mail.new do
192
- to 'you@test.lindsaar.net'
193
- message_id '<ThisIsMyMessageId@some.domain.com>'
194
- body 'Some simple body'
195
- end
196
-
197
- mail.to_s =~ /Message\-ID: <ThisIsMyMessageId@some.domain.com>/ #=> 27
198
-
199
- Mail will take the message_id you assign to it trusting that you know
200
- what you are doing.
201
-
202
- === Sending an email:
203
-
204
- Mail defaults to sending via SMTP to local host port 25. If you have a
205
- sendmail or postfix daemon running on on this port, sending email is as
206
- easy as:
207
-
208
- Mail.deliver do
209
- from 'me@test.lindsaar.net'
210
- to 'you@test.lindsaar.net'
211
- subject 'Here is the image you wanted'
212
- body File.read('body.txt')
213
- add_file '/full/path/to/somefile.png'
214
- end
215
-
216
- or
217
-
218
- mail = Mail.new do
219
- from 'me@test.lindsaar.net'
220
- to 'you@test.lindsaar.net'
221
- subject 'Here is the image you wanted'
222
- body File.read('body.txt')
223
- add_file {:filename => 'somefile.png', :content => File.read('/somefile.png')}
224
- end
225
-
226
- mail.deliver!
227
-
228
- Sending via sendmail can be done like so:
229
-
230
- mail = Mail.new do
231
- from 'me@test.lindsaar.net'
232
- to 'you@test.lindsaar.net'
233
- subject 'Here is the image you wanted'
234
- body File.read('body.txt')
235
- add_file {:filename => 'somefile.png', :content => File.read('/somefile.png')}
236
- end
237
-
238
- mail.delivery_method :sendmail
239
-
240
- mail.deliver
241
-
242
- {Learn more about SMTP Delivery}[link:classes/Mail/SMTP.html]
243
-
244
- {Learn more about File Delivery}[link:classes/Mail/FileDelivery.html]
245
-
246
- {Learn more about Sendmail Delivery}[link:classes/Mail/Sendmail.html]
247
-
248
- {Learn more about Test Email Delivery}[link:classes/Mail/TestMailer.html]
249
-
250
- === Getting emails from a pop server:
251
-
252
- The most recent email:
253
-
254
- Mail.defaults do
255
- retriever_method :pop3, { :address => "pop.gmail.com",
256
- :port => 995,
257
- :user_name => '<username>',
258
- :password => '<password>',
259
- :enable_ssl => true }
260
- end
261
-
262
- Mail.all #=> Returns an array of all emails
263
- Mail.first #=> Returns the first unread email
264
- Mail.last #=> Returns the first unread email
265
-
266
- The first 10 emails sorted by date in ascending order:
267
-
268
- require 'mail'
269
-
270
- Mail.defaults do
271
- retriever_method :pop3, { :address => "pop.gmail.com",
272
- :port => 995,
273
- :user_name => '<username>',
274
- :password => '<password>',
275
- :enable_ssl => true }
276
- end
277
-
278
- emails = Mail.find(:what => :first, :count => 10, :order => :asc)
279
- emails.length #=> 10
280
-
281
- Or even all emails:
282
-
283
- Mail.defaults do
284
- retriever_method :pop3, { :address => "pop.gmail.com",
285
- :port => 995,
286
- :user_name => '<username>',
287
- :password => '<password>',
288
- :enable_ssl => true }
289
- end
290
-
291
- emails = Mail.all
292
-
293
- emails.length #=> LOTS!
294
-
295
- {Learn more about POP3}[link:classes/Mail/POP3.html]
296
-
297
- {Learn more about IMAP}[link:classes/Mail/IMAP.html]
298
-
299
- === Reading an Email
300
-
301
- require 'mail'
302
-
303
- mail = Mail.read('/path/to/message.eml')
304
-
305
- mail.envelope.from #=> 'mikel@test.lindsaar.net'
306
- mail.from.addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
307
- mail.sender.address #=> 'mikel@test.lindsaar.net'
308
- mail.to #=> 'bob@test.lindsaar.net'
309
- mail.cc #=> 'sam@test.lindsaar.net'
310
- mail.subject #=> "This is the subject"
311
- mail.date.to_s #=> '21 Nov 1997 09:55:06 -0600'
312
- mail.message_id #=> '<4D6AA7EB.6490534@xxx.xxx>'
313
- mail.body.decoded #=> 'This is the body of the email...
314
-
315
- Many more methods available.
316
-
317
- === Reading a Multipart Email
318
-
319
- require 'mail'
320
-
321
- mail = Mail.read('multipart_email')
322
-
323
- mail.multipart? #=> true
324
- mail.parts.length #=> 2
325
- mail.preamble #=> "Text before the first part"
326
- mail.epilogue #=> "Text after the last part"
327
- mail.parts.map { |p| p.content_type } #=> ['text/plain', 'application/pdf']
328
- mail.parts.map { |p| p.class } #=> [Mail::Message, Mail::Message]
329
- mail.parts[0].content_type_parameters #=> {'charset' => 'ISO-8859-1'}
330
- mail.parts[1].content_type_parameters #=> {'name' => 'my.pdf'}
331
-
332
- Mail generates a tree of parts. Each message has many or no parts. Each part
333
- is another message which can have many or no parts.
334
-
335
- A message will only have parts if it is a multipart/mixed or related/mixed
336
- content type and has a boundary defined.
337
-
338
- === Writing and sending a multipart/alternative (html and text) email
339
-
340
- Mail makes some basic assumptions and makes doing the common thing as
341
- simple as possible.... (asking a lot from a mail library)
342
-
343
- require 'mail'
344
-
345
- mail = Mail.deliver do
346
- to 'nicolas@test.lindsaar.net.au'
347
- from 'Mikel Lindsaar <mikel@test.lindsaar.net.au>'
348
- subject 'First multipart email sent with Mail'
349
- text_part do
350
- body 'This is plain text'
351
- end
352
- html_part do
353
- content_type 'text/html; charset=UTF-8'
354
- body '<h1>This is HTML</h1>'
355
- end
356
- end
357
-
358
- Mail then delivers the email at the end of the block and returns the
359
- resulting Mail::Message object, which you can then inspect if you
360
- so desire...
361
-
362
- puts mail.to_s #=>
363
-
364
- To: nicolas@test.lindsaar.net.au
365
- From: Mikel Lindsaar <mikel@test.lindsaar.net.au>
366
- Subject: First multipart email sent with Mail
367
- Content-Type: multipart/alternative;
368
- boundary=--==_mimepart_4a914f0c911be_6f0f1ab8026659
369
- Message-ID: <4a914f12ac7e_6f0f1ab80267d1@baci.local.mail>
370
- Date: Mon, 24 Aug 2009 00:15:46 +1000
371
- Mime-Version: 1.0
372
- Content-Transfer-Encoding: 7bit
373
-
374
-
375
- ----==_mimepart_4a914f0c911be_6f0f1ab8026659
376
- Content-ID: <4a914f12c8c4_6f0f1ab80268d6@baci.local.mail>
377
- Date: Mon, 24 Aug 2009 00:15:46 +1000
378
- Mime-Version: 1.0
379
- Content-Type: text/plain
380
- Content-Transfer-Encoding: 7bit
381
-
382
- This is plain text
383
- ----==_mimepart_4a914f0c911be_6f0f1ab8026659
384
- Content-Type: text/html; charset=UTF-8
385
- Content-ID: <4a914f12cf86_6f0f1ab802692c@baci.local.mail>
386
- Date: Mon, 24 Aug 2009 00:15:46 +1000
387
- Mime-Version: 1.0
388
- Content-Transfer-Encoding: 7bit
389
-
390
- <h1>This is HTML</h1>
391
- ----==_mimepart_4a914f0c911be_6f0f1ab8026659--
392
-
393
- Mail inserts the content transfer encoding, the mime version,
394
- the content-id's and handles the content-type and boundary.
395
-
396
- Mail assumes that if your text in the body is only us-ascii, that your
397
- transfer encoding is 7bit and it is text/plain. You can override this
398
- by explicitly declaring it.
399
-
400
- === Making Multipart/Alternate, without a block
401
-
402
- You don't have to use a block with the text and html part included, you
403
- can just do it declaratively. However, you need to add Mail::Parts to
404
- an email, not Mail::Messages.
405
-
406
- require 'mail'
407
-
408
- mail = Mail.new do
409
- to 'nicolas@test.lindsaar.net.au'
410
- from 'Mikel Lindsaar <mikel@test.lindsaar.net.au>'
411
- subject 'First multipart email sent with Mail'
412
- end
413
-
414
- text_part = Mail::Part.new do
415
- body 'This is plain text'
416
- end
417
-
418
- html_part = Mail::Part.new do
419
- content_type 'text/html; charset=UTF-8'
420
- body '<h1>This is HTML</h1>'
421
- end
422
-
423
- mail.text_part = text_part
424
- mail.html_part = html_part
425
-
426
- Results in the same email as done using the block form
427
-
428
- === Getting error reports from an email:
429
-
430
- require 'mail'
431
-
432
- @mail = Mail.read('/path/to/bounce_message.eml')
433
-
434
- @mail.bounced? #=> true
435
- @mail.final_recipient #=> rfc822;mikel@dont.exist.com
436
- @mail.action #=> failed
437
- @mail.error_status #=> 5.5.0
438
- @mail.diagnostic_code #=> smtp;550 Requested action not taken: mailbox unavailable
439
- @mail.retryable? #=> false
440
-
441
- === Attaching and Detaching Files
442
-
443
- require 'mail'
444
-
445
- You can just read the file off an absolute path, Mail will try
446
- to guess the mime_type and will encode the file in Base64 for you.
447
-
448
- @mail = Mail.new
449
- @mail.add_file("/path/to/file.jpg")
450
- @mail.parts.first.attachment? #=> true
451
- @mail.parts.first.content_transfer_encoding.to_s #=> 'base64'
452
- @mail.attachments.first.mime_type #=> 'image/jpg'
453
- @mail.attachments.first.filename #=> 'file.jpg'
454
- @mail.attachments.first.decoded == File.read('/path/to/file.jpg') #=> true
455
-
456
- Or You can pass in file_data and give it a filename, again, mail
457
- will try and guess the mime_type for you.
458
-
459
- @mail = Mail.new
460
- @mail.attachments['myfile.pdf'] = File.read('path/to/myfile.pdf')
461
- @mail.parts.first.attachment? #=> true
462
- @mail.attachments.first.mime_type #=> 'application/pdf'
463
- @mail.attachments.first.decoded == File.read('path/to/myfile.pdf') #=> true
464
-
465
- You can also override the guessed MIME media type if you really know better
466
- than mail (this should be rarely needed)
467
-
468
- @mail = Mail.new
469
- file_data = File.read('path/to/myfile.pdf')
470
- @mail.attachments['myfile.pdf'] = { :mime_type => 'application/x-pdf',
471
- :content => File.read('path/to/myfile.pdf') }
472
- @mail.parts.first.mime_type #=> 'application/x-pdf'
473
-
474
- Of course... Mail will round trip an attachment as well
475
-
476
- @mail = Mail.new do
477
- to 'nicolas@test.lindsaar.net.au'
478
- from 'Mikel Lindsaar <mikel@test.lindsaar.net.au>'
479
- subject 'First multipart email sent with Mail'
480
- text_part do
481
- body 'Here is the attachment you wanted'
482
- end
483
- html_part do
484
- content_type 'text/html; charset=UTF-8'
485
- body '<h1>Funky Title</h1><p>Here is the attachment you wanted</p>'
486
- end
487
- add_file '/path/to/myfile.pdf'
488
- end
489
-
490
- @round_tripped_mail = Mail.new(@mail.encoded)
491
-
492
- @round_tripped_mail.attachments.length #=> 1
493
- @round_tripped_mail.attachments.first.filename #=> 'myfile.pdf'
494
-
495
- == Using Mail with Testing or Spec'ing Libraries
496
-
497
- If mail is part of your system, you'll need a way to test it without actually
498
- sending emails, the TestMailer can do this for you.
499
-
500
- require 'mail'
501
- => true
502
- Mail.defaults do
503
- delivery_method :test
504
- end
505
- => #<Mail::Configuration:0x19345a8 @delivery_method=Mail::TestMailer>
506
- Mail::TestMailer.deliveries
507
- => []
508
- Mail.deliver do
509
- to 'mikel@me.com'
510
- from 'you@you.com'
511
- subject 'testing'
512
- body 'hello'
513
- end
514
- => #<Mail::Message:0x19284ec ...
515
- Mail::TestMailer.deliveries.length
516
- => 1
517
- Mail::TestMailer.deliveries.first
518
- => #<Mail::Message:0x19284ec ...
519
- Mail::TestMailer.deliveries.clear
520
- => []
521
-
522
- == Excerpts from TREC Spam Corpus 2005
523
-
524
- The spec fixture files in spec/fixtures/emails/from_trec_2005 are from the
525
- 2005 TREC Public Spam Corpus. They remain copyrighted under the terms of
526
- that project and license agreement. They are used in this project to verify
527
- and describe the development of this email parser implementation.
528
-
529
- http://plg.uwaterloo.ca/~gvcormac/treccorpus/
530
-
531
- They are used as allowed by 'Permitted Uses, Clause 3':
532
-
533
- "Small excerpts of the information may be displayed to others
534
- or published in a scientific or technical context, solely for
535
- the purpose of describing the research and development and
536
- related issues."
537
-
538
- -- http://plg.uwaterloo.ca/~gvcormac/treccorpus/
539
-
540
- == License:
541
-
542
- (The MIT License)
543
-
544
- Copyright (c) 2009, 2010, 2011
545
-
546
- Permission is hereby granted, free of charge, to any person obtaining
547
- a copy of this software and associated documentation files (the
548
- 'Software'), to deal in the Software without restriction, including
549
- without limitation the rights to use, copy, modify, merge, publish,
550
- distribute, sublicense, and/or sell copies of the Software, and to
551
- permit persons to whom the Software is furnished to do so, subject to
552
- the following conditions:
553
-
554
- The above copyright notice and this permission notice shall be
555
- included in all copies or substantial portions of the Software.
556
-
557
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
558
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
559
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
560
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
561
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
562
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
563
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.