mattmatt-cijoe 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.
- data/lib/cijoe/version.rb +1 -1
- data/lib/mmmail.rb +1 -1
- data/lib/smtp_tls.rb +113 -0
- metadata +2 -1
data/lib/cijoe/version.rb
CHANGED
data/lib/mmmail.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
# http://github.com/lsegal/mmmail/
|
3
3
|
|
4
4
|
require 'net/smtp'
|
5
|
-
require File.expand_path(File.dirname(__FILE__) + '/
|
5
|
+
require File.expand_path(File.dirname(__FILE__) + '/smtp_tls')
|
6
6
|
|
7
7
|
module MmMail
|
8
8
|
# General exception class when something goes wrong in MmMail
|
data/lib/smtp_tls.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
# Include hook code here
|
2
|
+
|
3
|
+
require 'net/smtp'
|
4
|
+
require 'timeout'
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'openssl'
|
8
|
+
rescue LoadError
|
9
|
+
end
|
10
|
+
|
11
|
+
Net::SMTP.class_eval do
|
12
|
+
|
13
|
+
alias_method :old_initialize, :initialize
|
14
|
+
def initialize(*args)
|
15
|
+
@usetls = @@usetls
|
16
|
+
old_initialize *args
|
17
|
+
end
|
18
|
+
|
19
|
+
@@usetls = false
|
20
|
+
|
21
|
+
def self.enable_tls()
|
22
|
+
@@usetls = true
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.disable_tls()
|
26
|
+
@@usetls = false
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.use_tls?()
|
30
|
+
@@usetls
|
31
|
+
end
|
32
|
+
|
33
|
+
def use_tls?()
|
34
|
+
@usetls
|
35
|
+
end
|
36
|
+
|
37
|
+
def enable_tls()
|
38
|
+
print "tls enabled\n"
|
39
|
+
@usetls = true
|
40
|
+
end
|
41
|
+
|
42
|
+
def disable_tls()
|
43
|
+
@usetls = false
|
44
|
+
end
|
45
|
+
|
46
|
+
def use_tls?()
|
47
|
+
@usetls
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
def do_start(helodomain, user, secret, authtype)
|
52
|
+
raise IOError 'SMTP session already started' if @started
|
53
|
+
if user or secret
|
54
|
+
check_auth_method(authtype || DEFAULT_AUTH_TYPE)
|
55
|
+
check_auth_args user, secret
|
56
|
+
end
|
57
|
+
|
58
|
+
sock = timeout(@open_timeout) {TCPSocket.open(@address, @port) }
|
59
|
+
@socket = Net::InternetMessageIO.new(sock)
|
60
|
+
@socket.read_timeout = @read_timeout
|
61
|
+
@socket.debug_output = STDERR
|
62
|
+
|
63
|
+
check_response(critical {recv_response() } )
|
64
|
+
do_helo(helodomain)
|
65
|
+
|
66
|
+
if @usetls
|
67
|
+
raise 'openssl is not installed' unless defined?(OpenSSL)
|
68
|
+
ssl = OpenSSL::SSL::SSLSocket.new(sock)
|
69
|
+
starttls
|
70
|
+
ssl.sync_close = true
|
71
|
+
ssl.connect
|
72
|
+
|
73
|
+
@socket = Net::InternetMessageIO.new(ssl)
|
74
|
+
@socket.read_timeout = @read_timeout
|
75
|
+
@socket.debug_output = STDERR
|
76
|
+
do_helo(helodomain)
|
77
|
+
end
|
78
|
+
|
79
|
+
authenticate user, secret, authtype if user
|
80
|
+
@started = true
|
81
|
+
ensure
|
82
|
+
@socket.close if not @started and @socket and not @socket.closed?
|
83
|
+
end
|
84
|
+
|
85
|
+
def do_helo(helodomain)
|
86
|
+
begin
|
87
|
+
if @esmtp
|
88
|
+
ehlo helodomain
|
89
|
+
else
|
90
|
+
helo helodomain
|
91
|
+
end
|
92
|
+
rescue Net::ProtocolError
|
93
|
+
if @esmtp
|
94
|
+
@esmtp = false
|
95
|
+
@error_occured = false
|
96
|
+
retry
|
97
|
+
end
|
98
|
+
raise
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def starttls
|
103
|
+
getok('STARTTLS')
|
104
|
+
end
|
105
|
+
|
106
|
+
def quit
|
107
|
+
begin
|
108
|
+
getok('QUIT')
|
109
|
+
rescue EOFError
|
110
|
+
# gmail sucks
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mattmatt-cijoe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Wanstrath
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- lib/cijoe/version.rb
|
73
73
|
- lib/cijoe/views/template.erb
|
74
74
|
- lib/mmmail.rb
|
75
|
+
- lib/smtp_tls.rb
|
75
76
|
- spec/email_spec.rb
|
76
77
|
has_rdoc: true
|
77
78
|
homepage: http://github.com/defunkt/cijoe
|