zendesk-ar_mailer 2.1.5 → 2.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -395,6 +395,10 @@ class ActionMailer::ARSendmail
395
395
  @failed_auth_count = 0
396
396
  until emails.empty? do
397
397
  email = emails.shift
398
+ if locking_enabled?
399
+ next unless email.lock_with_expirey
400
+ end
401
+
398
402
  begin
399
403
  res = session.send_message email.mail, email.from, email.to
400
404
  hdr = ''
@@ -422,6 +426,10 @@ class ActionMailer::ARSendmail
422
426
  [email.id, e.message, e.class, e.backtrace.join("\n\t")]
423
427
  session.reset
424
428
  end
429
+
430
+ if locking_enabled?
431
+ email.unlock
432
+ end
425
433
  end
426
434
  end
427
435
  rescue Net::SMTPAuthenticationError => e
@@ -437,6 +445,10 @@ class ActionMailer::ARSendmail
437
445
  # ignore SMTPServerBusy/EPIPE/ECONNRESET from Net::SMTP.start's ensure
438
446
  end
439
447
 
448
+ def locking_enabled?
449
+ @locking_enabled ||= ActionMailer::Base.email_class.instance_methods.include?('lock_with_expirey')
450
+ end
451
+
440
452
  ##
441
453
  # Prepares ar_sendmail for exiting
442
454
 
@@ -514,6 +514,40 @@ Last send attempt: Thu Aug 10 11:40:05 %s 2006
514
514
  assert_equal "error sending email 1: \"timed out\"(Timeout::Error):\n\tone\n\ttwo\n\tthree\n", strip_log_prefix(err)
515
515
  end
516
516
 
517
+ def test_deliver_without_locking
518
+ email = Email.create :mail => 'body', :to => 'to', :from => 'from'
519
+ assert_equal false, @sm.locking_enabled?
520
+ out, err = capture_io do
521
+ @sm.deliver([ email ])
522
+ end
523
+
524
+ assert_equal 1, Net::SMTP.deliveries.length
525
+ end
526
+
527
+ def test_deliver_with_locking_acquired
528
+ email = Email.create :mail => 'body', :to => 'to', :from => 'from'
529
+ Email.any_instance.stubs(:lock_with_expirey).returns(true)
530
+ Email.any_instance.expects(:unlock)
531
+ assert_equal true, @sm.locking_enabled?
532
+ out, err = capture_io do
533
+ @sm.deliver([ email ])
534
+ end
535
+
536
+ assert_equal 1, Net::SMTP.deliveries.length
537
+ end
538
+
539
+ def test_deliver_with_locking_not_acquired
540
+ email = Email.create :mail => 'body', :to => 'to', :from => 'from'
541
+ Email.any_instance.stubs(:lock_with_expirey).returns(false)
542
+ Email.any_instance.expects(:unlock).never
543
+ assert_equal true, @sm.locking_enabled?
544
+ out, err = capture_io do
545
+ @sm.deliver([ email ])
546
+ end
547
+
548
+ assert_equal 0, Net::SMTP.deliveries.length
549
+ end
550
+
517
551
  def test_do_exit
518
552
  out, err = capture_io do
519
553
  assert_raises SystemExit do
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zendesk-ar_mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.5
4
+ hash: 7
5
+ prerelease: false
6
+ segments:
7
+ - 2
8
+ - 1
9
+ - 6
10
+ version: 2.1.6
5
11
  platform: ruby
6
12
  authors:
7
13
  - Eric Hodel
@@ -11,7 +17,7 @@ autorequire:
11
17
  bindir: bin
12
18
  cert_chain: []
13
19
 
14
- date: 2009-12-14 00:00:00 -05:00
20
+ date: 2010-07-26 00:00:00 -07:00
15
21
  default_executable: ar_sendmail
16
22
  dependencies: []
17
23
 
@@ -56,21 +62,27 @@ rdoc_options:
56
62
  require_paths:
57
63
  - lib
58
64
  required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
59
66
  requirements:
60
67
  - - ">="
61
68
  - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
62
72
  version: "0"
63
- version:
64
73
  required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
65
75
  requirements:
66
76
  - - ">="
67
77
  - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
68
81
  version: "0"
69
- version:
70
82
  requirements: []
71
83
 
72
84
  rubyforge_project: seattlerb
73
- rubygems_version: 1.3.5
85
+ rubygems_version: 1.3.7
74
86
  signing_key:
75
87
  specification_version: 3
76
88
  summary: A two-phase delivery agent for ActionMailer