cirandas.net

commit 9c38b74e5642395cf1f8b53c130ff73e5038f969

Author: Hugo Melo <hugo@riseup.net>

Truncate the hour to avoid sending over the limit of the hour

 app/mailers/mail_queuer.rb | 12 ++++++------


diff --git a/app/mailers/mail_queuer.rb b/app/mailers/mail_queuer.rb
index fd706bce55f785908b2827a79639913e27f36aae..3d44e79f724180eb04c1b41927c88486123008d1 100644
--- a/app/mailers/mail_queuer.rb
+++ b/app/mailers/mail_queuer.rb
@@ -46,12 +46,12 @@     end
 
     def deliver_schedule last_sched
       limit   = ENV['MAIL_QUEUER_LIMIT'].to_i - 1
-      orig_to = to.dup
-      orig_cc = cc.dup
+      orig_to = Array(to).dup
+      orig_cc = Array(cc).dup
       dests   = {
-        to:  self.to,
-        cc:  self.cc,
-        bcc: self.bcc,
+        to:  Array(self.to),
+        cc:  Array(self.cc),
+        bcc: Array(self.bcc),
       }
 
       loop do
@@ -69,7 +69,7 @@         ##
         # The last schedule is outside the quota period
         #
         if last_sched.scheduled_to < 1.hour.ago
-          last_sched = MailSchedule.create! dest_count: 0, scheduled_to: Time.now
+          last_sched = MailSchedule.create! dest_count: 0, scheduled_to: Time.now.beginning_of_hour
         end
 
         available_limit = limit - last_sched.dest_count