mailhandler 1.0.13 → 1.0.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mailhandler/receiving/file_filter/base.rb +56 -0
- data/lib/mailhandler/receiving/file_filter/filter.rb +167 -0
- data/lib/mailhandler/receiving/folder.rb +7 -10
- data/lib/mailhandler/receiving/imap.rb +1 -10
- data/lib/mailhandler/version.rb +1 -1
- data/spec/data/email-uni1.txt +47 -0
- data/spec/data/email-uni2.txt +46 -0
- data/spec/data/email2.txt +1 -1
- data/spec/unit/mailhandler/receiving/folder_spec.rb +28 -2
- metadata +6 -3
- data/lib/mailhandler/receiving/filter.rb +0 -163
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ec9ad0acba66aa31321e63ed9f9acf9b95f57ea
|
4
|
+
data.tar.gz: 16279973b129e4a3f384e7cfdaa025603b6b3814
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04381e76cc9adc9b6bfa1e2d649957cf60a2fbd1f5b2da7fa08d50d51d2e6fe3beaa61d13de6a4dcde7719c24c5affe8519d4bc13e97364a94a0ecf5e812d7fe
|
7
|
+
data.tar.gz: e0c657384c7679083bbe7047738fb2fb810fe58e9562a3a7ed9fd3d764178d155ce905a82e2722520786af049dbfbfe4aab991ed0e9d7e9b0a764f7401764a0f
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
# Base filtering class, which is used for reading list of all files based on passed pattern.
|
4
|
+
# Patterns to be used can be checked here: http://ruby-doc.org/core-1.9.3/Dir.html
|
5
|
+
module Filter
|
6
|
+
|
7
|
+
class Base
|
8
|
+
|
9
|
+
def Base.sort(files)
|
10
|
+
|
11
|
+
swapped = true
|
12
|
+
j = 0
|
13
|
+
|
14
|
+
while swapped do
|
15
|
+
|
16
|
+
swapped = false
|
17
|
+
j+=1
|
18
|
+
|
19
|
+
(files.size - j).times do |i|
|
20
|
+
|
21
|
+
if File.new(files[i]).ctime < File.new(files[i + 1]).ctime
|
22
|
+
tmp = files[i]
|
23
|
+
files[i] = files[i + 1]
|
24
|
+
files[i + 1] = tmp
|
25
|
+
swapped = true
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
files
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
def get(pattern)
|
38
|
+
|
39
|
+
files = []
|
40
|
+
Dir.glob(pattern).each { |file| files << File.absolute_path(file) }
|
41
|
+
files
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
protected
|
46
|
+
|
47
|
+
def read_email(content)
|
48
|
+
|
49
|
+
Mail.read_from_string(content)
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
@@ -0,0 +1,167 @@
|
|
1
|
+
require_relative 'base.rb'
|
2
|
+
|
3
|
+
# Implementations of base filtering, which will allow further filtering the list of files based on email content.
|
4
|
+
module Filter
|
5
|
+
|
6
|
+
class ByFilename < Base
|
7
|
+
|
8
|
+
def get(pattern)
|
9
|
+
|
10
|
+
super(pattern)
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
class ContentBase < Base
|
17
|
+
|
18
|
+
def initialize(content)
|
19
|
+
|
20
|
+
@content = content.to_s
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def filter_files(files)
|
27
|
+
|
28
|
+
files.select do |file|
|
29
|
+
|
30
|
+
begin
|
31
|
+
|
32
|
+
file_match_filter?(file)
|
33
|
+
|
34
|
+
rescue
|
35
|
+
|
36
|
+
# return false if error occurred or content was not found
|
37
|
+
false
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
def file_match_filter?(file)
|
46
|
+
|
47
|
+
raise StandardError, 'Not implemented'
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
class BySubject < ContentBase
|
54
|
+
|
55
|
+
def initialize(content)
|
56
|
+
|
57
|
+
super(content)
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
def get(pattern)
|
62
|
+
|
63
|
+
files = super(pattern)
|
64
|
+
filter_files(files)
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def file_match_filter?(file)
|
71
|
+
|
72
|
+
read_email(File.read(file)).subject.include? @content
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
class ByContent < ContentBase
|
79
|
+
|
80
|
+
def initialize(content)
|
81
|
+
|
82
|
+
super(content)
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
def get(pattern)
|
87
|
+
|
88
|
+
files = super(pattern)
|
89
|
+
filter_files(files)
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
def file_match_filter?(file)
|
96
|
+
|
97
|
+
File.read(file).include? @content
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
class ByDate < ContentBase
|
104
|
+
|
105
|
+
def initialize(date)
|
106
|
+
|
107
|
+
@date = date
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
def get(pattern)
|
112
|
+
|
113
|
+
files = super(pattern)
|
114
|
+
filter_files(files)
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
private
|
119
|
+
|
120
|
+
def file_match_filter?(file)
|
121
|
+
|
122
|
+
file = File.new(file)
|
123
|
+
if file != nil
|
124
|
+
|
125
|
+
file.ctime > @date
|
126
|
+
|
127
|
+
else
|
128
|
+
|
129
|
+
false
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
module Email
|
138
|
+
|
139
|
+
class ByRecipient < ContentBase
|
140
|
+
|
141
|
+
def initialize(recipient)
|
142
|
+
|
143
|
+
@recipient = recipient
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
def get(pattern)
|
148
|
+
|
149
|
+
files = super(pattern)
|
150
|
+
filter_files(files)
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
private
|
155
|
+
|
156
|
+
def file_match_filter?(file)
|
157
|
+
|
158
|
+
email = read_email(File.read(file))
|
159
|
+
email[@recipient.keys.first].to_s.include? @recipient.values.first
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
@@ -1,8 +1,10 @@
|
|
1
|
-
require_relative 'base.rb'
|
2
|
-
require_relative 'filter'
|
3
1
|
require 'mail'
|
2
|
+
require_relative 'base.rb'
|
4
3
|
require_relative '../errors'
|
5
4
|
|
5
|
+
require_relative 'file_filter/base.rb'
|
6
|
+
require_relative 'file_filter/filter.rb'
|
7
|
+
|
6
8
|
module MailHandler
|
7
9
|
|
8
10
|
module Receiving
|
@@ -45,7 +47,7 @@ module MailHandler
|
|
45
47
|
# filter options which need to be done by searching files
|
46
48
|
FILE_SEARCH_CLASSES = {
|
47
49
|
|
48
|
-
:by_subject => Filter::
|
50
|
+
:by_subject => Filter::BySubject,
|
49
51
|
:by_content => Filter::ByContent,
|
50
52
|
:by_date => Filter::ByDate,
|
51
53
|
:by_recipient => Filter::Email::ByRecipient
|
@@ -59,12 +61,7 @@ module MailHandler
|
|
59
61
|
|
60
62
|
def read_found_emails(files, count)
|
61
63
|
|
62
|
-
files.first(count).map
|
63
|
-
|
64
|
-
email_content = File.read(file)
|
65
|
-
Mail.read_from_string(email_content)
|
66
|
-
|
67
|
-
end
|
64
|
+
files.first(count).map { |file| Mail.read_from_string(File.read(file)) }
|
68
65
|
|
69
66
|
end
|
70
67
|
|
@@ -103,7 +100,7 @@ module MailHandler
|
|
103
100
|
|
104
101
|
def delete_file(file)
|
105
102
|
|
106
|
-
FileUtils.rm_r "#{inbox_folder}/#{file}", :force =>
|
103
|
+
FileUtils.rm_r "#{inbox_folder}/#{file}", :force => false
|
107
104
|
|
108
105
|
end
|
109
106
|
|
@@ -91,16 +91,7 @@ module MailHandler
|
|
91
91
|
|
92
92
|
def find_emails(options)
|
93
93
|
|
94
|
-
|
95
|
-
|
96
|
-
result = Mail.find_and_delete(:what => :last, :count => search_options[:count], :order => :desc, :keys => imap_filter_keys(options))
|
97
|
-
|
98
|
-
else
|
99
|
-
|
100
|
-
result = Mail.find(:what => :last, :count => search_options[:count], :order => :desc, :keys => imap_filter_keys(options))
|
101
|
-
|
102
|
-
end
|
103
|
-
|
94
|
+
result = Mail.find(:what => :last, :count => search_options[:count], :order => :desc, :keys => imap_filter_keys(options), :delete_after_find => options[:archive])
|
104
95
|
(result.kind_of? Array)? result : [result]
|
105
96
|
|
106
97
|
end
|
data/lib/mailhandler/version.rb
CHANGED
@@ -0,0 +1,47 @@
|
|
1
|
+
Delivered-To: igor@example.com
|
2
|
+
Received: by 12.74.171.199 with SMTP id 1w7csp487013o2c;
|
3
|
+
Mon, 21 Dec 2015 01:45:03 -0800 (PST)
|
4
|
+
X-Received: by 11.14.225.211 with SMTP id k202mr13688721ywe.168.1450691103560;
|
5
|
+
Mon, 21 Dec 2015 01:45:03 -0800 (PST)
|
6
|
+
Received: from sc-exam.mtasv.net (sc-exam.itasv.net. [51.32.152.221])
|
7
|
+
by mx.google.com with ESMTPS id n124si20919044ywc.44.2015.22.22.01.45.03
|
8
|
+
for <igor@example.com>
|
9
|
+
(version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128);
|
10
|
+
Mon, 21 Dec 2015 01:45:03 -0800 (PST)
|
11
|
+
Received-SPF: pass (google.com: domain of unces@wb.example.com designates 11.1.1.1 as permitted sender) client-ip=11.1.1.1;
|
12
|
+
Authentication-Results: mx.google.com;
|
13
|
+
spf=pass (google.com: domain of ounces@wb.example.com designates 11.1.1.1 as permitted sender) smtp.mailfrom=ounces@wb.example.com;
|
14
|
+
dkim=pass header.i=@example.com;
|
15
|
+
dmarc=pass (p=NONE dis=NONE) header.from=example.com
|
16
|
+
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; s=jan2013.pm; d=example.com;
|
17
|
+
h=From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:To:Reply-To:Message-ID; i=igor@example.com;
|
18
|
+
bh=PzwfK1FvIpe5JXJSkPKh5z/fDTY=;
|
19
|
+
b=Y8QAdWtGwwC9QSXtVQ+QJzOt+dzOm+WrOCJ/dnGbD8eBKYuEBRxwo18FqmSIP7petsfqU3NIXK85
|
20
|
+
uF7yvyaBdMkafiKrR4du+TFTf+QBfsOoSrCIvKhCqnRgTEeL/niuYMbjNDrUNWcxq5VvUWKrtyjf
|
21
|
+
cvyZhxW2Cwdbd5nZ2NM=
|
22
|
+
DomainKey-Signature: a=rsa-sha1; c=nofws; q=dns; s=jan2013.pm; d=example.com;
|
23
|
+
b=S7CL7EMB1XKFCedi2NHfRSxWEnzBXnt6f48UxDcpGBWQGRj5b53isqmr5dnwAvP+q6HdQDc0rDgk
|
24
|
+
hXnckMTHE1p1MmeBSvETDB+FU4VXnA4CaAfeRTf+rUZlz1w5d/aWKqBSa9kPJQvwQrCypxqcPJql
|
25
|
+
7K0YKl5PtWP3D5gn/KU=;
|
26
|
+
Received: by sc-exam.mtasv.net id hev51u1jk5kd for <igor@example.com>; Mon, 21 Dec 2015 04:45:03 -0500 (envelope-from <ounces@wb.example.com>)
|
27
|
+
X-IADB-IP: 11.1.1.1
|
28
|
+
X-IADB-IP-REVERSE: 11.1.1.2
|
29
|
+
From: "John Smith" <igor@example.com>
|
30
|
+
Date: Mon, 21 Dec 2015 04:45:03 -0500
|
31
|
+
Subject: =?UTF-8?Q?=D0=95-=D0=BC=D0=B0=D0=B8=D0=BB=20=D0=BF=D1=80?=
|
32
|
+
=?UTF-8?Q?=D0=B8=D0=BC=D0=B5=D1=80=2069578385=20?=
|
33
|
+
MIME-Version: 1.0
|
34
|
+
Content-Type: text/html; charset=UTF-8
|
35
|
+
Content-Transfer-Encoding: quoted-printable
|
36
|
+
X-Mailer: aspNetEmail ver 4.0.0.38
|
37
|
+
X-PM-RCPT: |bTB8MjA3NDd8MTYzODZ8aWJhbG9zaC50ZXN0aW5nQGdtYWlsLmNv11==|
|
38
|
+
X-PM-Message-Id: 1fb4ccd8-fe62-4424-a0aa-a30b281b9631
|
39
|
+
To: igor@example.com
|
40
|
+
Message-ID: <5677ca1e87ee0_de33fee2381c080708d8@Johns-MacBook-Pro.local.mail>
|
41
|
+
|
42
|
+
<=21DOCTYPE html>=0A<html>=0A=0A<body>=0A<h1>My First Heading</h1>=0A<p>M=
|
43
|
+
y first paragraph=2E</p>=0A<p>My first paragraph S=C3=BC=C3=9Fe =2E</p>=0A=
|
44
|
+
=0A<img src=3D=22http://ea=2Epstmrk=2Eit/open/MjA3NDdfMTYzODZfb3ZlcjUwXzh=
|
45
|
+
mYjRjY2Q4LWZlNjItNDQyNC1hMGFhLWEzMGIyODFiOTYzMF9pYmFsb3NoLnRlc3RpbmdAZ21h=
|
46
|
+
aWwuY29t=22 width=3D=221=22 height=3D=221=22 border=3D=220=22 /></body>=0A=
|
47
|
+
</html>
|
@@ -0,0 +1,46 @@
|
|
1
|
+
Delivered-To: igor@example.com
|
2
|
+
Received: by 12.74.171.199 with SMTP id 1w7csp487013o2c;
|
3
|
+
Mon, 21 Dec 2015 01:45:03 -0800 (PST)
|
4
|
+
X-Received: by 11.14.225.211 with SMTP id k202mr13688721ywe.168.1450691103560;
|
5
|
+
Mon, 21 Dec 2015 01:45:03 -0800 (PST)
|
6
|
+
Received: from sc-exam.mtasv.net (sc-exam.itasv.net. [51.32.152.221])
|
7
|
+
by mx.google.com with ESMTPS id n124si20919044ywc.44.2015.22.22.01.45.03
|
8
|
+
for <igor@example.com>
|
9
|
+
(version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128);
|
10
|
+
Mon, 21 Dec 2015 01:45:03 -0800 (PST)
|
11
|
+
Received-SPF: pass (google.com: domain of unces@wb.example.com designates 11.1.1.1 as permitted sender) client-ip=11.1.1.1;
|
12
|
+
Authentication-Results: mx.google.com;
|
13
|
+
spf=pass (google.com: domain of ounces@wb.example.com designates 11.1.1.1 as permitted sender) smtp.mailfrom=ounces@wb.example.com;
|
14
|
+
dkim=pass header.i=@example.com;
|
15
|
+
dmarc=pass (p=NONE dis=NONE) header.from=example.com
|
16
|
+
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; s=jan2013.pm; d=example.com;
|
17
|
+
h=From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:To:Reply-To:Message-ID; i=igor@example.com;
|
18
|
+
bh=PzwfK1FvIpe5JXJSkPKh5z/fDTY=;
|
19
|
+
b=Y8QAdWtGwwC9QSXtVQ+QJzOt+dzOm+WrOCJ/dnGbD8eBKYuEBRxwo18FqmSIP7petsfqU3NIXK85
|
20
|
+
uF7yvyaBdMkafiKrR4du+TFTf+QBfsOoSrCIvKhCqnRgTEeL/niuYMbjNDrUNWcxq5VvUWKrtyjf
|
21
|
+
cvyZhxW2Cwdbd5nZ2NM=
|
22
|
+
DomainKey-Signature: a=rsa-sha1; c=nofws; q=dns; s=jan2013.pm; d=example.com;
|
23
|
+
b=S7CL7EMB1XKFCedi2NHfRSxWEnzBXnt6f48UxDcpGBWQGRj5b53isqmr5dnwAvP+q6HdQDc0rDgk
|
24
|
+
hXnckMTHE1p1MmeBSvETDB+FU4VXnA4CaAfeRTf+rUZlz1w5d/aWKqBSa9kPJQvwQrCypxqcPJql
|
25
|
+
7K0YKl5PtWP3D5gn/KU=;
|
26
|
+
Received: by sc-exam.mtasv.net id hev51u1jk5kd for <igor@example.com>; Mon, 21 Dec 2015 04:45:03 -0500 (envelope-from <ounces@wb.example.com>)
|
27
|
+
X-IADB-IP: 11.1.1.1
|
28
|
+
X-IADB-IP-REVERSE: 11.1.1.2
|
29
|
+
From: "John Smith" <igor@example.com>
|
30
|
+
Date: Mon, 21 Dec 2015 04:45:03 -0500
|
31
|
+
Subject: =?UTF-8?Q?E-Mail=20beispiels=20m=C3=B6glich=201=20?=
|
32
|
+
MIME-Version: 1.0
|
33
|
+
Content-Type: text/html; charset=UTF-8
|
34
|
+
Content-Transfer-Encoding: quoted-printable
|
35
|
+
X-Mailer: aspNetEmail ver 4.0.0.38
|
36
|
+
X-PM-RCPT: |bTB8MjA3NDd8MTYzODZ8aWJhbG9zaC50ZXN0aW5nQGdtYWlsLmNv11==|
|
37
|
+
X-PM-Message-Id: 1fb4ccd8-fe62-4424-a0aa-a30b281b9631
|
38
|
+
To: igor@example.com
|
39
|
+
Message-ID: <5677ca1e87ee0_de33fee2381c080708d8@Johns-MacBook-Pro.local.mail>
|
40
|
+
|
41
|
+
<=21DOCTYPE html>=0A<html>=0A=0A<body>=0A<h1>My First Heading</h1>=0A<p>M=
|
42
|
+
y first paragraph=2E</p>=0A<p>My first paragraph S=C3=BC=C3=9Fe =2E</p>=0A=
|
43
|
+
=0A<img src=3D=22http://ea=2Epstmrk=2Eit/open/MjA3NDdfMTYzODZfb3ZlcjUwXzh=
|
44
|
+
mYjRjY2Q4LWZlNjItNDQyNC1hMGFhLWEzMGIyODFiOTYzMF9pYmFsb3NoLnRlc3RpbmdAZ21h=
|
45
|
+
aWwuY29t=22 width=3D=221=22 height=3D=221=22 border=3D=220=22 /></body>=0A=
|
46
|
+
</html>
|
data/spec/data/email2.txt
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe MailHandler::Receiving::FolderChecker do
|
@@ -131,7 +132,7 @@ describe MailHandler::Receiving::FolderChecker do
|
|
131
132
|
|
132
133
|
it 'by recipient' do
|
133
134
|
|
134
|
-
checker.find({:by_recipient => { to: 'igor@example.com'} })
|
135
|
+
checker.find({:by_recipient => { to: 'igor+nonexisting@example.com'} })
|
135
136
|
expect(checker.found_emails).to be_empty
|
136
137
|
|
137
138
|
end
|
@@ -161,6 +162,13 @@ describe MailHandler::Receiving::FolderChecker do
|
|
161
162
|
|
162
163
|
end
|
163
164
|
|
165
|
+
it 'by content' do
|
166
|
+
|
167
|
+
checker.find({:by_content => '1878271'})
|
168
|
+
expect(checker.found_emails.size).to be 1
|
169
|
+
|
170
|
+
end
|
171
|
+
|
164
172
|
it 'by subject - multiple' do
|
165
173
|
|
166
174
|
checker.find({:by_subject => 'test'})
|
@@ -183,7 +191,7 @@ describe MailHandler::Receiving::FolderChecker do
|
|
183
191
|
it 'by date' do
|
184
192
|
|
185
193
|
checker.find({:by_date => Time.new(2015,10,12,13,30,0, "+02:00")})
|
186
|
-
expect(checker.found_emails.size).to be
|
194
|
+
expect(checker.found_emails.size).to be 4
|
187
195
|
|
188
196
|
end
|
189
197
|
|
@@ -197,6 +205,24 @@ describe MailHandler::Receiving::FolderChecker do
|
|
197
205
|
|
198
206
|
end
|
199
207
|
|
208
|
+
context 'unicode' do
|
209
|
+
|
210
|
+
it 'by subject - cyrillic' do
|
211
|
+
|
212
|
+
checker.find({:by_subject => 'Е-маил пример'})
|
213
|
+
expect(checker.found_emails.size).to be 1
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
it 'by subject - german' do
|
218
|
+
|
219
|
+
checker.find({:by_subject => 'möglich'})
|
220
|
+
expect(checker.found_emails.size).to be 1
|
221
|
+
|
222
|
+
end
|
223
|
+
|
224
|
+
end
|
225
|
+
|
200
226
|
context 'archiving emails' do
|
201
227
|
|
202
228
|
before(:each) {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailhandler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Balos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mail
|
@@ -62,7 +62,8 @@ files:
|
|
62
62
|
- lib/mailhandler/errors.rb
|
63
63
|
- lib/mailhandler/receiver.rb
|
64
64
|
- lib/mailhandler/receiving/base.rb
|
65
|
-
- lib/mailhandler/receiving/
|
65
|
+
- lib/mailhandler/receiving/file_filter/base.rb
|
66
|
+
- lib/mailhandler/receiving/file_filter/filter.rb
|
66
67
|
- lib/mailhandler/receiving/folder.rb
|
67
68
|
- lib/mailhandler/receiving/imap.rb
|
68
69
|
- lib/mailhandler/receiving/notification/console.rb
|
@@ -78,6 +79,8 @@ files:
|
|
78
79
|
- lib/mailhandler/version.rb
|
79
80
|
- mailhandler.gemspec
|
80
81
|
- readme.md
|
82
|
+
- spec/data/email-uni1.txt
|
83
|
+
- spec/data/email-uni2.txt
|
81
84
|
- spec/data/email1.txt
|
82
85
|
- spec/data/email2.txt
|
83
86
|
- spec/spec_helper.rb
|
@@ -1,163 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
|
3
|
-
module Filter
|
4
|
-
|
5
|
-
class Base
|
6
|
-
|
7
|
-
def Base.sort(files)
|
8
|
-
|
9
|
-
swapped = true
|
10
|
-
j = 0
|
11
|
-
|
12
|
-
while swapped do
|
13
|
-
|
14
|
-
swapped = false
|
15
|
-
j+=1
|
16
|
-
|
17
|
-
(files.size - j).times do |i|
|
18
|
-
|
19
|
-
if File.new(files[i]).ctime < File.new(files[i + 1]).ctime
|
20
|
-
tmp = files[i]
|
21
|
-
files[i] = files[i + 1]
|
22
|
-
files[i + 1] = tmp
|
23
|
-
swapped = true
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
files
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
def get(pattern)
|
36
|
-
|
37
|
-
files = []
|
38
|
-
Dir.glob(pattern).each { |file| files << File.absolute_path(file) }
|
39
|
-
files
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
class ByFilename < Base
|
46
|
-
|
47
|
-
def get(pattern)
|
48
|
-
|
49
|
-
super(pattern)
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
class ByContent < Base
|
56
|
-
|
57
|
-
def initialize(content)
|
58
|
-
|
59
|
-
@content = content.to_s
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
def get(pattern)
|
64
|
-
|
65
|
-
files = super(pattern)
|
66
|
-
|
67
|
-
matched_files = []
|
68
|
-
|
69
|
-
files.each do |file|
|
70
|
-
|
71
|
-
begin
|
72
|
-
|
73
|
-
content = File.read(file)
|
74
|
-
matched_files << file if content.include? @content
|
75
|
-
|
76
|
-
rescue
|
77
|
-
|
78
|
-
# skip file reading if file is not there anymore
|
79
|
-
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
matched_files
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
class ByDate < Base
|
91
|
-
|
92
|
-
def initialize(date)
|
93
|
-
|
94
|
-
@date = date
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
def get(pattern)
|
99
|
-
|
100
|
-
files = super(pattern)
|
101
|
-
files.select { |filename|
|
102
|
-
|
103
|
-
file = nil
|
104
|
-
begin
|
105
|
-
|
106
|
-
file = File.new(filename)
|
107
|
-
|
108
|
-
rescue
|
109
|
-
|
110
|
-
# skip file reading if file is not there anymore
|
111
|
-
|
112
|
-
end
|
113
|
-
|
114
|
-
file.ctime > @date if (file != nil)
|
115
|
-
|
116
|
-
}
|
117
|
-
|
118
|
-
end
|
119
|
-
|
120
|
-
end
|
121
|
-
|
122
|
-
module Email
|
123
|
-
|
124
|
-
class ByRecipient < Base
|
125
|
-
|
126
|
-
def initialize(recipient)
|
127
|
-
|
128
|
-
@recipient = recipient
|
129
|
-
|
130
|
-
end
|
131
|
-
|
132
|
-
def get(pattern)
|
133
|
-
|
134
|
-
files = super(pattern)
|
135
|
-
|
136
|
-
matched_files = []
|
137
|
-
|
138
|
-
files.each do |file|
|
139
|
-
|
140
|
-
begin
|
141
|
-
|
142
|
-
content = File.read(file)
|
143
|
-
|
144
|
-
email = Mail.read_from_string(content)
|
145
|
-
matched_files << file if email[@recipient.keys.first].to_s.include? @recipient.values.first
|
146
|
-
|
147
|
-
rescue
|
148
|
-
|
149
|
-
# skip file reading if file is not there anymore
|
150
|
-
|
151
|
-
end
|
152
|
-
|
153
|
-
end
|
154
|
-
|
155
|
-
matched_files
|
156
|
-
|
157
|
-
end
|
158
|
-
|
159
|
-
end
|
160
|
-
|
161
|
-
end
|
162
|
-
|
163
|
-
end
|