Module: Mailpot::Mail
- Defined in:
- lib/mailpot/mail.rb
Class Method Summary collapse
- .add_message(message) ⇒ Object
- .detect_probe(msg) ⇒ Object
- .forward_probe(msg) ⇒ Object
-
.initialize ⇒ Object
setup connections etc.
- .store_message(key, value) ⇒ Object
Class Method Details
.add_message(message) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mailpot/mail.rb', line 26 def () if !@initialized initialize end msg = Hash.new msg[:source] = [:source] msg[:sender] = [:sender] msg[:source_ip] = [:ip] msg[:recipients] = [:recipients] msg[:probe] = detect_probe() # we must at this point detect probes because we need them to be sent = Marshal.dump(msg) digest = Digest::MD5.hexdigest() (digest, ) end |
.detect_probe(msg) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/mailpot/mail.rb', line 42 def detect_probe(msg) mail = Mail.new(msg[:source]) # Probes only have one recipient if msg[:recipients].length > 1 return [false, false] end # probes are short if msg[:source].length > 1024 return [false, false] end # ip address will be in the subject sometimes if mail.subject.include? Mailpot::Configuration.smtp_ip return [true, forward_probe(msg)] end return [false, false] end |
.forward_probe(msg) ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/mailpot/mail.rb', line 59 def forward_probe(msg) r = Regexp.new(/\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+?\.[a-zA-Z.]*\b/) sender = msg[:sender] sender = sender.scan(r) recipient = msg[:recipients].to_s recipient = recipient.scan(r) Net::SMTP.start('localhost') do | smtp| smtp. msg[:source], sender, recipient end end |
.initialize ⇒ Object
setup connections etc
17 18 19 20 21 22 23 24 |
# File 'lib/mailpot/mail.rb', line 17 def initialize yml = Mailpot::Configuration.key_data @bucket = yml['bucket'] @queue = yml['queue'] @s3 = AWS::S3.new(yml) @sqs = AWS::SQS.new(yml) @initialized = true end |
.store_message(key, value) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/mailpot/mail.rb', line 70 def (key, value) Thread.new { mail = @s3.buckets[@bucket].objects[key] = { :storage_class => :reduced_redundancy } mail.write(value, ) q = @sqs.queues[@queue] msg = q.(key) } end |