otherinbox-mail 2.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. data/CHANGELOG.rdoc +607 -0
  2. data/CONTRIBUTING.md +45 -0
  3. data/Dependencies.txt +3 -0
  4. data/Gemfile +26 -0
  5. data/Gemfile.lock +44 -0
  6. data/README.md +663 -0
  7. data/Rakefile +40 -0
  8. data/TODO.rdoc +9 -0
  9. data/lib/VERSION +4 -0
  10. data/lib/mail.rb +101 -0
  11. data/lib/mail/attachments_list.rb +104 -0
  12. data/lib/mail/body.rb +291 -0
  13. data/lib/mail/configuration.rb +75 -0
  14. data/lib/mail/core_extensions/nil.rb +17 -0
  15. data/lib/mail/core_extensions/object.rb +13 -0
  16. data/lib/mail/core_extensions/shell_escape.rb +56 -0
  17. data/lib/mail/core_extensions/smtp.rb +25 -0
  18. data/lib/mail/core_extensions/string.rb +33 -0
  19. data/lib/mail/core_extensions/string/access.rb +145 -0
  20. data/lib/mail/core_extensions/string/multibyte.rb +78 -0
  21. data/lib/mail/elements.rb +14 -0
  22. data/lib/mail/elements/address.rb +306 -0
  23. data/lib/mail/elements/address_list.rb +74 -0
  24. data/lib/mail/elements/content_disposition_element.rb +30 -0
  25. data/lib/mail/elements/content_location_element.rb +25 -0
  26. data/lib/mail/elements/content_transfer_encoding_element.rb +24 -0
  27. data/lib/mail/elements/content_type_element.rb +35 -0
  28. data/lib/mail/elements/date_time_element.rb +26 -0
  29. data/lib/mail/elements/envelope_from_element.rb +34 -0
  30. data/lib/mail/elements/message_ids_element.rb +29 -0
  31. data/lib/mail/elements/mime_version_element.rb +26 -0
  32. data/lib/mail/elements/phrase_list.rb +21 -0
  33. data/lib/mail/elements/received_element.rb +30 -0
  34. data/lib/mail/encodings.rb +274 -0
  35. data/lib/mail/encodings/7bit.rb +31 -0
  36. data/lib/mail/encodings/8bit.rb +31 -0
  37. data/lib/mail/encodings/base64.rb +33 -0
  38. data/lib/mail/encodings/binary.rb +31 -0
  39. data/lib/mail/encodings/quoted_printable.rb +38 -0
  40. data/lib/mail/encodings/transfer_encoding.rb +58 -0
  41. data/lib/mail/envelope.rb +35 -0
  42. data/lib/mail/field.rb +234 -0
  43. data/lib/mail/field_list.rb +33 -0
  44. data/lib/mail/fields.rb +35 -0
  45. data/lib/mail/fields/bcc_field.rb +56 -0
  46. data/lib/mail/fields/cc_field.rb +55 -0
  47. data/lib/mail/fields/comments_field.rb +41 -0
  48. data/lib/mail/fields/common/address_container.rb +16 -0
  49. data/lib/mail/fields/common/common_address.rb +125 -0
  50. data/lib/mail/fields/common/common_date.rb +42 -0
  51. data/lib/mail/fields/common/common_field.rb +51 -0
  52. data/lib/mail/fields/common/common_message_id.rb +44 -0
  53. data/lib/mail/fields/common/parameter_hash.rb +58 -0
  54. data/lib/mail/fields/content_description_field.rb +19 -0
  55. data/lib/mail/fields/content_disposition_field.rb +69 -0
  56. data/lib/mail/fields/content_id_field.rb +63 -0
  57. data/lib/mail/fields/content_location_field.rb +42 -0
  58. data/lib/mail/fields/content_transfer_encoding_field.rb +50 -0
  59. data/lib/mail/fields/content_type_field.rb +198 -0
  60. data/lib/mail/fields/date_field.rb +57 -0
  61. data/lib/mail/fields/from_field.rb +55 -0
  62. data/lib/mail/fields/in_reply_to_field.rb +55 -0
  63. data/lib/mail/fields/keywords_field.rb +44 -0
  64. data/lib/mail/fields/message_id_field.rb +83 -0
  65. data/lib/mail/fields/mime_version_field.rb +53 -0
  66. data/lib/mail/fields/optional_field.rb +13 -0
  67. data/lib/mail/fields/received_field.rb +75 -0
  68. data/lib/mail/fields/references_field.rb +55 -0
  69. data/lib/mail/fields/reply_to_field.rb +55 -0
  70. data/lib/mail/fields/resent_bcc_field.rb +55 -0
  71. data/lib/mail/fields/resent_cc_field.rb +55 -0
  72. data/lib/mail/fields/resent_date_field.rb +35 -0
  73. data/lib/mail/fields/resent_from_field.rb +55 -0
  74. data/lib/mail/fields/resent_message_id_field.rb +34 -0
  75. data/lib/mail/fields/resent_sender_field.rb +62 -0
  76. data/lib/mail/fields/resent_to_field.rb +55 -0
  77. data/lib/mail/fields/return_path_field.rb +65 -0
  78. data/lib/mail/fields/sender_field.rb +67 -0
  79. data/lib/mail/fields/structured_field.rb +51 -0
  80. data/lib/mail/fields/subject_field.rb +16 -0
  81. data/lib/mail/fields/to_field.rb +55 -0
  82. data/lib/mail/fields/unstructured_field.rb +191 -0
  83. data/lib/mail/header.rb +265 -0
  84. data/lib/mail/indifferent_hash.rb +146 -0
  85. data/lib/mail/mail.rb +255 -0
  86. data/lib/mail/matchers/has_sent_mail.rb +124 -0
  87. data/lib/mail/message.rb +2059 -0
  88. data/lib/mail/multibyte.rb +42 -0
  89. data/lib/mail/multibyte/chars.rb +474 -0
  90. data/lib/mail/multibyte/exceptions.rb +8 -0
  91. data/lib/mail/multibyte/unicode.rb +392 -0
  92. data/lib/mail/multibyte/utils.rb +60 -0
  93. data/lib/mail/network.rb +14 -0
  94. data/lib/mail/network/delivery_methods/exim.rb +53 -0
  95. data/lib/mail/network/delivery_methods/file_delivery.rb +40 -0
  96. data/lib/mail/network/delivery_methods/sendmail.rb +62 -0
  97. data/lib/mail/network/delivery_methods/smtp.rb +153 -0
  98. data/lib/mail/network/delivery_methods/smtp_connection.rb +74 -0
  99. data/lib/mail/network/delivery_methods/test_mailer.rb +40 -0
  100. data/lib/mail/network/retriever_methods/base.rb +63 -0
  101. data/lib/mail/network/retriever_methods/imap.rb +168 -0
  102. data/lib/mail/network/retriever_methods/pop3.rb +140 -0
  103. data/lib/mail/network/retriever_methods/test_retriever.rb +47 -0
  104. data/lib/mail/parsers/address_lists.rb +64 -0
  105. data/lib/mail/parsers/address_lists.treetop +19 -0
  106. data/lib/mail/parsers/content_disposition.rb +535 -0
  107. data/lib/mail/parsers/content_disposition.treetop +46 -0
  108. data/lib/mail/parsers/content_location.rb +139 -0
  109. data/lib/mail/parsers/content_location.treetop +20 -0
  110. data/lib/mail/parsers/content_transfer_encoding.rb +162 -0
  111. data/lib/mail/parsers/content_transfer_encoding.treetop +20 -0
  112. data/lib/mail/parsers/content_type.rb +967 -0
  113. data/lib/mail/parsers/content_type.treetop +68 -0
  114. data/lib/mail/parsers/date_time.rb +114 -0
  115. data/lib/mail/parsers/date_time.treetop +11 -0
  116. data/lib/mail/parsers/envelope_from.rb +194 -0
  117. data/lib/mail/parsers/envelope_from.treetop +32 -0
  118. data/lib/mail/parsers/message_ids.rb +45 -0
  119. data/lib/mail/parsers/message_ids.treetop +15 -0
  120. data/lib/mail/parsers/mime_version.rb +144 -0
  121. data/lib/mail/parsers/mime_version.treetop +19 -0
  122. data/lib/mail/parsers/phrase_lists.rb +45 -0
  123. data/lib/mail/parsers/phrase_lists.treetop +15 -0
  124. data/lib/mail/parsers/received.rb +71 -0
  125. data/lib/mail/parsers/received.treetop +11 -0
  126. data/lib/mail/parsers/rfc2045.rb +464 -0
  127. data/lib/mail/parsers/rfc2045.treetop +36 -0
  128. data/lib/mail/parsers/rfc2822.rb +5341 -0
  129. data/lib/mail/parsers/rfc2822.treetop +410 -0
  130. data/lib/mail/parsers/rfc2822_obsolete.rb +3768 -0
  131. data/lib/mail/parsers/rfc2822_obsolete.treetop +241 -0
  132. data/lib/mail/part.rb +116 -0
  133. data/lib/mail/parts_list.rb +55 -0
  134. data/lib/mail/patterns.rb +34 -0
  135. data/lib/mail/utilities.rb +215 -0
  136. data/lib/mail/version.rb +24 -0
  137. data/lib/mail/version_specific/ruby_1_8.rb +98 -0
  138. data/lib/mail/version_specific/ruby_1_9.rb +113 -0
  139. data/lib/tasks/corpus.rake +125 -0
  140. data/lib/tasks/treetop.rake +10 -0
  141. metadata +253 -0
