Class: MultiMail::Receiver::Cloudmailin
- Inherits:
-
Object
- Object
- MultiMail::Receiver::Cloudmailin
- Includes:
- Base
- Defined in:
- lib/multi_mail/cloudmailin/receiver.rb
Overview
Cloudmailin's incoming email receiver.
Cloudmailin recommends using basic authentication over HTTPS to ensure that a request originates from Cloudmailin.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Cloudmailin
constructor
Initializes a Cloudmailin incoming email receiver.
-
#spam?(message) ⇒ Boolean
Whether the message is spam.
-
#transform(params) ⇒ Array<Mail::Message>
Messages.
Methods included from Base
Constructor Details
#initialize(options = {}) ⇒ Cloudmailin
Initializes a Cloudmailin incoming email receiver.
18 19 20 21 |
# File 'lib/multi_mail/cloudmailin/receiver.rb', line 18 def initialize( = {}) super @http_post_format = [:http_post_format] end |
Instance Method Details
#spam?(message) ⇒ Boolean
Returns whether the message is spam.
85 86 87 |
# File 'lib/multi_mail/cloudmailin/receiver.rb', line 85 def spam?() ['spf-result'] && ['spf-result'].value == 'fail' end |
#transform(params) ⇒ Array<Mail::Message>
Returns messages.
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 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/multi_mail/cloudmailin/receiver.rb', line 28 def transform(params) case @http_post_format when 'raw', '', nil = self.class.condense(Mail.new(params['message'])) # Extra Cloudmailin parameters. ['spf-result'] = params['envelope']['spf']['result'] # Discard rest of `envelope`: `from`, `to`, `recipients`, # `helo_domain` and `remote_ip`. [] when 'multipart', 'json' # Mail changes `self`. headers = self.class.multimap(params['headers']) http_post_format = @http_post_format this = self = Mail.new do headers headers text_part do body params['plain'] end if params.key?('html') html_part do content_type 'text/html; charset=UTF-8' body params['html'] end end if params.key?('attachments') if http_post_format == 'json' params['attachments'].each do || add_file(:filename => ['file_name'], :content => Base64.decode64(['content'])) end else params['attachments'].each do |_,| add_file(this.class.add_file_arguments()) end end end end # Extra Cloudmailin parameters. The multipart format uses CRLF whereas # the JSON format uses LF. Normalize to LF. ['reply_plain'] = params['reply_plain'].gsub("\r\n", "\n") ['spf-result'] = params['envelope']['spf']['result'] [] else raise ArgumentError, "Can't handle Cloudmailin #{@http_post_format} HTTP POST format" end end |