sidekick-client 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/sidekick/client/sidekick_client.rb +0 -3
- data/lib/sidekick/shared/sidekick_queue_publisher.rb +1 -1
- data/sidekick-client.gemspec +1 -158
- metadata +1 -158
- data/lib/ext/eventmachine-0.12.10/.gitignore +0 -14
- data/lib/ext/eventmachine-0.12.10/README +0 -82
- data/lib/ext/eventmachine-0.12.10/Rakefile +0 -374
- data/lib/ext/eventmachine-0.12.10/docs/COPYING +0 -60
- data/lib/ext/eventmachine-0.12.10/docs/ChangeLog +0 -211
- data/lib/ext/eventmachine-0.12.10/docs/DEFERRABLES +0 -133
- data/lib/ext/eventmachine-0.12.10/docs/EPOLL +0 -141
- data/lib/ext/eventmachine-0.12.10/docs/GNU +0 -281
- data/lib/ext/eventmachine-0.12.10/docs/INSTALL +0 -13
- data/lib/ext/eventmachine-0.12.10/docs/KEYBOARD +0 -38
- data/lib/ext/eventmachine-0.12.10/docs/LEGAL +0 -25
- data/lib/ext/eventmachine-0.12.10/docs/LIGHTWEIGHT_CONCURRENCY +0 -70
- data/lib/ext/eventmachine-0.12.10/docs/PURE_RUBY +0 -75
- data/lib/ext/eventmachine-0.12.10/docs/RELEASE_NOTES +0 -94
- data/lib/ext/eventmachine-0.12.10/docs/SMTP +0 -2
- data/lib/ext/eventmachine-0.12.10/docs/SPAWNED_PROCESSES +0 -89
- data/lib/ext/eventmachine-0.12.10/docs/TODO +0 -8
- data/lib/ext/eventmachine-0.12.10/eventmachine.gemspec +0 -40
- data/lib/ext/eventmachine-0.12.10/examples/ex_channel.rb +0 -43
- data/lib/ext/eventmachine-0.12.10/examples/ex_queue.rb +0 -2
- data/lib/ext/eventmachine-0.12.10/examples/helper.rb +0 -2
- data/lib/ext/eventmachine-0.12.10/ext/binder.cpp +0 -125
- data/lib/ext/eventmachine-0.12.10/ext/binder.h +0 -46
- data/lib/ext/eventmachine-0.12.10/ext/cmain.cpp +0 -827
- data/lib/ext/eventmachine-0.12.10/ext/cplusplus.cpp +0 -202
- data/lib/ext/eventmachine-0.12.10/ext/ed.cpp +0 -1893
- data/lib/ext/eventmachine-0.12.10/ext/ed.h +0 -424
- data/lib/ext/eventmachine-0.12.10/ext/em.cpp +0 -2282
- data/lib/ext/eventmachine-0.12.10/ext/em.h +0 -232
- data/lib/ext/eventmachine-0.12.10/ext/emwin.cpp +0 -300
- data/lib/ext/eventmachine-0.12.10/ext/emwin.h +0 -94
- data/lib/ext/eventmachine-0.12.10/ext/epoll.cpp +0 -26
- data/lib/ext/eventmachine-0.12.10/ext/epoll.h +0 -25
- data/lib/ext/eventmachine-0.12.10/ext/eventmachine.h +0 -122
- data/lib/ext/eventmachine-0.12.10/ext/eventmachine_cpp.h +0 -96
- data/lib/ext/eventmachine-0.12.10/ext/extconf.rb +0 -148
- data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/extconf.rb +0 -83
- data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/mapper.cpp +0 -214
- data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/mapper.h +0 -59
- data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/rubymain.cpp +0 -127
- data/lib/ext/eventmachine-0.12.10/ext/files.cpp +0 -94
- data/lib/ext/eventmachine-0.12.10/ext/files.h +0 -65
- data/lib/ext/eventmachine-0.12.10/ext/kb.cpp +0 -81
- data/lib/ext/eventmachine-0.12.10/ext/page.cpp +0 -107
- data/lib/ext/eventmachine-0.12.10/ext/page.h +0 -51
- data/lib/ext/eventmachine-0.12.10/ext/pipe.cpp +0 -349
- data/lib/ext/eventmachine-0.12.10/ext/project.h +0 -151
- data/lib/ext/eventmachine-0.12.10/ext/rubymain.cpp +0 -1166
- data/lib/ext/eventmachine-0.12.10/ext/sigs.cpp +0 -89
- data/lib/ext/eventmachine-0.12.10/ext/sigs.h +0 -32
- data/lib/ext/eventmachine-0.12.10/ext/ssl.cpp +0 -460
- data/lib/ext/eventmachine-0.12.10/ext/ssl.h +0 -94
- data/lib/ext/eventmachine-0.12.10/java/.classpath +0 -8
- data/lib/ext/eventmachine-0.12.10/java/.project +0 -17
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EmReactor.java +0 -570
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EmReactorException.java +0 -40
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableChannel.java +0 -69
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableDatagramChannel.java +0 -189
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableSocketChannel.java +0 -364
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Application.java +0 -194
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Connection.java +0 -74
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/ConnectionFactory.java +0 -37
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java +0 -46
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/PeriodicTimer.java +0 -38
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Timer.java +0 -54
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/ApplicationTest.java +0 -109
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/ConnectTest.java +0 -148
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/EMTest.java +0 -80
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestDatagrams.java +0 -53
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestServers.java +0 -75
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestTimers.java +0 -90
- data/lib/ext/eventmachine-0.12.10/lib/em/buftok.rb +0 -138
- data/lib/ext/eventmachine-0.12.10/lib/em/callback.rb +0 -26
- data/lib/ext/eventmachine-0.12.10/lib/em/channel.rb +0 -57
- data/lib/ext/eventmachine-0.12.10/lib/em/connection.rb +0 -564
- data/lib/ext/eventmachine-0.12.10/lib/em/deferrable.rb +0 -192
- data/lib/ext/eventmachine-0.12.10/lib/em/file_watch.rb +0 -54
- data/lib/ext/eventmachine-0.12.10/lib/em/future.rb +0 -61
- data/lib/ext/eventmachine-0.12.10/lib/em/messages.rb +0 -66
- data/lib/ext/eventmachine-0.12.10/lib/em/process_watch.rb +0 -44
- data/lib/ext/eventmachine-0.12.10/lib/em/processes.rb +0 -119
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols/header_and_content.rb +0 -138
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols/httpclient.rb +0 -263
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols/httpclient2.rb +0 -590
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols/line_and_text.rb +0 -125
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols/linetext2.rb +0 -161
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols/memcache.rb +0 -323
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols/object_protocol.rb +0 -45
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols/postgres3.rb +0 -247
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols/saslauth.rb +0 -175
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols/smtpclient.rb +0 -357
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols/smtpserver.rb +0 -547
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols/socks4.rb +0 -66
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols/stomp.rb +0 -200
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols/tcptest.rb +0 -53
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols.rb +0 -36
- data/lib/ext/eventmachine-0.12.10/lib/em/queue.rb +0 -61
- data/lib/ext/eventmachine-0.12.10/lib/em/spawnable.rb +0 -85
- data/lib/ext/eventmachine-0.12.10/lib/em/streamer.rb +0 -130
- data/lib/ext/eventmachine-0.12.10/lib/em/timers.rb +0 -56
- data/lib/ext/eventmachine-0.12.10/lib/em/version.rb +0 -3
- data/lib/ext/eventmachine-0.12.10/lib/eventmachine.rb +0 -1592
- data/lib/ext/eventmachine-0.12.10/lib/evma/callback.rb +0 -32
- data/lib/ext/eventmachine-0.12.10/lib/evma/container.rb +0 -75
- data/lib/ext/eventmachine-0.12.10/lib/evma/factory.rb +0 -77
- data/lib/ext/eventmachine-0.12.10/lib/evma/protocol.rb +0 -87
- data/lib/ext/eventmachine-0.12.10/lib/evma/reactor.rb +0 -48
- data/lib/ext/eventmachine-0.12.10/lib/evma.rb +0 -32
- data/lib/ext/eventmachine-0.12.10/lib/jeventmachine.rb +0 -257
- data/lib/ext/eventmachine-0.12.10/lib/pr_eventmachine.rb +0 -1022
- data/lib/ext/eventmachine-0.12.10/setup.rb +0 -1585
- data/lib/ext/eventmachine-0.12.10/tasks/cpp.rake_example +0 -77
- data/lib/ext/eventmachine-0.12.10/tests/client.crt +0 -31
- data/lib/ext/eventmachine-0.12.10/tests/client.key +0 -51
- data/lib/ext/eventmachine-0.12.10/tests/test_attach.rb +0 -126
- data/lib/ext/eventmachine-0.12.10/tests/test_basic.rb +0 -284
- data/lib/ext/eventmachine-0.12.10/tests/test_channel.rb +0 -63
- data/lib/ext/eventmachine-0.12.10/tests/test_connection_count.rb +0 -35
- data/lib/ext/eventmachine-0.12.10/tests/test_defer.rb +0 -47
- data/lib/ext/eventmachine-0.12.10/tests/test_epoll.rb +0 -160
- data/lib/ext/eventmachine-0.12.10/tests/test_error_handler.rb +0 -35
- data/lib/ext/eventmachine-0.12.10/tests/test_errors.rb +0 -82
- data/lib/ext/eventmachine-0.12.10/tests/test_exc.rb +0 -55
- data/lib/ext/eventmachine-0.12.10/tests/test_file_watch.rb +0 -49
- data/lib/ext/eventmachine-0.12.10/tests/test_futures.rb +0 -198
- data/lib/ext/eventmachine-0.12.10/tests/test_get_sock_opt.rb +0 -30
- data/lib/ext/eventmachine-0.12.10/tests/test_handler_check.rb +0 -37
- data/lib/ext/eventmachine-0.12.10/tests/test_hc.rb +0 -218
- data/lib/ext/eventmachine-0.12.10/tests/test_httpclient.rb +0 -218
- data/lib/ext/eventmachine-0.12.10/tests/test_httpclient2.rb +0 -153
- data/lib/ext/eventmachine-0.12.10/tests/test_inactivity_timeout.rb +0 -50
- data/lib/ext/eventmachine-0.12.10/tests/test_kb.rb +0 -60
- data/lib/ext/eventmachine-0.12.10/tests/test_ltp.rb +0 -182
- data/lib/ext/eventmachine-0.12.10/tests/test_ltp2.rb +0 -317
- data/lib/ext/eventmachine-0.12.10/tests/test_next_tick.rb +0 -133
- data/lib/ext/eventmachine-0.12.10/tests/test_object_protocol.rb +0 -37
- data/lib/ext/eventmachine-0.12.10/tests/test_pause.rb +0 -70
- data/lib/ext/eventmachine-0.12.10/tests/test_pending_connect_timeout.rb +0 -48
- data/lib/ext/eventmachine-0.12.10/tests/test_process_watch.rb +0 -48
- data/lib/ext/eventmachine-0.12.10/tests/test_processes.rb +0 -128
- data/lib/ext/eventmachine-0.12.10/tests/test_proxy_connection.rb +0 -92
- data/lib/ext/eventmachine-0.12.10/tests/test_pure.rb +0 -125
- data/lib/ext/eventmachine-0.12.10/tests/test_queue.rb +0 -44
- data/lib/ext/eventmachine-0.12.10/tests/test_running.rb +0 -42
- data/lib/ext/eventmachine-0.12.10/tests/test_sasl.rb +0 -72
- data/lib/ext/eventmachine-0.12.10/tests/test_send_file.rb +0 -242
- data/lib/ext/eventmachine-0.12.10/tests/test_servers.rb +0 -76
- data/lib/ext/eventmachine-0.12.10/tests/test_smtpclient.rb +0 -83
- data/lib/ext/eventmachine-0.12.10/tests/test_smtpserver.rb +0 -85
- data/lib/ext/eventmachine-0.12.10/tests/test_spawn.rb +0 -322
- data/lib/ext/eventmachine-0.12.10/tests/test_ssl_args.rb +0 -79
- data/lib/ext/eventmachine-0.12.10/tests/test_ssl_methods.rb +0 -50
- data/lib/ext/eventmachine-0.12.10/tests/test_ssl_verify.rb +0 -82
- data/lib/ext/eventmachine-0.12.10/tests/test_timers.rb +0 -162
- data/lib/ext/eventmachine-0.12.10/tests/test_ud.rb +0 -36
- data/lib/ext/eventmachine-0.12.10/tests/testem.rb +0 -31
- data/lib/ext/eventmachine-0.12.10/web/whatis +0 -7
@@ -1,547 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
#
|
3
|
-
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
4
|
-
# Homepage:: http://rubyeventmachine.com
|
5
|
-
# Date:: 16 July 2006
|
6
|
-
#
|
7
|
-
# See EventMachine and EventMachine::Connection for documentation and
|
8
|
-
# usage examples.
|
9
|
-
#
|
10
|
-
#----------------------------------------------------------------------------
|
11
|
-
#
|
12
|
-
# Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
|
13
|
-
# Gmail: blackhedd
|
14
|
-
#
|
15
|
-
# This program is free software; you can redistribute it and/or modify
|
16
|
-
# it under the terms of either: 1) the GNU General Public License
|
17
|
-
# as published by the Free Software Foundation; either version 2 of the
|
18
|
-
# License, or (at your option) any later version; or 2) Ruby's License.
|
19
|
-
#
|
20
|
-
# See the file COPYING for complete licensing information.
|
21
|
-
#
|
22
|
-
#---------------------------------------------------------------------------
|
23
|
-
#
|
24
|
-
#
|
25
|
-
|
26
|
-
module EventMachine
|
27
|
-
module Protocols
|
28
|
-
|
29
|
-
# This is a protocol handler for the server side of SMTP.
|
30
|
-
# It's NOT a complete SMTP server obeying all the semantics of servers conforming to
|
31
|
-
# RFC2821. Rather, it uses overridable method stubs to communicate protocol states
|
32
|
-
# and data to user code. User code is responsible for doing the right things with the
|
33
|
-
# data in order to get complete and correct SMTP server behavior.
|
34
|
-
#
|
35
|
-
#--
|
36
|
-
# Useful paragraphs in RFC-2821:
|
37
|
-
# 4.3.2: Concise list of command-reply sequences, in essence a text representation
|
38
|
-
# of the command state-machine.
|
39
|
-
#
|
40
|
-
# STARTTLS is defined in RFC2487.
|
41
|
-
# Observe that there are important rules governing whether a publicly-referenced server
|
42
|
-
# (meaning one whose Internet address appears in public MX records) may require the
|
43
|
-
# non-optional use of TLS.
|
44
|
-
# Non-optional TLS does not apply to EHLO, NOOP, QUIT or STARTTLS.
|
45
|
-
class SmtpServer < EventMachine::Connection
|
46
|
-
include Protocols::LineText2
|
47
|
-
|
48
|
-
HeloRegex = /\AHELO\s*/i
|
49
|
-
EhloRegex = /\AEHLO\s*/i
|
50
|
-
QuitRegex = /\AQUIT/i
|
51
|
-
MailFromRegex = /\AMAIL FROM:\s*/i
|
52
|
-
RcptToRegex = /\ARCPT TO:\s*/i
|
53
|
-
DataRegex = /\ADATA/i
|
54
|
-
NoopRegex = /\ANOOP/i
|
55
|
-
RsetRegex = /\ARSET/i
|
56
|
-
VrfyRegex = /\AVRFY\s+/i
|
57
|
-
ExpnRegex = /\AEXPN\s+/i
|
58
|
-
HelpRegex = /\AHELP/i
|
59
|
-
StarttlsRegex = /\ASTARTTLS/i
|
60
|
-
AuthRegex = /\AAUTH\s+/i
|
61
|
-
|
62
|
-
|
63
|
-
# Class variable containing default parameters that can be overridden
|
64
|
-
# in application code.
|
65
|
-
# Individual objects of this class will make an instance-local copy of
|
66
|
-
# the class variable, so that they can be reconfigured on a per-instance
|
67
|
-
# basis.
|
68
|
-
#
|
69
|
-
# Chunksize is the number of data lines we'll buffer before
|
70
|
-
# sending them to the application. TODO, make this user-configurable.
|
71
|
-
#
|
72
|
-
@@parms = {
|
73
|
-
:chunksize => 4000,
|
74
|
-
:verbose => false
|
75
|
-
}
|
76
|
-
def self.parms= parms={}
|
77
|
-
@@parms.merge!(parms)
|
78
|
-
end
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
def initialize *args
|
83
|
-
super
|
84
|
-
@parms = @@parms
|
85
|
-
init_protocol_state
|
86
|
-
end
|
87
|
-
|
88
|
-
def parms= parms={}
|
89
|
-
@parms.merge!(parms)
|
90
|
-
end
|
91
|
-
|
92
|
-
# In SMTP, the server talks first. But by a (perhaps flawed) axiom in EM,
|
93
|
-
# #post_init will execute BEFORE the block passed to #start_server, for any
|
94
|
-
# given accepted connection. Since in this class we'll probably be getting
|
95
|
-
# a lot of initialization parameters, we want the guts of post_init to
|
96
|
-
# run AFTER the application has initialized the connection object. So we
|
97
|
-
# use a spawn to schedule the post_init to run later.
|
98
|
-
# It's a little weird, I admit. A reasonable alternative would be to set
|
99
|
-
# parameters as a class variable and to do that before accepting any connections.
|
100
|
-
#
|
101
|
-
# OBSOLETE, now we have @@parms. But the spawn is nice to keep as an illustration.
|
102
|
-
#
|
103
|
-
def post_init
|
104
|
-
#send_data "220 #{get_server_greeting}\r\n" (ORIGINAL)
|
105
|
-
#(EM.spawn {|x| x.send_data "220 #{x.get_server_greeting}\r\n"}).notify(self)
|
106
|
-
(EM.spawn {|x| x.send_server_greeting}).notify(self)
|
107
|
-
end
|
108
|
-
|
109
|
-
def send_server_greeting
|
110
|
-
send_data "220 #{get_server_greeting}\r\n"
|
111
|
-
end
|
112
|
-
|
113
|
-
def receive_line ln
|
114
|
-
@@parms[:verbose] and $>.puts ">>> #{ln}"
|
115
|
-
|
116
|
-
return process_data_line(ln) if @state.include?(:data)
|
117
|
-
|
118
|
-
case ln
|
119
|
-
when EhloRegex
|
120
|
-
process_ehlo $'.dup
|
121
|
-
when HeloRegex
|
122
|
-
process_helo $'.dup
|
123
|
-
when MailFromRegex
|
124
|
-
process_mail_from $'.dup
|
125
|
-
when RcptToRegex
|
126
|
-
process_rcpt_to $'.dup
|
127
|
-
when DataRegex
|
128
|
-
process_data
|
129
|
-
when RsetRegex
|
130
|
-
process_rset
|
131
|
-
when VrfyRegex
|
132
|
-
process_vrfy
|
133
|
-
when ExpnRegex
|
134
|
-
process_expn
|
135
|
-
when HelpRegex
|
136
|
-
process_help
|
137
|
-
when NoopRegex
|
138
|
-
process_noop
|
139
|
-
when QuitRegex
|
140
|
-
process_quit
|
141
|
-
when StarttlsRegex
|
142
|
-
process_starttls
|
143
|
-
when AuthRegex
|
144
|
-
process_auth $'.dup
|
145
|
-
else
|
146
|
-
process_unknown
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
# TODO - implement this properly, the implementation is a stub!
|
151
|
-
def process_vrfy
|
152
|
-
send_data "250 Ok, but unimplemented\r\n"
|
153
|
-
end
|
154
|
-
# TODO - implement this properly, the implementation is a stub!
|
155
|
-
def process_help
|
156
|
-
send_data "250 Ok, but unimplemented\r\n"
|
157
|
-
end
|
158
|
-
# TODO - implement this properly, the implementation is a stub!
|
159
|
-
def process_expn
|
160
|
-
send_data "250 Ok, but unimplemented\r\n"
|
161
|
-
end
|
162
|
-
|
163
|
-
#--
|
164
|
-
# This is called at several points to restore the protocol state
|
165
|
-
# to a pre-transaction state. In essence, we "forget" having seen
|
166
|
-
# any valid command except EHLO and STARTTLS.
|
167
|
-
# We also have to callback user code, in case they're keeping track
|
168
|
-
# of senders, recipients, and whatnot.
|
169
|
-
#
|
170
|
-
# We try to follow the convention of avoiding the verb "receive" for
|
171
|
-
# internal method names except receive_line (which we inherit), and
|
172
|
-
# using only receive_xxx for user-overridable stubs.
|
173
|
-
#
|
174
|
-
# init_protocol_state is called when we initialize the connection as
|
175
|
-
# well as during reset_protocol_state. It does NOT call the user
|
176
|
-
# override method. This enables us to promise the users that they
|
177
|
-
# won't see the overridable fire except after EHLO and RSET, and
|
178
|
-
# after a message has been received. Although the latter may be wrong.
|
179
|
-
# The standard may allow multiple DATA segments with the same set of
|
180
|
-
# senders and recipients.
|
181
|
-
#
|
182
|
-
def reset_protocol_state
|
183
|
-
init_protocol_state
|
184
|
-
s,@state = @state,[]
|
185
|
-
@state << :starttls if s.include?(:starttls)
|
186
|
-
@state << :ehlo if s.include?(:ehlo)
|
187
|
-
receive_transaction
|
188
|
-
end
|
189
|
-
def init_protocol_state
|
190
|
-
@state ||= []
|
191
|
-
end
|
192
|
-
|
193
|
-
|
194
|
-
#--
|
195
|
-
# EHLO/HELO is always legal, per the standard. On success
|
196
|
-
# it always clears buffers and initiates a mail "transaction."
|
197
|
-
# Which means that a MAIL FROM must follow.
|
198
|
-
#
|
199
|
-
# Per the standard, an EHLO/HELO or a RSET "initiates" an email
|
200
|
-
# transaction. Thereafter, MAIL FROM must be received before
|
201
|
-
# RCPT TO, before DATA. Not sure what this specific ordering
|
202
|
-
# achieves semantically, but it does make it easier to
|
203
|
-
# implement. We also support user-specified requirements for
|
204
|
-
# STARTTLS and AUTH. We make it impossible to proceed to MAIL FROM
|
205
|
-
# without fulfilling tls and/or auth, if the user specified either
|
206
|
-
# or both as required. We need to check the extension standard
|
207
|
-
# for auth to see if a credential is discarded after a RSET along
|
208
|
-
# with all the rest of the state. We'll behave as if it is.
|
209
|
-
# Now clearly, we can't discard tls after its been negotiated
|
210
|
-
# without dropping the connection, so that flag doesn't get cleared.
|
211
|
-
#
|
212
|
-
def process_ehlo domain
|
213
|
-
if receive_ehlo_domain domain
|
214
|
-
send_data "250-#{get_server_domain}\r\n"
|
215
|
-
if @@parms[:starttls]
|
216
|
-
send_data "250-STARTTLS\r\n"
|
217
|
-
end
|
218
|
-
if @@parms[:auth]
|
219
|
-
send_data "250-AUTH PLAIN LOGIN\r\n"
|
220
|
-
end
|
221
|
-
send_data "250-NO-SOLICITING\r\n"
|
222
|
-
# TODO, size needs to be configurable.
|
223
|
-
send_data "250 SIZE 20000000\r\n"
|
224
|
-
reset_protocol_state
|
225
|
-
@state << :ehlo
|
226
|
-
else
|
227
|
-
send_data "550 Requested action not taken\r\n"
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
def process_helo domain
|
232
|
-
if receive_ehlo_domain domain.dup
|
233
|
-
send_data "250 #{get_server_domain}\r\n"
|
234
|
-
reset_protocol_state
|
235
|
-
@state << :ehlo
|
236
|
-
else
|
237
|
-
send_data "550 Requested action not taken\r\n"
|
238
|
-
end
|
239
|
-
end
|
240
|
-
|
241
|
-
def process_quit
|
242
|
-
send_data "221 Ok\r\n"
|
243
|
-
close_connection_after_writing
|
244
|
-
end
|
245
|
-
|
246
|
-
def process_noop
|
247
|
-
send_data "250 Ok\r\n"
|
248
|
-
end
|
249
|
-
|
250
|
-
def process_unknown
|
251
|
-
send_data "500 Unknown command\r\n"
|
252
|
-
end
|
253
|
-
|
254
|
-
#--
|
255
|
-
# So far, only AUTH PLAIN is supported but we should do at least LOGIN as well.
|
256
|
-
# TODO, support clients that send AUTH PLAIN with no parameter, expecting a 3xx
|
257
|
-
# response and a continuation of the auth conversation.
|
258
|
-
#
|
259
|
-
def process_auth str
|
260
|
-
if @state.include?(:auth)
|
261
|
-
send_data "503 auth already issued\r\n"
|
262
|
-
elsif str =~ /\APLAIN\s+/i
|
263
|
-
plain = ($'.dup).unpack("m").first # Base64::decode64($'.dup)
|
264
|
-
discard,user,psw = plain.split("\000")
|
265
|
-
if receive_plain_auth user,psw
|
266
|
-
send_data "235 authentication ok\r\n"
|
267
|
-
@state << :auth
|
268
|
-
else
|
269
|
-
send_data "535 invalid authentication\r\n"
|
270
|
-
end
|
271
|
-
#elsif str =~ /\ALOGIN\s+/i
|
272
|
-
else
|
273
|
-
send_data "504 auth mechanism not available\r\n"
|
274
|
-
end
|
275
|
-
end
|
276
|
-
|
277
|
-
#--
|
278
|
-
# Unusually, we can deal with a Deferrable returned from the user application.
|
279
|
-
# This was added to deal with a special case in a particular application, but
|
280
|
-
# it would be a nice idea to add it to the other user-code callbacks.
|
281
|
-
#
|
282
|
-
def process_data
|
283
|
-
unless @state.include?(:rcpt)
|
284
|
-
send_data "503 Operation sequence error\r\n"
|
285
|
-
else
|
286
|
-
succeeded = proc {
|
287
|
-
send_data "354 Send it\r\n"
|
288
|
-
@state << :data
|
289
|
-
@databuffer = []
|
290
|
-
}
|
291
|
-
failed = proc {
|
292
|
-
send_data "550 Operation failed\r\n"
|
293
|
-
}
|
294
|
-
|
295
|
-
d = receive_data_command
|
296
|
-
|
297
|
-
if d.respond_to?(:callback)
|
298
|
-
d.callback(&succeeded)
|
299
|
-
d.errback(&failed)
|
300
|
-
else
|
301
|
-
(d ? succeeded : failed).call
|
302
|
-
end
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
|
-
def process_rset
|
307
|
-
reset_protocol_state
|
308
|
-
receive_reset
|
309
|
-
send_data "250 Ok\r\n"
|
310
|
-
end
|
311
|
-
|
312
|
-
def unbind
|
313
|
-
connection_ended
|
314
|
-
end
|
315
|
-
|
316
|
-
#--
|
317
|
-
# STARTTLS may not be issued before EHLO, or unless the user has chosen
|
318
|
-
# to support it.
|
319
|
-
# TODO, must support user-supplied certificates.
|
320
|
-
#
|
321
|
-
def process_starttls
|
322
|
-
if @@parms[:starttls]
|
323
|
-
if @state.include?(:starttls)
|
324
|
-
send_data "503 TLS Already negotiated\r\n"
|
325
|
-
elsif ! @state.include?(:ehlo)
|
326
|
-
send_data "503 EHLO required before STARTTLS\r\n"
|
327
|
-
else
|
328
|
-
send_data "220 Start TLS negotiation\r\n"
|
329
|
-
start_tls
|
330
|
-
@state << :starttls
|
331
|
-
end
|
332
|
-
else
|
333
|
-
process_unknown
|
334
|
-
end
|
335
|
-
end
|
336
|
-
|
337
|
-
|
338
|
-
#--
|
339
|
-
# Requiring TLS is touchy, cf RFC2784.
|
340
|
-
# Requiring AUTH seems to be much more reasonable.
|
341
|
-
# We don't currently support any notion of deriving an authentication from the TLS
|
342
|
-
# negotiation, although that would certainly be reasonable.
|
343
|
-
# We DON'T allow MAIL FROM to be given twice.
|
344
|
-
# We DON'T enforce all the various rules for validating the sender or
|
345
|
-
# the reverse-path (like whether it should be null), and notifying the reverse
|
346
|
-
# path in case of delivery problems. All of that is left to the calling application.
|
347
|
-
#
|
348
|
-
def process_mail_from sender
|
349
|
-
if (@@parms[:starttls]==:required and !@state.include?(:starttls))
|
350
|
-
send_data "550 This server requires STARTTLS before MAIL FROM\r\n"
|
351
|
-
elsif (@@parms[:auth]==:required and !@state.include?(:auth))
|
352
|
-
send_data "550 This server requires authentication before MAIL FROM\r\n"
|
353
|
-
elsif @state.include?(:mail_from)
|
354
|
-
send_data "503 MAIL already given\r\n"
|
355
|
-
else
|
356
|
-
unless receive_sender sender
|
357
|
-
send_data "550 sender is unacceptable\r\n"
|
358
|
-
else
|
359
|
-
send_data "250 Ok\r\n"
|
360
|
-
@state << :mail_from
|
361
|
-
end
|
362
|
-
end
|
363
|
-
end
|
364
|
-
|
365
|
-
#--
|
366
|
-
# Since we require :mail_from to have been seen before we process RCPT TO,
|
367
|
-
# we don't need to repeat the tests for TLS and AUTH.
|
368
|
-
# Note that we don't remember or do anything else with the recipients.
|
369
|
-
# All of that is on the user code.
|
370
|
-
# TODO: we should enforce user-definable limits on the total number of
|
371
|
-
# recipients per transaction.
|
372
|
-
# We might want to make sure that a given recipient is only seen once, but
|
373
|
-
# for now we'll let that be the user's problem.
|
374
|
-
#
|
375
|
-
# User-written code can return a deferrable from receive_recipient.
|
376
|
-
#
|
377
|
-
def process_rcpt_to rcpt
|
378
|
-
unless @state.include?(:mail_from)
|
379
|
-
send_data "503 MAIL is required before RCPT\r\n"
|
380
|
-
else
|
381
|
-
succeeded = proc {
|
382
|
-
send_data "250 Ok\r\n"
|
383
|
-
@state << :rcpt unless @state.include?(:rcpt)
|
384
|
-
}
|
385
|
-
failed = proc {
|
386
|
-
send_data "550 recipient is unacceptable\r\n"
|
387
|
-
}
|
388
|
-
|
389
|
-
d = receive_recipient rcpt
|
390
|
-
|
391
|
-
if d.respond_to?(:set_deferred_status)
|
392
|
-
d.callback(&succeeded)
|
393
|
-
d.errback(&failed)
|
394
|
-
else
|
395
|
-
(d ? succeeded : failed).call
|
396
|
-
end
|
397
|
-
|
398
|
-
=begin
|
399
|
-
unless receive_recipient rcpt
|
400
|
-
send_data "550 recipient is unacceptable\r\n"
|
401
|
-
else
|
402
|
-
send_data "250 Ok\r\n"
|
403
|
-
@state << :rcpt unless @state.include?(:rcpt)
|
404
|
-
end
|
405
|
-
=end
|
406
|
-
end
|
407
|
-
end
|
408
|
-
|
409
|
-
|
410
|
-
# Send the incoming data to the application one chunk at a time, rather than
|
411
|
-
# one line at a time. That lets the application be a little more flexible about
|
412
|
-
# storing to disk, etc.
|
413
|
-
# Since we clear the chunk array every time we submit it, the caller needs to be
|
414
|
-
# aware to do things like dup it if he wants to keep it around across calls.
|
415
|
-
#
|
416
|
-
# DON'T reset the transaction upon disposition of the incoming message.
|
417
|
-
# This means another DATA command can be accepted with the same sender and recipients.
|
418
|
-
# If the client wants to reset, he can call RSET.
|
419
|
-
# Not sure whether the standard requires a transaction-reset at this point, but it
|
420
|
-
# appears not to.
|
421
|
-
#
|
422
|
-
# User-written code can return a Deferrable as a response from receive_message.
|
423
|
-
#
|
424
|
-
def process_data_line ln
|
425
|
-
if ln == "."
|
426
|
-
if @databuffer.length > 0
|
427
|
-
receive_data_chunk @databuffer
|
428
|
-
@databuffer.clear
|
429
|
-
end
|
430
|
-
|
431
|
-
|
432
|
-
succeeded = proc {
|
433
|
-
send_data "250 Message accepted\r\n"
|
434
|
-
}
|
435
|
-
failed = proc {
|
436
|
-
send_data "550 Message rejected\r\n"
|
437
|
-
}
|
438
|
-
|
439
|
-
d = receive_message
|
440
|
-
|
441
|
-
if d.respond_to?(:set_deferred_status)
|
442
|
-
d.callback(&succeeded)
|
443
|
-
d.errback(&failed)
|
444
|
-
else
|
445
|
-
(d ? succeeded : failed).call
|
446
|
-
end
|
447
|
-
|
448
|
-
@state.delete :data
|
449
|
-
else
|
450
|
-
# slice off leading . if any
|
451
|
-
ln.slice!(0...1) if ln[0] == 46
|
452
|
-
@databuffer << ln
|
453
|
-
if @databuffer.length > @@parms[:chunksize]
|
454
|
-
receive_data_chunk @databuffer
|
455
|
-
@databuffer.clear
|
456
|
-
end
|
457
|
-
end
|
458
|
-
end
|
459
|
-
|
460
|
-
|
461
|
-
#------------------------------------------
|
462
|
-
# Everything from here on can be overridden in user code.
|
463
|
-
|
464
|
-
# The greeting returned in the initial connection message to the client.
|
465
|
-
def get_server_greeting
|
466
|
-
"EventMachine SMTP Server"
|
467
|
-
end
|
468
|
-
# The domain name returned in the first line of the response to a
|
469
|
-
# successful EHLO or HELO command.
|
470
|
-
def get_server_domain
|
471
|
-
"Ok EventMachine SMTP Server"
|
472
|
-
end
|
473
|
-
|
474
|
-
# A false response from this user-overridable method will cause a
|
475
|
-
# 550 error to be returned to the remote client.
|
476
|
-
#
|
477
|
-
def receive_ehlo_domain domain
|
478
|
-
true
|
479
|
-
end
|
480
|
-
|
481
|
-
# Return true or false to indicate that the authentication is acceptable.
|
482
|
-
def receive_plain_auth user, password
|
483
|
-
true
|
484
|
-
end
|
485
|
-
|
486
|
-
# Receives the argument of the MAIL FROM command. Return false to
|
487
|
-
# indicate to the remote client that the sender is not accepted.
|
488
|
-
# This can only be successfully called once per transaction.
|
489
|
-
#
|
490
|
-
def receive_sender sender
|
491
|
-
true
|
492
|
-
end
|
493
|
-
|
494
|
-
# Receives the argument of a RCPT TO command. Can be given multiple
|
495
|
-
# times per transaction. Return false to reject the recipient.
|
496
|
-
#
|
497
|
-
def receive_recipient rcpt
|
498
|
-
true
|
499
|
-
end
|
500
|
-
|
501
|
-
# Sent when the remote peer issues the RSET command.
|
502
|
-
# Since RSET is not allowed to fail (according to the protocol),
|
503
|
-
# we ignore any return value from user overrides of this method.
|
504
|
-
#
|
505
|
-
def receive_reset
|
506
|
-
end
|
507
|
-
|
508
|
-
# Sent when the remote peer has ended the connection.
|
509
|
-
#
|
510
|
-
def connection_ended
|
511
|
-
end
|
512
|
-
|
513
|
-
# Called when the remote peer sends the DATA command.
|
514
|
-
# Returning false will cause us to send a 550 error to the peer.
|
515
|
-
# This can be useful for dealing with problems that arise from processing
|
516
|
-
# the whole set of sender and recipients.
|
517
|
-
#
|
518
|
-
def receive_data_command
|
519
|
-
true
|
520
|
-
end
|
521
|
-
|
522
|
-
# Sent when data from the remote peer is available. The size can be controlled
|
523
|
-
# by setting the :chunksize parameter. This call can be made multiple times.
|
524
|
-
# The goal is to strike a balance between sending the data to the application one
|
525
|
-
# line at a time, and holding all of a very large message in memory.
|
526
|
-
#
|
527
|
-
def receive_data_chunk data
|
528
|
-
@smtps_msg_size ||= 0
|
529
|
-
@smtps_msg_size += data.join.length
|
530
|
-
STDERR.write "<#{@smtps_msg_size}>"
|
531
|
-
end
|
532
|
-
|
533
|
-
# Sent after a message has been completely received. User code
|
534
|
-
# must return true or false to indicate whether the message has
|
535
|
-
# been accepted for delivery.
|
536
|
-
def receive_message
|
537
|
-
@@parms[:verbose] and $>.puts "Received complete message"
|
538
|
-
true
|
539
|
-
end
|
540
|
-
|
541
|
-
# This is called when the protocol state is reset. It happens
|
542
|
-
# when the remote client calls EHLO/HELO or RSET.
|
543
|
-
def receive_transaction
|
544
|
-
end
|
545
|
-
end
|
546
|
-
end
|
547
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
module EventMachine
|
2
|
-
module Protocols
|
3
|
-
# Basic SOCKS v4 client implementation
|
4
|
-
#
|
5
|
-
# Use as you would any regular connection:
|
6
|
-
#
|
7
|
-
# class MyConn < EM::P::Socks4
|
8
|
-
# def post_init
|
9
|
-
# send_data("sup")
|
10
|
-
# end
|
11
|
-
#
|
12
|
-
# def receive_data(data)
|
13
|
-
# send_data("you said: #{data}")
|
14
|
-
# end
|
15
|
-
# end
|
16
|
-
#
|
17
|
-
# EM.connect socks_host, socks_port, MyConn, host, port
|
18
|
-
#
|
19
|
-
class Socks4 < Connection
|
20
|
-
def initialize(host, port)
|
21
|
-
@host = Socket.gethostbyname(host).last
|
22
|
-
@port = port
|
23
|
-
@socks_error_code = nil
|
24
|
-
@buffer = ''
|
25
|
-
setup_methods
|
26
|
-
end
|
27
|
-
|
28
|
-
def setup_methods
|
29
|
-
class << self
|
30
|
-
def post_init; socks_post_init; end
|
31
|
-
def receive_data(*a); socks_receive_data(*a); end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def restore_methods
|
36
|
-
class << self
|
37
|
-
remove_method :post_init
|
38
|
-
remove_method :receive_data
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def socks_post_init
|
43
|
-
header = [4, 1, @port, @host, 0].flatten.pack("CCnA4C")
|
44
|
-
send_data(header)
|
45
|
-
end
|
46
|
-
|
47
|
-
def socks_receive_data(data)
|
48
|
-
@buffer << data
|
49
|
-
return if @buffer.size < 8
|
50
|
-
|
51
|
-
header_resp = @buffer.slice! 0, 8
|
52
|
-
_, r = header_resp.unpack("cc")
|
53
|
-
if r != 90
|
54
|
-
@socks_error_code = r
|
55
|
-
close_connection
|
56
|
-
return
|
57
|
-
end
|
58
|
-
|
59
|
-
restore_methods
|
60
|
-
|
61
|
-
post_init
|
62
|
-
receive_data(@buffer) unless @buffer.empty?
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|