@@ -0,0 +1,14 @@
1
+ require 'mail/network/retriever_methods/base'
2
+
3
+ module Mail
4
+ register_autoload :SMTP, 'mail/network/delivery_methods/smtp'
5
+ register_autoload :FileDelivery, 'mail/network/delivery_methods/file_delivery'
6
+ register_autoload :Sendmail, 'mail/network/delivery_methods/sendmail'
7
+ register_autoload :Exim, 'mail/network/delivery_methods/exim'
8
+ register_autoload :SMTPConnection, 'mail/network/delivery_methods/smtp_connection'
9
+ register_autoload :TestMailer, 'mail/network/delivery_methods/test_mailer'
10
+
11
+ register_autoload :POP3, 'mail/network/retriever_methods/pop3'
12
+ register_autoload :IMAP, 'mail/network/retriever_methods/imap'
13
+ register_autoload :TestRetriever, 'mail/network/retriever_methods/test_retriever'
14
+ end
@@ -0,0 +1,53 @@
1
+ module Mail
2
+
3
+ # A delivery method implementation which sends via exim.
4
+ #
5
+ # To use this, first find out where the exim binary is on your computer,
6
+ # if you are on a mac or unix box, it is usually in /usr/sbin/exim, this will
7
+ # be your exim location.
8
+ #
9
+ # Mail.defaults do
10
+ # delivery_method :exim
11
+ # end
12
+ #
13
+ # Or if your exim binary is not at '/usr/sbin/exim'
14
+ #
15
+ # Mail.defaults do
16
+ # delivery_method :exim, :location => '/absolute/path/to/your/exim'
17
+ # end
18
+ #
19
+ # Then just deliver the email as normal:
20
+ #
21
+ # Mail.deliver do
22
+ # to 'mikel@test.lindsaar.net'
23
+ # from 'ada@test.lindsaar.net'
24
+ # subject 'testing exim'
25
+ # body 'testing exim'
26
+ # end
27
+ #
28
+ # Or by calling deliver on a Mail message
29
+ #
30
+ # mail = Mail.new do
31
+ # to 'mikel@test.lindsaar.net'
32
+ # from 'ada@test.lindsaar.net'
33
+ # subject 'testing exim'
34
+ # body 'testing exim'
35
+ # end
36
+ #
37
+ # mail.deliver!
38
+ class Exim < Sendmail
39
+
40
+ def initialize(values)
41
+ self.settings = { :location => '/usr/sbin/exim',
42
+ :arguments => '-i -t' }.merge(values)
43
+ end
44
+
45
+ def self.call(path, arguments, mail)
46
+ IO.popen("#{path} #{arguments}", "w+") do |io|
47
+ io.puts mail.encoded.to_lf
48
+ io.flush
49
+ end
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,40 @@
1
+ module Mail
2
+
3
+ # FileDelivery class delivers emails into multiple files based on the destination
4
+ # address. Each file is appended to if it already exists.
5
+ #
6
+ # So if you have an email going to fred@test, bob@test, joe@anothertest, and you
7
+ # set your location path to /path/to/mails then FileDelivery will create the directory
8
+ # if it does not exist, and put one copy of the email in three files, called
9
+ # by their message id
10
+ #
11
+ # Make sure the path you specify with :location is writable by the Ruby process
12
+ # running Mail.
13
+ class FileDelivery
14
+
15
+ if RUBY_VERSION >= '1.9.1'
16
+ require 'fileutils'
17
+ else
18
+ require 'ftools'
19
+ end
20
+
21
+ def initialize(values)
22
+ self.settings = { :location => './mails' }.merge!(values)
23
+ end
24
+
25
+ attr_accessor :settings
26
+
27
+ def deliver!(mail)
28
+ if ::File.respond_to?(:makedirs)
29
+ ::File.makedirs settings[:location]
30
+ else
31
+ ::FileUtils.mkdir_p settings[:location]
32
+ end
33
+
34
+ mail.destinations.uniq.each do |to|
35
+ ::File.open(::File.join(settings[:location], File.basename(to.to_s)), 'a') { |f| "#{f.write(mail.encoded)}\r\n\r\n" }
36
+ end
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,62 @@
1
+ module Mail
2
+ # A delivery method implementation which sends via sendmail.
3
+ #
4
+ # To use this, first find out where the sendmail binary is on your computer,
5
+ # if you are on a mac or unix box, it is usually in /usr/sbin/sendmail, this will
6
+ # be your sendmail location.
7
+ #
8
+ # Mail.defaults do
9
+ # delivery_method :sendmail
10
+ # end
11
+ #
12
+ # Or if your sendmail binary is not at '/usr/sbin/sendmail'
13
+ #
14
+ # Mail.defaults do
15
+ # delivery_method :sendmail, :location => '/absolute/path/to/your/sendmail'
16
+ # end
17
+ #
18
+ # Then just deliver the email as normal:
19
+ #
20
+ # Mail.deliver do
21
+ # to 'mikel@test.lindsaar.net'
22
+ # from 'ada@test.lindsaar.net'
23
+ # subject 'testing sendmail'
24
+ # body 'testing sendmail'
25
+ # end
26
+ #
27
+ # Or by calling deliver on a Mail message
28
+ #
29
+ # mail = Mail.new do
30
+ # to 'mikel@test.lindsaar.net'
31
+ # from 'ada@test.lindsaar.net'
32
+ # subject 'testing sendmail'
33
+ # body 'testing sendmail'
34
+ # end
35
+ #
36
+ # mail.deliver!
37
+ class Sendmail
38
+
39
+ def initialize(values)
40
+ self.settings = { :location => '/usr/sbin/sendmail',
41
+ :arguments => '-i -t' }.merge(values)
42
+ end
43
+
44
+ attr_accessor :settings
45
+
46
+ def deliver!(mail)
47
+ envelope_from = mail.return_path || mail.sender || mail.from_addrs.first
48
+ return_path = "-f " + '"' + envelope_from.escape_for_shell + '"' if envelope_from
49
+
50
+ arguments = [settings[:arguments], return_path].compact.join(" ")
51
+
52
+ self.class.call(settings[:location], arguments, mail.destinations.collect(&:escape_for_shell).join(" "), mail)
53
+ end
54
+
55
+ def self.call(path, arguments, destinations, mail)
56
+ IO.popen("#{path} #{arguments} #{destinations}", "w+") do |io|
57
+ io.puts mail.encoded.to_lf
58
+ io.flush
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,153 @@
1
+ module Mail
2
+ # == Sending Email with SMTP
3
+ #
4
+ # Mail allows you to send emails using SMTP. This is done by wrapping Net::SMTP in
5
+ # an easy to use manner.
6
+ #
7
+ # === Sending via SMTP server on Localhost
8
+ #
9
+ # Sending locally (to a postfix or sendmail server running on localhost) requires
10
+ # no special setup. Just to Mail.deliver &block or message.deliver! and it will
11
+ # be sent in this method.
12
+ #
13
+ # === Sending via MobileMe
14
+ #
15
+ # Mail.defaults do
16
+ # delivery_method :smtp, { :address => "smtp.me.com",
17
+ # :port => 587,
18
+ # :domain => 'your.host.name',
19
+ # :user_name => '<username>',
20
+ # :password => '<password>',
21
+ # :authentication => 'plain',
22
+ # :enable_starttls_auto => true }
23
+ # end
24
+ #
25
+ # === Sending via GMail
26
+ #
27
+ # Mail.defaults do
28
+ # delivery_method :smtp, { :address => "smtp.gmail.com",
29
+ # :port => 587,
30
+ # :domain => 'your.host.name',
31
+ # :user_name => '<username>',
32
+ # :password => '<password>',
33
+ # :authentication => 'plain',
34
+ # :enable_starttls_auto => true }
35
+ # end
36
+ #
37
+ # === Certificate verification
38
+ #
39
+ # When using TLS, some mail servers provide certificates that are self-signed
40
+ # or whose names do not exactly match the hostname given in the address.
41
+ # OpenSSL will reject these by default. The best remedy is to use the correct
42
+ # hostname or update the certificate authorities trusted by your ruby. If
43
+ # that isn't possible, you can control this behavior with
44
+ # an :openssl_verify_mode setting. Its value may be either an OpenSSL
45
+ # verify mode constant (OpenSSL::SSL::VERIFY_NONE), or a string containing
46
+ # the name of an OpenSSL verify mode (none, peer, client_once,
47
+ # fail_if_no_peer_cert).
48
+ #
49
+ # === Others
50
+ #
51
+ # Feel free to send me other examples that were tricky
52
+ #
53
+ # === Delivering the email
54
+ #
55
+ # Once you have the settings right, sending the email is done by:
56
+ #
57
+ # Mail.deliver do
58
+ # to 'mikel@test.lindsaar.net'
59
+ # from 'ada@test.lindsaar.net'
60
+ # subject 'testing sendmail'
61
+ # body 'testing sendmail'
62
+ # end
63
+ #
64
+ # Or by calling deliver on a Mail message
65
+ #
66
+ # mail = Mail.new do
67
+ # to 'mikel@test.lindsaar.net'
68
+ # from 'ada@test.lindsaar.net'
69
+ # subject 'testing sendmail'
70
+ # body 'testing sendmail'
71
+ # end
72
+ #
73
+ # mail.deliver!
74
+ class SMTP
75
+
76
+ def initialize(values)
77
+ self.settings = { :address => "localhost",
78
+ :port => 25,
79
+ :domain => 'localhost.localdomain',
80
+ :user_name => nil,
81
+ :password => nil,
82
+ :authentication => nil,
83
+ :enable_starttls_auto => true,
84
+ :openssl_verify_mode => nil,
85
+ :ssl => nil,
86
+ :tls => nil
87
+ }.merge!(values)
88
+ end
89
+
90
+ attr_accessor :settings
91
+
92
+ # Send the message via SMTP.
93
+ # The from and to attributes are optional. If not set, they are retrieve from the Message.
94
+ def deliver!(mail)
95
+
96
+ # Set the envelope from to be either the return-path, the sender or the first from address
97
+ envelope_from = mail.return_path || mail.sender || mail.from_addrs.first
98
+ if envelope_from.blank?
99
+ raise ArgumentError.new('A sender (Return-Path, Sender or From) required to send a message')
100
+ end
101
+
102
+ destinations ||= mail.destinations if mail.respond_to?(:destinations) && mail.destinations
103
+ if destinations.blank?
104
+ raise ArgumentError.new('At least one recipient (To, Cc or Bcc) is required to send a message')
105
+ end
106
+
107
+ message ||= mail.encoded if mail.respond_to?(:encoded)
108
+ if message.blank?
109
+ raise ArgumentError.new('A encoded content is required to send a message')
110
+ end
111
+
112
+ smtp = Net::SMTP.new(settings[:address], settings[:port])
113
+ if settings[:tls] || settings[:ssl]
114
+ if smtp.respond_to?(:enable_tls)
115
+ unless settings[:openssl_verify_mode]
116
+ smtp.enable_tls
117
+ else
118
+ openssl_verify_mode = settings[:openssl_verify_mode]
119
+ if openssl_verify_mode.kind_of?(String)
120
+ openssl_verify_mode = "OpenSSL::SSL::VERIFY_#{openssl_verify_mode.upcase}".constantize
121
+ end
122
+ context = Net::SMTP.default_ssl_context
123
+ context.verify_mode = openssl_verify_mode
124
+ smtp.enable_tls(context)
125
+ end
126
+ end
127
+ elsif settings[:enable_starttls_auto]
128
+ if smtp.respond_to?(:enable_starttls_auto)
129
+ unless settings[:openssl_verify_mode]
130
+ smtp.enable_starttls_auto
131
+ else
132
+ openssl_verify_mode = settings[:openssl_verify_mode]
133
+ if openssl_verify_mode.kind_of?(String)
134
+ openssl_verify_mode = "OpenSSL::SSL::VERIFY_#{openssl_verify_mode.upcase}".constantize
135
+ end
136
+ context = Net::SMTP.default_ssl_context
137
+ context.verify_mode = openssl_verify_mode
138
+ smtp.enable_starttls_auto(context)
139
+ end
140
+ end
141
+ end
142
+
143
+ response = nil
144
+ smtp.start(settings[:domain], settings[:user_name], settings[:password], settings[:authentication]) do |smtp_obj|
145
+ response = smtp_obj.sendmail(message, envelope_from, destinations)
146
+ end
147
+
148
+ return settings[:return_response] ? response : self
149
+ end
150
+
151
+
152
+ end
153
+ end
@@ -0,0 +1,74 @@
1
+ module Mail
2
+ # == Sending Email with SMTP
3
+ #
4
+ # Mail allows you to send emails using an open SMTP connection. This is done by
5
+ # passing a created Net::SMTP object. This way we can get better performance to
6
+ # our local mail server by reducing the number of connections at any one time.
7
+ #
8
+ # === Sending via SMTP server on Localhost
9
+ #
10
+ # To send mail open a connection with Net::Smtp using any options you like
11
+ # === Delivering the email
12
+ #
13
+ # Once you have the settings right, sending the email is done by:
14
+ #
15
+ # smtp_conn = Net::SMTP.start(settings[:address], settings[:port])
16
+ # Mail.defaults do
17
+ # delivery_method :smtp_connection, { :connection => smtp_conn }
18
+ # end
19
+ #
20
+ # Mail.deliver do
21
+ # to 'mikel@test.lindsaar.net'
22
+ # from 'ada@test.lindsaar.net'
23
+ # subject 'testing sendmail'
24
+ # body 'testing sendmail'
25
+ # end
26
+ #
27
+ # Or by calling deliver on a Mail message
28
+ #
29
+ # mail = Mail.new do
30
+ # to 'mikel@test.lindsaar.net'
31
+ # from 'ada@test.lindsaar.net'
32
+ # subject 'testing sendmail'
33
+ # body 'testing sendmail'
34
+ # end
35
+ #
36
+ # mail.deliver!
37
+ class SMTPConnection
38
+
39
+ def initialize(values)
40
+ raise ArgumentError.new('A Net::SMTP object is required for this delivery method') if values[:connection].nil?
41
+ self.smtp = values[:connection]
42
+ self.settings = values
43
+ end
44
+
45
+ attr_accessor :smtp
46
+ attr_accessor :settings
47
+
48
+ # Send the message via SMTP.
49
+ # The from and to attributes are optional. If not set, they are retrieve from the Message.
50
+ def deliver!(mail)
51
+
52
+ # Set the envelope from to be either the return-path, the sender or the first from address
53
+ envelope_from = mail.return_path || mail.sender || mail.from_addrs.first
54
+ if envelope_from.blank?
55
+ raise ArgumentError.new('A sender (Return-Path, Sender or From) required to send a message')
56
+ end
57
+
58
+ destinations ||= mail.destinations if mail.respond_to?(:destinations) && mail.destinations
59
+ if destinations.blank?
60
+ raise ArgumentError.new('At least one recipient (To, Cc or Bcc) is required to send a message')
61
+ end
62
+
63
+ message ||= mail.encoded if mail.respond_to?(:encoded)
64
+ if message.blank?
65
+ raise ArgumentError.new('A encoded content is required to send a message')
66
+ end
67
+
68
+ response = smtp.sendmail(message, envelope_from, destinations)
69
+
70
+ settings[:return_response] ? response : self
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,40 @@
1
+ module Mail
2
+ # The TestMailer is a bare bones mailer that does nothing. It is useful
3
+ # when you are testing.
4
+ #
5
+ # It also provides a template of the minimum methods you require to implement
6
+ # if you want to make a custom mailer for Mail
7
+ class TestMailer
8
+
9
+ # Provides a store of all the emails sent with the TestMailer so you can check them.
10
+ def TestMailer.deliveries
11
+ @@deliveries ||= []
12
+ end
13
+
14
+ # Allows you to over write the default deliveries store from an array to some
15
+ # other object. If you just want to clear the store,
16
+ # call TestMailer.deliveries.clear.
17
+ #
18
+ # If you place another object here, please make sure it responds to:
19
+ #
20
+ # * << (message)
21
+ # * clear
22
+ # * length
23
+ # * size
24
+ # * and other common Array methods
25
+ def TestMailer.deliveries=(val)
26
+ @@deliveries = val
27
+ end
28
+
29
+ def initialize(values)
30
+ @settings = {}
31
+ end
32
+
33
+ attr_accessor :settings
34
+
35
+ def deliver!(mail)
36
+ Mail::TestMailer.deliveries << mail
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,63 @@
1
+ # encoding: utf-8
2
+
3
+ module Mail
4
+
5
+ class Retriever
6
+
7
+ # Get the oldest received email(s)
8
+ #
9
+ # Possible options:
10
+ # count: number of emails to retrieve. The default value is 1.
11
+ # order: order of emails returned. Possible values are :asc or :desc. Default value is :asc.
12
+ #
13
+ def first(options = {}, &block)
14
+ options ||= {}
15
+ options[:what] = :first
16
+ options[:count] ||= 1
17
+ find(options, &block)
18
+ end
19
+
20
+ # Get the most recent received email(s)
21
+ #
22
+ # Possible options:
23
+ # count: number of emails to retrieve. The default value is 1.
24
+ # order: order of emails returned. Possible values are :asc or :desc. Default value is :asc.
25
+ #
26
+ def last(options = {}, &block)
27
+ options ||= {}
28
+ options[:what] = :last
29
+ options[:count] ||= 1
30
+ find(options, &block)
31
+ end
32
+
33
+ # Get all emails.
34
+ #
35
+ # Possible options:
36
+ # order: order of emails returned. Possible values are :asc or :desc. Default value is :asc.
37
+ #
38
+ def all(options = {}, &block)
39
+ options ||= {}
40
+ options[:count] = :all
41
+ find(options, &block)
42
+ end
43
+
44
+ # Find emails in the mailbox, and then deletes them. Without any options, the
45
+ # five last received emails are returned.
46
+ #
47
+ # Possible options:
48
+ # what: last or first emails. The default is :first.
49
+ # order: order of emails returned. Possible values are :asc or :desc. Default value is :asc.
50
+ # count: number of emails to retrieve. The default value is 10. A value of 1 returns an
51
+ # instance of Message, not an array of Message instances.
52
+ # delete_after_find: flag for whether to delete each retreived email after find. Default
53
+ # is true. Call #find if you would like this to default to false.
54
+ #
55
+ def find_and_delete(options = {}, &block)
56
+ options ||= {}
57
+ options[:delete_after_find] ||= true
58
+ find(options, &block)
59
+ end
60
+
61
+ end
62
+
63
+ end