imap-filter 0.0.2

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: bd4508c320978c8e671d778d278acb636f4e53a4
4
+ data.tar.gz: 2d7b0f4d4002bb82aaaf369e8d4d79b4f7ad6dea
5
+ SHA512:
6
+ metadata.gz: fdd58ff83f6b8ff66e942bb44f42eb11ebd68d508540fdc24ab25e3bd17658424edfe589cce2a55cb5978e9a43610512617e359f9f6d4858a067f827655f2e14
7
+ data.tar.gz: 7f7acc334eb004be3eb61c71dd1d9a7c4c06db4816246a8e9097fc18e3ffda81c0fc93d0489e7da8293834e6885299d1709796ca59ebd216a7ee7333030bcd52
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
data/.semver ADDED
@@ -0,0 +1,5 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 0
4
+ :patch: 2
5
+ :special: ''
data/Gemfile ADDED
@@ -0,0 +1,24 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "semver", "~> 1"
4
+ gem "awesome_print", "~> 1"
5
+ gem "text-table", "~> 1"
6
+ gem "thor", "~> 0"
7
+ gem "colorize", "~> 0"
8
+
9
+ # Add dependencies to develop your gem here.
10
+ # Include everything needed to run rake, tests, features, etc.
11
+ group :development do
12
+ gem "rspec", "~> 2"
13
+ gem "yard", "~> 0"
14
+ gem "rdoc", "~> 3"
15
+ gem "bundler", "~> 1"
16
+ gem "juwelier", "~> 2"
17
+ gem "simplecov", "~> 0"
18
+ gem 'pry', '~> 0'
19
+ gem 'pry-byebug', '~> 3'
20
+ gem 'pry-doc', '~> 0'
21
+ gem 'pry-remote', '~> 0'
22
+ gem 'pry-rescue', '~> 1'
23
+ gem 'pry-stack_explorer', '~> 0'
24
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,122 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ addressable (2.4.0)
5
+ awesome_print (1.7.0)
6
+ binding_of_caller (0.7.2)
7
+ debug_inspector (>= 0.0.1)
8
+ builder (3.2.2)
9
+ byebug (9.0.5)
10
+ coderay (1.1.1)
11
+ colorize (0.8.1)
12
+ debug_inspector (0.0.2)
13
+ descendants_tracker (0.0.4)
14
+ thread_safe (~> 0.3, >= 0.3.1)
15
+ diff-lcs (1.1.3)
16
+ docile (1.1.5)
17
+ faraday (0.9.2)
18
+ multipart-post (>= 1.2, < 3)
19
+ git (1.3.0)
20
+ github_api (0.14.5)
21
+ addressable (~> 2.4.0)
22
+ descendants_tracker (~> 0.0.4)
23
+ faraday (~> 0.8, < 0.10)
24
+ hashie (>= 3.4)
25
+ oauth2 (~> 1.0)
26
+ hashie (3.4.6)
27
+ highline (1.7.8)
28
+ interception (0.5)
29
+ json (1.8.3)
30
+ juwelier (2.1.2)
31
+ builder
32
+ bundler (>= 1.0)
33
+ git (>= 1.2.5)
34
+ github_api
35
+ highline (>= 1.6.15)
36
+ nokogiri (>= 1.5.10)
37
+ rake
38
+ rdoc
39
+ semver
40
+ jwt (1.5.6)
41
+ method_source (0.8.2)
42
+ mini_portile2 (2.1.0)
43
+ multi_json (1.12.1)
44
+ multi_xml (0.5.5)
45
+ multipart-post (2.0.0)
46
+ nokogiri (1.6.8)
47
+ mini_portile2 (~> 2.1.0)
48
+ pkg-config (~> 1.1.7)
49
+ oauth2 (1.2.0)
50
+ faraday (>= 0.8, < 0.10)
51
+ jwt (~> 1.0)
52
+ multi_json (~> 1.3)
53
+ multi_xml (~> 0.5)
54
+ rack (>= 1.2, < 3)
55
+ pkg-config (1.1.7)
56
+ pry (0.10.4)
57
+ coderay (~> 1.1.0)
58
+ method_source (~> 0.8.1)
59
+ slop (~> 3.4)
60
+ pry-byebug (3.4.0)
61
+ byebug (~> 9.0)
62
+ pry (~> 0.10)
63
+ pry-doc (0.9.0)
64
+ pry (~> 0.9)
65
+ yard (~> 0.8)
66
+ pry-remote (0.1.8)
67
+ pry (~> 0.9)
68
+ slop (~> 3.0)
69
+ pry-rescue (1.4.4)
70
+ interception (>= 0.5)
71
+ pry
72
+ pry-stack_explorer (0.4.9.2)
73
+ binding_of_caller (>= 0.7)
74
+ pry (>= 0.9.11)
75
+ rack (2.0.1)
76
+ rake (11.3.0)
77
+ rdoc (3.12.2)
78
+ json (~> 1.4)
79
+ rspec (2.8.0)
80
+ rspec-core (~> 2.8.0)
81
+ rspec-expectations (~> 2.8.0)
82
+ rspec-mocks (~> 2.8.0)
83
+ rspec-core (2.8.0)
84
+ rspec-expectations (2.8.0)
85
+ diff-lcs (~> 1.1.2)
86
+ rspec-mocks (2.8.0)
87
+ semver (1.0.1)
88
+ simplecov (0.12.0)
89
+ docile (~> 1.1.0)
90
+ json (>= 1.8, < 3)
91
+ simplecov-html (~> 0.10.0)
92
+ simplecov-html (0.10.0)
93
+ slop (3.6.0)
94
+ text-table (1.2.4)
95
+ thor (0.19.1)
96
+ thread_safe (0.3.5)
97
+ yard (0.9.5)
98
+
99
+ PLATFORMS
100
+ ruby
101
+
102
+ DEPENDENCIES
103
+ awesome_print (~> 1)
104
+ bundler (~> 1)
105
+ colorize (~> 0)
106
+ juwelier (~> 2)
107
+ pry (~> 0)
108
+ pry-byebug (~> 3)
109
+ pry-doc (~> 0)
110
+ pry-remote (~> 0)
111
+ pry-rescue (~> 1)
112
+ pry-stack_explorer (~> 0)
113
+ rdoc (~> 3)
114
+ rspec (~> 2)
115
+ semver (~> 1)
116
+ simplecov (~> 0)
117
+ text-table (~> 1)
118
+ thor (~> 0)
119
+ yard (~> 0)
120
+
121
+ BUNDLED WITH
122
+ 1.12.5
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2016 Fred Mitchell
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.org ADDED
@@ -0,0 +1,321 @@
1
+ * imap-filter
2
+ imap-filter is a Ruby implementation of an IMAP filtering application.
3
+ it can handle multiple IMAP accounts, and create IMAP folders automatically
4
+ where none exists.
5
+
6
+ The imap-filter DSL makes it easy to filter. You can also do "dry-runs"
7
+ to make sure what happens is what is expected.
8
+
9
+ ** Installation
10
+ This is a Ruby CLI application. If you are running Linux, most likely
11
+ you have Ruby already installed. If you are running MacOSX or Windows,
12
+ you may have to Install Ruby. We support Ruby 2.2 and later.
13
+
14
+ Simply, do:
15
+
16
+ #+begin_src bash
17
+ gem install imap-filter
18
+ #+end_src
19
+
20
+ or if in a Gemfile:
21
+
22
+ #+begin_src ruby
23
+ gem 'imap-filter'
24
+ #+end_src
25
+
26
+ By default,
27
+
28
+ ** Documentation
29
+ I think that to make this documenation truly "complete", I would wind up writing
30
+ more lines than in the imap-filter code itself!!! I will attempt to be as concise
31
+ as possible, and besides me writing a thick manual, no one wants to read such either.
32
+
33
+ *** Tutorial and Examples
34
+ Let's go though the steps with just one Email account, then we'll add a second
35
+ account. Then you can look at the sample [[examples/default.imap][default.imap]]
36
+ file, and go beyond.
37
+
38
+ This tutorial assumes you have both a Gmail and a Yahoo account. Please feel free
39
+ to substitute with your own accounts.
40
+
41
+ First, install imap-filter as described in [[#installation][Installation]].
42
+
43
+ Next, create a default.imap file with Emacs, vi, nano, or whatever suits your fancy. Place
44
+ in it the following:
45
+
46
+ #+begin_src ruby
47
+ account :gmail do
48
+ login 'youruserid@gmail.com', 'yourpassword'
49
+ serv "imap.gmail.com"
50
+ auth :plain
51
+ end
52
+ #+end_src
53
+
54
+ And obviously adjust your userid and password to your own. Now let's try to run
55
+ your new script:
56
+
57
+ #+begin_src basn
58
+ imap-filter filter default.imap -t
59
+ #+end_src
60
+
61
+ Note that the '-t' is the test flag. It will simply test the connections
62
+ to your accounts and nothing more.
63
+
64
+ And nothing happens. Why not? Very simple. The directive of this file
65
+ must be activated. Edit your default.imap and add "activate :all" to the very
66
+ end:
67
+
68
+ #+begin_src ruby
69
+ account :gmail do
70
+ login 'youruserid@gmail.com', 'yourpassword'
71
+ serv "imap.gmail.com"
72
+ auth :plain
73
+ end
74
+
75
+ activate :all
76
+ #+end_src
77
+
78
+ Now run the command again:
79
+ #+begin_src basn
80
+ imap-filter filter default.imap -t
81
+ #+end_src
82
+
83
+ Ah, something happens now! If all goes well, you should see the following:
84
+
85
+ #+begin_src bash
86
+ ====== Test Accounts
87
+ gmail...SUCCESS, delim /
88
+ #+end_src
89
+
90
+ The "delim" is the mailbox delimiter for your paricular vendor. Most places
91
+ use the forward slash (/). Some might use a period (.). This lets you know what
92
+ to use, so make particular note of that.
93
+
94
+ If something is wrong with your settings, you might see an error message similar to:
95
+
96
+ #+begin_src bash
97
+ ====== Test Accounts
98
+ gmail...FAILED: Lookup failed xxxxxxxxxxxxx
99
+ #+end_src
100
+
101
+ And so check your login line to make sure your userID and password is correct.
102
+ For some vendors, the userID is your complete email address. For others, it might
103
+ just be what procedes the '@'. Please check with your vendor to see what it is for
104
+ you. Usually, your vendor will have IMAP Client instructions on their website.
105
+
106
+ We use ssl connections by default, and it would be extremely insecure not to. But
107
+ you can turn off the ssl if need be. You can also change your port settings
108
+ accordingly, if your vendor uses a non-standard port. For example,
109
+
110
+ #+begin_src ruby
111
+ account :gmail do
112
+ login 'youruserid@gmail.com', 'yourpassword'
113
+ serv "imap.gmail.com"
114
+ auth :plain
115
+ ssl true
116
+ port 993
117
+ end
118
+
119
+ activate :all
120
+ #+end_src
121
+
122
+ You may set ssl to "false" or make the port "2001". You have full
123
+ control over the settings. auth could be :login or :plain, so try
124
+ :login if :plain doesn't work.
125
+
126
+ There are more extensive authenication methods that IMAP can use, but
127
+ we do not support them at this time. If you have need for that support,
128
+ please let me know!!!!!
129
+
130
+ Now, let's assume you have your settings working. Now what? There are no
131
+ filters specified, which is the entire point of this program!!! So let's
132
+ add one:
133
+
134
+ #+begin_src ruby
135
+ account :gmail do
136
+ login 'youruserid@gmail.com', 'yourpassword'
137
+ serv "imap.gmail.com"
138
+ auth :plain
139
+ end
140
+
141
+ filter :github, 'gmail:INBOX' do
142
+ search do
143
+ from 'github.com'
144
+ unseen
145
+ end
146
+
147
+ cp 'gmail:test/Github'
148
+ end
149
+
150
+ activate :all
151
+ #+end_src
152
+
153
+ Note that the "actvate :all" is always the last entry. The filter
154
+ directive is fairly sophisticated, supporing most of what is possible
155
+ with IMAP search. We will document this more throughly at a later date.
156
+
157
+ In this filter example, we are receiving email notifications from github
158
+ which is cluttering up the Inbox. This filter will copy the "unseen", or
159
+ unread ones to the "test/Github" mailbox.
160
+
161
+ Notice in the string, we also specify the target account label. This is
162
+ required, and will allow you to specify alternate accounts very easily.
163
+
164
+ The mailbox will automatically be created if it does not exist yet.
165
+
166
+ So now, let's run it with the following commands. First, we wish to do a
167
+ sanity check, so we will do a dry run:
168
+
169
+ #+begin_src bash
170
+ imap-filter filter default.imap -u -v1
171
+ #+end_src
172
+
173
+ The "-u" is the alias for "--dryrun" The "-v1" is the verbosity switch. While
174
+ doing your setups and debugging your scripts, you will want to use "-v1" or even
175
+ "-v2" verbosity settings.
176
+
177
+ If you actually have a match for the search critieria, you may see a list of messages
178
+ that matched the search scroll by. In my test case:
179
+
180
+ #+begin_src bash
181
+ ...
182
+ ##Subject: Re: [jekyll/jekyll] jekyll serve can't work (#5216)
183
+ ##Subject: [jruby/jruby] Fix Socket.tcp connect_timeout option (#4061)
184
+ ##Subject: Re: [ansible/ansible-modules-core] Add state=empty into file module (#902)
185
+ ##Subject: [ansible/ansible] Publish modules to Galaxy? (#17027)
186
+ ##Subject: [ansible/ansible-modules-core] Add support for password aging on Solaris (#4372)
187
+ ##Subject: Re: [jruby/jruby] Fix Socket.tcp connect_timeout option (#4061)
188
+ ##Subject: Re: [tmux/tmux] Keeps getting "lost server" in tmux 2.1 and 2.2. Installed using Homebrew (#498)
189
+ ##Subject: [jekyll/jekyll] Add link to Staticman (#5224)
190
+ ##Subject: Re: [ansible/ansible] Ansible facts override special variables (#16935)
191
+ ##Subject: Re: [elixir-lang/elixir] Introduce List.pop_at/3 (#5118)
192
+ ...
193
+ #+end_src
194
+
195
+ Which are all unread or "unseen" as per our specificaions. Now no modifications
196
+ were peformed due to the "-u" dry run switch.
197
+
198
+ Now that we are feeling a bit more confident, let's run the same
199
+ command without the "-u" setting:
200
+
201
+ #+begin_src bash
202
+ imap-filter filter default.imap -v1
203
+ #+end_src
204
+
205
+ And now you will find that the filter actually executed what we wanted. A new
206
+ test/Gitub mailbox was created, and all the matching messages are now copied there.
207
+ Neat, huh?
208
+
209
+ Well, that's it for the tutorial. Please have a look at the [[examples/default.imap][example]].
210
+
211
+ There's a shorthand for the filters that may interest you for the
212
+ majority of your cases. For example:
213
+
214
+ #+begin_src ruby
215
+ filter :slashdot, 'gmx:INBOX', from: 'slashdot' do
216
+ mark :seen
217
+ cp 'google:INBOX'
218
+ mv 'gmx:Slashdot'
219
+ end
220
+ #+end_src
221
+
222
+ Uses the short-hand of "from: 'slashdot'" when all you need
223
+ to do is search a single field, like in this case, the From
224
+ field.
225
+
226
+ Others are obvios: to:, cc:, subject: will all work here.
227
+
228
+ *** Environment variables
229
+ | Variable | Description |
230
+ |-----------------+-------------------------------------------------------------------|
231
+ | IMAPF_IMAP_FILE | pathname to the default .imap file. The default is ./default.imap |
232
+
233
+ *** Accessing your Gmail
234
+ Google may automatically block this application by default.
235
+ Please visit the follow page to understand how to allow
236
+ imap-filter to access your Gmail account.
237
+
238
+ https://support.google.com/accounts/answer/6010255
239
+
240
+ *** Automatic blocks might happen while you are testing your Email accounts
241
+ Depending on the vendor, while you are setting up your scripts, you will
242
+ be doing many tests. Some vendors like Yahoo might block the app if it sees
243
+ what it consideres to be "too much" activity. If you see this happen, wait about
244
+ 30 minutes before trying again. Should work in most cases.
245
+
246
+ *** DSL
247
+ #+begin_src Ruby
248
+ account :redbird do
249
+ login "you@redbird.org", "password"
250
+ serv "imap.redbird.org"
251
+ ssl false
252
+ port 993
253
+ end
254
+
255
+ account :yahoo do
256
+ login "you@yahoo.com", "password"
257
+ serv "imap.yahoo.com"
258
+ end
259
+
260
+ account :google do
261
+ login "you@google.com", "password"
262
+ serv "imap.google.com"
263
+ end
264
+
265
+ filter :workmail, redbird.inbox, from: 'sally' do
266
+ cp yahoo.girlfriend
267
+ mv google.inbox
268
+ end
269
+
270
+ filter :maillist, google.inbox, from: 'github' do
271
+ mv google.groups.github
272
+ end
273
+
274
+ #+end_src
275
+
276
+ *** Reference Documents
277
+ https://tools.ietf.org/html/rfc3501
278
+ https://www.ietf.org/rfc/rfc2822.txt
279
+
280
+ ** Release Notes and Known Issues
281
+ *** Release Notes
282
+ | Version | Breif | Description |
283
+ |---------+-----------------+-------------|
284
+ | v0.0.2 | Initial Release | |
285
+ *** Known Issues
286
+ | Date | Description |
287
+ |------------+----------------------------------------------------------------|
288
+ | 2016-09-25 | Remote copy / moves of HTML-based email does not work cleanly. |
289
+ | | |
290
+
291
+ ** Contributing to imap-filter
292
+
293
+ - Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet. |
294
+ - Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it. |
295
+ - Fork the project. |
296
+ - Start a feature/bugfix branch. |
297
+ - Commit and push until you are happy with your contribution. |
298
+ - Make sure to add tests for it. This is important so I don't break it in a future version unintentionally. |
299
+ - Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it. |
300
+
301
+ ** Copyright
302
+
303
+ Copyright (c) 2016 Fred Mitchell. See LICENSE.txt for
304
+ further details.
305
+
306
+ ** Scratchpad
307
+ This section is my personal scratchpad. Should be of
308
+ no revelance to anyone else. Please ignore what's in
309
+ this section.
310
+
311
+ :Login:
312
+ imap = Net::IMAP.new('imap.gmail.com', ssl: true)
313
+ imap.authenticate('PLAIN', ENV['GOOGLE_EMAIL'], ENV['GOOGLE_PASS'])
314
+ imap.select('Shelby')
315
+ seq = imap.search(['ALL'])
316
+ :END:
317
+
318
+ :FETCH:
319
+ acc.imap.fetch(1..2, 'BODY[TEXT]') -- the entire text, flags as well.
320
+ acc.imap.fetch(1..2, 'BODY[HEADER.FIELDS (SUBJECT)]')
321
+ :END: