rhizmail 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/lib/rhizmail.rb +10 -15
  2. data/lib/rhizmail.rb~ +56 -5
  3. metadata +2 -2
data/lib/rhizmail.rb CHANGED
@@ -48,7 +48,7 @@ require 'net/smtp'
48
48
  require 'text/format'
49
49
 
50
50
  module RhizMail
51
- Version = '0.1.3'
51
+ Version = '0.1.4'
52
52
 
53
53
  # Sets RhizMail to run using mocks for use in testing. Calling
54
54
  # <tt>RhizMail.mock = true</tt> sets the Mailer to use MockMailer instead.
@@ -120,24 +120,19 @@ module RhizMail
120
120
  end
121
121
 
122
122
  # Sends an email message. +email+ needs to respond to +verify_sendable+;
123
- # Mailer##send_email will call +verify_sendable+ before sending the email.
124
- def send_email(email)
123
+ # Mailer##send_message will call +verify_sendable+ before sending the email.
124
+ def send_message(email)
125
125
  email.verify_sendable
126
126
  msg = []
127
127
  email.headers.each { |header| msg << "#{header}\n" }
128
128
  msg << "\n"
129
129
  msg << email.body
130
- begin
131
- @@smtpClass.start(
132
- @@smtpServer, @@smtpLogin, @@smtpPassword, @@smtpAuthType
133
- ) { |smtp|
134
- smtp.sendmail(msg, email.from_address, [ email.to_address ])
135
- }
136
- @@messagesSent << email
137
- rescue Net::ProtoFatalError, TimeoutError, Errno::ECONNREFUSED,
138
- Errno::ECONNRESET
139
- # whatever
130
+ @@smtpClass.start(
131
+ @@smtpServer, @@smtpLogin, @@smtpPassword, @@smtpAuthType
132
+ ) do |smtp|
133
+ smtp.sendmail( msg, email.from_address, [ email.to_address ] )
140
134
  end
135
+ @@messagesSent << email
141
136
  end
142
137
 
143
138
  # Returns an array of what messages have been sent.
@@ -183,7 +178,7 @@ module RhizMail
183
178
  end
184
179
 
185
180
  # Sends the email.
186
- def deliver; Mailer.get_mailer.send_email( self ); end
181
+ def deliver; Mailer.get_mailer.send_message( self ); end
187
182
 
188
183
  def from_header # :nodoc:
189
184
  fromHeader = "From: "
@@ -260,7 +255,7 @@ module RhizMail
260
255
 
261
256
  # Pretends to send an email, recording it in +messages_sent+ to allow
262
257
  # inspection later.
263
- def send_email(email)
258
+ def send_message(email)
264
259
  email.verify_sendable
265
260
  @messages_sent << email
266
261
  end
data/lib/rhizmail.rb~ CHANGED
@@ -30,6 +30,10 @@
30
30
  # RhizMail comes with a SimpleTemplateMessage class, suited for times when you
31
31
  # want email templating that is simpler than Amrita or ERB.
32
32
  #
33
+ # == Contributors
34
+ #
35
+ # Brian Takita added SMTP authentication for 0.1.3.
36
+ #
33
37
  # == Dependencies
34
38
  #
35
39
  # RhizMail depends on three external libraries:
@@ -44,7 +48,17 @@ require 'net/smtp'
44
48
  require 'text/format'
45
49
 
46
50
  module RhizMail
47
- Version = '0.1.2'
51
+ Version = '0.1.3'
52
+
53
+ # Sets RhizMail to run using mocks for use in testing. Calling
54
+ # <tt>RhizMail.mock = true</tt> sets the Mailer to use MockMailer instead.
55
+ def self.mock=( maybe_mock )
56
+ if maybe_mock and Mailer.get_mailer.is_a?( Mailer )
57
+ Mailer.set_mailer MockMailer.new
58
+ elsif !maybe_mock and Mailer.get_mailer.is_a?( MockMailer )
59
+ ContextualService::Context.instance.set_resource( Mailer, nil )
60
+ end
61
+ end
48
62
 
49
63
  # Returns a boolean value describing whether <tt>address</tt> is a plausible
50
64
  # email address format.
@@ -61,7 +75,42 @@ module RhizMail
61
75
  class Mailer < ContextualService::Service
62
76
  @@smtpServer = 'localhost'
63
77
  @@smtpClass = Net::SMTP
78
+ @@smtpLogin = nil
79
+ @@smtpPassword = nil
80
+ @@smtpAuthType = nil
64
81
  @@messagesSent = []
82
+
83
+ def self.smtp_server
84
+ @@smtpServer
85
+ end
86
+
87
+ def self.smtp_server=(smtpServer)
88
+ @@smtpServer = smtpServer
89
+ end
90
+
91
+ def self.smtp_login
92
+ @@smtpLogin
93
+ end
94
+
95
+ def self.smtp_login=(smtpLogin)
96
+ @@smtpLogin = smtpLogin
97
+ end
98
+
99
+ def self.smtp_password
100
+ @@smtpPassword
101
+ end
102
+
103
+ def self.smtp_password=(smtpPassword)
104
+ @@smtpPassword = smtpPassword
105
+ end
106
+
107
+ def self.smtp_auth_type
108
+ @@smtpAuthType
109
+ end
110
+
111
+ def self.smtp_auth_type=(smtpAuthType)
112
+ @@smtpAuthType = smtpAuthType
113
+ end
65
114
 
66
115
  # Flushes record of messages sent.
67
116
  def self.flush; @@messagesSent = []; end
@@ -79,7 +128,9 @@ module RhizMail
79
128
  msg << "\n"
80
129
  msg << email.body
81
130
  begin
82
- @@smtpClass.start( @@smtpServer ) { |smtp|
131
+ @@smtpClass.start(
132
+ @@smtpServer, @@smtpLogin, @@smtpPassword, @@smtpAuthType
133
+ ) { |smtp|
83
134
  smtp.sendmail(msg, email.from_address, [ email.to_address ])
84
135
  }
85
136
  @@messagesSent << email
@@ -137,7 +188,7 @@ module RhizMail
137
188
  def from_header # :nodoc:
138
189
  fromHeader = "From: "
139
190
  if @from_name
140
- fromHeader += "#{@from_name} <#{@from_address}>"
191
+ fromHeader += "\"#{@from_name}\" <#{@from_address}>"
141
192
  else
142
193
  fromHeader += "#{@from_address}"
143
194
  end
@@ -164,9 +215,9 @@ module RhizMail
164
215
  def to_header # :nodoc:
165
216
  toHeader = "To: "
166
217
  if @to_name
167
- toHeader += " #{@to_name} <#{@to_address}>"
218
+ toHeader += "\"#{@to_name}\" <#{@to_address}>"
168
219
  else
169
- toHeader += " #{@to_address}"
220
+ toHeader += "#{@to_address}"
170
221
  end
171
222
  toHeader
172
223
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.6
3
3
  specification_version: 1
4
4
  name: rhizmail
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.3
7
- date: 2005-10-26
6
+ version: 0.1.4
7
+ date: 2005-12-28
8
8
  summary: RhizMail is a test-friendly library for sending out customized emails.
9
9
  require_paths:
10
10
  - lib