eventmachine-email_server 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f9618746cec3c86bbed9a6ec20828cc326279246
4
- data.tar.gz: 99191abe30a58e83b6a1c764a354c4ec5d4337dd
3
+ metadata.gz: d9dea5dce0287d7485b0b8462a66bea7afc23c86
4
+ data.tar.gz: d3bc7ee13bed421cdba2bca4142dabc1286c494f
5
5
  SHA512:
6
- metadata.gz: 4dd0f0614b1522e4421fe937c22cc064a2f2cb9da4cd231de94b0288d36ae62f28c70dd852c62c3e60b8ada66e7397dbba021d7328b98b9d4d8d07a61c302485
7
- data.tar.gz: 461427eb727203f4850c8d2d52d3fdf716df05e23ad316c9621a91de959c0e222006a7c18bbe96cba023c6fc6e46b0849cff58cb7ff9c5404e89c81bce5596e7
6
+ metadata.gz: 2c988c984b9525db659d0c1c266183ab226a5170d71cc525a7698e42d0a349d56d303b18e6c97634ae0af9fd29b8bd98fc09bd6c93088ff1f036b9400f640ca7
7
+ data.tar.gz: bdf1b88902363fc6de4fab8190669ae1116bfc083973b4c5241afec2bc4f8dbe453cdecd9f117e37497653cd711a3c07e12b78fc4a35b3caa66cc0287689021c
@@ -5,6 +5,8 @@ module EventMachine
5
5
  module EmailServer
6
6
  class POP3Server < EventMachine::Connection
7
7
  @@capabilities = [ "TOP", "USER", "UIDL" ]
8
+ attr_accessor :debug
9
+
8
10
  def initialize(hostname, userstore, emailstore)
9
11
  @hostname = hostname
10
12
  @userstore = userstore
@@ -12,7 +14,7 @@ module EventMachine
12
14
  @state = 'auth' # 'trans' and 'data'
13
15
  @auth_attempts = 0
14
16
  @apop_challenge = "<#{rand(10**4 - 1)}.#{rand(10**9 - 1)}@#{@hostname}>"
15
- @debug = true
17
+ @debug = false
16
18
  @emails = Array.new
17
19
  end
18
20
 
@@ -31,7 +33,8 @@ module EventMachine
31
33
  def send(data, close=false)
32
34
  puts "<< #{data}" if @debug
33
35
  send_data("#{data}\r\n")
34
- close_connection if close
36
+ puts "++ closing connection" if @debug and close
37
+ close_connection(true) if close
35
38
  end
36
39
 
37
40
  def unbind(reason=nil)
@@ -183,6 +186,23 @@ module EventMachine
183
186
  msg += "#{msgid} #{Digest::MD5.new.update(e.body).hexdigest}\r\n"
184
187
  end
185
188
  send("+OK\r\n#{msg}.")
189
+ when /^UIDL (\d+)$/
190
+ mid = $1
191
+ msgid = 0
192
+ msg = ''
193
+ @emails.each do |e|
194
+ msgid += 1
195
+ next if e.marked
196
+ if mid == msgid
197
+ msg += "#{msgid} #{Digest::MD5.new.update(e.body).hexdigest}\r\n"
198
+ last
199
+ end
200
+ end
201
+ if msg.length > 0
202
+ send("+OK\r\n#{msg}.")
203
+ else
204
+ send("-ERR no such message, only #{msgid} messages in maildrop")
205
+ end
186
206
  else
187
207
  send("-ERR unknown command")
188
208
  end
@@ -20,7 +20,7 @@ module EventMachine
20
20
  @@reverse_ptr_check = false
21
21
  @@spf_check = false
22
22
  @@reject_filters = Array.new
23
- @classifier = nil
23
+ @@classifier = nil
24
24
  end
25
25
 
26
26
  def self.reverse_ptr_check(ptr=nil)
@@ -72,11 +72,13 @@ module EventMachine
72
72
  @@classifier
