Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Sidekiq delivery method for non-UTF8 email #43

Merged
merged 1 commit into from
Sep 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## mail_room 0.5.2 ##

* Fix Sidekiq delivery method for non-UTF8 email

*Douwe Maan <@DouweM>*

## mail_room 0.5.1 ##

* Re-idle after 29 minutes to maintain IDLE connection
Expand Down
16 changes: 15 additions & 1 deletion lib/mail_room/delivery/sidekiq.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "redis"
require "securerandom"
require "json"
require "charlock_holmes"

module MailRoom
module Delivery
Expand Down Expand Up @@ -53,14 +54,27 @@ def client
def item_for(message)
{
'class' => options.worker,
'args' => [message],
'args' => [utf8_encode_message(message)],

'queue' => options.queue,
'jid' => SecureRandom.hex(12),
'retry' => false,
'enqueued_at' => Time.now.to_f
}
end

def utf8_encode_message(message)
message = message.dup

message.force_encoding("UTF-8")
return message if message.valid_encoding?

detection = CharlockHolmes::EncodingDetector.detect(message)
return message unless detection && detection[:encoding]

# Convert non-UTF-8 body UTF-8 so it can be dumped as JSON.
CharlockHolmes::Converter.convert(message, detection[:encoding], 'UTF-8')
end
end
end
end
1 change: 1 addition & 0 deletions mail_room.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ Gem::Specification.new do |gem|
gem.add_development_dependency "letter_opener"
gem.add_development_dependency "redis"
gem.add_development_dependency "pg"
gem.add_development_dependency "charlock_holmes"
end