#!/usr/bin/env ruby require 'date' require 'liquid' require 'optparse' require 'ostruct' OPTIONS = OpenStruct.new # Default options OPTIONS.format = '%A %d %B' OPTIONS.subject = '' OPTIONS.dates = [`LC_ALL=C date +'#{OPTIONS.format}'`.chop!] opts = OptionParser.new do |opts| opts.on('-v', '--verbose') do |verbose| OPTIONS.verbose = verbose end opts.on('-l', '--locale LOCALE') do |locale| OPTIONS.locale = locale end opts.on('-s', '--format FORMAT') do |format| OPTIONS.format = format end opts.on('-t', '--template TEMPLATE') do |template| OPTIONS.template = template end opts.on('-d', '--date DATE', '--dates DATES') do |dates| OPTIONS.dates = dates.split end opts.on('-t', '--to TO') do |to| to.gsub!(',', ' ') OPTIONS.to = to.split(' ') OPTIONS.to.collect! {|to| "'#{to}'"} end opts.on('-e', '--encrypt-to RECIPIENT') do |recipient| OPTIONS.recipient = recipient end opts.on('-f', '--from FROM') do |from| OPTIONS.from = from end opts.on('-s', '--subject SUBJECT') do |subject| OPTIONS.subject = subject end end opts.parse!(ARGV) OPTIONS.dates.collect! {|date| `LC_ALL="#{OPTIONS.locale}" date --date='#{date}' +'#{OPTIONS.format}'`.chop!} file = File.readlines(OPTIONS.template).join() template = Liquid::Template.parse(file) email = template.render( 'date' => OPTIONS.dates[0], 'dates' => OPTIONS.dates ) if OPTIONS.recipient puts "gpg --encrypt --armor --trust-model always --default-recipient #{OPTIONS.recipient}" if OPTIONS.verbose gpg = IO.popen("gpg --encrypt --armor --trust-model always --default-recipient #{OPTIONS.recipient}", 'w+') gpg.puts email gpg.close_write email = gpg.readlines.join() end if OPTIONS.to if OPTIONS.from puts "mutt -e 'set send_charset=utf-8' -e 'set from=#{OPTIONS.from}' -s '#{OPTIONS.subject}' -- #{OPTIONS.to.join(' ')}" if OPTIONS.verbose mutt = IO.popen("mutt -e 'set send_charset=utf-8' -e 'set from=#{OPTIONS.from}' -s '#{OPTIONS.subject}' -- #{OPTIONS.to.join(' ')}", 'w+') else puts "mutt -s '#{OPTIONS.subject}' -- #{OPTIONS.to.join(' ')}" if OPTIONS.verbose mutt = IO.popen("mutt -s '#{OPTIONS.subject}' -- #{OPTIONS.to.join(' ')}", 'w+') end mutt.puts email mutt.close_write else if OPTIONS.subject.length > 0 puts OPTIONS.subject puts "="*OPTIONS.subject.length puts end puts email end