73
73
  end
74
74
 
75
+ attr_accessor :debug
76
+
75
77
  def initialize(hostname, userstore, emailstore)
76
78
  @hostname = hostname
77
79
  @userstore = userstore
78
80
  @emailstore = emailstore
79
- @debug = true
81
+ @debug = false
80
82
  @data_mode = false
81
83
  @email_body = ""
82
84
  @ptr_ok = true
@@ -243,7 +245,7 @@ module EventMachine
243
245
  check_reject
244
246
  check_classifier
245
247
  @pending_checks -= [:content]
246
- p @pending_checks
248
+ p @pending_checks if @debug
247
249
  if @pending_checks.length == 0
248
250
  send_answer
249
251
  end
@@ -261,14 +263,14 @@ module EventMachine
261
263
  send("221 #{@hostname} ESMTP server closing connection")
262
264
  self.close_connection
263
265
  elsif (line =~ /^MAIL FROM\:/)
264
- @mail_from = (/^MAIL FROM\:<(.+)>.*$/).match(line)[1]
266
+ @mail_from = (/^MAIL FROM\:\s*<(.+)>.*$/).match(line)[1]
265
267
  if @@spf_check
266
268
  port, ip = Socket.unpack_sockaddr_in(get_peername)
267
269
  check_spf(helo, ip, @mail_from)
268
270
  end
269
271
  send("250 OK")
270
272
  elsif (line =~ /^RCPT TO\:/)
271
- rcpt_to = (/^RCPT TO\:<(.+)>.*$/).match(line)[1]
273
+ rcpt_to = (/^RCPT TO\:\s*<(.+)>.*$/).match(line)[1]
272
274
  if @userstore.user_by_emailaddress(rcpt_to.strip)
273
275
  @rcpt_to = rcpt_to
274
276
  send("250 OK")
@@ -290,10 +292,10 @@ module EventMachine
290
292
 
291
293
  def save
292
294
  begin
293
- subject = @email_body.match(/Subject\: (.*?)[\r\n]/i)[1]
295
+ subject = @email_body.match(/Subject\:\s*(.*?)[\r\n]/i)[1]
294
296
  u = @userstore.user_by_emailaddress(@rcpt_to.strip)
295
297
  rescue Exception => err
296
- puts err
298
+ puts err if @debug
297
299
  return
298
300
  end
299
301
  if u and @mail_from and @rcpt_to
@@ -1,5 +1,5 @@
1
1
  module EventMachine
2
2
  module EmailServer
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
@@ -11,6 +11,7 @@ include EventMachine::EmailServer
11
11
  require 'net/pop'
12
12
  require 'net/smtp'
13
13
  require 'ratelimit/bucketbased'
14
+ require 'fileutils'
14
15
 
15
16
  $dns_port = 53
16
17
 
@@ -32,7 +33,7 @@ class TestEmailServer < Minitest::Test
32
33
  To: chris@example.org
33
34
  Subject: What to do when you're not doing.
34
35
 
35
- Could I interest you in some cialis?
36
+ Could I interest you in some cialis or levitra?
36
37
  ")
37
38
  @ham_email = EmailTemplate.new("friend@example.org", "chris@example.org", "From: friend@example.org
38
39
  To: chris@example.org
@@ -53,6 +54,7 @@ Looks like we had fun!
53
54
  end
54
55
 
55
56
  def remove_scraps
57
+ FileUtils.remove_dir("test/test.classifier", true)
56
58
  end
57
59
 
58
60
  def teardown
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eventmachine-email_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - chrislee35
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-11 00:00:00.000000000 Z
11
+ date: 2015-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine
@@ -209,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
209
209
  version: '0'
210
210
  requirements: []
211
211
  rubyforge_project:
212
- rubygems_version: 2.2.2
212
+ rubygems_version: 2.4.6
213
213
  signing_key:
214
214
  specification_version: 4
215
215
  summary: EventMachine-based implementations of a POP3 and SMTP server