summaryrefslogtreecommitdiff
path: root/mail.rb
blob: 1aac68cb33f054e1b51bb015b1c9200fe0eddbd4 (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
39
40
41
42
43
44
45
46
47
48
#!/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)
nr_tracks = Dir['*.flac'].size
type = if nr_tracks == 1
         'single'
       elsif nr_tracks < 6
         'ep'
       elsif nr_tracks > 0
         'lp'
       end
content = ["From: info@pdp8.info
Subject: [pdp8] #{title.gsub('_', ' ')} #{type}
Content-Type: text/plain
List-Unsubscribe: <mailto: info@pdp8.info?subject=unsubscribe>"]
content << ''
content << "the new pdp8 #{type} \"#{title.gsub('_', ' ')}\" is online:"
# content << File.read('README').chomp
content << ''
content << "web: https://pdp8.info/music.html\##{date}"
content << "internet archive: https://archive.org/details/pdp8_#{title}"
bc = if File.exist?('bandcamp')
       "bandcamp: #{File.read('bandcamp').chomp}"
     else
       "bandcamp: 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