airmail 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea5d4e063ac91379c28d4032483cef08f4b54f90
4
- data.tar.gz: 91cff38097db09ac3dc842695d8f4a5f2f095f57
3
+ metadata.gz: 53bc23d7faeb939dbe4979a1ca3c2b1f8472ced5
4
+ data.tar.gz: efac7aba3d82be84e5279a1a2935d30d9c5eab27
5
5
  SHA512:
6
- metadata.gz: 90cd3d0093850d5eefd97d6d88f8613412b09a64483bf6770c9191e585d78f5f240cf2ba9fa1d1aa88ea2275729b812d02b44e18200bedcb5b7abca2b0cb50f9
7
- data.tar.gz: d2d6a33f5b34870f88bddcf8ffc65acdc5cd171cf88da293ce8efa9ac69c0631ff679025e425b64af9544ad11d7bf470b871317de4907c89e49e3ccd14f1a9e9
6
+ metadata.gz: f8071018a6fe158054fcfaef1335bcb81274b3059834d6ee49e0b4345b3e56386876bdb11bc3f87db2223065319ebcc563c677a7361042528177f942128b9068
7
+ data.tar.gz: 2fb20facaacc7a09de459ec4c4e87cbb2551003d3cffdcb4e1e1d5496d96459b15146e171beb5ffbe90131b925a69b6cb5d5664e233ba2c395531f213edd217d
data/README.md CHANGED
@@ -30,3 +30,11 @@ Then receive emails!
30
30
  EOF
31
31
 
32
32
  Airmail.receive( mail )
33
+
34
+
35
+ There is a poor man's implementation of a "sentiment analyzer." You can make some fuzzy logic to figure out
36
+ some actions. For instance if you wanted "action bob@thomas.com" to do trigger some "action."
37
+
38
+ Airmail.route do
39
+ deliver SomeActionController if sentiment "action", Airmail::EMAIL_PATTERN
40
+ end
data/lib/airmail.rb CHANGED
@@ -5,3 +5,5 @@ require 'airmail/mail_controller'
5
5
  require 'airmail/airmail_default_controller'
6
6
  require 'airmail/airmail' #tmp
7
7
 
8
+ require 'airmail/sentiment'
9
+ require 'airmail/patterns'
@@ -25,6 +25,17 @@ class MailProcessor
25
25
  @mail.attachments.size > 0
26
26
  end
27
27
 
28
+ #poor mans sentiment analyzer
29
+ def sentiment *phrase
30
+ analizer = Sentiment.new(phrase)
31
+ !!analizer.analyze(@mail.body.raw_source)
32
+ end
33
+
34
+ def or_regex(phrase)
35
+ return "[#{phrase.join("|")}]" if phrase.is_a? Array
36
+ phrase
37
+ end
38
+
28
39
  def deliver controller
29
40
  @delivering_controller ||= controller
30
41
  end
@@ -0,0 +1,3 @@
1
+ module Airmail
2
+ EMAIL_PATTERN = "[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,3}"
3
+ end
@@ -0,0 +1,18 @@
1
+ class Sentiment
2
+ def initialize(*pattern)
3
+ @pattern = /#{"(" + pattern.map{|a| or_regex(a) }.join(').*(') + ")"}/
4
+ end
5
+
6
+ def analyze(phrase)
7
+ sentiments = @pattern.match phrase
8
+ !!sentiments
9
+ end
10
+
11
+ private
12
+
13
+ def or_regex(phrase)
14
+ return "#{phrase.join("|")}" if phrase.is_a? Array
15
+ phrase
16
+ end
17
+
18
+ end
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ describe Airmail do
4
+
5
+ context 'multiple controllers' do
6
+
7
+ let(:mail) { Mail.new(body: "include bob@thomas.com") }
8
+ let(:subscribe_mail) { Mail.new(body: "subscribe bob@thomas.com") }
9
+
10
+ it 'matches sentiment' do
11
+ Counter.reset
12
+
13
+ Airmail.route do
14
+ if sentiment "include", Airmail::EMAIL_PATTERN
15
+ deliver CountController
16
+ end
17
+ end
18
+
19
+ Airmail.receive(mail)
20
+ expect(Counter.count).to eq(1)
21
+ end
22
+
23
+ it 'matches word bag sentiment' do
24
+
25
+ Counter.reset
26
+
27
+ Airmail.route do
28
+ if sentiment ["include", "subscribe"], Airmail::EMAIL_PATTERN
29
+ deliver CountController
30
+ end
31
+ end
32
+
33
+ Airmail.receive(mail)
34
+ expect(Counter.count).to eq(1)
35
+
36
+ Airmail.receive(subscribe_mail)
37
+ expect(Counter.count).to eq(2)
38
+ end
39
+
40
+ it 'rejects mismatched sentiment' do
41
+ Counter.reset
42
+
43
+ Airmail.route do
44
+ if sentiment "alksfdlaklsdfjslf"
45
+ deliver CountController
46
+ end
47
+ end
48
+
49
+ Airmail.receive(mail)
50
+ expect(Counter.count).to eq(0)
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+
57
+ class CountController < Airmail::Controller
58
+ def receive
59
+ Counter.inc
60
+ end
61
+ end
62
+
63
+ class BlankController < Airmail::Controller
64
+ def receive
65
+ end
66
+ end
67
+
68
+ class Counter
69
+ @@val = 0
70
+
71
+ def self.reset
72
+ @@val = 0
73
+ end
74
+
75
+ def self.inc
76
+ @@val += 1
77
+ end
78
+
79
+ def self.count
80
+ @@val
81
+ end
82
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: airmail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trevor Grayson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-13 00:00:00.000000000 Z
11
+ date: 2016-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mail
@@ -51,7 +51,10 @@ files:
51
51
  - lib/airmail/mail_controller.rb
52
52
  - lib/airmail/mail_processor.rb
53
53
  - lib/airmail/mail_router.rb
54
+ - lib/airmail/patterns.rb
55
+ - lib/airmail/sentiment.rb
54
56
  - spec/airmail_spec.rb
57
+ - spec/sentiment_spec.rb
55
58
  - spec/spec_helper.rb
56
59
  homepage: https://rubygems.org/gems/airmail
57
60
  licenses:
@@ -73,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
76
  version: '0'
74
77
  requirements: []
75
78
  rubyforge_project:
76
- rubygems_version: 2.4.5.1
79
+ rubygems_version: 2.5.1
77
80
  signing_key:
78
81
  specification_version: 4
79
82
  summary: Incoming Email Router