[
https://issues.apache.org/jira/browse/MIME4J-73?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12631746#action_12631746
]
Markus Wiederkehr commented on MIME4J-73:
-----------------------------------------
I would like to do that, but before I write any patches I would like to reach a
consensus on what should be done and how.
And there are also other things related to this issue. Take a look at the
Message(InputStream) constructor. It catches the MimeException from
ContentHandler and converts it into an IllegalStateException. In my opinion
this is very ugly because as a rule of thumb runtime exceptions should be
reserved for programming errors.
The programmer did not do anything wrong just because a certain MIME message
happens to be malformed. So in this case a checked exception is required. And
the MimeException thrown by ContentHandler seems to be perfectly suitable for
this.
The same thing happens in the Header(InputStream) constructor too.
Speaking of MimeException, is it a good idea that it extends IOException? The
MessagingException from javax.mail does not do that. I think a MimeException
should indicate a malformed message and that has nothing to do with an I/O
error.
So I propose the following changes:
* MimeException extends Exception
* Message(InputStream), Header(InputStream) and Field.parse(String) throw a
MimeException instead of a runtime exception
* Message.MessageBuilder becomes a public static inner class so it can be
subclassed
What is your opinion?
> IllegalArgumentException in Message constructor when parsing erroneous message
> ------------------------------------------------------------------------------
>
> Key: MIME4J-73
> URL: https://issues.apache.org/jira/browse/MIME4J-73
> Project: JAMES Mime4j
> Issue Type: Bug
> Affects Versions: 0.5
> Reporter: Markus Wiederkehr
>
> The constructor of Message(InputStream) uses its inner class MessageBuilder
> to parse the input stream and create the object. The method
> MessageBuilder.field(String) calls Field.parse(String) to parse header
> fields. This method throws an IllegalArgumentException on parse errors.
> Clearly the Message constructor should throw a MimeException instead of an
> IllegalArgumentException if an invalid header field is encountered (or else
> it should simply ignore the field). So either Field.parse(String) should
> throw a MimeException or MessageBuilder.field(String) should catch and
> convert it.
> And by the way, could you make MessageBuilder public so it can be extended if
> a slightly different behavior is desired.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]