mayaml 4.0.4 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -13
- data/README.md +4 -4
- data/bin/mayaml-mutt-init +75 -0
- data/lib/mayaml/base.rb +19 -0
- data/lib/mayaml/mutt_account_alternates/generator.rb +29 -0
- data/lib/mayaml/mutt_account_alternates/presenter.rb +18 -0
- data/lib/mayaml/mutt_account_alternates/template.mustache +1 -0
- data/lib/mayaml/mutt_account_alternates/validator.rb +18 -0
- data/lib/mayaml/mutt_account_alternates.rb +32 -0
- data/lib/mayaml/mutt_account_creds/generator.rb +29 -0
- data/lib/mayaml/mutt_account_creds/presenter.rb +29 -0
- data/lib/mayaml/mutt_account_creds/template.mustache +8 -0
- data/lib/mayaml/mutt_account_creds/validator.rb +25 -0
- data/lib/mayaml/mutt_account_creds.rb +32 -0
- data/lib/mayaml/mutt_account_init/generator.rb +30 -0
- data/lib/mayaml/mutt_account_init/presenter.rb +37 -0
- data/lib/mayaml/mutt_account_init/template.mustache +3 -0
- data/lib/mayaml/mutt_account_init/validator.rb +24 -0
- data/lib/mayaml/mutt_account_init.rb +32 -0
- data/lib/mayaml/mutt_config_accounts.rb +19 -0
- data/lib/mayaml/mutt_config_default_account.rb +18 -0
- data/lib/mayaml/mutt_config_init.rb +20 -0
- data/lib/mayaml/mutt_config_static.rb +18 -0
- data/lib/mayaml/mutt_configs_accounts/handler.rb +30 -0
- data/lib/mayaml/mutt_configs_default_account/handler.rb +46 -0
- data/lib/mayaml/mutt_configs_init/handler.rb +37 -0
- data/lib/mayaml/mutt_configs_static/assets/account_chooser.sh +20 -0
- data/lib/mayaml/mutt_configs_static/assets/csk.muttrc +94 -0
- data/lib/mayaml/mutt_configs_static/assets/mailcap +4 -0
- data/lib/mayaml/mutt_configs_static/assets/muttrc +125 -0
- data/lib/mayaml/mutt_configs_static/handler.rb +40 -0
- data/lib/mayaml/version.rb +1 -18
- data/lib/mayaml.rb +3 -47
- metadata +82 -24
- data/bin/mayaml-check +0 -42
- data/lib/mayaml/error.rb +0 -23
- data/lib/mayaml/mail_account/builder.rb +0 -127
- data/lib/mayaml/mail_account/default_flag_validator.rb +0 -43
- data/lib/mayaml/mail_account/error.rb +0 -47
- data/lib/mayaml/mail_account/mailboxes_validator.rb +0 -53
- data/lib/mayaml/mail_account/port_validator.rb +0 -44
- data/lib/mayaml/mail_account/required_attributes_validator.rb +0 -91
- data/lib/mayaml/mail_account/smtp_protocol_validator.rb +0 -53
- data/lib/mayaml/mail_account/type_validator.rb +0 -53
- data/lib/mayaml/mail_account.rb +0 -47
- data/lib/mayaml/parser.rb +0 -29
data/bin/mayaml-check
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
# Copyright (C) 2016, 2017, 2018 Szymon Kopciewski
|
5
|
-
#
|
6
|
-
# This file is part of Mayaml.
|
7
|
-
#
|
8
|
-
# This program is free software: you can redistribute it and/or modify
|
9
|
-
# it under the terms of the GNU General Public License as published by
|
10
|
-
# the Free Software Foundation, either version 3 of the License, or
|
11
|
-
# (at your option) any later version.
|
12
|
-
#
|
13
|
-
# This program is distributed in the hope that it will be useful,
|
14
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
-
# GNU General Public License for more details.
|
17
|
-
#
|
18
|
-
# You should have received a copy of the GNU General Public License
|
19
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
20
|
-
#
|
21
|
-
require "mayaml"
|
22
|
-
|
23
|
-
def puts_ussage_message
|
24
|
-
puts <<-END_HELP
|
25
|
-
Ussage: mayaml-check <path_to_yaml_file>
|
26
|
-
END_HELP
|
27
|
-
end
|
28
|
-
|
29
|
-
def main(args)
|
30
|
-
yaml_path = args.shift
|
31
|
-
if yaml_path.nil?
|
32
|
-
puts_ussage_message
|
33
|
-
exit 1
|
34
|
-
elsif File.exist? yaml_path
|
35
|
-
Mayaml.accounts_from_file(yaml_path).each { |acc| puts acc.to_str }
|
36
|
-
else
|
37
|
-
puts "Could not find file: #{yaml_path}"
|
38
|
-
exit 1
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
main ARGV
|
data/lib/mayaml/error.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright (C) 2016, 2017, 2018 Szymon Kopciewski
|
4
|
-
#
|
5
|
-
# This file is part of Mayaml.
|
6
|
-
#
|
7
|
-
# This program is free software: you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation, either version 3 of the License, or
|
10
|
-
# (at your option) any later version.
|
11
|
-
#
|
12
|
-
# This program is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
# GNU General Public License for more details.
|
16
|
-
#
|
17
|
-
# You should have received a copy of the GNU General Public License
|
18
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
|
-
|
20
|
-
module Mayaml
|
21
|
-
class Error < StandardError
|
22
|
-
end
|
23
|
-
end
|
@@ -1,127 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright (C) 2016, 2017, 2018 Szymon Kopciewski
|
4
|
-
#
|
5
|
-
# This file is part of Mayaml.
|
6
|
-
#
|
7
|
-
# This program is free software: you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation, either version 3 of the License, or
|
10
|
-
# (at your option) any later version.
|
11
|
-
#
|
12
|
-
# This program is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
# GNU General Public License for more details.
|
16
|
-
#
|
17
|
-
# You should have received a copy of the GNU General Public License
|
18
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
|
-
require "mayaml/mail_account"
|
20
|
-
require "mayaml/mail_account/error"
|
21
|
-
require "mayaml/mail_account/required_attributes_validator"
|
22
|
-
require "mayaml/mail_account/type_validator"
|
23
|
-
require "mayaml/mail_account/port_validator"
|
24
|
-
require "mayaml/mail_account/mailboxes_validator"
|
25
|
-
require "mayaml/mail_account/default_flag_validator"
|
26
|
-
require "mayaml/mail_account/smtp_protocol_validator"
|
27
|
-
|
28
|
-
module Mayaml
|
29
|
-
class MailAccount
|
30
|
-
class Builder
|
31
|
-
def self.build
|
32
|
-
builder = new
|
33
|
-
yield(builder)
|
34
|
-
builder.account
|
35
|
-
end
|
36
|
-
|
37
|
-
def initialize
|
38
|
-
@account = ::Mayaml::MailAccount.new
|
39
|
-
end
|
40
|
-
|
41
|
-
def name(name)
|
42
|
-
@account.name = name
|
43
|
-
end
|
44
|
-
|
45
|
-
def default(flag)
|
46
|
-
if flag.nil? || flag == ""
|
47
|
-
@account.set_default_flag
|
48
|
-
else
|
49
|
-
valid_attribute DefaultFlagValidator, WrongDefaultFlag, flag
|
50
|
-
@account.default = (["true", true].include? flag)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def realname(realname)
|
55
|
-
@account.realname = realname
|
56
|
-
end
|
57
|
-
|
58
|
-
def type(str)
|
59
|
-
valid_attribute TypeValidator, WrongAccountType, str
|
60
|
-
@account.type = str.to_sym
|
61
|
-
end
|
62
|
-
|
63
|
-
def server(str)
|
64
|
-
@account.server = str
|
65
|
-
end
|
66
|
-
|
67
|
-
def port(nr)
|
68
|
-
valid_attribute PortValidator, WrongAccountPort, nr
|
69
|
-
@account.port = nr.to_i
|
70
|
-
end
|
71
|
-
|
72
|
-
def user(str)
|
73
|
-
@account.user = str
|
74
|
-
end
|
75
|
-
|
76
|
-
def pass(str)
|
77
|
-
@account.pass = str
|
78
|
-
end
|
79
|
-
|
80
|
-
def mailboxes(arr)
|
81
|
-
if arr.nil? || arr.empty?
|
82
|
-
@account.set_default_mailboxes
|
83
|
-
else
|
84
|
-
valid_attribute MailboxesValidator, WrongAccountMailboxes, arr
|
85
|
-
@account.mailboxes = arr
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def smtp_protocol(str)
|
90
|
-
valid_attribute SmtpProtocolValidator, WrongAccountSmtpProtocol, str
|
91
|
-
@account.smtp_protocol = str.to_sym
|
92
|
-
end
|
93
|
-
|
94
|
-
def smtp_port(nr)
|
95
|
-
valid_attribute PortValidator, WrongAccountSmtpPort, nr
|
96
|
-
@account.smtp_port = nr.to_i
|
97
|
-
end
|
98
|
-
|
99
|
-
def smtp_authenticator(str)
|
100
|
-
@account.smtp_authenticator = str
|
101
|
-
end
|
102
|
-
|
103
|
-
def smtp_server(str)
|
104
|
-
@account.smtp_server = str
|
105
|
-
end
|
106
|
-
|
107
|
-
def account
|
108
|
-
obj = valid_account
|
109
|
-
@account = ::Mayaml::MailAccount.new
|
110
|
-
obj
|
111
|
-
end
|
112
|
-
|
113
|
-
private
|
114
|
-
|
115
|
-
def valid_account
|
116
|
-
validator = RequiredAttributesValidator.new @account
|
117
|
-
raise MissingAttributes, validator.errors.join(" ") unless validator.valid?
|
118
|
-
@account.dup
|
119
|
-
end
|
120
|
-
|
121
|
-
def valid_attribute(validator_class, error_class, attribute)
|
122
|
-
validator = validator_class.new attribute
|
123
|
-
raise error_class, validator.errors.join(" ") unless validator.valid?
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright (C) 2016, 2017, 2018 Szymon Kopciewski
|
4
|
-
#
|
5
|
-
# This file is part of Mayaml.
|
6
|
-
#
|
7
|
-
# This program is free software: you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation, either version 3 of the License, or
|
10
|
-
# (at your option) any later version.
|
11
|
-
#
|
12
|
-
# This program is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
# GNU General Public License for more details.
|
16
|
-
#
|
17
|
-
# You should have received a copy of the GNU General Public License
|
18
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
|
-
|
20
|
-
module Mayaml
|
21
|
-
class MailAccount
|
22
|
-
class DefaultFlagValidator
|
23
|
-
def initialize(flag)
|
24
|
-
@flag = flag
|
25
|
-
errors << "Flag need to be 'true' or 'false'" unless valid_flag?
|
26
|
-
end
|
27
|
-
|
28
|
-
def valid?
|
29
|
-
errors.empty?
|
30
|
-
end
|
31
|
-
|
32
|
-
def errors
|
33
|
-
@errors ||= []
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def valid_flag?
|
39
|
-
[true, false, "true", "false"].include? @flag
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright (C) 2016, 2017, 2018 Szymon Kopciewski
|
4
|
-
#
|
5
|
-
# This file is part of Mayaml.
|
6
|
-
#
|
7
|
-
# This program is free software: you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation, either version 3 of the License, or
|
10
|
-
# (at your option) any later version.
|
11
|
-
#
|
12
|
-
# This program is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
# GNU General Public License for more details.
|
16
|
-
#
|
17
|
-
# You should have received a copy of the GNU General Public License
|
18
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
|
-
require "mayaml/error"
|
20
|
-
|
21
|
-
module Mayaml
|
22
|
-
class MailAccount
|
23
|
-
class Error < ::Mayaml::Error
|
24
|
-
end
|
25
|
-
|
26
|
-
class MissingAttributes < Error
|
27
|
-
end
|
28
|
-
|
29
|
-
class WrongDefaultFlag < Error
|
30
|
-
end
|
31
|
-
|
32
|
-
class WrongAccountType < Error
|
33
|
-
end
|
34
|
-
|
35
|
-
class WrongAccountPort < Error
|
36
|
-
end
|
37
|
-
|
38
|
-
class WrongAccountMailboxes < Error
|
39
|
-
end
|
40
|
-
|
41
|
-
class WrongAccountSmtpPort < Error
|
42
|
-
end
|
43
|
-
|
44
|
-
class WrongAccountSmtpProtocol < Error
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright (C) 2016, 2017, 2018 Szymon Kopciewski
|
4
|
-
#
|
5
|
-
# This file is part of Mayaml.
|
6
|
-
#
|
7
|
-
# This program is free software: you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation, either version 3 of the License, or
|
10
|
-
# (at your option) any later version.
|
11
|
-
#
|
12
|
-
# This program is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
# GNU General Public License for more details.
|
16
|
-
#
|
17
|
-
# You should have received a copy of the GNU General Public License
|
18
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
|
-
|
20
|
-
module Mayaml
|
21
|
-
class MailAccount
|
22
|
-
class MailboxesValidator
|
23
|
-
def initialize(mailboxes)
|
24
|
-
@mailboxes = mailboxes
|
25
|
-
errors << "Mailboxes should be array." unless right_mailboxes_type?
|
26
|
-
errors << "Mailboxes can not be empty." unless mailboxes_exists?
|
27
|
-
errors << "Mailboxes should all be strings." unless right_mailboxes_content?
|
28
|
-
end
|
29
|
-
|
30
|
-
def valid?
|
31
|
-
errors.empty?
|
32
|
-
end
|
33
|
-
|
34
|
-
def errors
|
35
|
-
@errors ||= []
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def right_mailboxes_type?
|
41
|
-
@mailboxes.instance_of? Array
|
42
|
-
end
|
43
|
-
|
44
|
-
def mailboxes_exists?
|
45
|
-
right_mailboxes_type? && !@mailboxes.empty?
|
46
|
-
end
|
47
|
-
|
48
|
-
def right_mailboxes_content?
|
49
|
-
right_mailboxes_type? && @mailboxes.all? { |box| box.instance_of? String }
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright (C) 2016, 2017, 2018 Szymon Kopciewski
|
4
|
-
#
|
5
|
-
# This file is part of Mayaml.
|
6
|
-
#
|
7
|
-
# This program is free software: you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation, either version 3 of the License, or
|
10
|
-
# (at your option) any later version.
|
11
|
-
#
|
12
|
-
# This program is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
# GNU General Public License for more details.
|
16
|
-
#
|
17
|
-
# You should have received a copy of the GNU General Public License
|
18
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
|
-
|
20
|
-
module Mayaml
|
21
|
-
class MailAccount
|
22
|
-
class PortValidator
|
23
|
-
def initialize(port)
|
24
|
-
port = conver_port(port)
|
25
|
-
errors << "Mail account port is invalid." if port.zero?
|
26
|
-
errors << "Mail account port could not be negative." if port.negative?
|
27
|
-
end
|
28
|
-
|
29
|
-
def valid?
|
30
|
-
errors.empty?
|
31
|
-
end
|
32
|
-
|
33
|
-
def errors
|
34
|
-
@errors ||= []
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def conver_port(port)
|
40
|
-
port.respond_to?(:to_i) ? port.to_i : 0
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,91 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright (C) 2016, 2017, 2018 Szymon Kopciewski
|
4
|
-
#
|
5
|
-
# This file is part of Mayaml.
|
6
|
-
#
|
7
|
-
# This program is free software: you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation, either version 3 of the License, or
|
10
|
-
# (at your option) any later version.
|
11
|
-
#
|
12
|
-
# This program is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
# GNU General Public License for more details.
|
16
|
-
#
|
17
|
-
# You should have received a copy of the GNU General Public License
|
18
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
|
-
|
20
|
-
module Mayaml
|
21
|
-
class MailAccount
|
22
|
-
class RequiredAttributesValidator
|
23
|
-
attr_reader :errors
|
24
|
-
|
25
|
-
def initialize(mail_account)
|
26
|
-
@errors = []
|
27
|
-
@mail_account = mail_account
|
28
|
-
check_mail_account_attrs
|
29
|
-
end
|
30
|
-
|
31
|
-
def valid?
|
32
|
-
@errors.empty?
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
def check_mail_account_attrs
|
38
|
-
check_missing_name
|
39
|
-
check_missing_realname
|
40
|
-
check_missing_type
|
41
|
-
check_missing_server
|
42
|
-
check_missing_user
|
43
|
-
check_missing_pass
|
44
|
-
check_missing_smtp_protocol
|
45
|
-
check_missing_smtp_port
|
46
|
-
check_missing_smtp_authenticator
|
47
|
-
check_missing_smtp_server
|
48
|
-
end
|
49
|
-
|
50
|
-
def check_missing_name
|
51
|
-
@errors << "Missing name attribute." if @mail_account.name.nil?
|
52
|
-
end
|
53
|
-
|
54
|
-
def check_missing_realname
|
55
|
-
@errors << "Missing realname attribute." if @mail_account.realname.nil?
|
56
|
-
end
|
57
|
-
|
58
|
-
def check_missing_type
|
59
|
-
@errors << "Missing type attribute." if @mail_account.type.nil?
|
60
|
-
end
|
61
|
-
|
62
|
-
def check_missing_server
|
63
|
-
@errors << "Missing server attribute." if @mail_account.server.nil?
|
64
|
-
end
|
65
|
-
|
66
|
-
def check_missing_user
|
67
|
-
@errors << "Missing user attribute." if @mail_account.user.nil?
|
68
|
-
end
|
69
|
-
|
70
|
-
def check_missing_pass
|
71
|
-
@errors << "Missing pass attribute." if @mail_account.pass.nil?
|
72
|
-
end
|
73
|
-
|
74
|
-
def check_missing_smtp_protocol
|
75
|
-
@errors << "Missing smtp_protocol attribute." if @mail_account.smtp_protocol.nil?
|
76
|
-
end
|
77
|
-
|
78
|
-
def check_missing_smtp_port
|
79
|
-
@errors << "Missing smtp_port attribute." if @mail_account.smtp_port.nil?
|
80
|
-
end
|
81
|
-
|
82
|
-
def check_missing_smtp_authenticator
|
83
|
-
@errors << "Missing smtp_authenticator attribute." if @mail_account.smtp_authenticator.nil?
|
84
|
-
end
|
85
|
-
|
86
|
-
def check_missing_smtp_server
|
87
|
-
@errors << "Missing smtp_server attribute." if @mail_account.smtp_server.nil?
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright (C) 2016, 2017, 2018 Szymon Kopciewski
|
4
|
-
#
|
5
|
-
# This file is part of Mayaml.
|
6
|
-
#
|
7
|
-
# This program is free software: you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation, either version 3 of the License, or
|
10
|
-
# (at your option) any later version.
|
11
|
-
#
|
12
|
-
# This program is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
# GNU General Public License for more details.
|
16
|
-
#
|
17
|
-
# You should have received a copy of the GNU General Public License
|
18
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
|
-
|
20
|
-
module Mayaml
|
21
|
-
class MailAccount
|
22
|
-
class SmtpProtocolValidator
|
23
|
-
VALID_TYPES = %i[smtp smtps].freeze
|
24
|
-
|
25
|
-
def initialize(type)
|
26
|
-
@type = convert_type(type)
|
27
|
-
errors << "Mail account smtp_protocol is invalid. Allowed: #{types}." unless valid_type?
|
28
|
-
end
|
29
|
-
|
30
|
-
def valid?
|
31
|
-
errors.empty?
|
32
|
-
end
|
33
|
-
|
34
|
-
def errors
|
35
|
-
@errors ||= []
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def convert_type(type)
|
41
|
-
type.to_sym if type.respond_to? :to_sym
|
42
|
-
end
|
43
|
-
|
44
|
-
def valid_type?
|
45
|
-
VALID_TYPES.include? @type
|
46
|
-
end
|
47
|
-
|
48
|
-
def types
|
49
|
-
VALID_TYPES.join(", ")
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright (C) 2016, 2017, 2018 Szymon Kopciewski
|
4
|
-
#
|
5
|
-
# This file is part of Mayaml.
|
6
|
-
#
|
7
|
-
# This program is free software: you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation, either version 3 of the License, or
|
10
|
-
# (at your option) any later version.
|
11
|
-
#
|
12
|
-
# This program is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
# GNU General Public License for more details.
|
16
|
-
#
|
17
|
-
# You should have received a copy of the GNU General Public License
|
18
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
|
-
|
20
|
-
module Mayaml
|
21
|
-
class MailAccount
|
22
|
-
class TypeValidator
|
23
|
-
VALID_TYPES = %i[imap pop3 imapssl pop3ssl].freeze
|
24
|
-
|
25
|
-
def initialize(type)
|
26
|
-
@type = convert_type(type)
|
27
|
-
errors << "Mail account type is invalid. Allowed types: #{valid_types}." unless valid_type?
|
28
|
-
end
|
29
|
-
|
30
|
-
def valid?
|
31
|
-
errors.empty?
|
32
|
-
end
|
33
|
-
|
34
|
-
def errors
|
35
|
-
@errors ||= []
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def convert_type(type)
|
41
|
-
type.to_sym if type.respond_to? :to_sym
|
42
|
-
end
|
43
|
-
|
44
|
-
def valid_type?
|
45
|
-
VALID_TYPES.include? @type
|
46
|
-
end
|
47
|
-
|
48
|
-
def valid_types
|
49
|
-
VALID_TYPES.join(", ")
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
data/lib/mayaml/mail_account.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright (C) 2016, 2017, 2018 Szymon Kopciewski
|
4
|
-
#
|
5
|
-
# This file is part of Mayaml.
|
6
|
-
#
|
7
|
-
# This program is free software: you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation, either version 3 of the License, or
|
10
|
-
# (at your option) any later version.
|
11
|
-
#
|
12
|
-
# This program is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
# GNU General Public License for more details.
|
16
|
-
#
|
17
|
-
# You should have received a copy of the GNU General Public License
|
18
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
|
-
|
20
|
-
module Mayaml
|
21
|
-
class MailAccount
|
22
|
-
attr_accessor :name, :default, :realname, :type, :server, :port, :user, :pass, \
|
23
|
-
:mailboxes, :smtp_protocol, :smtp_port, :smtp_authenticator, :smtp_server
|
24
|
-
|
25
|
-
def initialize
|
26
|
-
set_default_flag
|
27
|
-
set_default_mailboxes
|
28
|
-
end
|
29
|
-
|
30
|
-
def set_default_flag
|
31
|
-
@default = false
|
32
|
-
end
|
33
|
-
|
34
|
-
def set_default_mailboxes
|
35
|
-
@mailboxes = []
|
36
|
-
end
|
37
|
-
|
38
|
-
def to_str
|
39
|
-
default_mark = @default ? "*" : ""
|
40
|
-
<<-DESC
|
41
|
-
Account#{default_mark}: #{@name}<#{@realname}> | user: #{@user}:#{@pass}
|
42
|
-
#{@type} - #{@server}:#{@port} [#{@mailboxes.join(",")}]
|
43
|
-
#{@smtp_protocol} - #{@smtp_server}:#{@smtp_port} [auth: #{@smtp_authenticator}]
|
44
|
-
DESC
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
data/lib/mayaml/parser.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright (C) 2016, 2017, 2018 Szymon Kopciewski
|
4
|
-
#
|
5
|
-
# This file is part of Mayaml.
|
6
|
-
#
|
7
|
-
# This program is free software: you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation, either version 3 of the License, or
|
10
|
-
# (at your option) any later version.
|
11
|
-
#
|
12
|
-
# This program is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
# GNU General Public License for more details.
|
16
|
-
#
|
17
|
-
# You should have received a copy of the GNU General Public License
|
18
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
|
-
require "yaml"
|
20
|
-
|
21
|
-
module Mayaml
|
22
|
-
class Parser
|
23
|
-
def self.get_accounts(json_file)
|
24
|
-
YAML.load_file json_file
|
25
|
-
rescue Errno::ENOENT, Psych::SyntaxError
|
26
|
-
[]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|