1#!/usr/bin/ruby 2 3# $Id: addFromIfMissing,v 1.6 2018/08/31 11:21:54 gilles Exp gilles $ 4 5# Credits: Emiliano Heyns 6 7# https://github.com/imapsync/imapsync/issues/54 8# https://github.com/mikel/mail 9 10# Test example in command line: 11# { echo "Date: Fri, 31 Aug 2018 12:58:59 +0000" ; echo ; echo "Hello World!" ; } | ./addFromIfMissing 12 13# Add mail gem with the command: 14# gem install mail 15 16require 'mail' 17 18data = STDIN.read 19 20exit(0) if data.strip == '' 21 22message = Mail.read_from_string(data) 23if message.from && message.from.length > 0 24 puts data 25else 26 message.from = 'emiliano.heyns@han.nl' 27 puts message.to_s 28end 29 30