summaryrefslogtreecommitdiff
path: root/mail.rb
blob: dc983c21c19082f68008a90accc2e6cedd0b4af1 (plain)
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
#!/usr/bin/env ruby

mailfile = if ARGV[1] and ARGV[1] == 'publish'
             File.join(__dir__, 'mail', 'emails')
           else
             File.join(__dir__, 'mail', 'testmail')
           end

Dir.chdir ARGV[0]
date, title = File.basename(ARGV[0]).split('_', 2)
content = ["From: info@pdp8.info
Subject: [pdp8] #{title.gsub('_', ' ')}
Content-Type: text/plain
List-Unsubscribe: <mailto: info@pdp8.info?subject=unsubscribe>"]
content << ''
content << File.read('README')
content << ''
content << "https://pdp8.info/music.html\##{date}"
bc = if File.exist?('bandcamp')
       File.read('bandcamp').chomp
     else
       "https://pdp8.bandcamp.com/album/#{title.gsub(' ', '-')}"
     end
content << bc
content << ''
content << '=='
content << 'List-Unsubscribe: <mailto: info@pdp8.info?subject=unsubscribe>'
File.open('/tmp/mail.txt', 'w+') { |f| f.puts content.join("\n") }
# system 'hx /tmp/mail.txt'
content = File.read('/tmp/mail.txt')

File.open(mailfile).each_line do |mail|
  mail.chomp!
  txt = "To: #{mail}\n" + content
  cmd = "echo -e \"#{txt}\" | sendmail #{mail}"
  # puts cmd
  puts mail + `#{cmd}`
end