NET::POPMail: Any progress information for pop()?

Saluton!

Is it possible to have any progress information when using
Net::POPMail’s instance method pop?

If a message of 500 KiB is transferred via a modem connection (which
means a download of about two minutes) it is no fun not to have any
information about the dowload.

Gis,

Josef ‘Jupp’ Schugt

···


e-mails that do not contain plain text, are larger than 50 KiB, are
unsolicited, or contain binarys are ignored unless payment from your
side or technical reasons give rise to a non-standard treatment.
Schroedinger’s cat is not alive.

Hi,

In mail “NET::POPMail: Any progress information for pop()?”

Saluton!

Is it possible to have any progress information when using
Net::POPMail’s instance method pop?

If a message of 500 KiB is transferred via a modem connection (which
means a download of about two minutes) it is no fun not to have any
information about the dowload.

You can use iterator style #pop.

Example: CUI base progress bar

Net::POP.start(host, 110, user, pass) {|pop|
pop.each_mail do |msg|
$stderr.print 'reading a message: ’
read = 0
msg.pop do |chunk|
read += chunk.size
if (read * 100 / msg.size) >= 10
$stderr.print ‘.’
read = 0
end
end
$stderr.puts
# msg.delete
end
}

Result:

% ruby poptest.rb
reading a message: …
%

Regards,
Minero Aoki

···

“Josef ‘Jupp’ Schugt” jupp@gmx.de wrote:

Saluton!

You can use iterator style #pop.

Thanks. I was quite sure that such a possiblity did exist but simply
didn’t find it.

Net::POP.start(host, 110, user, pass) {|pop|
pop.each_mail do |msg|
$stderr.print 'reading a message: ’
read = 0
msg.pop do |chunk|
read += chunk.size
if (read * 100 / msg.size) >= 10
$stderr.print ‘.’
read = 0
end
end
$stderr.puts
# msg.delete
end
}

Question on delete (assuming it were not commented out):

I prefer the following approach:

begin
msg.pop do |chunk|
read += chunk.size
if (read * 100 / msg.size) >= 10
$stderr.print ‘.’
read = 0
end
end
$stderr.puts
rescue => e
puts “\n#{e}”
else
msg.delete
end

This makes explicit that no message is deleted unless fetching was
successful. I use the follwing routine to fetch a mesage from a POP
server and have procmail deliver it locally. When this has been added
to the released version of my ‘popclient.rb’ program I will
officially announce the program. Purpose of the program is:

  • remove messages with headers that indicate they are unwanted

  • deliver other messages (or leave them on server)

By using procmail as an external MDA it is possible to make use of an
existing procmail configuration which may make use of a spamfilter
like spamassassin, deliver different types of messages to different
mailboxes, etc.

Deliver a message using procmail as MDA

def deliver(msg)
read = 0
bar = ‘|’
iter = 0
mail =
rubout = BS.chr * (kib(msg.size).to_s.length + 12)
begin
msg.all{ |chunk|
mail.push(chunk)
print rubout unless read == 0
read += chunk.size
print “#{pad(kib(read), kib(msg.size))} KiB fetched”
$stdout.flush
}
origin = mail.grep(/^Sender: /)
from = nil
if origin.empty?
origin = mail.grep(/^From: /)
unless origin.empty?
origin = RMail::Address.parse(origin[0].gsub(/^From: /, ‘’))[0]
from = origin.address unless origin.nil?
end
else
origin = RMail::Address.parse(origin[0].gsub(/^Sender: /, ‘’))[0]
from = origin.address unless origin.nil?
end
from = ‘MAILER-DAEMON’ if from.nil?
print '. Delivering … ’
$stdout.flush
mda = IO.popen(“procmail -f #{from}”, ‘a’)
mail.each{ |line|
mda.puts line.gsub(/\r/, ‘’)
}
mda.close
puts ‘Done.’
rescue => e
puts “\n{e}”
else
msg.delete
end
end

Gis,

Josef ‘Jupp’ Schugt

···


e-mails that do not contain plain text, are larger than 50 KiB, are
unsolicited, or contain binarys are ignored unless payment from your
side or technical reasons give rise to a non-standard treatment.
Schroedinger’s cat is not alive.

Hi,

In mail “Re: NET::POPMail: Any progress information for pop()?”

···

“Josef ‘Jupp’ Schugt” jupp@gmx.de wrote:

  # msg.delete
end

}

Question on delete (assuming it were not commented out):

I prefer the following approach:

This makes explicit that no message is deleted unless fetching was
successful. I use the follwing routine to fetch a mesage from a POP

Yes. My script is just for test.
Your code is better in real application.

Regards,
Minero Aoki