-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1525 from postalserver/rspamd
Support for rspamd
- Loading branch information
Showing
11 changed files
with
267 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module Postal | ||
class MessageInspector | ||
|
||
def initialize(config) | ||
@config = config | ||
end | ||
|
||
# Inspect a message and update the inspection with the results | ||
# as appropriate. | ||
def inspect_message(message, scope, inspection) | ||
end | ||
|
||
private | ||
|
||
def logger | ||
Postal.logger_for(:message_inspection) | ||
end | ||
|
||
class << self | ||
# Return an array of all inspectors that are available for this | ||
# installation. | ||
def inspectors | ||
Array.new.tap do |inspectors| | ||
|
||
if Postal.config.rspamd&.enabled | ||
inspectors << MessageInspectors::Rspamd.new(Postal.config.rspamd) | ||
elsif Postal.config.spamd&.enabled | ||
inspectors << MessageInspectors::SpamAssassin.new(Postal.config.spamd) | ||
end | ||
|
||
if Postal.config.clamav&.enabled | ||
inspectors << MessageInspectors::Clamav.new(Postal.config.clamav) | ||
end | ||
|
||
end | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Postal | ||
module MessageInspectors | ||
extend ActiveSupport::Autoload | ||
eager_autoload do | ||
autoload :Clamav | ||
autoload :Rspamd | ||
autoload :SpamAssassin | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module Postal | ||
module MessageInspectors | ||
class Clamav < MessageInspector | ||
|
||
def inspect_message(inspection) | ||
raw_message = inspection.message.raw_message | ||
|
||
data = nil | ||
Timeout.timeout(10) do | ||
tcp_socket = TCPSocket.new(@config.host, @config.port) | ||
tcp_socket.write("zINSTREAM\0") | ||
tcp_socket.write([raw_message.bytesize].pack("N")) | ||
tcp_socket.write(raw_message) | ||
tcp_socket.write([0].pack("N")) | ||
tcp_socket.close_write | ||
data = tcp_socket.read | ||
end | ||
|
||
if data && data =~ /\Astream\:\s+(.*?)[\s\0]+?/ | ||
if $1.upcase == 'OK' | ||
inspection.threat = false | ||
inspection.threat_message = "No threats found" | ||
else | ||
inspection.threat = true | ||
inspection.threat_message = $1 | ||
end | ||
else | ||
inspection.threat = false | ||
inspection.threat_message = "Could not scan message" | ||
end | ||
rescue Timeout::Error | ||
inspection.threat = false | ||
inspection.threat_message = "Timed out scanning for threats" | ||
rescue => e | ||
logger.error "Error talking to clamav: #{e.class} (#{e.message})" | ||
logger.error e.backtrace[0,5] | ||
inspection.threat = false | ||
inspection.threat_message = "Error when scanning for threats" | ||
ensure | ||
tcp_socket.close rescue nil | ||
end | ||
|
||
end | ||
end | ||
end |
Oops, something went wrong.