Forum: Ruby Finding out in-memory size of an email

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
40920c2420f2ed4841ff4ed2fc34c99f?d=identicon&s=25 Petr Janda (petrjanda)
on 2008-12-17 08:40
Hi all,
I have a script that executes sendmail binary like this

exec '/usr/sbin/sendmail'

This opens op the sendmail STDIN that waits for the email to be typed or
inputed via other means(postfix). Is it at all possible to actually
find out the size of the email(in bytes) thats going into sendmail?

Petr
753dcb78b3a3651127665da4bed3c782?d=identicon&s=25 Brian Candler (candlerb)
on 2008-12-17 12:18
Petr Janda wrote:
> I have a script that executes sendmail binary like this
>
> exec '/usr/sbin/sendmail'
>
> This opens op the sendmail STDIN that waits for the email to be typed or
> inputed via other means(postfix). Is it at all possible to actually
> find out the size of the email(in bytes) thats going into sendmail?

Not sure how this relates to Ruby.

If your ruby script is using 'exec' like that, then it is *replacing*
the entire Ruby interpreter with sendmail. At that point, sendmail is
running, accepting data on stdin, and Ruby has terminated. So sendmail
knows the size of the E-mail, but there is no-one to tell.

Perhaps what you want is to keep Ruby running while sending data to
sendmail, e.g. (untested)

  count = 0
  IO.popen("/usr/sbin/sendmail","w") do |sendmail|
    while data = $stdin.read(4096)
      sendmail << data
      count += data.size
    end
  end
  STDERR.puts "Thank you. You sent #{count} bytes."
This topic is locked and can not be replied to.