You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by "Markus Wiederkehr (JIRA)" <se...@james.apache.org> on 2008/09/23 18:47:44 UTC

[jira] Created: (MIME4J-79) Message.writeTo() prematurely closes output stream if transfer encoding is BASE64

Message.writeTo() prematurely closes output stream if transfer encoding is BASE64
---------------------------------------------------------------------------------

                 Key: MIME4J-79
                 URL: https://issues.apache.org/jira/browse/MIME4J-79
             Project: JAMES Mime4j
          Issue Type: Bug
    Affects Versions: 0.5
            Reporter: Markus Wiederkehr
            Priority: Blocker
             Fix For: 0.5


Entity.writeTo(OutputStream out, int mode) wraps the output stream in a Base64OutputStream if the transfer encoding is BASE64. Later the wrapper stream gets closed and (despite of a comment that says otherwise) the inner stream gets closed, too.

-- 
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: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[jira] Updated: (MIME4J-79) Message.writeTo() prematurely closes output stream if transfer encoding is BASE64

Posted by "Markus Wiederkehr (JIRA)" <se...@james.apache.org>.
     [ https://issues.apache.org/jira/browse/MIME4J-79?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Markus Wiederkehr updated MIME4J-79:
------------------------------------

    Attachment: mime4j-close-codec-ioex.patch

Before this gets postponed please review my mime4j-close-codec-ioex.patch.

It is based on Oleg's patch with the following changes:
* encoders / decoders throw IOException from read / write once closed
* makes QuotedPrintableOutputStream a public class
* QuotedPrintableOutputStream.write(int) no longer throws an UnsupportedOperationException
* unit tests for QuotedPrintableOutputStream
* QuotedPrintableEncoder becomes a package private class

> Message.writeTo() prematurely closes output stream if transfer encoding is BASE64
> ---------------------------------------------------------------------------------
>
>                 Key: MIME4J-79
>                 URL: https://issues.apache.org/jira/browse/MIME4J-79
>             Project: JAMES Mime4j
>          Issue Type: Bug
>    Affects Versions: 0.5
>            Reporter: Markus Wiederkehr
>            Priority: Blocker
>             Fix For: 0.5
>
>         Attachments: Base64BugDemo.java, mime4j-base64.patch, mime4j-close-codec-ioex.patch, mime4j-close-codec.patch
>
>
> Entity.writeTo(OutputStream out, int mode) wraps the output stream in a Base64OutputStream if the transfer encoding is BASE64. Later the wrapper stream gets closed and (despite of a comment that says otherwise) the inner stream gets closed, too.

-- 
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: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[jira] Commented: (MIME4J-79) Message.writeTo() prematurely closes output stream if transfer encoding is BASE64

Posted by "Stefano Bagnara (JIRA)" <se...@james.apache.org>.
    [ https://issues.apache.org/jira/browse/MIME4J-79?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12634093#action_12634093 ] 

Stefano Bagnara commented on MIME4J-79:
---------------------------------------

My bad.. I fixed this issue in the old Base64OutputStream implementation and I forgot about it when I changed the implementation. I thought "tests pass, so it must be ok".. mea culpa I didn't wrote a unit test the first time I fixed it.

The patch proposed by Oleg seems fine; Markus hint about the IOException may be appropriate but the class is for internal use ATM, and it should never happen to call that methods when the stream is closed in mime4j, so we can improve this even in a future release.

> Message.writeTo() prematurely closes output stream if transfer encoding is BASE64
> ---------------------------------------------------------------------------------
>
>                 Key: MIME4J-79
>                 URL: https://issues.apache.org/jira/browse/MIME4J-79
>             Project: JAMES Mime4j
>          Issue Type: Bug
>    Affects Versions: 0.5
>            Reporter: Markus Wiederkehr
>            Priority: Blocker
>             Fix For: 0.5
>
>         Attachments: Base64BugDemo.java, mime4j-base64.patch, mime4j-close-codec.patch
>
>
> Entity.writeTo(OutputStream out, int mode) wraps the output stream in a Base64OutputStream if the transfer encoding is BASE64. Later the wrapper stream gets closed and (despite of a comment that says otherwise) the inner stream gets closed, too.

-- 
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: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[jira] Commented: (MIME4J-79) Message.writeTo() prematurely closes output stream if transfer encoding is BASE64

Posted by "Markus Wiederkehr (JIRA)" <se...@james.apache.org>.
    [ https://issues.apache.org/jira/browse/MIME4J-79?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12634144#action_12634144 ] 

Markus Wiederkehr commented on MIME4J-79:
-----------------------------------------

@Stefano: Sorry, I did not mean to imply that it does any harm. Thanks for applying the patch.

> Message.writeTo() prematurely closes output stream if transfer encoding is BASE64
> ---------------------------------------------------------------------------------
>
>                 Key: MIME4J-79
>                 URL: https://issues.apache.org/jira/browse/MIME4J-79
>             Project: JAMES Mime4j
>          Issue Type: Bug
>    Affects Versions: 0.5
>            Reporter: Markus Wiederkehr
>            Assignee: Stefano Bagnara
>            Priority: Blocker
>             Fix For: 0.5
>
>         Attachments: Base64BugDemo.java, mime4j-base64.patch, mime4j-close-codec-ioex.patch, mime4j-close-codec.patch
>
>
> Entity.writeTo(OutputStream out, int mode) wraps the output stream in a Base64OutputStream if the transfer encoding is BASE64. Later the wrapper stream gets closed and (despite of a comment that says otherwise) the inner stream gets closed, too.

-- 
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: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[jira] Updated: (MIME4J-79) Message.writeTo() prematurely closes output stream if transfer encoding is BASE64

Posted by "Markus Wiederkehr (JIRA)" <se...@james.apache.org>.
     [ https://issues.apache.org/jira/browse/MIME4J-79?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Markus Wiederkehr updated MIME4J-79:
------------------------------------

    Attachment: mime4j-base64.patch

The attached patch mime4j-base64.patch would resolve the problem but you might prefer another solution..

> Message.writeTo() prematurely closes output stream if transfer encoding is BASE64
> ---------------------------------------------------------------------------------
>
>                 Key: MIME4J-79
>                 URL: https://issues.apache.org/jira/browse/MIME4J-79
>             Project: JAMES Mime4j
>          Issue Type: Bug
>    Affects Versions: 0.5
>            Reporter: Markus Wiederkehr
>            Priority: Blocker
>             Fix For: 0.5
>
>         Attachments: Base64BugDemo.java, mime4j-base64.patch
>
>
> Entity.writeTo(OutputStream out, int mode) wraps the output stream in a Base64OutputStream if the transfer encoding is BASE64. Later the wrapper stream gets closed and (despite of a comment that says otherwise) the inner stream gets closed, too.

-- 
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: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[jira] Commented: (MIME4J-79) Message.writeTo() prematurely closes output stream if transfer encoding is BASE64

Posted by "Markus Wiederkehr (JIRA)" <se...@james.apache.org>.
    [ https://issues.apache.org/jira/browse/MIME4J-79?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12634126#action_12634126 ] 

Markus Wiederkehr commented on MIME4J-79:
-----------------------------------------

Adding "closed = true" would not have been necessary because this branch only gets executed if len < 0.

len < 0 would normally be an illegal argument for this method and should be punished by throwing an IllegalArgumentException. In case of this implementation it is used by close() to indicate EOF. And close() already takes care of setting closed to true in its finally block.

> Message.writeTo() prematurely closes output stream if transfer encoding is BASE64
> ---------------------------------------------------------------------------------
>
>                 Key: MIME4J-79
>                 URL: https://issues.apache.org/jira/browse/MIME4J-79
>             Project: JAMES Mime4j
>          Issue Type: Bug
>    Affects Versions: 0.5
>            Reporter: Markus Wiederkehr
>            Assignee: Stefano Bagnara
>            Priority: Blocker
>             Fix For: 0.5
>
>         Attachments: Base64BugDemo.java, mime4j-base64.patch, mime4j-close-codec-ioex.patch, mime4j-close-codec.patch
>
>
> Entity.writeTo(OutputStream out, int mode) wraps the output stream in a Base64OutputStream if the transfer encoding is BASE64. Later the wrapper stream gets closed and (despite of a comment that says otherwise) the inner stream gets closed, too.

-- 
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: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[jira] Commented: (MIME4J-79) Message.writeTo() prematurely closes output stream if transfer encoding is BASE64

Posted by "Stefano Bagnara (JIRA)" <se...@james.apache.org>.
    [ https://issues.apache.org/jira/browse/MIME4J-79?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12634141#action_12634141 ] 

Stefano Bagnara commented on MIME4J-79:
---------------------------------------

@Markus: as we don't actually throw the IllegalArgumentException I prefer to deal with a possible len == -1 updating the closed variable. Of course the whole thing could be refactored to do that code in another method and not "abuse" the "standard" write method. Do you see any harm with the change I made?

> Message.writeTo() prematurely closes output stream if transfer encoding is BASE64
> ---------------------------------------------------------------------------------
>
>                 Key: MIME4J-79
>                 URL: https://issues.apache.org/jira/browse/MIME4J-79
>             Project: JAMES Mime4j
>          Issue Type: Bug
>    Affects Versions: 0.5
>            Reporter: Markus Wiederkehr
>            Assignee: Stefano Bagnara
>            Priority: Blocker
>             Fix For: 0.5
>
>         Attachments: Base64BugDemo.java, mime4j-base64.patch, mime4j-close-codec-ioex.patch, mime4j-close-codec.patch
>
>
> Entity.writeTo(OutputStream out, int mode) wraps the output stream in a Base64OutputStream if the transfer encoding is BASE64. Later the wrapper stream gets closed and (despite of a comment that says otherwise) the inner stream gets closed, too.

-- 
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: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[jira] Commented: (MIME4J-79) Message.writeTo() prematurely closes output stream if transfer encoding is BASE64

Posted by "Markus Wiederkehr (JIRA)" <se...@james.apache.org>.
    [ https://issues.apache.org/jira/browse/MIME4J-79?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12633871#action_12633871 ] 

Markus Wiederkehr commented on MIME4J-79:
-----------------------------------------

If there are no use cases where the underlying stream should be closed as well you could simply remove the statement out.close() from Base64OutputStream.close() (line 393) to resolve the issue.

> Message.writeTo() prematurely closes output stream if transfer encoding is BASE64
> ---------------------------------------------------------------------------------
>
>                 Key: MIME4J-79
>                 URL: https://issues.apache.org/jira/browse/MIME4J-79
>             Project: JAMES Mime4j
>          Issue Type: Bug
>    Affects Versions: 0.5
>            Reporter: Markus Wiederkehr
>            Priority: Blocker
>             Fix For: 0.5
>
>         Attachments: Base64BugDemo.java, mime4j-base64.patch
>
>
> Entity.writeTo(OutputStream out, int mode) wraps the output stream in a Base64OutputStream if the transfer encoding is BASE64. Later the wrapper stream gets closed and (despite of a comment that says otherwise) the inner stream gets closed, too.

-- 
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: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[jira] Commented: (MIME4J-79) Message.writeTo() prematurely closes output stream if transfer encoding is BASE64

Posted by "Markus Wiederkehr (JIRA)" <se...@james.apache.org>.
    [ https://issues.apache.org/jira/browse/MIME4J-79?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12633918#action_12633918 ] 

Markus Wiederkehr commented on MIME4J-79:
-----------------------------------------

I think this is a good idea and your patch looks fine to me.

But maybe the same concept should also be applied to QuotedPrintableOutputStream? Although it is an inner class of CodecUtil it can be accessed the same way as the base64 version through wrapQuotedPrintable(OutputStream, boolean). Maybe it should even become a public class for consistency reasons..

> Message.writeTo() prematurely closes output stream if transfer encoding is BASE64
> ---------------------------------------------------------------------------------
>
>                 Key: MIME4J-79
>                 URL: https://issues.apache.org/jira/browse/MIME4J-79
>             Project: JAMES Mime4j
>          Issue Type: Bug
>    Affects Versions: 0.5
>            Reporter: Markus Wiederkehr
>            Priority: Blocker
>             Fix For: 0.5
>
>         Attachments: Base64BugDemo.java, mime4j-base64.patch, mime4j-close-codec.patch
>
>
> Entity.writeTo(OutputStream out, int mode) wraps the output stream in a Base64OutputStream if the transfer encoding is BASE64. Later the wrapper stream gets closed and (despite of a comment that says otherwise) the inner stream gets closed, too.

-- 
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: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[jira] Commented: (MIME4J-79) Message.writeTo() prematurely closes output stream if transfer encoding is BASE64

Posted by "Markus Wiederkehr (JIRA)" <se...@james.apache.org>.
    [ https://issues.apache.org/jira/browse/MIME4J-79?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12634029#action_12634029 ] 

Markus Wiederkehr commented on MIME4J-79:
-----------------------------------------

One more thing that you might want to consider is the general contract of InputStream / OutputStream. Although it is more slack than the one of Reader / Writer it seems to indicate that an IOException should be thrown in read() / write() once the stream has been closed. Closing an already closed stream should have no effect.

For example see InputStream.read(byte[]): "Throws: IOException - If the first byte cannot be read for any reason other than the end of the file, if the input stream has been closed, or if some other I/O error occurs."

> Message.writeTo() prematurely closes output stream if transfer encoding is BASE64
> ---------------------------------------------------------------------------------
>
>                 Key: MIME4J-79
>                 URL: https://issues.apache.org/jira/browse/MIME4J-79
>             Project: JAMES Mime4j
>          Issue Type: Bug
>    Affects Versions: 0.5
>            Reporter: Markus Wiederkehr
>            Priority: Blocker
>             Fix For: 0.5
>
>         Attachments: Base64BugDemo.java, mime4j-base64.patch, mime4j-close-codec.patch
>
>
> Entity.writeTo(OutputStream out, int mode) wraps the output stream in a Base64OutputStream if the transfer encoding is BASE64. Later the wrapper stream gets closed and (despite of a comment that says otherwise) the inner stream gets closed, too.

-- 
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: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[jira] Updated: (MIME4J-79) Message.writeTo() prematurely closes output stream if transfer encoding is BASE64

Posted by "Oleg Kalnichevski (JIRA)" <se...@james.apache.org>.
     [ https://issues.apache.org/jira/browse/MIME4J-79?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Oleg Kalnichevski updated MIME4J-79:
------------------------------------

    Attachment: mime4j-close-codec.patch

Slightly different take at fixing the problem. Encoding / decoding streams no longer close the underlying stream. They become unreadable / non-writable instead. 

Here's the patch includes test cases. Please review.

Oleg 

> Message.writeTo() prematurely closes output stream if transfer encoding is BASE64
> ---------------------------------------------------------------------------------
>
>                 Key: MIME4J-79
>                 URL: https://issues.apache.org/jira/browse/MIME4J-79
>             Project: JAMES Mime4j
>          Issue Type: Bug
>    Affects Versions: 0.5
>            Reporter: Markus Wiederkehr
>            Priority: Blocker
>             Fix For: 0.5
>
>         Attachments: Base64BugDemo.java, mime4j-base64.patch, mime4j-close-codec.patch
>
>
> Entity.writeTo(OutputStream out, int mode) wraps the output stream in a Base64OutputStream if the transfer encoding is BASE64. Later the wrapper stream gets closed and (despite of a comment that says otherwise) the inner stream gets closed, too.

-- 
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: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[jira] Updated: (MIME4J-79) Message.writeTo() prematurely closes output stream if transfer encoding is BASE64

Posted by "Markus Wiederkehr (JIRA)" <se...@james.apache.org>.
     [ https://issues.apache.org/jira/browse/MIME4J-79?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Markus Wiederkehr updated MIME4J-79:
------------------------------------

    Attachment: Base64BugDemo.java

See attachment Base64BugDemo.java for a simple test that shows the problem.

> Message.writeTo() prematurely closes output stream if transfer encoding is BASE64
> ---------------------------------------------------------------------------------
>
>                 Key: MIME4J-79
>                 URL: https://issues.apache.org/jira/browse/MIME4J-79
>             Project: JAMES Mime4j
>          Issue Type: Bug
>    Affects Versions: 0.5
>            Reporter: Markus Wiederkehr
>            Priority: Blocker
>             Fix For: 0.5
>
>         Attachments: Base64BugDemo.java
>
>
> Entity.writeTo(OutputStream out, int mode) wraps the output stream in a Base64OutputStream if the transfer encoding is BASE64. Later the wrapper stream gets closed and (despite of a comment that says otherwise) the inner stream gets closed, too.

-- 
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: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[jira] Commented: (MIME4J-79) Message.writeTo() prematurely closes output stream if transfer encoding is BASE64

Posted by "Oleg Kalnichevski (JIRA)" <se...@james.apache.org>.
    [ https://issues.apache.org/jira/browse/MIME4J-79?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12633862#action_12633862 ] 

Oleg Kalnichevski commented on MIME4J-79:
-----------------------------------------

I think content encoding / decoding streams MUST NOT close the underlying stream EVER, as the encoded content may be just a part of a larger message. 

Oleg

> Message.writeTo() prematurely closes output stream if transfer encoding is BASE64
> ---------------------------------------------------------------------------------
>
>                 Key: MIME4J-79
>                 URL: https://issues.apache.org/jira/browse/MIME4J-79
>             Project: JAMES Mime4j
>          Issue Type: Bug
>    Affects Versions: 0.5
>            Reporter: Markus Wiederkehr
>            Priority: Blocker
>             Fix For: 0.5
>
>         Attachments: Base64BugDemo.java, mime4j-base64.patch
>
>
> Entity.writeTo(OutputStream out, int mode) wraps the output stream in a Base64OutputStream if the transfer encoding is BASE64. Later the wrapper stream gets closed and (despite of a comment that says otherwise) the inner stream gets closed, too.

-- 
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: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[jira] Resolved: (MIME4J-79) Message.writeTo() prematurely closes output stream if transfer encoding is BASE64

Posted by "Stefano Bagnara (JIRA)" <se...@james.apache.org>.
     [ https://issues.apache.org/jira/browse/MIME4J-79?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Stefano Bagnara resolved MIME4J-79.
-----------------------------------

    Resolution: Fixed
      Assignee: Stefano Bagnara

Patch applied.

The only change from the proposed patch is the "closed = true" when "len < 0" (in Base64OutputStream) because len == -1 is the way we are notified of a stream end and writing more data would result in corrupted output, so it seems safer to consider the stream closed after that call.

I also changed some really trivial code formatting things.

> Message.writeTo() prematurely closes output stream if transfer encoding is BASE64
> ---------------------------------------------------------------------------------
>
>                 Key: MIME4J-79
>                 URL: https://issues.apache.org/jira/browse/MIME4J-79
>             Project: JAMES Mime4j
>          Issue Type: Bug
>    Affects Versions: 0.5
>            Reporter: Markus Wiederkehr
>            Assignee: Stefano Bagnara
>            Priority: Blocker
>             Fix For: 0.5
>
>         Attachments: Base64BugDemo.java, mime4j-base64.patch, mime4j-close-codec-ioex.patch, mime4j-close-codec.patch
>
>
> Entity.writeTo(OutputStream out, int mode) wraps the output stream in a Base64OutputStream if the transfer encoding is BASE64. Later the wrapper stream gets closed and (despite of a comment that says otherwise) the inner stream gets closed, too.

-- 
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: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org