From: Robert Klemme Date: 2005-06-06T19:30:25+09:00 Subject: Re: A Ruby script to add email disclaimers Johann Spies wrote: > A few years after my first contact with ruby (and not using it) I am > like a newbie again. > > I want to use a ruby script to add a disclaimer to a message passed to > it by exim. > > So far I can add a disclaimer to a message file by the following > script: > ============================= > #!/usr/bin/ruby > > require 'tmail' > > mail = TMail::Mail.load( ARGV[0]) > > disklymer = "\n\nDit is 'n aangeplakte disklymer hierdie... :( \n" > > if not mail.key?("X-Disclaimer") then > mail.[]=("X-Disclaimer","added") > if mail.multipart? then > mail.preamble += disklymer > > else > mail.body += disklymer > end > end > puts mail.encoded > ============================== > > But when exim calls the script the message is not saved in a temporary > file. The script should thus be able to handle a message passed to it > like in the following command: > > cat | disclaimerscript.rb > > I have experimented a little bit with "/usr/bin/ruby -n" and $_ but I > did not have success. > > I would appreciate some help with this one please. I'm not 100% sure about your use case. If your script is invoked like this: add-disclaimer.rb mail-file then you can use option "-i.bak" which does in place modification and saves the original in a backup file (or leave the ".bak" in that case you get just the modified file). If you want to use it in a pipe context, I'd try mail = TMail::Mail.load( ARGF ) or mail = TMail::Mail.load( STDIN ) Dunno which of the two TMail can handle. A quick glance at the sources reveales that maybe you have to implement a sub class of Port to handle reading from streams. Kind regards robert