imapsync/W/tools/addFromIfMissing
Nick Bebout 62531f58cd 1.920
2019-07-02 18:17:46 -05:00

29 lines
619 B
Ruby
Executable file

#!/usr/bin/ruby
# $Id: addFromIfMissing,v 1.6 2018/08/31 11:21:54 gilles Exp gilles $
# Credits: Emiliano Heyns
# https://github.com/imapsync/imapsync/issues/54
# https://github.com/mikel/mail
# Test example in command line:
# { echo "Date: Fri, 31 Aug 2018 12:58:59 +0000" ; echo ; echo "Hello World!" ; } | ./addFromIfMissing
# Add mail gem with the command:
# gem install mail
require 'mail'
data = STDIN.read
exit(0) if data.strip == ''
message = Mail.read_from_string(data)
if message.from && message.from.length > 0
puts data
else
message.from = 'emiliano.heyns@han.nl'
puts message.to_s
end