#!/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; charset='utf-8' List-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: ' 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