Exemple #1
0
        public void read(TextReader rr)
        {
            {
                EML_Media m = new EML_Media();
                m.readHeaders(rr);
                m.processHeader();
                m.readBody(rr, m);

                ArrayList al = new ArrayList();
                al.Add(m);

                while (rr.Peek() != -1)
                {
                    EML_Media mm = new EML_Media();
                    mm.readHeaders(rr);
                    mm.processHeader();
                    bool isTerm = mm.readBody(rr, m) == BoundaryTy.Term;

                    al.Add(mm);

                    if (isTerm)
                    {
                        break;
                    }
                }

                medium = (EML_Media[])al.ToArray(typeof(EML_Media));
            }
        }
Exemple #2
0
        public void writeTo(TextWriter wr)
        {
            int cx = medium.Count;

            if (cx > 0)
            {
                EML_Media M0       = (EML_Media)medium[0];
                string    boundary = M0.mlContentType.boundary;
                int       n        = 0;
                foreach (EML_Media Mx in medium)
                {
                    if (boundary != null && n != 0)
                    {
                        wr.WriteLine();
                        wr.WriteLine("--" + boundary);
                    }
                    Mx.writeTo(wr);
                    n++;
                }
                if (boundary != null)
                {
                    wr.WriteLine();
                    wr.WriteLine("--" + boundary + "--");
                }
            }
        }
Exemple #3
0
        public BoundaryTy readBody(TextReader rr, EML_Media parent)
        {
            mlBody   = null;
            mlBinary = null;

            string major = mlContentType.major;

            string boundary = parent.mlContentType.boundary;

            bool binaryMedia = !major.Equals("text");

            string         charSet     = mlContentType.charSet;
            CharsetEncoder charSet_enc = charSetEnc.getEncoding(charSet);

            if (charSet_enc == null)
            {
                throw new ArgumentException("不明な文字コード", charSet);
            }

            string          transferEncoding = parent.mlContentTransferEncoding.major;
            TransferEncoder transfer_enc     = transferEnc.getEncoding(transferEncoding);

            if (transfer_enc == null)
            {
                throw new ArgumentException("不明な変換コード", transferEncoding);
            }

            mlBody   = new StringBuilder();
            mlBinary = new MemoryStream();

            String boundaryPass = (boundary != null)
                ? "--" + boundary
                : null
            ;
            String boundaryTerm = (boundary != null)
                ? "--" + boundary + "--"
                : null
            ;

            MemoryStream tempText = new MemoryStream();

            bool preserveCRLF = transfer_enc.preserveCRLF;

            ArrayList  alDEBUG = new ArrayList();
            BoundaryTy bty     = BoundaryTy.Pass;

            while (true)
            {
                string lin = rr.ReadLine();
                if (lin == null)
                {
                    break;
                }
                alDEBUG.Add(lin);
                if (boundaryTerm != null && lin.Equals(boundaryTerm))
                {
                    bty = BoundaryTy.Term;
                    break;
                }
                if (boundaryPass != null && lin.Equals(boundaryPass))
                {
                    break;
                }
                byte[] bin = transfer_enc.decodeBinary(lin);
                if (binaryMedia)
                {
                    mlBinary.Write(bin, 0, bin.Length);
                    if (preserveCRLF)
                    {
                        mlBinary.WriteByte((byte)'\r');
                        mlBinary.WriteByte((byte)'\n');
                    }
                    continue;
                }
                tempText.Write(bin, 0, bin.Length);
                if (preserveCRLF)
                {
                    tempText.WriteByte((byte)'\r');
                    tempText.WriteByte((byte)'\n');
                }
            }
            if (!binaryMedia)
            {
                string text = charSet_enc.decodeText(tempText.ToArray());
                mlBody.Append(text);
            }
            return(bty);
        }
Exemple #4
0
 public void addMedia(EML_Media media)
 {
     medium.Add(media);
 }
Exemple #5
0
        public void read(TextReader rr) {
            {
                EML_Media m = new EML_Media();
                m.readHeaders(rr);
                m.processHeader();
                m.readBody(rr, m);

                ArrayList al = new ArrayList();
                al.Add(m);

                while (rr.Peek() != -1) {
                    EML_Media mm = new EML_Media();
                    mm.readHeaders(rr);
                    mm.processHeader();
                    bool isTerm = mm.readBody(rr, m) == BoundaryTy.Term;

                    al.Add(mm);

                    if (isTerm) break;
                }

                medium = (EML_Media[])al.ToArray(typeof(EML_Media));
            }
        }
Exemple #6
0
 public void addMedia(EML_Media media) {
     medium.Add(media);
 }
Exemple #7
0
        public BoundaryTy readBody(TextReader rr, EML_Media parent) {
            mlBody = null;
            mlBinary = null;

            string major = mlContentType.major;

            string boundary = parent.mlContentType.boundary;

            bool binaryMedia = !major.Equals("text");

            string charSet = mlContentType.charSet;
            CharsetEncoder charSet_enc = charSetEnc.getEncoding(charSet);
            if (charSet_enc == null) {
                throw new ArgumentException("不明な文字コード", charSet);
            }

            string transferEncoding = parent.mlContentTransferEncoding.major;
            TransferEncoder transfer_enc = transferEnc.getEncoding(transferEncoding);
            if (transfer_enc == null) {
                throw new ArgumentException("不明な変換コード", transferEncoding);
            }

            mlBody = new StringBuilder();
            mlBinary = new MemoryStream();

            String boundaryPass = (boundary != null)
                ? "--" + boundary
                : null
                ;
            String boundaryTerm = (boundary != null)
                ? "--" + boundary + "--"
                : null
                ;

            MemoryStream tempText = new MemoryStream();

            bool preserveCRLF = transfer_enc.preserveCRLF;

            ArrayList alDEBUG = new ArrayList();
            BoundaryTy bty = BoundaryTy.Pass;
            while (true) {
                string lin = rr.ReadLine();
                if (lin == null)
                    break;
                alDEBUG.Add(lin);
                if (boundaryTerm != null && lin.Equals(boundaryTerm)) {
                    bty = BoundaryTy.Term;
                    break;
                }
                if (boundaryPass != null && lin.Equals(boundaryPass))
                    break;
                byte[] bin = transfer_enc.decodeBinary(lin);
                if (binaryMedia) {
                    mlBinary.Write(bin, 0, bin.Length);
                    if (preserveCRLF) {
                        mlBinary.WriteByte((byte)'\r');
                        mlBinary.WriteByte((byte)'\n');
                    }
                    continue;
                }
                tempText.Write(bin, 0, bin.Length);
                if (preserveCRLF) {
                    tempText.WriteByte((byte)'\r');
                    tempText.WriteByte((byte)'\n');
                }
            }
            if (!binaryMedia) {
                string text = charSet_enc.decodeText(tempText.ToArray());
                mlBody.Append(text);
            }
            return bty;
        }