/lib/sisimai/rhost/spectrum.rb

https://github.com/sisimai/rb-Sisimai · Ruby · 73 lines · 46 code · 6 blank · 21 comment · 5 complexity · 60d826d23e15974f4cc838c1a3e0e7d4 MD5 · raw file

  1. module Sisimai
  2. module Rhost
  3. # Sisimai::Rhost detects the bounce reason from the content of Sisimai::Data
  4. # object as an argument of get() method when the value of "destination" of
  5. # the object is "charter.net". This class is called only Sisimai::Data class.
  6. module Spectrum
  7. class << self
  8. # Imported from p5-Sisimail/lib/Sisimai/Rhost/Spectrum.pm
  9. ErrorCodes = {
  10. # https://www.spectrumbusiness.net/support/internet/understanding-email-error-codes
  11. # Error codes are placed in one of two categories: incoming or outgoing.
  12. # 1. If youre trying to send an email to a Charter email address from
  13. # a non-Charter email address (such as Gmail, Yahoo, Hotmail, etc.),
  14. # you may receive an error that begins with AUP#I, followed by four numbers.
  15. #
  16. # 2. If you are trying to send an email from a Charter email address
  17. # to an outgoing recipient, you may get an error code beginning with
  18. # AUP#O, also followed by four numbers.
  19. #
  20. 1000 => 'blocked', # Your IP address has been blocked due to suspicious activity.
  21. 1010 => 'rejected', # This email account has been blocked from sending emails due to suspicious activity.
  22. 1090 => 'systemerror', # The email you're trying to send can't be processed. Try sending again at a later time.
  23. 1260 => 'networkerror', # Spectrum doesn't process IPV6 addresses. Connect with an IPv4 address and try again.
  24. 1500 => 'rejected', # Your email was rejected for attempting to send as a different email address than you signed in under.
  25. 1520 => 'rejected', # Your email was rejected for attempting to send as a different email address than a domain that we host.
  26. 1530 => 'mesgtoobig', # Your email was rejected because it's larger than the maximum size of 20MB.
  27. 1540 => 'toomanyconn', # Your emails were deferred for attempting to send too many in a single session.
  28. 1550 => 'toomanyconn', # Your email was rejected for having too many recipients in one message.
  29. 1560 => 'policyviolation', # Your email was rejected for having too many invalid recipients.
  30. }.freeze
  31. CodeRanges = [
  32. [1020, 1080, 'rejected'], # This email account has limited access to send emails based on suspicious activity.
  33. [1100, 1150, 'blocked'], # The IP address you're trying to connect from has an issue with the Domain Name System.
  34. [1160, 1190, 'policyviolation'], # The email you tried to send goes against your domain's security policies.
  35. [1200, 1210, 'blocked'], # The IP address you're trying to send from has been flagged by Cloudmark CSI as potential spam.
  36. [1220, 1250, 'blokced'], # Your IP address has been blacklisted by Spamhaus.
  37. [1300, 1340, 'toomanyconn'], # Spectrum limits the number of concurrent connections from a sender
  38. [1350, 1490, 'toomanyconn'], # Spectrum limits emails by the number of messages sent, amount of recipients,...
  39. ].freeze
  40. # Detect bounce reason from https://www.spectrum.com/
  41. # @param [Sisimai::Data] argvs Parsed email object
  42. # @return [String, Nil] The bounce reason at Spectrum
  43. # @since v4.25.8
  44. def get(argvs)
  45. statusmesg = argvs.diagnosticcode
  46. codenumber = 0
  47. if cv = statusmesg.match(/AUP#[-A-Za-z]*(\d{4})/)
  48. # Capture the numeric part of the error code
  49. codenumber = cv[1].to_i
  50. end
  51. reasontext = ErrorCodes[codenumber] || ''
  52. if reasontext.empty?
  53. # The error code was not found in ErrorCodes
  54. CodeRanges.each do |e|
  55. # Check the code range
  56. next if codenumber < e[0]
  57. next if codenumber > e[1]
  58. reasontext = e[2]
  59. break
  60. end
  61. end
  62. return reasontext
  63. end
  64. end
  65. end
  66. end
  67. end