Exemplo n.º 1
0
        /// <summary>
        /// Gets the uncompressed RTF body of a message
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static byte[] GetBodyRtf(IMessage msg)
        {
            byte[] bodyRtf = null;

            IUnknown unk;
            Error hr = msg.OpenProperty(Tags.PR_RTF_COMPRESSED, IStream.IID, 0, 0, out unk);
            if (hr == Error.Success) {
                using (unk) {
                    IStream compressedStream = (IStream)unk;
                    using (compressedStream) {
                        IStream uncompStream = null;

                        hr = MAPI33.EDK.RTF.WrapCompressedRTFStream(compressedStream, 0, out uncompStream);
                        if (hr == Error.Success) {
                            using (uncompStream) {
                                int bytesRead = 0;
                                ArrayList streamContents = new ArrayList();
                                byte[] buffer = new byte[1024];

                                do {
                                    uncompStream.Read(buffer, (uint)buffer.Length, out bytesRead);
                                    if (bytesRead == buffer.Length) {
                                        streamContents.AddRange(buffer);
                                    } else {
                                        for (int idx = 0; idx < (int)bytesRead; idx++) {
                                            streamContents.Add(buffer[idx]);
                                        }
                                    }
                                } while (bytesRead > 0);

                                bodyRtf = (byte[])streamContents.ToArray(typeof(byte));
                            }
                        }
                    }
                }
            }

            return bodyRtf;
        }