Finding out in-memory size of an email


#1

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


#2

Petr J. 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.”