actionmailbox-imap 0.1.2 → 0.2.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.
- checksums.yaml +4 -4
- data/README.md +11 -10
- data/config/actionmailbox_imap.yaml +6 -0
- data/lib/actionmailbox/imap.rb +0 -21
- data/lib/actionmailbox/imap/version.rb +1 -1
- data/lib/generators/imap/install_generator.rb +6 -4
- data/lib/generators/imap/templates/config.yml +6 -14
- data/lib/tasks/actionmailbox/ingress.rake +12 -26
- metadata +6 -8
- data/lib/actionmailbox/imap/adapters/net_imap.rb +0 -50
- data/lib/actionmailbox/imap/mailbox.rb +0 -21
- data/lib/actionmailbox/imap/message.rb +0 -32
- data/lib/actionmailbox/imap/messages.rb +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 376f10979ea6f2c65fccb83629829919116f6022940af536622fb4873d1745d2
|
4
|
+
data.tar.gz: 12b8fa355b3dab2f0a1f5d3aafc6f1dbf2ebf9cdf653e85dc74e8925c97e7a94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b5e9f33726a4607eaf3b2eb848004b8e9f237900a952e3240bebb5f5ecedfb941b3e0ae9a57e67b510e2d9fd25ccb0deaeece0c87963fe415f6202dcfccd04a
|
7
|
+
data.tar.gz: c4d1d058b1a1277e2c35d32d33fe1ada479f8e4bd4887bb97f62581c3049802f744543f0e3a58ff647f62ac40ee9f8209d3c4912190d70f6814a8d34f67993f8
|
data/README.md
CHANGED
@@ -1,19 +1,18 @@
|
|
1
1
|
# ActionMailbox::IMAP
|
2
|
-
[](https://circleci.com/gh/kimmelsg/actionmailbox-imap)
|
3
|
-
[](https://rubygems.org/gems/actionmailbox-imap)
|
2
|
+
[](https://circleci.com/gh/kimmelsg/actionmailbox-imap)
|
3
|
+
[](https://rubygems.org/gems/actionmailbox-imap)
|
4
4
|
[](https://github.com/testdouble/standard)
|
5
5
|
|
6
6
|
A IMAP relay for ActionMailbox.
|
7
7
|
|
8
|
-
This is a very simple gem that provides a rake task
|
8
|
+
This is a very simple gem that provides a rake task attempt to relay messsages to ActionMailbox from the [ActionMailbox::IMAP Client](https://github.com/kimmelsg/actionmailbox-imap/blob/master/CLIENT.md).
|
9
9
|
|
10
|
-
If
|
11
|
-
|
12
|
-
If the rake task fails to relay a message to ActionMailbox then it will ignore it and move on to the next message leaving the message on the IMAP server.
|
10
|
+
If a message is successuflly relayed to ActionMailbox, then the message will be marked deleted.
|
11
|
+
If a message is not successfully relayed to ActionMailbox, then the message will be marked Unread in order to be processed again later.
|
13
12
|
|
14
13
|
### Why it was created
|
15
14
|
|
16
|
-
It seems that there is no plans to create some sort of IMAP implementation relay in ActionMailbox.
|
15
|
+
It seems that there is no plans to create some sort of IMAP implementation relay in ActionMailbox.
|
17
16
|
https://github.com/rails/actionmailbox/issues/14
|
18
17
|
|
19
18
|
There is probably a reason for this. We did not want to setup or maintain a mailserver which would probably be the route to go for a robust inbound email application.
|
@@ -52,11 +51,13 @@ $ rails g imap:install
|
|
52
51
|
|
53
52
|
Prepare your IMAP server and account by ensuring/creating the mailboxes for `ingress_mailbox`, ex: "INBOX".
|
54
53
|
|
55
|
-
Update the `config/imap.yml` that was generated to include server and credentials information, `
|
54
|
+
Update the `config/imap.yml` that was generated to include server and credentials information, `mailbox`. Currently SSL is required.
|
55
|
+
|
56
|
+
Run the [ActionMailbox::IMAP Client](https://github.com/kimmelsg/actionmailbox-imap/blob/master/CLIENT.md) like so `URL=... INGRESS_PASSWORD=... ./actionmailbox-imap` to begin processing emails.
|
56
57
|
|
57
|
-
|
58
|
+
### Rake Task
|
58
59
|
|
59
|
-
The
|
60
|
+
The rake task behaves much like that of the other `action_mailbox:ingress:...` commands in that it relays the message the same way. Although messages should be piped to the other ingress commands and `rails action_mailbox:ingress:imap ...` needs to be scheduled appropriately.
|
60
61
|
|
61
62
|
## Installation
|
62
63
|
Add this line to your application's Gemfile:
|
data/lib/actionmailbox/imap.rb
CHANGED
@@ -1,29 +1,8 @@
|
|
1
1
|
require "actionmailbox/imap/railtie"
|
2
|
-
require "actionmailbox/imap/mailbox"
|
3
2
|
|
4
3
|
module ActionMailbox
|
5
4
|
module IMAP
|
6
5
|
class Base
|
7
|
-
def initialize(adapter:)
|
8
|
-
@adapter = adapter
|
9
|
-
end
|
10
|
-
|
11
|
-
def login(username:, password:)
|
12
|
-
adapter.login(username: username, password: password)
|
13
|
-
end
|
14
|
-
|
15
|
-
def mailbox(mailbox)
|
16
|
-
adapter.select_mailbox(mailbox)
|
17
|
-
Mailbox.new(adapter: adapter, mailbox: mailbox)
|
18
|
-
end
|
19
|
-
|
20
|
-
def disconnect
|
21
|
-
adapter.disconnect
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
attr_reader :adapter
|
27
6
|
end
|
28
7
|
end
|
29
8
|
end
|
@@ -1,7 +1,9 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Imap
|
2
|
+
class InstallGenerator < Rails::Generators::Base
|
3
|
+
source_root File.expand_path("templates", __dir__)
|
3
4
|
|
4
|
-
|
5
|
-
|
5
|
+
def copy_imap_config_file
|
6
|
+
copy_file "config.yml", "config/actionmailbox_imap.yml"
|
7
|
+
end
|
6
8
|
end
|
7
9
|
end
|
@@ -1,14 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
ingress_mailbox: "INBOX"
|
8
|
-
take: <%= ENV.fetch("IMAP_TAKE") { 100 } %>
|
9
|
-
|
10
|
-
development:
|
11
|
-
<<: *default
|
12
|
-
|
13
|
-
production:
|
14
|
-
<<: *default
|
1
|
+
server: "imap.domain.com"
|
2
|
+
port: 993
|
3
|
+
tls: true
|
4
|
+
username: "username"
|
5
|
+
password: "password"
|
6
|
+
mailbox: "INBOX"
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require "actionmailbox/imap/adapters/net_imap"
|
2
|
-
|
3
1
|
namespace :action_mailbox do
|
4
2
|
namespace :ingress do
|
5
3
|
task :environment do
|
@@ -12,34 +10,22 @@ namespace :action_mailbox do
|
|
12
10
|
task imap: "action_mailbox:ingress:environment" do
|
13
11
|
url, password = ENV.values_at("URL", "INGRESS_PASSWORD")
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
port: config[:port],
|
20
|
-
usessl: config[:usessl]
|
21
|
-
)
|
22
|
-
|
23
|
-
imap = ActionMailbox::IMAP::Base.new(adapter: adapter)
|
24
|
-
|
25
|
-
imap.login(username: config[:username], password: config[:password])
|
26
|
-
|
27
|
-
mailbox = imap.mailbox(config[:ingress_mailbox])
|
28
|
-
|
29
|
-
relayer = ActionMailbox::Relayer.new(url: url, password: password)
|
30
|
-
|
31
|
-
messages = mailbox.messages.take(config[:take])
|
13
|
+
if url.blank? || password.blank?
|
14
|
+
print "URL and INGRESS_PASSWORD are required"
|
15
|
+
exit 64 # EX_USAGE
|
16
|
+
end
|
32
17
|
|
33
|
-
|
18
|
+
ActionMailbox::Relayer.new(url: url, password: password).relay(STDIN.read).tap do |result|
|
19
|
+
print result.message
|
34
20
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
21
|
+
if result.success?
|
22
|
+
exit 0
|
23
|
+
elsif result.transient_failure?
|
24
|
+
exit 75 # EX_TEMPFAIL
|
25
|
+
else
|
26
|
+
exit 69 # EX_UNAVAILABLE
|
39
27
|
end
|
40
28
|
end
|
41
|
-
|
42
|
-
imap.disconnect
|
43
29
|
end
|
44
30
|
end
|
45
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: actionmailbox-imap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ethan Knowlton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -66,7 +66,8 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description: Relay IMAP messages to ActionMailbox
|
69
|
+
description: Relay IMAP messages to ActionMailbox. This package requires the rust
|
70
|
+
imap client binary to be run. Visit the repository ReadMe for more information.
|
70
71
|
email:
|
71
72
|
- eknowlton@gmail.com
|
72
73
|
executables: []
|
@@ -76,11 +77,8 @@ files:
|
|
76
77
|
- MIT-LICENSE
|
77
78
|
- README.md
|
78
79
|
- Rakefile
|
80
|
+
- config/actionmailbox_imap.yaml
|
79
81
|
- lib/actionmailbox/imap.rb
|
80
|
-
- lib/actionmailbox/imap/adapters/net_imap.rb
|
81
|
-
- lib/actionmailbox/imap/mailbox.rb
|
82
|
-
- lib/actionmailbox/imap/message.rb
|
83
|
-
- lib/actionmailbox/imap/messages.rb
|
84
82
|
- lib/actionmailbox/imap/railtie.rb
|
85
83
|
- lib/actionmailbox/imap/version.rb
|
86
84
|
- lib/generators/imap/install_generator.rb
|
@@ -106,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
104
|
- !ruby/object:Gem::Version
|
107
105
|
version: '0'
|
108
106
|
requirements: []
|
109
|
-
rubygems_version: 3.0.
|
107
|
+
rubygems_version: 3.0.1
|
110
108
|
signing_key:
|
111
109
|
specification_version: 4
|
112
110
|
summary: Relay IMAP messages to ActionMailbox
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require "net/imap"
|
2
|
-
|
3
|
-
module ActionMailbox
|
4
|
-
module IMAP
|
5
|
-
module Adapters
|
6
|
-
class NetImap
|
7
|
-
def initialize(server:, port: 993, usessl: true)
|
8
|
-
@imap = Net::IMAP.new(server, port, usessl)
|
9
|
-
end
|
10
|
-
|
11
|
-
def login(username:, password:)
|
12
|
-
imap.login(username, password)
|
13
|
-
end
|
14
|
-
|
15
|
-
def select_mailbox(mailbox)
|
16
|
-
imap.select(mailbox)
|
17
|
-
end
|
18
|
-
|
19
|
-
def disconnect
|
20
|
-
imap.expunge
|
21
|
-
imap.disconnect
|
22
|
-
end
|
23
|
-
|
24
|
-
def messages
|
25
|
-
imap.search(["NOT", "DELETED", "NOT", "SEEN"])
|
26
|
-
end
|
27
|
-
|
28
|
-
def delete_message(id)
|
29
|
-
imap.store(id, "+FLAGS", [:Deleted])
|
30
|
-
end
|
31
|
-
|
32
|
-
def mark_message_seen(id)
|
33
|
-
imap.store(id, "+FLAGS", [:Seen])
|
34
|
-
end
|
35
|
-
|
36
|
-
def mark_message_unseen(id)
|
37
|
-
imap.store(id, "-FLAGS", [:Seen])
|
38
|
-
end
|
39
|
-
|
40
|
-
def fetch_message_attr(id, attr)
|
41
|
-
imap.fetch(id, attr).first.attr[attr]
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
attr_reader :imap
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require "actionmailbox/imap/messages"
|
2
|
-
|
3
|
-
module ActionMailbox
|
4
|
-
module IMAP
|
5
|
-
class Mailbox
|
6
|
-
def initialize(adapter:, mailbox:)
|
7
|
-
@adapter = adapter
|
8
|
-
@mailbox = mailbox
|
9
|
-
end
|
10
|
-
|
11
|
-
def messages
|
12
|
-
result = adapter.messages
|
13
|
-
Messages.new(adapter: adapter, message_ids: result)
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
attr_reader :adapter, :mailbox
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module ActionMailbox
|
2
|
-
module IMAP
|
3
|
-
class Message
|
4
|
-
RFC822 = "RFC822".freeze
|
5
|
-
|
6
|
-
def initialize(adapter:, id:)
|
7
|
-
@adapter = adapter
|
8
|
-
@id = id
|
9
|
-
end
|
10
|
-
|
11
|
-
def rfc822
|
12
|
-
adapter.fetch_message_attr(id, RFC822)
|
13
|
-
end
|
14
|
-
|
15
|
-
def delete
|
16
|
-
adapter.delete_message(id)
|
17
|
-
end
|
18
|
-
|
19
|
-
def mark_read
|
20
|
-
adapter.mark_message_seen(id)
|
21
|
-
end
|
22
|
-
|
23
|
-
def mark_unread
|
24
|
-
adapter.mark_message_unseen(id)
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
attr_reader :adapter, :id
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require "actionmailbox/imap/message"
|
2
|
-
|
3
|
-
module ActionMailbox
|
4
|
-
module IMAP
|
5
|
-
class Messages
|
6
|
-
def initialize(adapter:, message_ids:)
|
7
|
-
@adapter = adapter
|
8
|
-
@message_ids = message_ids
|
9
|
-
end
|
10
|
-
|
11
|
-
def take(n)
|
12
|
-
taken_ids = message_ids.take(n)
|
13
|
-
Messages.new(adapter: adapter, message_ids: taken_ids)
|
14
|
-
end
|
15
|
-
|
16
|
-
def length
|
17
|
-
message_ids.length
|
18
|
-
end
|
19
|
-
|
20
|
-
def each
|
21
|
-
return unless block_given? # @TODO Need to test this branch
|
22
|
-
|
23
|
-
message_ids.each do |id|
|
24
|
-
yield Message.new(adapter: adapter, id: id)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def mark_read
|
29
|
-
message_ids.each do |id|
|
30
|
-
adapter.mark_message_seen(id)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def mark_unread
|
35
|
-
message_ids.each do |id|
|
36
|
-
adapter.mark_message_unseen(id)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
attr_reader :adapter, :message_ids
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|