mailchain_connector_imap 0.1.4 → 0.1.5
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/.gitignore +11 -11
- data/.rspec +3 -3
- data/.travis.yml +6 -6
- data/CODE_OF_CONDUCT.md +74 -74
- data/Gemfile +6 -6
- data/Gemfile.lock +71 -73
- data/LICENSE +201 -201
- data/README.md +62 -58
- data/Rakefile +6 -6
- data/SPECIFICATION.md +140 -0
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/exe/mailchain_connector_imap +7 -7
- data/lib/api/mailchain.rb +50 -50
- data/lib/connection/mailchain.rb +160 -159
- data/lib/connection_configuration/imap.rb +89 -89
- data/lib/connection_configuration/mailchain.rb +139 -139
- data/lib/mailchain_connector_imap/version.rb +5 -5
- data/mailchain_connector_imap.gemspec +38 -38
- metadata +7 -6
@@ -1,89 +1,89 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class ConnectionConfigurationImap
|
4
|
-
attr_reader :config
|
5
|
-
attr_reader :print_settings
|
6
|
-
def initialize(config)
|
7
|
-
@config = config
|
8
|
-
end
|
9
|
-
|
10
|
-
# Run the IMAP configuration wizard
|
11
|
-
# Returns hash or either: { "save" => true, "config" => "{ #config }" }
|
12
|
-
# - or -
|
13
|
-
# { "save" => false }
|
14
|
-
def configuration_wizard
|
15
|
-
@prompt = TTY::Prompt.new
|
16
|
-
|
17
|
-
prompt_server
|
18
|
-
prompt_username
|
19
|
-
prompt_port
|
20
|
-
prompt_ssl
|
21
|
-
|
22
|
-
result = prompt_confirm_save_settings
|
23
|
-
@prompt = nil
|
24
|
-
result
|
25
|
-
end
|
26
|
-
|
27
|
-
# Prints the IMAP server settings as output in a nice format
|
28
|
-
def print_settings
|
29
|
-
puts "IMAP Settings:\n" \
|
30
|
-
"--------------\n" \
|
31
|
-
"Server:\t\t#{@config['imap']['server']}\n" \
|
32
|
-
"Port:\t\t#{@config['imap']['port']}\n" \
|
33
|
-
"SSL:\t\t#{@config['imap']['ssl']}\n" \
|
34
|
-
"Username:\t#{@config['imap']['username']}"
|
35
|
-
end
|
36
|
-
|
37
|
-
# Get imap server config
|
38
|
-
def prompt_server
|
39
|
-
@config['imap']['server'] = @prompt.ask(
|
40
|
-
'Enter your imap server (e.g. imap.example.com)',
|
41
|
-
default: @config['imap']['server']
|
42
|
-
)
|
43
|
-
end
|
44
|
-
|
45
|
-
# Get imap username
|
46
|
-
def prompt_username
|
47
|
-
@config['imap']['username'] = @prompt.ask(
|
48
|
-
'Enter your imap username/ email address (e.g. tim@example.com)',
|
49
|
-
default: @config['imap']['username']
|
50
|
-
)
|
51
|
-
end
|
52
|
-
|
53
|
-
# Get imap port
|
54
|
-
def prompt_port
|
55
|
-
@config['imap']['port'] = @config['imap']['port'] || '993'
|
56
|
-
@config['imap']['port'] = @prompt.ask(
|
57
|
-
'Enter the imap port to connect to (e.g. IMAP = 143; IMAP SSL = 993)',
|
58
|
-
default: @config['imap']['port']
|
59
|
-
)
|
60
|
-
end
|
61
|
-
|
62
|
-
# Get imap ssl status
|
63
|
-
def prompt_ssl
|
64
|
-
@config['imap']['ssl'] = @config['imap']['ssl'] != false
|
65
|
-
imap_ssl_val = @config['imap']['ssl'] ? 1 : 2
|
66
|
-
imap_ssl_val = @prompt.select('Use SSL?', cycle: true) do |menu|
|
67
|
-
menu.default imap_ssl_val
|
68
|
-
menu.choice 'Yes', 1
|
69
|
-
menu.choice 'No', 2
|
70
|
-
end
|
71
|
-
@config['imap']['ssl'] = imap_ssl_val == 1
|
72
|
-
end
|
73
|
-
|
74
|
-
# Confirm settings with user
|
75
|
-
def prompt_confirm_save_settings
|
76
|
-
server_settings = print_settings
|
77
|
-
imap_confirm_val = @prompt.select(
|
78
|
-
"Would you like to save the following settings?\n" \
|
79
|
-
"NOTE: Any existing configuration will be overwritten\n\n" \
|
80
|
-
"#{server_settings}",
|
81
|
-
cycle: true
|
82
|
-
) do |menu|
|
83
|
-
menu.choice 'Save', true
|
84
|
-
menu.choice 'Cancel', false
|
85
|
-
end
|
86
|
-
|
87
|
-
imap_confirm_val ? { 'save' => true, 'config' => @config } : { 'save' => false }
|
88
|
-
end
|
89
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class ConnectionConfigurationImap
|
4
|
+
attr_reader :config
|
5
|
+
attr_reader :print_settings
|
6
|
+
def initialize(config)
|
7
|
+
@config = config
|
8
|
+
end
|
9
|
+
|
10
|
+
# Run the IMAP configuration wizard
|
11
|
+
# Returns hash or either: { "save" => true, "config" => "{ #config }" }
|
12
|
+
# - or -
|
13
|
+
# { "save" => false }
|
14
|
+
def configuration_wizard
|
15
|
+
@prompt = TTY::Prompt.new
|
16
|
+
|
17
|
+
prompt_server
|
18
|
+
prompt_username
|
19
|
+
prompt_port
|
20
|
+
prompt_ssl
|
21
|
+
|
22
|
+
result = prompt_confirm_save_settings
|
23
|
+
@prompt = nil
|
24
|
+
result
|
25
|
+
end
|
26
|
+
|
27
|
+
# Prints the IMAP server settings as output in a nice format
|
28
|
+
def print_settings
|
29
|
+
puts "IMAP Settings:\n" \
|
30
|
+
"--------------\n" \
|
31
|
+
"Server:\t\t#{@config['imap']['server']}\n" \
|
32
|
+
"Port:\t\t#{@config['imap']['port']}\n" \
|
33
|
+
"SSL:\t\t#{@config['imap']['ssl']}\n" \
|
34
|
+
"Username:\t#{@config['imap']['username']}"
|
35
|
+
end
|
36
|
+
|
37
|
+
# Get imap server config
|
38
|
+
def prompt_server
|
39
|
+
@config['imap']['server'] = @prompt.ask(
|
40
|
+
'Enter your imap server (e.g. imap.example.com)',
|
41
|
+
default: @config['imap']['server']
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Get imap username
|
46
|
+
def prompt_username
|
47
|
+
@config['imap']['username'] = @prompt.ask(
|
48
|
+
'Enter your imap username/ email address (e.g. tim@example.com)',
|
49
|
+
default: @config['imap']['username']
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Get imap port
|
54
|
+
def prompt_port
|
55
|
+
@config['imap']['port'] = @config['imap']['port'] || '993'
|
56
|
+
@config['imap']['port'] = @prompt.ask(
|
57
|
+
'Enter the imap port to connect to (e.g. IMAP = 143; IMAP SSL = 993)',
|
58
|
+
default: @config['imap']['port']
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Get imap ssl status
|
63
|
+
def prompt_ssl
|
64
|
+
@config['imap']['ssl'] = @config['imap']['ssl'] != false
|
65
|
+
imap_ssl_val = @config['imap']['ssl'] ? 1 : 2
|
66
|
+
imap_ssl_val = @prompt.select('Use SSL?', cycle: true) do |menu|
|
67
|
+
menu.default imap_ssl_val
|
68
|
+
menu.choice 'Yes', 1
|
69
|
+
menu.choice 'No', 2
|
70
|
+
end
|
71
|
+
@config['imap']['ssl'] = imap_ssl_val == 1
|
72
|
+
end
|
73
|
+
|
74
|
+
# Confirm settings with user
|
75
|
+
def prompt_confirm_save_settings
|
76
|
+
server_settings = print_settings
|
77
|
+
imap_confirm_val = @prompt.select(
|
78
|
+
"Would you like to save the following settings?\n" \
|
79
|
+
"NOTE: Any existing configuration will be overwritten\n\n" \
|
80
|
+
"#{server_settings}",
|
81
|
+
cycle: true
|
82
|
+
) do |menu|
|
83
|
+
menu.choice 'Save', true
|
84
|
+
menu.choice 'Cancel', false
|
85
|
+
end
|
86
|
+
|
87
|
+
imap_confirm_val ? { 'save' => true, 'config' => @config } : { 'save' => false }
|
88
|
+
end
|
89
|
+
end
|
@@ -1,139 +1,139 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class ConnectionConfigurationMailchain
|
4
|
-
FOLDER_STRUCTURE = { 'by_network' => 'Protocol>Network>Address', 'by_address' => 'Address>Protocol>Network' }.freeze
|
5
|
-
|
6
|
-
attr_reader :config
|
7
|
-
def initialize(config)
|
8
|
-
@config = config
|
9
|
-
end
|
10
|
-
|
11
|
-
# Runs the Mailchain API configuration wizard
|
12
|
-
# Returns hash or either: { "save" => true, "config" => "{ #config }" }
|
13
|
-
# - or -
|
14
|
-
# { "save" => false }
|
15
|
-
def configuration_wizard
|
16
|
-
@prompt = TTY::Prompt.new
|
17
|
-
prompt_hostname
|
18
|
-
prompt_ssl
|
19
|
-
prompt_port
|
20
|
-
prompt_folder_format
|
21
|
-
prompt_mainnet_to_inbox
|
22
|
-
prompt_polling_interval
|
23
|
-
result = prompt_confirm_save_settings
|
24
|
-
@prompt = nil
|
25
|
-
result
|
26
|
-
end
|
27
|
-
|
28
|
-
# Prints the Mailchain API settings as output in a nice format
|
29
|
-
def print_settings
|
30
|
-
ssl = @config['mailchain']['ssl'] ? 'https' : 'http'
|
31
|
-
hostname = @config['mailchain']['hostname']
|
32
|
-
port = @config['mailchain']['port']
|
33
|
-
folders = @config['mailchain']['folders']
|
34
|
-
mainnet_inbox = @config['mailchain']['mainnet_to_inbox'] ? 'To Inbox' : 'To Mainnet Folder'
|
35
|
-
interval = @config['mailchain']['interval'].to_i > 60 ? @config['mailchain']['interval'].to_i : 60
|
36
|
-
|
37
|
-
puts "Mailchain Settings:\n" \
|
38
|
-
"-------------------\n" \
|
39
|
-
"http/https:\t#{ssl}\n" \
|
40
|
-
"Hostname:\t#{hostname}\n" \
|
41
|
-
"Port:\t\t#{port}\n" \
|
42
|
-
"API URL:\t#{ssl}://#{hostname}:#{port}/api\n" \
|
43
|
-
"Mainnet messages: #{mainnet_inbox}\n" \
|
44
|
-
"Store messages: #{FOLDER_STRUCTURE[folders]}\n" \
|
45
|
-
"Polling interval: #{interval} seconds #{'(' + (interval / 60).to_s + ' minutes)' if interval > 60}"
|
46
|
-
end
|
47
|
-
|
48
|
-
# Get Mailchain server config
|
49
|
-
def prompt_hostname
|
50
|
-
@config['mailchain']['hostname'] = @prompt.ask(
|
51
|
-
'Enter your Mailchain client hostname (e.g. 127.0.0.1 or mailchain.example.com)',
|
52
|
-
default: @config['mailchain']['hostname'] || '127.0.0.1'
|
53
|
-
)
|
54
|
-
end
|
55
|
-
|
56
|
-
# Get Mailchain ssl status
|
57
|
-
def prompt_ssl
|
58
|
-
@config['mailchain']['ssl'] = @config['mailchain']['ssl'] != false
|
59
|
-
ssl_val = @config['mailchain']['ssl'] ? 1 : 2
|
60
|
-
ssl_val = @prompt.select('Use https (SSL)?', cycle: true) do |menu|
|
61
|
-
menu.default ssl_val
|
62
|
-
menu.choice 'https (SSL)', 1
|
63
|
-
menu.choice 'http', 2
|
64
|
-
end
|
65
|
-
@config['mailchain']['ssl'] = ssl_val == 1
|
66
|
-
end
|
67
|
-
|
68
|
-
# Get Mailchain port
|
69
|
-
def prompt_port
|
70
|
-
custom_port = @prompt.yes?('Connect to a custom port?')
|
71
|
-
case custom_port
|
72
|
-
when false && @config['mailchain']['ssl']
|
73
|
-
@config['mailchain']['port'] = 443
|
74
|
-
when false && !@config['mailchain']['ssl']
|
75
|
-
@config['mailchain']['port'] = 80
|
76
|
-
when true
|
77
|
-
@config['mailchain']['port'] = @config['mailchain']['port'] || '8080'
|
78
|
-
@config['mailchain']['port'] = @prompt.ask(
|
79
|
-
'Enter the port to connect to the Mailchain client (e.g. 8080)',
|
80
|
-
default: @config['mailchain']['port']
|
81
|
-
)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
# Folder format
|
86
|
-
def prompt_folder_format
|
87
|
-
choices = {
|
88
|
-
1 => 'by_network',
|
89
|
-
'by_network' => 1,
|
90
|
-
|
91
|
-
2 => 'by_address',
|
92
|
-
'by_address' => 2
|
93
|
-
}
|
94
|
-
folder_choice = @prompt.select(
|
95
|
-
'How would you like to structure your folders in IMAP?',
|
96
|
-
cycle: true
|
97
|
-
) do |menu|
|
98
|
-
menu.default choices[@config['mailchain']['folders']] || 1
|
99
|
-
menu.choice FOLDER_STRUCTURE['by_network'], 1
|
100
|
-
menu.choice FOLDER_STRUCTURE['by_address'], 2
|
101
|
-
end
|
102
|
-
@config['mailchain']['folders'] = choices[folder_choice]
|
103
|
-
end
|
104
|
-
|
105
|
-
# Mainnet to Inbox
|
106
|
-
def prompt_mainnet_to_inbox
|
107
|
-
@config['mailchain']['mainnet_to_inbox'] = @prompt.select(
|
108
|
-
"Most email clients don't alert you when messages are delivered to your folders. Would you like 'Mainnet' messages delivered to your Inbox folder so you get new message alerts?",
|
109
|
-
cycle: true
|
110
|
-
) do |menu|
|
111
|
-
menu.choice 'Yes', true
|
112
|
-
menu.choice 'No', false
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
# Polling Interval
|
117
|
-
def prompt_polling_interval
|
118
|
-
@config['mailchain']['interval'] = @config['mailchain']['interval'] || '300'
|
119
|
-
@config['mailchain']['interval'] = @prompt.ask(
|
120
|
-
'How often would you like to check for messages (in seconds)? (e.g. 300 = 5 minutes; Minimum interval is 1 minute)',
|
121
|
-
default: @config['mailchain']['interval']
|
122
|
-
)
|
123
|
-
end
|
124
|
-
|
125
|
-
# Confirm settings with user
|
126
|
-
def prompt_confirm_save_settings
|
127
|
-
settings = print_settings
|
128
|
-
mailchain_confirm_val = @prompt.select(
|
129
|
-
"Would you like to save the following settings?\n" \
|
130
|
-
"NOTE: Any existing configuration will be overwritten\n\n" \
|
131
|
-
"#{settings}",
|
132
|
-
cycle: true
|
133
|
-
) do |menu|
|
134
|
-
menu.choice 'Save', true
|
135
|
-
menu.choice 'Cancel', false
|
136
|
-
end
|
137
|
-
mailchain_confirm_val ? { 'save' => true, 'config' => @config } : { 'save' => false }
|
138
|
-
end
|
139
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class ConnectionConfigurationMailchain
|
4
|
+
FOLDER_STRUCTURE = { 'by_network' => 'Protocol>Network>Address', 'by_address' => 'Address>Protocol>Network' }.freeze
|
5
|
+
|
6
|
+
attr_reader :config
|
7
|
+
def initialize(config)
|
8
|
+
@config = config
|
9
|
+
end
|
10
|
+
|
11
|
+
# Runs the Mailchain API configuration wizard
|
12
|
+
# Returns hash or either: { "save" => true, "config" => "{ #config }" }
|
13
|
+
# - or -
|
14
|
+
# { "save" => false }
|
15
|
+
def configuration_wizard
|
16
|
+
@prompt = TTY::Prompt.new
|
17
|
+
prompt_hostname
|
18
|
+
prompt_ssl
|
19
|
+
prompt_port
|
20
|
+
prompt_folder_format
|
21
|
+
prompt_mainnet_to_inbox
|
22
|
+
prompt_polling_interval
|
23
|
+
result = prompt_confirm_save_settings
|
24
|
+
@prompt = nil
|
25
|
+
result
|
26
|
+
end
|
27
|
+
|
28
|
+
# Prints the Mailchain API settings as output in a nice format
|
29
|
+
def print_settings
|
30
|
+
ssl = @config['mailchain']['ssl'] ? 'https' : 'http'
|
31
|
+
hostname = @config['mailchain']['hostname']
|
32
|
+
port = @config['mailchain']['port']
|
33
|
+
folders = @config['mailchain']['folders']
|
34
|
+
mainnet_inbox = @config['mailchain']['mainnet_to_inbox'] ? 'To Inbox' : 'To Mainnet Folder'
|
35
|
+
interval = @config['mailchain']['interval'].to_i > 60 ? @config['mailchain']['interval'].to_i : 60
|
36
|
+
|
37
|
+
puts "Mailchain Settings:\n" \
|
38
|
+
"-------------------\n" \
|
39
|
+
"http/https:\t#{ssl}\n" \
|
40
|
+
"Hostname:\t#{hostname}\n" \
|
41
|
+
"Port:\t\t#{port}\n" \
|
42
|
+
"API URL:\t#{ssl}://#{hostname}:#{port}/api\n" \
|
43
|
+
"Mainnet messages: #{mainnet_inbox}\n" \
|
44
|
+
"Store messages: #{FOLDER_STRUCTURE[folders]}\n" \
|
45
|
+
"Polling interval: #{interval} seconds #{'(' + (interval / 60).to_s + ' minutes)' if interval > 60}"
|
46
|
+
end
|
47
|
+
|
48
|
+
# Get Mailchain server config
|
49
|
+
def prompt_hostname
|
50
|
+
@config['mailchain']['hostname'] = @prompt.ask(
|
51
|
+
'Enter your Mailchain client hostname (e.g. 127.0.0.1 or mailchain.example.com)',
|
52
|
+
default: @config['mailchain']['hostname'] || '127.0.0.1'
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Get Mailchain ssl status
|
57
|
+
def prompt_ssl
|
58
|
+
@config['mailchain']['ssl'] = @config['mailchain']['ssl'] != false
|
59
|
+
ssl_val = @config['mailchain']['ssl'] ? 1 : 2
|
60
|
+
ssl_val = @prompt.select('Use https (SSL)?', cycle: true) do |menu|
|
61
|
+
menu.default ssl_val
|
62
|
+
menu.choice 'https (SSL)', 1
|
63
|
+
menu.choice 'http', 2
|
64
|
+
end
|
65
|
+
@config['mailchain']['ssl'] = ssl_val == 1
|
66
|
+
end
|
67
|
+
|
68
|
+
# Get Mailchain port
|
69
|
+
def prompt_port
|
70
|
+
custom_port = @prompt.yes?('Connect to a custom port?')
|
71
|
+
case custom_port
|
72
|
+
when false && @config['mailchain']['ssl']
|
73
|
+
@config['mailchain']['port'] = 443
|
74
|
+
when false && !@config['mailchain']['ssl']
|
75
|
+
@config['mailchain']['port'] = 80
|
76
|
+
when true
|
77
|
+
@config['mailchain']['port'] = @config['mailchain']['port'] || '8080'
|
78
|
+
@config['mailchain']['port'] = @prompt.ask(
|
79
|
+
'Enter the port to connect to the Mailchain client (e.g. 8080)',
|
80
|
+
default: @config['mailchain']['port']
|
81
|
+
)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Folder format
|
86
|
+
def prompt_folder_format
|
87
|
+
choices = {
|
88
|
+
1 => 'by_network',
|
89
|
+
'by_network' => 1,
|
90
|
+
|
91
|
+
2 => 'by_address',
|
92
|
+
'by_address' => 2
|
93
|
+
}
|
94
|
+
folder_choice = @prompt.select(
|
95
|
+
'How would you like to structure your folders in IMAP?',
|
96
|
+
cycle: true
|
97
|
+
) do |menu|
|
98
|
+
menu.default choices[@config['mailchain']['folders']] || 1
|
99
|
+
menu.choice FOLDER_STRUCTURE['by_network'], 1
|
100
|
+
menu.choice FOLDER_STRUCTURE['by_address'], 2
|
101
|
+
end
|
102
|
+
@config['mailchain']['folders'] = choices[folder_choice]
|
103
|
+
end
|
104
|
+
|
105
|
+
# Mainnet to Inbox
|
106
|
+
def prompt_mainnet_to_inbox
|
107
|
+
@config['mailchain']['mainnet_to_inbox'] = @prompt.select(
|
108
|
+
"Most email clients don't alert you when messages are delivered to your folders. Would you like 'Mainnet' messages delivered to your Inbox folder so you get new message alerts?",
|
109
|
+
cycle: true
|
110
|
+
) do |menu|
|
111
|
+
menu.choice 'Yes', true
|
112
|
+
menu.choice 'No', false
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# Polling Interval
|
117
|
+
def prompt_polling_interval
|
118
|
+
@config['mailchain']['interval'] = @config['mailchain']['interval'] || '300'
|
119
|
+
@config['mailchain']['interval'] = @prompt.ask(
|
120
|
+
'How often would you like to check for messages (in seconds)? (e.g. 300 = 5 minutes; Minimum interval is 1 minute)',
|
121
|
+
default: @config['mailchain']['interval']
|
122
|
+
)
|
123
|
+
end
|
124
|
+
|
125
|
+
# Confirm settings with user
|
126
|
+
def prompt_confirm_save_settings
|
127
|
+
settings = print_settings
|
128
|
+
mailchain_confirm_val = @prompt.select(
|
129
|
+
"Would you like to save the following settings?\n" \
|
130
|
+
"NOTE: Any existing configuration will be overwritten\n\n" \
|
131
|
+
"#{settings}",
|
132
|
+
cycle: true
|
133
|
+
) do |menu|
|
134
|
+
menu.choice 'Save', true
|
135
|
+
menu.choice 'Cancel', false
|
136
|
+
end
|
137
|
+
mailchain_confirm_val ? { 'save' => true, 'config' => @config } : { 'save' => false }
|
138
|
+
end
|
139
|
+
end
|