Class: MultiMail::Receiver::SendGrid
- Inherits:
-
Object
- Object
- MultiMail::Receiver::SendGrid
- Includes:
- Base
- Defined in:
- lib/multi_mail/sendgrid/receiver.rb
Overview
SendGrid's incoming email receiver.
Instance Method Summary collapse
- #encode(key) ⇒ Object
-
#initialize(options = {}) ⇒ SendGrid
constructor
Initializes a SendGrid incoming email receiver.
-
#spam?(message) ⇒ Boolean
Returns whether a message is spam.
-
#transform(params) ⇒ Array<Mail::Messages>
Transforms the content of SendGrid's webook into a list of messages.
Methods included from Base
Constructor Details
#initialize(options = {}) ⇒ SendGrid
Initializes a SendGrid incoming email receiver.
11 12 13 14 |
# File 'lib/multi_mail/sendgrid/receiver.rb', line 11 def initialize( = {}) super @spamassassin_threshold = [:spamassassin_threshold] || 5 end |
Instance Method Details
#encode(key) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/multi_mail/sendgrid/receiver.rb', line 78 def encode(key) if @charsets.key?(key) if @params[key].respond_to?(:force_encoding) @params[key].force_encoding(@charsets[key]).encode('UTF-8') else Iconv.conv('UTF-8', @charsets[key], @params[key]) end else @params[key] end end |
#spam?(message) ⇒ Boolean
Returns whether a message is spam.
74 75 76 |
# File 'lib/multi_mail/sendgrid/receiver.rb', line 74 def spam?() ['spam_score'] && ['spam_score'].value.to_f > @spamassassin_threshold end |
#transform(params) ⇒ Array<Mail::Messages>
Transforms the content of SendGrid's webook into a list of messages.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/multi_mail/sendgrid/receiver.rb', line 21 def transform(params) # Make variables available to the `encode` method. @params = params @charsets = JSON.load(params['charsets']) # Mail changes `self`. this = self = Mail.new do # SendGrid includes a `charsets` parameter, which describes the # encodings of the `from`, `to`, `cc` and `subject` parameters, which # we don't need because we parse the headers directly. # @see http://sendgrid.com/docs/API_Reference/Webhooks/parse.html#-Character-Sets-and-Header-Decoding header params['headers'] # The following are redundant with `headers`: # # from params['from'] # to params['to'] # cc params['cc'] # subject params['subject'] text_part do body this.encode('text') end if params.key?('html') html_part do content_type 'text/html; charset=UTF-8' body this.encode('html') end end 1.upto(params['attachments'].to_i) do |n| = params["attachment#{n}"] add_file(this.class.add_file_arguments()) end end # Extra SendGrid parameters. Discard %w(dkim SPF spam_report spam_score).each do |key| [key] = params[key] end # Discard `envelope`, which contains `to` and `from`, and the # undocumented `attachment-info`. [] end |