forked from ripienaar/angelia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
angelia-send.rb
executable file
·50 lines (40 loc) · 1.03 KB
/
angelia-send.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/ruby
require 'angelia'
require 'getoptlong'
conffile = nil
recipient = nil
subject = ""
message = ""
opts = GetoptLong.new(
[ '--config', '-c', GetoptLong::REQUIRED_ARGUMENT],
[ '--recipient', '-r', GetoptLong::REQUIRED_ARGUMENT],
[ '--subject', '-s', GetoptLong::REQUIRED_ARGUMENT],
[ '--message', '-m', GetoptLong::REQUIRED_ARGUMENT]
)
opts.each do |opt, arg|
case opt
when '--config'
conffile = arg
when '--recipient'
recipient = arg
when '--subject'
subject = arg
when '--message'
message = arg.gsub "\\n", "\n"
end
end
unless File.exists? conffile
raise "Can't find config file #{conffile}"
end
if message == ""
raise "Must give a message to send using --message"
end
begin
Angelia::Config.new(conffile, false)
Angelia::Spool.createmsg Angelia::Message.new(recipient, message, subject, "")
rescue Angelia::CorruptMessage => e
Angelia::Util.fatal("Could not create message: #{e}")
rescue Exception => e
$stderr.puts("Fatal error, message not sent: #{e}")
raise
end