My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions

Issue 106 attachment: tls_patch_preference_v2.patch (4.6 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
Index: /home/edmundo/workspace_aptana/trunk/vendor/plugins/substruct/app/views/admin/preferences/index.rhtml
===================================================================
--- /home/edmundo/workspace_aptana/trunk/vendor/plugins/substruct/app/views/admin/preferences/index.rhtml (revision 104)
+++ /home/edmundo/workspace_aptana/trunk/vendor/plugins/substruct/app/views/admin/preferences/index.rhtml (working copy)
@@ -105,6 +105,14 @@
<div class="padLeft">
<div class="floatHalf">
<p>
+ <label>
+ <%= check_box_tag('prefs[use_smtp_tls_patch]', 1, (@prefs['use_smtp_tls_patch'].is_true?)) %>
+ Use SMTP TLS monkey patch?
+ </label>
+ <input name="prefs[use_smtp_tls_patch]" type="hidden" value="0" />
+ <span class="info">If set, a monkey patch will be applied to Ruby's Net::SMTP class adding TLS support.</span>
+ </p>
+ <p>
<%= make_label('SMTP Authentication Type', true) %>
<%= select_tag('prefs[mail_auth_type]', options_for_select(Preference::MAIL_AUTH, @prefs['mail_auth_type'].value)) %>
</p>
Index: /home/edmundo/workspace_aptana/trunk/vendor/plugins/substruct/app/models/preference.rb
===================================================================
--- /home/edmundo/workspace_aptana/trunk/vendor/plugins/substruct/app/models/preference.rb (revision 104)
+++ /home/edmundo/workspace_aptana/trunk/vendor/plugins/substruct/app/models/preference.rb (working copy)
@@ -6,7 +6,7 @@
# Prefs are used all over to handle decisions that we'd rather
# not use config files for.
#
-require "smtp_tls"
+
class Preference < ActiveRecord::Base
# Types can hold strings, booleans, or pointers to
# other records (like country)
@@ -18,6 +18,25 @@
# Can throw an error if these items aren't set.
# Make sure to wrap any block that calls this
def self.init_mail_settings
+ if Preference.find_by_name('use_smtp_tls_patch').is_true?
+ require "smtp_tls"
+ else
+ # Remove the Net::SMTP::Revision constant.
+ Net::SMTP.class_eval do
+ remove_const :Revision.to_s if const_defined? :Revision.to_s
+ end
+ # Remove the Net::SMTPSession constant.
+ Net.class_eval do
+ remove_const :SMTPSession.to_s if const_defined? :SMTPSession.to_s
+ end
+ # Remove the SMTP constant.
+ Object.class_eval do
+ remove_const :SMTP.to_s if const_defined? :SMTP.to_s
+ end
+ # Reload the net/smtp.rb class.
+ require "net/smtp"
+ end
+
# SET MAIL SERVER SETTINGS FROM PREFERENCES
mail_host = find_by_name('mail_host').value
mail_server_settings = {
Index: /home/edmundo/workspace_aptana/trunk/vendor/plugins/substruct/lib/smtp_tls.rb
===================================================================
--- /home/edmundo/workspace_aptana/trunk/vendor/plugins/substruct/lib/smtp_tls.rb (revision 104)
+++ /home/edmundo/workspace_aptana/trunk/vendor/plugins/substruct/lib/smtp_tls.rb (working copy)
@@ -11,10 +11,13 @@
@socket = Net::InternetMessageIO.new(sock)
@socket.read_timeout = 60 #@read_timeout

+ # Uncomment that for debug purposes only.
+ # @socket.debug_output = STDERR #@debug_output
+
check_response(critical { recv_response() })
do_helo(helodomain)

- if starttls
+ if @starttls_offered and starttls
raise 'openssl library not installed' unless defined?(OpenSSL)
ssl = OpenSSL::SSL::SSLSocket.new(sock)
ssl.sync_close = true
@@ -37,9 +40,9 @@
def do_helo(helodomain)
begin
if @esmtp
- ehlo helodomain
+ getokandverifytls('EHLO %s', helodomain)
else
- helo helodomain
+ getokandverifytls('HELO %s', helodomain)
end
rescue Net::ProtocolError
if @esmtp
@@ -56,6 +59,17 @@
return true
end

+ def getokandverifytls( fmt, *args )
+ res = critical {
+ @socket.writeline sprintf(fmt, *args)
+ recv_response()
+ }
+ if /STARTTLS/ === res
+ @starttls_offered = true
+ end
+ return check_response(res)
+ end
+
def quit
begin
getok('QUIT')
@@ -62,4 +76,5 @@
rescue EOFError
end
end
+
end
\ No newline at end of file
Index: /home/edmundo/workspace_aptana/trunk/vendor/plugins/substruct/db/bootstrap/preferences.yml
===================================================================
--- /home/edmundo/workspace_aptana/trunk/vendor/plugins/substruct/db/bootstrap/preferences.yml (revision 104)
+++ /home/edmundo/workspace_aptana/trunk/vendor/plugins/substruct/db/bootstrap/preferences.yml (working copy)
@@ -67,3 +67,7 @@
name: store_test_transactions
id: 17
value: "1"
+use_smtp_tls_patch:
+ name: use_smtp_tls_patch
+ id: 18
+ value: "0"
\ No newline at end of file


Powered by Google Project Hosting