Discussion:
how to detect empty attachments?
Oleg Sukhodolsky
2008-12-04 12:23:24 UTC
Permalink
Hi,

from time to time I receive mails with empty attachments, i.e. the
message contains a part which marked as attachment but has
zero length. I would like to filter out such attachments
without reading and it looks like the condition
"part.getInputStream().available() == 0" can be used for this purpose,
but it is not documented, that this method must return non-zero for non-empty
streams, so I decided to check here if I can use check or I must read
the stream to find out that the stream is empty.

Thanks in advance, Oleg.

===========================================================================
To unsubscribe, send email to ***@java.sun.com and include in the body
of the message "signoff JAVAMAIL-INTEREST". For general help, send email to
***@java.sun.com and include in the body of the message "help".
Bill Shannon
2008-12-04 18:51:15 UTC
Permalink
Post by Oleg Sukhodolsky
Hi,
from time to time I receive mails with empty attachments, i.e. the
message contains a part which marked as attachment but has
zero length. I would like to filter out such attachments
without reading and it looks like the condition
"part.getInputStream().available() == 0" can be used for this purpose,
but it is not documented, that this method must return non-zero for non-empty
streams, so I decided to check here if I can use check or I must read
the stream to find out that the stream is empty.
You need to read the stream.

You might want to try Part.getSize first. If it returns a non-negative
number, it should be correct.

===========================================================================
To unsubscribe, send email to ***@java.sun.com and include in the body
of the message "signoff JAVAMAIL-INTEREST". For general help, send email to
***@java.sun.com and include in the body of the message "help".
Oleg Sukhodolsky
2008-12-05 03:28:40 UTC
Permalink
Post by Bill Shannon
Post by Oleg Sukhodolsky
Hi,
from time to time I receive mails with empty attachments, i.e. the
message contains a part which marked as attachment but has
zero length. I would like to filter out such attachments
without reading and it looks like the condition
"part.getInputStream().available() == 0" can be used for this purpose,
but it is not documented, that this method must return non-zero for non-empty
streams, so I decided to check here if I can use check or I must read
the stream to find out that the stream is empty.
You need to read the stream.
You might want to try Part.getSize first. If it returns a non-negative
number, it should be correct.
Thanks for suggestion.I will try it.

Oleg.

===========================================================================
To unsubscribe, send email to ***@java.sun.com and include in the body
of the message "signoff JAVAMAIL-INTEREST". For general help, send email to
***@java.sun.com and include in the body of the message "help".
Continue reading on narkive:
Loading...