command_line_email 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -11,55 +11,71 @@ Mail.defaults do
|
|
11
11
|
delivery_method :smtp, user_config.mail_options
|
12
12
|
end
|
13
13
|
|
14
|
-
|
14
|
+
class CleOptparse
|
15
15
|
|
16
|
-
|
16
|
+
def self.parse(args, user_config)
|
17
17
|
|
18
|
-
|
19
|
-
mail_attrs[:to] = to_string_to_mailing_list(user_config, to, mail_attrs[:to])
|
20
|
-
end
|
18
|
+
mail_attrs = {to: []}
|
21
19
|
|
22
|
-
|
23
|
-
mail_attrs[:from] = from
|
24
|
-
end
|
20
|
+
option_parser = OptionParser.new do |opts|
|
25
21
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
22
|
+
opts.on("-t TO","--to TO") do |to|
|
23
|
+
mail_attrs[:to] = to_string_to_mailing_list(user_config, to, mail_attrs[:to])
|
24
|
+
end
|
30
25
|
|
31
|
-
|
32
|
-
|
33
|
-
|
26
|
+
opts.on("-f FROM","--from FROM") do |from|
|
27
|
+
mail_attrs[:from] = from
|
28
|
+
end
|
29
|
+
|
30
|
+
opts.on("-b BODY","--body BODY") do |body|
|
31
|
+
mail_attrs[:body] ||= ""
|
32
|
+
mail_attrs[:body] << body + "\n"
|
33
|
+
end
|
34
|
+
|
35
|
+
opts.on("-s SUBJECT","--subject SUBJECT") do |subject|
|
36
|
+
mail_attrs[:subject] = subject
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on("-c CC","--cc CC") do |cc|
|
40
|
+
if user_config.mailing_lists.has_key? cc.to_sym
|
41
|
+
mail_attrs[:cc] = user_config.mailing_lists[cc.to_sym]
|
42
|
+
else
|
43
|
+
mail_attrs[:cc] = cc
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
opts.on("-f FILE","--add-file FILE") do |file|
|
48
|
+
mail_attrs[:files] ||= []
|
49
|
+
mail_attrs[:files] << file
|
50
|
+
end
|
51
|
+
|
52
|
+
opts.on("-d DIRECTORY","--directory DIRECTORY") do |directory|
|
53
|
+
mail_attrs[:directory] = directory
|
54
|
+
end
|
34
55
|
|
35
|
-
opts.on("-c CC","--cc CC") do |cc|
|
36
|
-
if user_config.mailing_lists.has_key? cc.to_sym
|
37
|
-
mail_attrs[:cc] = user_config.mailing_lists[cc.to_sym]
|
38
|
-
else
|
39
|
-
mail_attrs[:cc] = cc
|
40
56
|
end
|
41
|
-
end
|
42
57
|
|
43
|
-
|
44
|
-
mail_attrs[:files] ||= []
|
45
|
-
mail_attrs[:files] << file
|
46
|
-
end
|
58
|
+
option_parser.parse!(args)
|
47
59
|
|
48
|
-
|
49
|
-
|
60
|
+
mail_attrs
|
61
|
+
|
62
|
+
end # parse()
|
63
|
+
|
64
|
+
def self.to_string_to_mailing_list(user_config, to, list=[])
|
65
|
+
# takes optional list in case you want to add to an existing list
|
66
|
+
if user_config.mailing_lists.has_key? to.to_sym
|
67
|
+
Array(user_config.mailing_lists[to.to_sym]).each { |address| list << address }
|
68
|
+
else
|
69
|
+
list << to
|
70
|
+
end
|
71
|
+
list
|
50
72
|
end
|
51
73
|
|
52
|
-
end
|
74
|
+
end # class CleOptparse
|
53
75
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
Array(user_config.mailing_lists[to.to_sym]).each { |address| list << address }
|
58
|
-
else
|
59
|
-
list << to
|
60
|
-
end
|
61
|
-
list
|
62
|
-
end
|
76
|
+
mail_attrs = CleOptparse.parse(ARGV, user_config)
|
77
|
+
|
78
|
+
puts mail_attrs
|
63
79
|
|
64
80
|
def grab_text_from_filename_if_file_exists(filename_or_text)
|
65
81
|
if File.exists?(filename_or_text)
|
@@ -69,10 +85,6 @@ def grab_text_from_filename_if_file_exists(filename_or_text)
|
|
69
85
|
end
|
70
86
|
end
|
71
87
|
|
72
|
-
option_parser.parse!
|
73
|
-
|
74
|
-
puts mail_attrs
|
75
|
-
|
76
88
|
mail = Mail.new do
|
77
89
|
from mail_attrs[:from] || user_config.defaults[:from]
|
78
90
|
to mail_attrs[:to] || user_config.defaults[:to]
|