This project is read-only.
1

Closed

pivotal -- How to handle configurable encoding for parts in a multipart stream based on mime type

description

For example, the parts in a multipart mime.
Closed Jul 27, 2011 at 2:49 PM by tcabanski
Moved to pivotal

comments

joefeser wrote Jul 10, 2011 at 4:53 AM

It was meant to replace that big case statement that exists now. this was the updated code.
                    var encoder = factory.GetEncodingForMimeType(part.MimeType);
                    var encoderResult = encoder.Encode(part);

                    //TODO optimize call to get the bytes from the stream
                    byte[] data = null;
                    using (var sr = new BinaryReader(part.CopyOfStream())) {
                        data = sr.ReadBytes((int)part.CopyOfStream().Length);
                    }
                    //TODO determine if this is how we should handle it.
                    if (!part.MimeType.Equals(MimeTypeHelper.JdfMimeType) 
                            && !part.MimeType.Equals(MimeTypeHelper.JmfMimeType) 
                            && !part.MimeType.StartsWith("text/")) {
                        //for text and jdf/jmf documents, do not base64 encode them.
                        mimePart.EncodingType = Mime.MimeEncoding.Base64;
                    }
                    mimePart.SetBodyFromBinary(data);

tcabanski wrote Jul 10, 2011 at 1:08 PM

The problem with mime is binary has to be base64 encoded while text does not. PassThroughEncoding would technically send binary files as binary, though there is nothing in JDF for handling plain binary posts.

tcabanski wrote Jul 10, 2011 at 4:41 PM

Original:


I must not have been pushing enough. You were making changes while I was working on the class.

in changeset dd9e08953505

I went with what I thought was correct, which is to use the resolver to get the correct encoder for the mime type

//var encoder = factory.GetEncodingForMimeType(part.MimeType);
//encoder.Encode(part);

and then attach that encoded part to the mime part but during your changes, this part was never used.

We need to discuss this and see what the "correct" way is since every mime type can have a decoder/encoder.