autoreply 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b10664ddf4e1e2a762b3c7d8e196954ace9cee32
4
+ data.tar.gz: f8d0f36c3eac43af8d8cefbcb7222e734a6a1b03
5
+ SHA512:
6
+ metadata.gz: fcf8cc47805ada0a4bc8c1eb1c9c3ba0f1b14aaf13dee2c716b0137be607d44df514eb28dc8c2e45797b6549a9b380a6048615bc299b299e2960818fb0f3138c
7
+ data.tar.gz: cf12079fc5681687c355c6094f587bf7c8bef91d3f96f24b292861c697d46f2059bde190a8dceb11ac8268bd04b4994d3ffb7a25fcd3a0431abb071b9eac57c0
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.3
4
+ - 2.2.2
5
+ before_install: gem install bundler -v 1.10.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in autoreply.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Edufii
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Sergey Kishenin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # autoreply
2
+ Detect if email is autoresponder or "out-of-office" email
3
+
4
+ # Usage
5
+
6
+ `Autoreply.autoreply?(mail)`
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/autoreply.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'autoreply/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "autoreply"
8
+ spec.version = Autoreply::VERSION
9
+ spec.authors = ["Sergey Kishenin", "Dmitry Naumov"]
10
+ spec.email = ["sergey.kishenin@gmail.com", "naumovmail@gmail.com"]
11
+
12
+ spec.summary = %q{Detect if email is autoresponder or "out-of-office" email}
13
+ spec.description = %q{Detect if email is autoresponder or "out-of-office" email}
14
+ spec.homepage = "https://github.com/edufii/autoreply"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "mail"
26
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "autoreply"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/lib/autoreply.rb ADDED
@@ -0,0 +1,17 @@
1
+ require "autoreply/version"
2
+ require "autoreply/scanner"
3
+ require "autoreply/scanner/base"
4
+ require "autoreply/scanner/sender"
5
+ require "autoreply/scanner/subject"
6
+ require "autoreply/scanner/headers"
7
+ require "autoreply/scanner/headers/base"
8
+ require "autoreply/scanner/headers/by_existance"
9
+ require "autoreply/scanner/headers/by_value"
10
+
11
+ module Autoreply
12
+ extend self
13
+
14
+ def autoreply?(mail)
15
+ Scanner.new(mail).autoreply?
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ module Autoreply
2
+ class Scanner
3
+ attr_reader :mail
4
+
5
+ def initialize(mail)
6
+ @mail = mail
7
+ end
8
+
9
+ def autoreply?
10
+ sender_scanner.autoreply? ||
11
+ subject_scanner.autoreply? ||
12
+ headers_scanner.autoreply?
13
+ end
14
+
15
+ private
16
+
17
+ def sender_scanner
18
+ Scanner::Sender.new(mail)
19
+ end
20
+
21
+ def subject_scanner
22
+ Scanner::Subject.new(mail)
23
+ end
24
+
25
+ def headers_scanner
26
+ Scanner::Headers.new(mail)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ module Autoreply
2
+ class Scanner::Base
3
+ attr_reader :mail
4
+
5
+ def initialize(mail)
6
+ @mail = mail
7
+ end
8
+
9
+ def autoreply?
10
+ raise NotImplementedError
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ module Autoreply
2
+ class Scanner::Headers < Scanner::Base
3
+ def autoreply?
4
+ headers_by_existance.autoreply? || headers_by_value.autoreply?
5
+ end
6
+
7
+ private
8
+
9
+ def headers_by_existance
10
+ Scanner::Headers::ByExistance.new(header_fields)
11
+ end
12
+
13
+ def headers_by_value
14
+ Scanner::Headers::ByValue.new(header_fields)
15
+ end
16
+
17
+ def header_fields
18
+ @header_fields ||= mail.header_fields
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ module Autoreply
2
+ class Scanner::Headers::Base
3
+ attr_reader :header_fields
4
+
5
+ def initialize(header_fields)
6
+ @header_fields = header_fields ||= []
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ module Autoreply
2
+ class Scanner::Headers::ByExistance < Scanner::Headers::Base
3
+ KNOWN_HEADERS = %w(
4
+ list-help
5
+ list-unsubscribe
6
+ list-subscribe
7
+ list-owner
8
+ list-post
9
+ list-archive
10
+ list-id
11
+ mailing-list
12
+ x-facebook-notify
13
+ x-mailing-list
14
+ x-cron-env
15
+ x-autoresponse
16
+ x-ebay-mailtracker
17
+ x-autoresponder
18
+ x-autorespond
19
+ )
20
+
21
+ def autoreply?
22
+ !(KNOWN_HEADERS & header_fields.map(&:name).map(&:downcase)).blank?
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,38 @@
1
+ module Autoreply
2
+ class Scanner::Headers::ByValue < Scanner::Headers::Base
3
+ KNOWN_HEADERS = {
4
+ "x-spam-flag" => /yes/,
5
+ "x-spam-status" => /yes/,
6
+ "x-spam-flag2" => /yes/,
7
+ "precedence" => /(bulk|list|junk)/,
8
+ "x-precedence" => /(bulk|list|junk)/,
9
+ "x-barracuda-spam-status" => /yes/,
10
+ "x-dspam-result" => /(spam|bl[ao]cklisted)/,
11
+ "x-mailer" => /^[mM]ail$/,
12
+ "auto-submitted" => /auto-replied/,
13
+ "x-autogenerated" => /reply/,
14
+ "x-autosubmitted" => /(?!no)/
15
+ }
16
+
17
+ def autoreply?
18
+ !detected_headers.blank?
19
+ end
20
+
21
+ private
22
+
23
+ def detected_headers
24
+ header_fields.inject([]) do |result, incoming_header|
25
+ name = incoming_header.name.downcase
26
+ value = incoming_header.value
27
+
28
+ KNOWN_HEADERS.each do |header_name, regexp|
29
+ if name == header_name && value =~ regexp
30
+ result.push(name)
31
+ end
32
+ end
33
+
34
+ result
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,46 @@
1
+ module Autoreply
2
+ class Scanner::Sender < Scanner::Base
3
+ KNOWN_SENDER_REGEXPS = [
4
+ /^owner-/,
5
+ /^request-/,
6
+ /-request@/,
7
+ /bounce.*@/,
8
+ /-confirm@/,
9
+ /-errors@/,
10
+ /^no[-]?reply/,
11
+ /^donotreply/,
12
+ /^postmaster@/,
13
+ /^mailer[-_]daemon@/,
14
+ /^mailer@/,
15
+ /^listserv@/,
16
+ /^majordom[o]?@/,
17
+ /^mailman@/,
18
+ /^nobody@/,
19
+ /^bounce/,
20
+ /^www(-data)?@/,
21
+ /^mdaemon@/,
22
+ /^root@/,
23
+ /^news(letter)?@/,
24
+ /^webmaster@/,
25
+ /^administrator@/,
26
+ /^support@/
27
+ ]
28
+
29
+ def autoreply?
30
+ !detected_senders.blank?
31
+ end
32
+
33
+ private
34
+
35
+ def detected_senders
36
+ mail.from ||= []
37
+ mail.from.inject([]) do |result, email|
38
+ KNOWN_SENDER_REGEXPS.each do |regexp|
39
+ result.push(email) if email =~ regexp
40
+ end
41
+
42
+ result
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,39 @@
1
+ module Autoreply
2
+ class Scanner::Subject < Scanner::Base
3
+ KNOWN_SUBJECTS = [
4
+ "Auto:",
5
+ "Automatic reply",
6
+ "Autosvar",
7
+ "Automatisk svar",
8
+ "Automatisch antwoord",
9
+ "Abwesenheitsnotiz",
10
+ "Risposta Non al computer",
11
+ "Automatisch antwoord",
12
+ "Auto Response",
13
+ "Respuesta automática",
14
+ "Fuori sede",
15
+ "Out of Office",
16
+ "Frånvaro",
17
+ "Réponse automatique"
18
+ ]
19
+
20
+ def autoreply?
21
+ !detected_subjects.blank?
22
+ end
23
+
24
+ private
25
+
26
+ def detected_subjects
27
+ return unless mail.subject
28
+
29
+ KNOWN_SUBJECTS.inject([]) do |result, subject|
30
+ result << subject if starts_with?(mail.subject, subject)
31
+ result
32
+ end
33
+ end
34
+
35
+ def starts_with?(string, prefix)
36
+ string[0, prefix.length] == prefix
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module Autoreply
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: autoreply
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sergey Kishenin
8
+ - Dmitry Naumov
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2015-08-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.10'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.10'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: mail
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ description: Detect if email is autoresponder or "out-of-office" email
71
+ email:
72
+ - sergey.kishenin@gmail.com
73
+ - naumovmail@gmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - LICENSE
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - autoreply.gemspec
87
+ - bin/console
88
+ - bin/setup
89
+ - lib/autoreply.rb
90
+ - lib/autoreply/scanner.rb
91
+ - lib/autoreply/scanner/base.rb
92
+ - lib/autoreply/scanner/headers.rb
93
+ - lib/autoreply/scanner/headers/base.rb
94
+ - lib/autoreply/scanner/headers/by_existance.rb
95
+ - lib/autoreply/scanner/headers/by_value.rb
96
+ - lib/autoreply/scanner/sender.rb
97
+ - lib/autoreply/scanner/subject.rb
98
+ - lib/autoreply/version.rb
99
+ homepage: https://github.com/edufii/autoreply
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.4.7
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Detect if email is autoresponder or "out-of-office" email
123
+ test_files: []