Skip to content

Instantly share code, notes, and snippets.

@johnskopis
Created February 27, 2013 00:13
Show Gist options
  • Save johnskopis/5043622 to your computer and use it in GitHub Desktop.
Save johnskopis/5043622 to your computer and use it in GitHub Desktop.
class ProxyMail
def initialize(contents)
# The mail gem is implemented using STDERR.puts for all warnings
# We want to suppress warnings of the format:
# WARNING: Could not parse (and so ignorning) 'Your message:'
@stderr = $stderr.clone
silence_warnings do
@mail = Mail.new(contents)
end
@mail
end
def silence_warnings
$stderr.reopen File.new('/dev/null', 'w+')
yield
$stderr.reopen @stderr
end
def method_missing(meth, *args, &block)
rval = nil
if @mail.respond_to?(meth)
silence_warnings do
rval = @mail.send(meth, *args, &block)
end
else
raise NameError, "Mail does not respond to #{meth}"
end
rval
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment