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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf597bbca58917880d28d6b9ea482e0c67d0dc1aba28c3ce643f297e5c0860df
4
- data.tar.gz: be76ffc403639b411d67d18e651b7933633c95e0abe5be55cfbf365e84bc369f
3
+ metadata.gz: 376f10979ea6f2c65fccb83629829919116f6022940af536622fb4873d1745d2
4
+ data.tar.gz: 12b8fa355b3dab2f0a1f5d3aafc6f1dbf2ebf9cdf653e85dc74e8925c97e7a94
5
5
  SHA512:
6
- metadata.gz: b501f7a5e650d176d287c773115f11cebcaf639a54dfd81ce781350c9fbedfd89134fbf0011764dd7efc500bc0d6947faf0724be58a4d78bb2269ef0ce66e0dd
7
- data.tar.gz: d8c7e4a75a3b89fac41c5a426aaf8f3b1b34cc06369be9657bbeaaea275fc11947a7376f34c47fc89d296b69d35af05f957263670b0d593d34b565e8e7d88d19
6
+ metadata.gz: 8b5e9f33726a4607eaf3b2eb848004b8e9f237900a952e3240bebb5f5ecedfb941b3e0ae9a57e67b510e2d9fd25ccb0deaeece0c87963fe415f6202dcfccd04a
7
+ data.tar.gz: c4d1d058b1a1277e2c35d32d33fe1ada479f8e4bd4887bb97f62581c3049802f744543f0e3a58ff647f62ac40ee9f8209d3c4912190d70f6814a8d34f67993f8
data/README.md CHANGED
@@ -1,19 +1,18 @@
1
1
  # ActionMailbox::IMAP
2
- [![CircleCI](https://circleci.com/gh/kimmelsg/actionmailbox-imap.svg?style=svg)](https://circleci.com/gh/kimmelsg/actionmailbox-imap)
3
- [![RubyGems](https://badge.fury.io/rb/actionmailbox-imap.svg)](https://rubygems.org/gems/actionmailbox-imap)
2
+ [![CircleCI](https://circleci.com/gh/kimmelsg/actionmailbox-imap.svg?style=svg)](https://circleci.com/gh/kimmelsg/actionmailbox-imap)
3
+ [![RubyGems](https://badge.fury.io/rb/actionmailbox-imap.svg)](https://rubygems.org/gems/actionmailbox-imap)
4
4
  [![Standard](https://camo.githubusercontent.com/58fbab8bb63d069c1e4fb3fa37c2899c38ffcd18/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64655f7374796c652d7374616e646172642d627269676874677265656e2e737667)](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 which will connect to an IMAP server, grab some (`take`) emails, attempt to relay them to ActionMailbox.
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 the rake task successfully relays a message to ActionMailbox then it will flag the message as "Deleted" on the IMAP server, and continue to the next message.
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, `ingress_mailbox` and an appropriate `take` amount ( the amount of emails to grab in a single run ).
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
- Run or schedule `rails action_mailbox:ingress:imap URL="http://localhost/rails/action_mailbox/relay/inbound_email" INGRESS_PASSWORD="YourIngressPassword"` to run at a selected interval.
58
+ ### Rake Task
58
59
 
59
- The command 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
+ 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:
@@ -0,0 +1,6 @@
1
+ server: "smtp.testing.com"
2
+ port: 993
3
+ tls: true
4
+ username: "test@test.com"
5
+ password: "test"
6
+ mailbox: "INBOX"
@@ -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,5 +1,5 @@
1
1
  module Actionmailbox
2
2
  module Imap
3
- VERSION = "0.1.2"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
@@ -1,7 +1,9 @@
1
- class Imap::InstallGenerator < Rails::Generators::Base
2
- source_root File.expand_path("templates", __dir__)
1
+ module Imap
2
+ class InstallGenerator < Rails::Generators::Base
3
+ source_root File.expand_path("templates", __dir__)
3
4
 
4
- def copy_imap_config_file
5
- copy_file "config.yml", "config/actionmailbox_imap.yml"
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
- default: &default
2
- server: <%= ENV.fetch("IMAP_SERVER") { "" } %>
3
- port: <%= ENV.fetch("IMAP_PORT") { 993 } %>
4
- usessl: <%= ENV.fetch("IMAP_USE_SSL") { true } %>
5
- username: <%= ENV.fetch("IMAP_ACCOUNT_USERNAME") { "" } %>
6
- password: <%= ENV.fetch("IMAP_ACCOUNT_PASSWORD") { "" } %>
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
- config = Rails.application.config_for(:actionmailbox_imap)
16
-
17
- adapter = ActionMailbox::IMAP::Adapters::NetImap.new(
18
- server: config[:server],
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
- messages.mark_read
18
+ ActionMailbox::Relayer.new(url: url, password: password).relay(STDIN.read).tap do |result|
19
+ print result.message
34
20
 
35
- messages.each do |message|
36
- relayer.relay(message.rfc822).tap do |result|
37
- message.delete if result.success?
38
- message.mark_unread unless result.success?
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.2
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-23 00:00:00.000000000 Z
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.4
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