mailgates 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +43 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/lib/mailgates.rb +5 -0
- data/lib/mailgates/log_parser.rb +28 -0
- data/lib/mailgates/version.rb +3 -0
- data/mailgates.gemspec +24 -0
- data/spec/log_parser_spec.rb +25 -0
- data/spec/spec_helper.rb +0 -0
- metadata +108 -0
data/.gitignore
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
2
|
+
# 注意:
|
3
|
+
#
|
4
|
+
# 文件添加至本地文件,而依然被跟踪,可使用下面代码,把该文件从cached中删除。
|
5
|
+
# git rm --cached un_wanted_be_tracked_file_name
|
6
|
+
#
|
7
|
+
*.vcf
|
8
|
+
*.gz
|
9
|
+
# 由数据库内容动态改变
|
10
|
+
|
11
|
+
# 项目本地文件夹
|
12
|
+
/log/
|
13
|
+
/db/
|
14
|
+
/tmp/
|
15
|
+
/vendor/
|
16
|
+
/public
|
17
|
+
.sass-cache/
|
18
|
+
|
19
|
+
# 数据库/log文件
|
20
|
+
/db/*.db
|
21
|
+
/db/*.sqlite3
|
22
|
+
/log/*.log
|
23
|
+
|
24
|
+
# 系统配置文件
|
25
|
+
.ruby-version
|
26
|
+
.DS_Store
|
27
|
+
|
28
|
+
# 临时文件
|
29
|
+
*.gem
|
30
|
+
*.rbc
|
31
|
+
.config
|
32
|
+
*.lock
|
33
|
+
*.out
|
34
|
+
.sass*
|
35
|
+
.coffee*
|
36
|
+
*cache
|
37
|
+
.git
|
38
|
+
.bundle
|
39
|
+
*.swp
|
40
|
+
*~
|
41
|
+
|
42
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
43
|
+
.rvmrc
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 jay16
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Mailgates
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'mailgates'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install mailgates
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/mailgates/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/mailgates.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Mailgates
|
2
|
+
class Log
|
3
|
+
def self.parser(line)
|
4
|
+
regexp = /\[(.*?)\]\s+\[(.*?)\] Mail\.RR\s(.*?\s*->\s*.*?)\s\((.*?)\)\[(.*)\]\[(.*?)\]\[(.*?)\]\[(.*?)\]/
|
5
|
+
line = line.force_encoding("UTF-8")
|
6
|
+
match = line.scan(regexp) rescue [nil]
|
7
|
+
|
8
|
+
if match[0] and match[0].size == 8
|
9
|
+
timestamp, emailfile, from_to, subject, result, mgham, mgtaglog, charset = match[0]
|
10
|
+
from, to = from_to.split(/->/).map { |str| str.gsub(/<|>/, "").strip } rescue ["", ""]
|
11
|
+
|
12
|
+
from = from.scan(/.*?_(\d+)_0@(.*)/)[0].join("/") rescue from if from
|
13
|
+
to = to.scan(/.*?_(\d+)_0@(.*)/)[0].join("/") rescue to if to
|
14
|
+
if subject.start_with?("Returned Mail:")
|
15
|
+
result = result + "<br>subject: " + subject
|
16
|
+
subject = subject.scan(/(Returned\sMail\:\s\w+)/)[0][0]
|
17
|
+
elsif subject.start_with?("Warning--")
|
18
|
+
result = result + "<br>subject: " + subject
|
19
|
+
subject = "Warning#Mailgates"
|
20
|
+
end
|
21
|
+
return {timestamp: timestamp.split.last, emailfile: emailfile, from: from, to: to,
|
22
|
+
subject: subject, result: result, mgham: mgham, mgtaglog: mgtaglog, charset: charset}
|
23
|
+
else
|
24
|
+
return {raw: line}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/mailgates.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mailgates/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mailgates"
|
8
|
+
spec.version = Mailgates::VERSION
|
9
|
+
spec.authors = ["jay16"]
|
10
|
+
spec.email = ["jay_li@intfocus.com"]
|
11
|
+
spec.summary = %q{Mailgates utils.}
|
12
|
+
spec.description = %q{Mailgates tools kit.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake", "~>10.4.2"
|
23
|
+
spec.add_development_dependency "rspec", "~>3.2.0"
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
require File.expand_path '../../lib/mailgates.rb', __FILE__
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
4
|
+
|
5
|
+
describe "mailgates log parser" do
|
6
|
+
it "an ok log line should be parsed into hash with 9 keys" do
|
7
|
+
log = "[2015/03/03 19:25:03] [19129-1061775740-qq.com_1425381890.5615237.eml] Mail.RR <1061775740_149_0@online-edm.com> -> <1061775740@qq.com> (集享卡会员帐号激活/1544)[OK][MGHAM--0][MGTAGLOG ][utf-8]"
|
8
|
+
parser = Mailgates::Log.parser(log)
|
9
|
+
|
10
|
+
expect(parser.keys.count).to eq(9)
|
11
|
+
expect(parser.keys.sort).to eq([:timestamp, :emailfile, :from, :to, :subject, :result, :mgham, :mgtaglog, :charset].sort)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "not a log line should be parsed into hash with 1 key" do
|
15
|
+
log = []
|
16
|
+
log.push "[2015/03/03 22:10:03] [9951-54F5C0B9.0008F593] Error job run/54F5C0B9.0008F593 (mqueue_open:Permission denied)."
|
17
|
+
log.push "[2015/03/03 22:10:04] [MASTER] Warning -- Mailer 9666 exited.(0)"
|
18
|
+
log.each do |line|
|
19
|
+
parser = Mailgates::Log.parser(line)
|
20
|
+
|
21
|
+
expect(parser.keys.count).to eq(1)
|
22
|
+
expect(parser.keys.sort).to eq([:raw])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/spec/spec_helper.rb
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mailgates
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- jay16
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-03-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.6'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.6'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 10.4.2
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 10.4.2
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 3.2.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.2.0
|
62
|
+
description: Mailgates tools kit.
|
63
|
+
email:
|
64
|
+
- jay_li@intfocus.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE.txt
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- lib/mailgates.rb
|
75
|
+
- lib/mailgates/log_parser.rb
|
76
|
+
- lib/mailgates/version.rb
|
77
|
+
- mailgates.gemspec
|
78
|
+
- spec/log_parser_spec.rb
|
79
|
+
- spec/spec_helper.rb
|
80
|
+
homepage: ''
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 1.8.23
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: Mailgates utils.
|
105
|
+
test_files:
|
106
|
+
- spec/log_parser_spec.rb
|
107
|
+
- spec/spec_helper.rb
|
108
|
+
has_rdoc:
|